How to use sortSet method in Jest

Best JavaScript code snippet using jest

jmesa.js

Source:jmesa.js Github

copy

Full Screen

1function TableFacadeManager() {2}3TableFacadeManager.tableFacades = new Object();4TableFacadeManager.addTableFacade = function(tableFacade) {5 TableFacadeManager.tableFacades[tableFacade.limit.id] = tableFacade;6}7TableFacadeManager.getTableFacade = function(id) {8 return TableFacadeManager.tableFacades[id];9}10function TableFacade(id) {11 this.limit = new Limit(id);12 this.worksheet = new Worksheet();13}14function Worksheet() {15 this.save;16 this.filter;17}18function Limit(id) {19 this.id = id;20 this.page;21 this.maxRows;22 this.sortSet = new Array();23 this.filterSet = new Array();24 this.exportType;25}26function Sort(position, property, order) {27 this.position = position;28 this.property = property;29 this.order = order;30}31function Filter(property, value) {32 this.property = property;33 this.value = value;34}35Limit.prototype.getId = function() {36 return this.id;37}38Limit.prototype.setId = function(id) {39 this.id = id;40}41Limit.prototype.getPage = function() {42 return this.page;43}44Limit.prototype.setPage = function(page) {45 this.page = page;46}47Limit.prototype.getMaxRows = function() {48 return this.maxRows;49}50Limit.prototype.setMaxRows = function(maxRows) {51 this.maxRows = maxRows;52}53Limit.prototype.getSortSet = function() {54 return this.sortSet;55}56Limit.prototype.addSort = function(sort) {57 this.sortSet[this.sortSet.length] = sort;58}59Limit.prototype.setSortSet = function(sortSet) {60 this.sortSet = sortSet;61}62Limit.prototype.getFilterSet = function() {63 return this.filterSet;64}65Limit.prototype.addFilter = function(filter) {66 this.filterSet[this.filterSet.length] = filter;67}68Limit.prototype.setFilterSet = function(filterSet) {69 this.filterSet = filterSet;70}71Limit.prototype.getExport = function() {72 return this.exportType;73}74Limit.prototype.setExport = function(exportType) {75 this.exportType = exportType;76}77/*other helper methods*/78TableFacade.prototype.createHiddenInputFields = function(form) {79 var limit = this.limit;80 81 var exists = jQuery(form).find(':hidden[name=' + limit.id + '_p_]').val();82 if (exists) {83 return false;84 }85 86 if (this.worksheet.save) {87 jQuery(form).append('<input type="hidden" name="' + limit.id + '_sw_" value="true"/>');88 }89 90 if (this.worksheet.filter) {91 jQuery(form).append('<input type="hidden" name="' + limit.id + '_fw_" value="true"/>');92 }93 94 /* tip the API off that in the loop of working with the table */95 jQuery(form).append('<input type="hidden" name="' + limit.id + '_tr_" value="true"/>');96 97 /* the current page */98 jQuery(form).append('<input type="hidden" name="' + limit.id + '_p_" value="' + limit.page + '"/>');99 jQuery(form).append('<input type="hidden" name="' + limit.id + '_mr_" value="' + limit.maxRows + '"/>');100 101 /* the sort objects */102 var sortSet = limit.getSortSet();103 jQuery.each(sortSet, function(index, sort) {104 jQuery(form).append('<input type="hidden" name="' + limit.id + '_s_' + sort.position + '_' + sort.property + '" value="' + sort.order + '"/>');105 });106 107 /* the filter objects */108 var filterSet = limit.getFilterSet();109 jQuery.each(filterSet, function(index, filter) {110 jQuery(form).append('<input type="hidden" name="' + limit.id + '_f_' + filter.property + '" value="' + filter.value + '"/>');111 });112 113 return true;114}115TableFacade.prototype.createParameterString = function() {116 var limit = this.limit;117 118 var url = '';119 120 /* the current page */121 url += limit.id + '_p_=' + limit.page;122 123 /* the max rows */124 url += '&' + limit.id + '_mr_=' + limit.maxRows;125 126 /* the sort objects */127 var sortSet = limit.getSortSet();128 jQuery.each(sortSet, function(index, sort) {129 url += '&' + limit.id + '_s_' + sort.position + '_' + sort.property + '=' + sort.order;130 });131 132 /* the filter objects */133 var filterSet = limit.getFilterSet();134 jQuery.each(filterSet, function(index, filter) {135 url += '&' + limit.id + '_f_' + filter.property + '=' + encodeURIComponent(filter.value);136 });137 138 /* the export */139 if (limit.exportType) {140 url += '&' + limit.id + '_e_=' + limit.exportType;141 }142 143 /* tip the API off that in the loop of working with the table */144 url += '&' + limit.id + '_tr_=true';145 146 if (this.worksheet.save) {147 url += '&' + limit.id + '_sw_=true';148 }149 150 if (this.worksheet.filter) {151 url += '&' + limit.id + '_fw_=true';152 }153 154 return url;155}156/* convenience methods so do not have to manually work with the api */157function addTableFacadeToManager(id) {158 var tableFacade = new TableFacade(id);159 TableFacadeManager.addTableFacade(tableFacade); 160}161function setSaveToWorksheet(id) {162 TableFacadeManager.getTableFacade(id).worksheet.save='true';163}164function setFilterToWorksheet(id) {165 TableFacadeManager.getTableFacade(id).worksheet.filter='true';166 setPageToLimit(id, '1');167}168function removeFilterFromWorksheet(id) {169 TableFacadeManager.getTableFacade(id).worksheet.filter=null;170 setPageToLimit(id, '1');171}172function setPageToLimit(id, page) {173 TableFacadeManager.getTableFacade(id).limit.setPage(page);174}175function setMaxRowsToLimit(id, maxRows) {176 TableFacadeManager.getTableFacade(id).limit.setMaxRows(maxRows);177 setPageToLimit(id, '1');178}179function addSortToLimit(id, position, property, order) {180 /*First remove the sort if it is set on the limit, 181 and then set the page back to the first one.*/182 removeSortFromLimit(id, property);183 setPageToLimit(id, '1');184 185 var limit = TableFacadeManager.getTableFacade(id).limit;186 var sort = new Sort(position, property, order); 187 limit.addSort(sort);188}189function removeSortFromLimit(id, property) {190 var limit = TableFacadeManager.getTableFacade(id).limit;191 var sortSet = limit.getSortSet();192 jQuery.each(sortSet, function(index, sort) {193 if (sort.property == property) {194 sortSet.splice(index, 1);195 return false;196 }197 });198}199function removeAllSortsFromLimit(id) {200 var limit = TableFacadeManager.getTableFacade(id).limit;201 limit.setSortSet(new Array());202 setPageToLimit(id, '1');203}204function getSortFromLimit(id, property) {205 var limit = TableFacadeManager.getTableFacade(id).limit;206 var sortSet = limit.getSortSet();207 jQuery.each(sortSet, function(index, sort) {208 if (sort.property == property) {209 return sort;210 }211 });212}213function addFilterToLimit(id, property, value) {214 /*First remove the filter if it is set on the limit, 215 and then set the page back to the first one.*/216 removeFilterFromLimit(id, property);217 setPageToLimit(id, '1');218 219 var limit = TableFacadeManager.getTableFacade(id).limit;220 var filter = new Filter(property, value); 221 limit.addFilter(filter);222}223function removeFilterFromLimit(id, property) {224 var limit = TableFacadeManager.getTableFacade(id).limit;225 var filterSet = limit.getFilterSet();226 jQuery.each(filterSet, function(index, filter) {227 if (filter.property == property) {228 filterSet.splice(index, 1);229 return false;230 }231 });232}233function removeAllFiltersFromLimit(id) {234 var tableFacade = TableFacadeManager.getTableFacade(id);235 236 var limit = tableFacade.limit;237 limit.setFilterSet(new Array());238 setPageToLimit(id, '1');239 240 var worksheet = tableFacade.worksheet;241 worksheet.filter = null;242}243function getFilterFromLimit(id, property) {244 var limit = TableFacadeManager.getTableFacade(id).limit;245 var filterSet = limit.getFilterSet();246 jQuery.each(filterSet, function(index, filter) {247 if (filter.property == property) {248 return filter;249 }250 });251}252function setExportToLimit(id, exportType) {253 TableFacadeManager.getTableFacade(id).limit.setExport(exportType);254}255function createHiddenInputFieldsForLimit(id) {256 var tableFacade = TableFacadeManager.getTableFacade(id);257 var form = getFormByTableId(id);258 tableFacade.createHiddenInputFields(form);259}260function createHiddenInputFieldsForLimitAndSubmit(id) {261 var tableFacade = TableFacadeManager.getTableFacade(id);262 var form = getFormByTableId(id);263 var created = tableFacade.createHiddenInputFields(form);264 if (created) {265 form.submit();266 }267}268function createParameterStringForLimit(id) {269 var tableFacade = TableFacadeManager.getTableFacade(id);270 return tableFacade.createParameterString();271}272function getFormByTableId(id) {273 var node = document.getElementById(id);274 var found = false;275 while (!found) {276 node = node.parentNode;277 if (node.nodeName == 'FORM') {278 found = true;279 return node;280 }281 }282}283/* Special Effects */284var dynFilter;285function DynFilter(filter, id, property) {286 this.filter = filter;287 this.id = id;288 this.property = property;289}290function createDynFilter(filter, id, property) {291 if (dynFilter) {292 return;293 }294 295 dynFilter = new DynFilter(filter, id, property);296 297 var cell = jQuery(filter);298 var width = cell.width() + 1;299 var originalValue = cell.text();300 301 cell.html('<div id="dynFilterDiv"><input id="dynFilterInput" name="filter" style="width:' + width + 'px" value="' + originalValue + '" /></div>');302 303 var input = jQuery('#dynFilterInput');304 input.focus();305 306 jQuery(input).keypress(function(event) {307 if (event.keyCode == 13) { // press the enter key 308 var changedValue = input.val();309 cell.html(changedValue);310 addFilterToLimit(dynFilter.id, dynFilter.property, changedValue);311 onInvokeAction(dynFilter.id);312 dynFilter = null;313 }314 });315 316 jQuery(input).blur(function() {317 var changedValue = input.val();318 cell.html(changedValue);319 addFilterToLimit(dynFilter.id, dynFilter.property, changedValue);320 dynFilter = null;321 });322}323function createDynDroplistFilter(filter, id, property, options) {324 if (dynFilter) {325 return;326 }327 dynFilter = new DynFilter(filter, id, property);328 329 if (jQuery('#dynFilterDroplistDiv').size() > 0) {330 return; // filter already created331 }332 333 /* The cell that represents the filter. */334 var cell = jQuery(filter);335 336 /* Get the original filter value and width. */337 var originalValue = cell.text();338 var width = cell.width();339 340 /* Need to first get the size of the arrary. */341 var size = 1;342 jQuery.each(options, function() {343 size++;344 if (size > 10) {345 size = 10;346 return false;347 }348 });349 350 /* Create the dynamic select input box. */351 cell.html('<div id="dynFilterDroplistDiv" style="top:17px">');352 353 var html = '<select id="dynFilterDroplist" name="filter" size="' + size + '">';354 html += '<option value=""> </option>';355 jQuery.each(options, function(key, value) {356 if (key == originalValue) {357 html += '<option selected="selected" value="' + key + '">' + value + '</option>';358 } else {359 html += '<option value="' + key + '">' + value + '</option>';360 }361 });362 363 html += '</select>';364 var div = jQuery('#dynFilterDroplistDiv');365 div.html(html);366 var input = jQuery('#dynFilterDroplist');367 /* Resize the column if it is not at least as wide as the column. */ 368 var selectWidth = input.width();369 if (selectWidth < width) {370 input.width(width + 5); // always make the droplist overlap some371 }372 input.focus();373 var originalBackgroundColor = cell.css("backgroundColor");374 cell.css({backgroundColor:div.css("backgroundColor")});375 /* Something was selected or the clicked off the droplist. */376 jQuery(input).change(function() {377 var changedValue = jQuery("#dynFilterDroplistDiv option:selected").val();378 cell.text(changedValue);379 addFilterToLimit(dynFilter.id, dynFilter.property, changedValue);380 onInvokeAction(dynFilter.id);381 dynFilter = null;382 });383 jQuery(input).blur(function() {384 var changedValue = jQuery("#dynFilterDroplistDiv option:selected").val();385 cell.text(changedValue);386 jQuery('#dynFilterDroplistDiv').remove();387 cell.css({backgroundColor:originalBackgroundColor});388 dynFilter = null;389 });390}391/* Create a dropshadow for the tables */392function addDropShadow(imagesPath, theme) {393 if (!theme) {394 theme = 'jmesa';395 }396 jQuery('div.' + theme + ' .table')397 .wrap("<div class='wrap0'><div class='wrap1'><div class='wrap2'><div class='dropShadow'></div></div></div></div>")398 .css({'background': 'url(' + imagesPath + 'shadow_back.gif) 100% repeat'});399 400 jQuery('.' + theme + ' div.wrap0').css({'background': 'url(' + imagesPath + 'shadow.gif) right bottom no-repeat', 'float':'left'});401 jQuery('.' + theme + ' div.wrap1').css({'background': 'url(' + imagesPath + 'shadow180.gif) no-repeat'});402 jQuery('.' + theme + ' div.wrap2').css({'background': 'url(' + imagesPath + 'corner_bl.gif) -18px 100% no-repeat'});403 jQuery('.' + theme + ' div.dropShadow').css({'background': 'url(' + imagesPath + 'corner_tr.gif) 100% -18px no-repeat'});404 405 jQuery('div.' + theme).append('<div style="clear:both">&nbsp;</div>');406}407/* Worksheet */408var wsColumn;409function WsColumn(column, id, uniqueProperties, property) {410 this.column = column;411 this.id = id;412 this.uniqueProperties = uniqueProperties;413 this.property = property;414}415function createWsColumn(column, id, uniqueProperties, property) {416 if (wsColumn) {417 return;418 }419 wsColumn = new WsColumn(column, id, uniqueProperties, property);420 421 var cell = jQuery(column);422 var width = cell.width();423 var originalValue = cell.text();424 425 cell.parent().width(width); // set the outer width to avoid dynamic column width changes426 427 cell.html('<div id="wsColumnDiv"><input id="wsColumnInput" name="column" style="width:' + (width + 1) + 'px" value="' + originalValue + '"/></div>');428 429 var input = jQuery('#wsColumnInput'); 430 input.focus();431 432 jQuery('#wsColumnInput').keypress(function(event) {433 if (event.keyCode == 13) { // press the enter key 434 var changedValue = input.val();435 cell.html(changedValue);436 if (changedValue != originalValue) {437 submitWsColumn(originalValue, changedValue);438 }439 wsColumn = null;440 }441 });442 443 jQuery('#wsColumnInput').blur(function() {444 var changedValue = input.val();445 cell.html(changedValue);446 if (changedValue != originalValue) {447 submitWsColumn(originalValue, changedValue);448 }449 wsColumn = null;450 });451}452function submitWsCheckboxColumn(column, id, uniqueProperties, property) {453 wsColumn = new WsColumn(column, id, uniqueProperties, property);454 455 var checked = column.checked;456 457 var changedValue = 'unchecked';458 if (checked) {459 changedValue = 'checked';460 }461 462 var originalValue = 'unchecked';463 if (!checked) { // the first time the original value is the opposite464 originalValue = 'checked';465 }466 467 submitWsColumn(originalValue, changedValue);468 469 wsColumn = null;470}471function submitWsColumn(originalValue, changedValue) {472 var data = '{ "id" : "' + wsColumn.id + '"';473 474 data += ', "cp_" : "' + wsColumn.property + '"';475 476 var props = wsColumn.uniqueProperties;477 jQuery.each(props, function(key, value) {478 data += ', "up_' + key + '" : "' + value + '"';479 });480 481 data += ', "ov_" : "' + originalValue + '"';482 data += ', "cv_" : "' + changedValue + '"';483 484 data += '}'485 486 jQuery.post('jmesa.wrk?', eval('(' + data + ')'), function(data) {}); ...

Full Screen

Full Screen

powerSet.test.js

Source:powerSet.test.js Github

copy

Full Screen

...35 });36 it('should work for sets of length 3', function(){37 // recall that with sets, order doesn't matter (if order did matter, it38 // wouldn't be called a `set`.) so the set 'abc' is equivalent to 'bca',39 // 'cba', etc. this allows us to do `sortSet('abc') === sortSet('bca')` to40 // easily test set equality. With that in mind, we'll just sort41 // ahead of time each set we get back from `powerSet()`42 var sortSet = function(set){43 // takes a set like 'bca' or 'cba' and returns 'abc'44 return set.split('').sort().join('');45 }46 // `result` is the power set of `"fun"`47 var result = powerSet('fun');48 // sort each set in the power set49 for(var i = 0; i < result.length; i++){50 result[i] = sortSet(result[i]);51 }52 // should include all the original characters53 (result.includes('f') && result.includes('u') && result.includes('n')).should.be.equal(true);54 // should include all sub sets of length 255 (result.includes('fu') && result.includes('nu') && result.includes('fn')).should.be.equal(true);56 // should include the original set57 result.includes(sortSet('fun')).should.be.equal(true);58 });59 it('should contain the original set for larger sets', function(){60 // takes a set like 'bca' or 'cba' and returns 'abc'61 var sortSet = function(set){62 return set.split('').sort().join('');63 }64 // `result` is the power set of `"jump"`65 var result = powerSet('jump');66 // sort each set in the power set67 for(var i = 0; i < result.length; i++){68 result[i] = sortSet(result[i]);69 }70 // should include all sub sets of length 1 (aka, all the original characters)71 result.includes('j').should.be.equal(true);72 result.includes('u').should.be.equal(true);73 result.includes('m').should.be.equal(true);74 result.includes('p').should.be.equal(true);75 // should include all sub sets of length 276 result.includes(sortSet('ju')).should.be.equal(true);77 result.includes(sortSet('jm')).should.be.equal(true);78 result.includes(sortSet('jp')).should.be.equal(true);79 result.includes(sortSet('um')).should.be.equal(true);80 result.includes(sortSet('up')).should.be.equal(true);81 result.includes(sortSet('mp')).should.be.equal(true);82 // should include all sub sets of length 383 result.includes(sortSet('jum')).should.be.equal(true);84 result.includes(sortSet('jup')).should.be.equal(true);85 result.includes(sortSet('jmp')).should.be.equal(true);86 result.includes(sortSet('ump')).should.be.equal(true);87 // should include the original set88 result.includes(sortSet('jump')).should.be.equal(true);89 });90 it('should not include duplicate sets', function(){91 // make sure you remove duplicate sets. 'vic' is the same set as 'civ'92 // takes a set like 'bca' or 'cba' and returns 'abc'93 var sortSet = function(set){94 return set.split('').sort().join('');95 }96 // `result` is the power set of `"jump"`97 var result = powerSet('jump');98 // sort each set in the power set99 for(var i = 0; i < result.length; i++){100 result[i] = sortSet(result[i]);101 }102 // check for duplicate sets103 for(var i = 0; i < result.length; i++){104 for(var j = 0; j < result.length; j++){105 if(i === j) { continue; }106 result[i].should.not.equal(result[j], 'the set ' + result[i] + ' appears twice in your solution');107 }108 }109 });110 it('should remove duplicates from the original set', function(){111 // you're doing awesome! This test is more of a caveat of the fact that we're112 // using strings to store our sets but by definition, each element in a113 // set must be unique. because of this, you should remove duplicate items114 // from the original set. said another way, the power set of 'bbbaaa'115 // should be the same as the power set of 'ab'.116 // takes a set like 'bca' or 'cba' and returns 'abc'117 var sortSet = function(set){118 return set.split('').sort().join('');119 }120 // `result` is the power set of `"bbbaaa"`121 var result = powerSet('bbbaaa');122 // sort each set in the power set123 for(var i = 0; i < result.length; i++){124 result[i] = sortSet(result[i]);125 }126 result.includes('aa').should.be.equal(false);127 result.includes('aaa').should.be.equal(false);128 result.includes('bb').should.be.equal(false);129 result.includes('bbb').should.be.equal(false);130 result.includes('a').should.be.equal(true);131 result.includes('b').should.be.equal(true);132 result.includes('ab').should.be.equal(true);133 });134 it('should include the empty set', function(){135 // holly cannoli batman! you're kicking so much ass!! you've gotten through136 // almost all the tests!! this is the last one, I promise. we saved this137 // one for last because it's sort of lame but... _technically_, the power138 // set, by definition, includes the empty set....

Full Screen

Full Screen

TestSortSet.test.js

Source:TestSortSet.test.js Github

copy

Full Screen

1var Out = require("../utils/Out").Out;2var checkInterpretedOutput = require("../../parser/BaseEParserTest").checkInterpretedOutput;3var checkTranspiledOutput = require("../../parser/BaseEParserTest").checkTranspiledOutput;4beforeEach( () => {5 Out.init();6});7afterEach( () => {8 Out.restore();9});10test('Interpreted SortBooleans', () => {11 checkInterpretedOutput('sortSet/sortBooleans.pec');12});13test('Transpiled SortBooleans', () => {14 checkTranspiledOutput('sortSet/sortBooleans.pec');15});16test('Interpreted SortDateTimes', () => {17 checkInterpretedOutput('sortSet/sortDateTimes.pec');18});19test('Transpiled SortDateTimes', () => {20 checkTranspiledOutput('sortSet/sortDateTimes.pec');21});22test('Interpreted SortDates', () => {23 checkInterpretedOutput('sortSet/sortDates.pec');24});25test('Transpiled SortDates', () => {26 checkTranspiledOutput('sortSet/sortDates.pec');27});28test('Interpreted SortDecimals', () => {29 checkInterpretedOutput('sortSet/sortDecimals.pec');30});31test('Transpiled SortDecimals', () => {32 checkTranspiledOutput('sortSet/sortDecimals.pec');33});34test('Interpreted SortDescBooleans', () => {35 checkInterpretedOutput('sortSet/sortDescBooleans.pec');36});37test('Transpiled SortDescBooleans', () => {38 checkTranspiledOutput('sortSet/sortDescBooleans.pec');39});40test('Interpreted SortDescDateTimes', () => {41 checkInterpretedOutput('sortSet/sortDescDateTimes.pec');42});43test('Transpiled SortDescDateTimes', () => {44 checkTranspiledOutput('sortSet/sortDescDateTimes.pec');45});46test('Interpreted SortDescDates', () => {47 checkInterpretedOutput('sortSet/sortDescDates.pec');48});49test('Transpiled SortDescDates', () => {50 checkTranspiledOutput('sortSet/sortDescDates.pec');51});52test('Interpreted SortDescDecimals', () => {53 checkInterpretedOutput('sortSet/sortDescDecimals.pec');54});55test('Transpiled SortDescDecimals', () => {56 checkTranspiledOutput('sortSet/sortDescDecimals.pec');57});58test('Interpreted SortDescExpressions', () => {59 checkInterpretedOutput('sortSet/sortDescExpressions.pec');60});61test('Transpiled SortDescExpressions', () => {62 checkTranspiledOutput('sortSet/sortDescExpressions.pec');63});64test('Interpreted SortDescIntegers', () => {65 checkInterpretedOutput('sortSet/sortDescIntegers.pec');66});67test('Transpiled SortDescIntegers', () => {68 checkTranspiledOutput('sortSet/sortDescIntegers.pec');69});70test('Interpreted SortDescKeys', () => {71 checkInterpretedOutput('sortSet/sortDescKeys.pec');72});73test('Transpiled SortDescKeys', () => {74 checkTranspiledOutput('sortSet/sortDescKeys.pec');75});76test('Interpreted SortDescMethods', () => {77 checkInterpretedOutput('sortSet/sortDescMethods.pec');78});79test('Transpiled SortDescMethods', () => {80 checkTranspiledOutput('sortSet/sortDescMethods.pec');81});82test('Interpreted SortDescNames', () => {83 checkInterpretedOutput('sortSet/sortDescNames.pec');84});85test('Transpiled SortDescNames', () => {86 checkTranspiledOutput('sortSet/sortDescNames.pec');87});88test('Interpreted SortDescTexts', () => {89 checkInterpretedOutput('sortSet/sortDescTexts.pec');90});91test('Transpiled SortDescTexts', () => {92 checkTranspiledOutput('sortSet/sortDescTexts.pec');93});94test('Interpreted SortDescTimes', () => {95 checkInterpretedOutput('sortSet/sortDescTimes.pec');96});97test('Transpiled SortDescTimes', () => {98 checkTranspiledOutput('sortSet/sortDescTimes.pec');99});100test('Interpreted SortExpressions', () => {101 checkInterpretedOutput('sortSet/sortExpressions.pec');102});103test('Transpiled SortExpressions', () => {104 checkTranspiledOutput('sortSet/sortExpressions.pec');105});106test('Interpreted SortIntegers', () => {107 checkInterpretedOutput('sortSet/sortIntegers.pec');108});109test('Transpiled SortIntegers', () => {110 checkTranspiledOutput('sortSet/sortIntegers.pec');111});112test('Interpreted SortKeys', () => {113 checkInterpretedOutput('sortSet/sortKeys.pec');114});115test('Transpiled SortKeys', () => {116 checkTranspiledOutput('sortSet/sortKeys.pec');117});118test('Interpreted SortMethods', () => {119 checkInterpretedOutput('sortSet/sortMethods.pec');120});121test('Transpiled SortMethods', () => {122 checkTranspiledOutput('sortSet/sortMethods.pec');123});124test('Interpreted SortNames', () => {125 checkInterpretedOutput('sortSet/sortNames.pec');126});127test('Transpiled SortNames', () => {128 checkTranspiledOutput('sortSet/sortNames.pec');129});130test('Interpreted SortTexts', () => {131 checkInterpretedOutput('sortSet/sortTexts.pec');132});133test('Transpiled SortTexts', () => {134 checkTranspiledOutput('sortSet/sortTexts.pec');135});136test('Interpreted SortTimes', () => {137 checkInterpretedOutput('sortSet/sortTimes.pec');138});139test('Transpiled SortTimes', () => {140 checkTranspiledOutput('sortSet/sortTimes.pec');...

Full Screen

Full Screen

SimpleQueryEngine.js.uncompressed.js

Source:SimpleQueryEngine.js.uncompressed.js Github

copy

Full Screen

1define("dojo/store/util/SimpleQueryEngine", ["../../_base/array" /*=====, "../api/Store" =====*/], function(arrayUtil /*=====, Store =====*/){2// module:3// dojo/store/util/SimpleQueryEngine4return function(query, options){5 // summary:6 // Simple query engine that matches using filter functions, named filter7 // functions or objects by name-value on a query object hash8 //9 // description:10 // The SimpleQueryEngine provides a way of getting a QueryResults through11 // the use of a simple object hash as a filter. The hash will be used to12 // match properties on data objects with the corresponding value given. In13 // other words, only exact matches will be returned.14 //15 // This function can be used as a template for more complex query engines;16 // for example, an engine can be created that accepts an object hash that17 // contains filtering functions, or a string that gets evaluated, etc.18 //19 // When creating a new dojo.store, simply set the store's queryEngine20 // field as a reference to this function.21 //22 // query: Object23 // An object hash with fields that may match fields of items in the store.24 // Values in the hash will be compared by normal == operator, but regular expressions25 // or any object that provides a test() method are also supported and can be26 // used to match strings by more complex expressions27 // (and then the regex's or object's test() method will be used to match values).28 //29 // options: dojo/store/api/Store.QueryOptions?30 // An object that contains optional information such as sort, start, and count.31 //32 // returns: Function33 // A function that caches the passed query under the field "matches". See any34 // of the "query" methods on dojo.stores.35 //36 // example:37 // Define a store with a reference to this engine, and set up a query method.38 //39 // | var myStore = function(options){40 // | // ...more properties here41 // | this.queryEngine = SimpleQueryEngine;42 // | // define our query method43 // | this.query = function(query, options){44 // | return QueryResults(this.queryEngine(query, options)(this.data));45 // | };46 // | };47 // create our matching query function48 switch(typeof query){49 default:50 throw new Error("Can not query with a " + typeof query);51 case "object": case "undefined":52 var queryObject = query;53 query = function(object){54 for(var key in queryObject){55 var required = queryObject[key];56 if(required && required.test){57 // an object can provide a test method, which makes it work with regex58 if(!required.test(object[key], object)){59 return false;60 }61 }else if(required != object[key]){62 return false;63 }64 }65 return true;66 };67 break;68 case "string":69 // named query70 if(!this[query]){71 throw new Error("No filter function " + query + " was found in store");72 }73 query = this[query];74 // fall through75 case "function":76 // fall through77 }78 function execute(array){79 // execute the whole query, first we filter80 var results = arrayUtil.filter(array, query);81 // next we sort82 var sortSet = options && options.sort;83 if(sortSet){84 results.sort(typeof sortSet == "function" ? sortSet : function(a, b){85 for(var sort, i=0; sort = sortSet[i]; i++){86 var aValue = a[sort.attribute];87 var bValue = b[sort.attribute];88 if (aValue != bValue){89 return !!sort.descending == (aValue == null || aValue > bValue) ? -1 : 1;90 }91 }92 return 0;93 });94 }95 // now we paginate96 if(options && (options.start || options.count)){97 var total = results.length;98 results = results.slice(options.start || 0, (options.start || 0) + (options.count || Infinity));99 results.total = total;100 }101 return results;102 }103 execute.matches = query;104 return execute;105};...

Full Screen

Full Screen

SimpleQueryEngine.js

Source:SimpleQueryEngine.js Github

copy

Full Screen

1define(["../../_base/array" /*=====, "../api/Store" =====*/], function(arrayUtil /*=====, Store =====*/){2// module:3// dojo/store/util/SimpleQueryEngine4return function(query, options){5 // summary:6 // Simple query engine that matches using filter functions, named filter7 // functions or objects by name-value on a query object hash8 //9 // description:10 // The SimpleQueryEngine provides a way of getting a QueryResults through11 // the use of a simple object hash as a filter. The hash will be used to12 // match properties on data objects with the corresponding value given. In13 // other words, only exact matches will be returned.14 //15 // This function can be used as a template for more complex query engines;16 // for example, an engine can be created that accepts an object hash that17 // contains filtering functions, or a string that gets evaluated, etc.18 //19 // When creating a new dojo.store, simply set the store's queryEngine20 // field as a reference to this function.21 //22 // query: Object23 // An object hash with fields that may match fields of items in the store.24 // Values in the hash will be compared by normal == operator, but regular expressions25 // or any object that provides a test() method are also supported and can be26 // used to match strings by more complex expressions27 // (and then the regex's or object's test() method will be used to match values).28 //29 // options: Store.QueryOptions?30 // An object that contains optional information such as sort, start, and count.31 //32 // returns: Function33 // A function that caches the passed query under the field "matches". See any34 // of the "query" methods on dojo.stores.35 //36 // example:37 // Define a store with a reference to this engine, and set up a query method.38 //39 // | var myStore = function(options){40 // | // ...more properties here41 // | this.queryEngine = SimpleQueryEngine;42 // | // define our query method43 // | this.query = function(query, options){44 // | return QueryResults(this.queryEngine(query, options)(this.data));45 // | };46 // | };47 // create our matching query function48 switch(typeof query){49 default:50 throw new Error("Can not query with a " + typeof query);51 case "object": case "undefined":52 var queryObject = query;53 query = function(object){54 for(var key in queryObject){55 var required = queryObject[key];56 if(required && required.test){57 // an object can provide a test method, which makes it work with regex58 if(!required.test(object[key], object)){59 return false;60 }61 }else if(required != object[key]){62 return false;63 }64 }65 return true;66 };67 break;68 case "string":69 // named query70 if(!this[query]){71 throw new Error("No filter function " + query + " was found in store");72 }73 query = this[query];74 // fall through75 case "function":76 // fall through77 }78 function execute(array){79 // execute the whole query, first we filter80 var results = arrayUtil.filter(array, query);81 // next we sort82 var sortSet = options && options.sort;83 if(sortSet){84 results.sort(typeof sortSet == "function" ? sortSet : function(a, b){85 for(var sort, i=0; sort = sortSet[i]; i++){86 var aValue = a[sort.attribute];87 var bValue = b[sort.attribute];88 if (aValue != bValue){89 return !!sort.descending == (aValue == null || aValue > bValue) ? -1 : 1;90 }91 }92 return 0;93 });94 }95 // now we paginate96 if(options && (options.start || options.count)){97 var total = results.length;98 results = results.slice(options.start || 0, (options.start || 0) + (options.count || Infinity));99 results.total = total;100 }101 return results;102 }103 execute.matches = query;104 return execute;105};...

Full Screen

Full Screen

TestRemoteSetTypes.js

Source:TestRemoteSetTypes.js Github

copy

Full Screen

...27 obj.obj1 = [TestUtils.createObjectPrimitiveTypes()];28 obj.date1 = [new Date(1600, 01, 01, 12, 13, 14), new Date(), new Date(3000, 01, 01, 10, 11, 12)];29 30 remote.setBoolean1(obj.boolean1);31 TestUtils.assertEquals(log, "boolean1", sortSet(obj.boolean1), sortSet(remote.getBoolean1()));32 remote.setByte1(obj.byte1);33 TestUtils.assertEquals(log, "byte1", sortSet(obj.byte1), sortSet(remote.getByte1()));34 remote.setChar1(obj.char1);35 TestUtils.assertEquals(log, "char1", sortSet(obj.char1), sortSet(remote.getChar1()));36 remote.setDouble1(obj.double1);37 TestUtils.assertEquals(log, "double1", sortSet(obj.double1), sortSet(remote.getDouble1()));38 remote.setFloat1(obj.float1);39 TestUtils.assertEquals(log, "float1", sortSet(obj.float1), sortSet(remote.getFloat1()));40 remote.setInt1(obj.int1);41 TestUtils.assertEquals(log, "int1", sortSet(obj.int1), sortSet(remote.getInt1()));42 remote.setLong1(obj.long1);43 TestUtils.assertEquals(log, "long1", sortSet(obj.long1), sortSet(remote.getLong1()));44 remote.setPrimitiveTypes1(obj.primitiveTypes1);45 TestUtils.assertEquals(log, "primitiveTypes1", sortSet(obj.primitiveTypes1), sortSet(remote.getPrimitiveTypes1()));46 remote.setShort1(obj.short1);47 TestUtils.assertEquals(log, "short1", sortSet(obj.short1), sortSet(remote.getShort1()));48 remote.setString1(obj.string1);49 TestUtils.assertEquals(log, "string1", sortSet(obj.string1), sortSet(remote.getString1()));50 remote.setObj1(obj.obj1);51 TestUtils.assertEquals(log, "obj1", sortSet(obj.obj1), sortSet(remote.getObj1()));52 remote.setDate1(obj.date1);53 TestUtils.assertEquals(log, "date1", sortSet(obj.date1), sortSet(remote.getDate1()));54 55 log.info(")testRemoteSetTypes");56 });57 58 ...

Full Screen

Full Screen

Jest Testing Tutorial

LambdaTest’s Jest Testing Tutorial covers step-by-step guides around Jest with code examples to help you be proficient with the Jest framework. The Jest tutorial has chapters to help you learn right from the basics of Jest framework to code-based tutorials around testing react apps with Jest, perform snapshot testing, import ES modules and more.

Chapters

  1. What is Jest Framework
  2. Advantages of Jest - Jest has 3,898,000 GitHub repositories, as mentioned on its official website. Learn what makes Jest special and why Jest has gained popularity among the testing and developer community.
  3. Jest Installation - All the prerequisites and set up steps needed to help you start Jest automation testing.
  4. Using Jest with NodeJS Project - Learn how to leverage Jest framework to automate testing using a NodeJS Project.
  5. Writing First Test for Jest Framework - Get started with code-based tutorial to help you write and execute your first Jest framework testing script.
  6. Jest Vocabulary - Learn the industry renowned and official jargons of the Jest framework by digging deep into the Jest vocabulary.
  7. Unit Testing with Jest - Step-by-step tutorial to help you execute unit testing with Jest framework.
  8. Jest Basics - Learn about the most pivotal and basic features which makes Jest special.
  9. Jest Parameterized Tests - Avoid code duplication and fasten automation testing with Jest using parameterized tests. Parameterization allows you to trigger the same test scenario over different test configurations by incorporating parameters.
  10. Jest Matchers - Enforce assertions better with the help of matchers. Matchers help you compare the actual output with the expected one. Here is an example to see if the object is acquired from the correct class or not. -

|<p>it('check_object_of_Car', () => {</p><p> expect(newCar()).toBeInstanceOf(Car);</p><p> });</p>| | :- |

  1. Jest Hooks: Setup and Teardown - Learn how to set up conditions which needs to be followed by the test execution and incorporate a tear down function to free resources after the execution is complete.
  2. Jest Code Coverage - Unsure there is no code left unchecked in your application. Jest gives a specific flag called --coverage to help you generate code coverage.
  3. HTML Report Generation - Learn how to create a comprehensive HTML report based on your Jest test execution.
  4. Testing React app using Jest Framework - Learn how to test your react web-application with Jest framework in this detailed Jest tutorial.
  5. Test using LambdaTest cloud Selenium Grid - Run your Jest testing script over LambdaTest cloud-based platform and leverage parallel testing to help trim down your test execution time.
  6. Snapshot Testing for React Front Ends - Capture screenshots of your react based web-application and compare them automatically for visual anomalies with the help of Jest tutorial.
  7. Bonus: Import ES modules with Jest - ES modules are also known as ECMAScript modules. Learn how to best use them by importing in your Jest testing scripts.
  8. Jest vs Mocha vs Jasmine - Learn the key differences between the most popular JavaScript-based testing frameworks i.e. Jest, Mocha, and Jasmine.
  9. Jest FAQs(Frequently Asked Questions) - Explore the most commonly asked questions around Jest framework, with their answers.

Run Jest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful