How to use newQuery method in Best

Best JavaScript code snippet using best

Tests.gs

Source:Tests.gs Github

copy

Full Screen

...29function testWords() {30 Logger.log("--- testWords ---");31 var query;32 33 query = newQuery().words("One").build();34 Logger.log("query=%s", query);35 assertEquals(query, "One");36 37 query = newQuery().words("One Two").build();38 Logger.log("query=%s", query);39 assertEquals(query, "One Two");40 41 Logger.log("Fail to set words: number");42 assertThrows("Words must be a string", function() {43 newQuery().words(1);44 });45 46 Logger.log("Fail to set words: boolean");47 assertThrows("Words must be a string", function() {48 newQuery().words(true);49 });50 51 Logger.log("Fail to set words: null");52 assertThrows("Words must be a string", function() {53 newQuery().words(null);54 });55 56 Logger.log("Fail to set words: undefined");57 assertThrows("Words must be a string", function() {58 newQuery().words();59 });60}61function testSubject() {62 Logger.log("--- testSubject ---");63 var query;64 65 query = newQuery().subject("One").build();66 Logger.log("query=%s", query);67 assertEquals(query, "subject:One");68 69 query = newQuery().subject('"One Two"').build();70 Logger.log("query=%s", query);71 assertEquals(query, 'subject:"One Two"');72 73 Logger.log("Fail to set subject: number");74 assertThrows("Subject words must be a string", function() {75 newQuery().subject(1);76 });77 78 Logger.log("Fail to set subject: boolean");79 assertThrows("Subject words must be a string", function() {80 newQuery().subject(true);81 });82 83 Logger.log("Fail to set subject: null");84 assertThrows("Subject words must be a string", function() {85 newQuery().subject(null);86 });87 88 Logger.log("Fail to set subject: undefined");89 assertThrows("Subject words must be a string", function() {90 newQuery().subject();91 });92}93function testLabel() {94 Logger.log("--- testLabel ---");95 var query;96 97 query = newQuery().label("My Label").build();98 Logger.log("query=%s", query);99 assertEquals(query, "label:My-Label");100 101 Logger.log("Fail to set label: number");102 assertThrows("Lable name must be a string", function() {103 newQuery().label(1);104 });105 106 Logger.log("Fail to set label: no arguments");107 assertThrows("Lable name must be a string", function() {108 newQuery().label();109 });110 111 Logger.log("Fail to set label: null");112 assertThrows("Lable name must be a string", function() {113 newQuery().label(null);114 });115 116 Logger.log("Fail to set label: boolean");117 assertThrows("Lable name must be a string", function() {118 newQuery().label(true);119 });120}121function testHasUserLabels() {122 Logger.log("--- testHasUserLabels ---");123 var query;124 125 query = newQuery().hasUserLabels().build();126 Logger.log("query=%s", query);127 assertEquals(query, "has:userlabels");128}129function testHasNoUserLabels() {130 Logger.log("--- testHasNoUserLabels ---");131 var query;132 133 query = newQuery().hasNoUserLabels().build();134 Logger.log("query=%s", query);135 assertEquals(query, "has:nouserlabels");136}137function testCategory() {138 Logger.log("--- testCategory ---");139 var query;140 141 query = newQuery().category("My Category").build();142 Logger.log("query=%s", query);143 assertEquals(query, "category:My-Category");144 145 Logger.log("Fail to set category: number");146 assertThrows("Category must be a not empty string", function() {147 newQuery().category(1);148 });149 150 Logger.log("Fail to set category: boolean");151 assertThrows("Category must be a not empty string", function() {152 newQuery().category(true);153 });154 155 Logger.log("Fail to set category: null");156 assertThrows("Category must be a not empty string", function() {157 newQuery().category(null);158 });159 160 Logger.log("Fail to set category: undefined");161 assertThrows("Category must be a not empty string", function() {162 newQuery().category();163 });164}165function testOlderThan() {166 Logger.log("--- testOlderThan ---");167 var query;168 169 query = newQuery().olderThan(1,DateType.DAY).build();170 Logger.log("query=%s", query);171 assertEquals(query, "older_than:1d");172 173 query = newQuery().olderThan(0,DateType.MONTH).build();174 Logger.log("query=%s", query);175 assertEquals(query, "older_than:0m");176 177 query = newQuery().olderThan(60,DateType.YEAR).build();178 Logger.log("query=%s", query);179 assertEquals(query, "older_than:60y");180 181 query = newQuery().olderThan(1,'d').build();182 Logger.log("query=%s", query);183 assertEquals(query, "older_than:1d");184 185 query = newQuery().olderThan(0,'m').build();186 Logger.log("query=%s", query);187 assertEquals(query, "older_than:0m");188 189 query = newQuery().olderThan(60,'y').build();190 Logger.log("query=%s", query);191 assertEquals(query, "older_than:60y");192 193 Logger.log("Fail to set older_than: period=string");194 assertThrows("Period must be a non negative integer number", function() {195 newQuery().olderThan('1',DateType.DAY);196 });197 198 Logger.log("Fail to set older_than: period=null");199 assertThrows("Period must be a non negative integer number", function() {200 newQuery().olderThan(null,DateType.DAY);201 });202 203 Logger.log("Fail to set older_than: period=undefined");204 assertThrows("Period must be a non negative integer number", function() {205 newQuery().olderThan(undefined,DateType.DAY);206 });207 208 Logger.log("Fail to set older_than: period=negative");209 assertThrows("Period must be a non negative integer number", function() {210 newQuery().olderThan(-1,DateType.DAY);211 });212 213 Logger.log("Fail to set older_than: period=float");214 assertThrows("Period must be a non negative integer number", function() {215 newQuery().olderThan(1.1,DateType.DAY);216 });217 218 Logger.log("Fail to set older_than: type=string");219 assertThrows("Type must be a valid DateType value", function() {220 newQuery().olderThan(1,'blabla');221 });222 223 Logger.log("Fail to set older_than: type=number");224 assertThrows("Type must be a valid DateType value", function() {225 newQuery().olderThan(1,1);226 });227 228 Logger.log("Fail to set older_than: type=null");229 assertThrows("Type must be a valid DateType value", function() {230 newQuery().olderThan(1,null);231 });232 233 Logger.log("Fail to set older_than: type=undefined");234 assertThrows("Type must be a valid DateType value", function() {235 newQuery().olderThan(1);236 });237 238 Logger.log("Fail to set older_than: type=boolean");239 assertThrows("Type must be a valid DateType value", function() {240 newQuery().olderThan(1,true);241 });242}243function testNewerThan() {244 Logger.log("--- testNewerThan ---");245 var query;246 247 query = newQuery().newerThan(1,DateType.DAY).build();248 Logger.log("query=%s", query);249 assertEquals(query, "newer_than:1d");250 251 query = newQuery().newerThan(0,DateType.MONTH).build();252 Logger.log("query=%s", query);253 assertEquals(query, "newer_than:0m");254 255 query = newQuery().newerThan(60,DateType.YEAR).build();256 Logger.log("query=%s", query);257 assertEquals(query, "newer_than:60y");258 259 query = newQuery().newerThan(1,'d').build();260 Logger.log("query=%s", query);261 assertEquals(query, "newer_than:1d");262 263 query = newQuery().newerThan(0,'m').build();264 Logger.log("query=%s", query);265 assertEquals(query, "newer_than:0m");266 267 query = newQuery().newerThan(60,'y').build();268 Logger.log("query=%s", query);269 assertEquals(query, "newer_than:60y");270 271 Logger.log("Fail to set newer_than: period=string");272 assertThrows("Period must be a non negative integer number", function() {273 newQuery().newerThan('1',DateType.DAY);274 });275 276 Logger.log("Fail to set newer_than: period=null");277 assertThrows("Period must be a non negative integer number", function() {278 newQuery().newerThan(null,DateType.DAY);279 });280 281 Logger.log("Fail to set newer_than: period=undefined");282 assertThrows("Period must be a non negative integer number", function() {283 newQuery().newerThan(undefined,DateType.DAY);284 });285 286 Logger.log("Fail to set newer_than: period=negative");287 assertThrows("Period must be a non negative integer number", function() {288 newQuery().newerThan(-1,DateType.DAY);289 });290 291 Logger.log("Fail to set newer_than: period=float");292 assertThrows("Period must be a non negative integer number", function() {293 newQuery().newerThan(1.1,DateType.DAY);294 });295 296 Logger.log("Fail to set newer_than: type=string");297 assertThrows("Type must be a valid DateType value", function() {298 newQuery().newerThan(1,'blabla');299 });300 301 Logger.log("Fail to set newer_than: type=number");302 assertThrows("Type must be a valid DateType value", function() {303 newQuery().newerThan(1,1);304 });305 306 Logger.log("Fail to set newer_than: type=null");307 assertThrows("Type must be a valid DateType value", function() {308 newQuery().newerThan(1,null);309 });310 311 Logger.log("Fail to set newer_than: type=undefined");312 assertThrows("Type must be a valid DateType value", function() {313 newQuery().newerThan(1);314 });315 316 Logger.log("Fail to set newer_than: type=boolean");317 assertThrows("Type must be a valid DateType value", function() {318 newQuery().newerThan(1,true);319 });320}321function testBefore() {322 Logger.log("--- testBefore ---");323 var query;324 325 query = newQuery().before(new Date(2012,7,9)).build(); // 7->Aug - Month: 0..11326 Logger.log("query=%s", query);327 assertEquals(query, "before:2012/08/09");328 329 Logger.log("Fail to build query with before: string");330 assertThrows("date must be an instance of Date", function() {331 newQuery().before('bla');332 });333 334 Logger.log("Fail to build query with before: null");335 assertThrows("date must be an instance of Date", function() {336 newQuery().before(null);337 });338 339 Logger.log("Fail to build query with before: number");340 assertThrows("date must be an instance of Date", function() {341 newQuery().before(7);342 });343 344 Logger.log("Fail to build query with before: boolean");345 assertThrows("date must be an instance of Date", function() {346 newQuery().before(true);347 });348 349 Logger.log("Fail to build query with before: undefined");350 assertThrows("date must be an instance of Date", function() {351 newQuery().before();352 });353}354function testAfter() {355 Logger.log("--- testAfter ---");356 var query;357 358 query = newQuery().after(new Date(2012,7,9)).build(); // 7->Aug - Month: 0..11359 Logger.log("query=%s", query);360 assertEquals(query, "after:2012/08/09");361 362 Logger.log("Fail to build query with after: string");363 assertThrows("date must be an instance of Date", function() {364 newQuery().after('bla');365 });366 367 Logger.log("Fail to build query with after: null");368 assertThrows("date must be an instance of Date", function() {369 newQuery().after(null);370 });371 372 Logger.log("Fail to build query with after: number");373 assertThrows("date must be an instance of Date", function() {374 newQuery().after(7);375 });376 377 Logger.log("Fail to build query with after: boolean");378 assertThrows("date must be an instance of Date", function() {379 newQuery().after(true);380 });381 382 Logger.log("Fail to build query with after: undefined");383 assertThrows("date must be an instance of Date", function() {384 newQuery().after();385 });386}387function testOr() {388 Logger.log("--- testOr ---");389 var query;390 391 query = newQuery().label("label1").or().label("label2").build();392 Logger.log("query=%s", query);393 assertEquals(query, "label:label1 OR label:label2");394 395 Logger.log("Fail to add OR after OR");396 assertThrows("Query is in an intermediate state", function() {397 newQuery().label("label1").or().or();398 });399 400 Logger.log("Fail to start query with OR");401 assertThrows("OR must follow a term", function() {402 newQuery().or();403 });404 405 Logger.log("Fail to build query ending with OR");406 assertThrows("Query is in an intermediate state", function() {407 newQuery().label("label1").or().build();408 });409}410function testExclude() {411 Logger.log("--- testExclude ---");412 var query;413 414 query = newQuery().label("label1").exclude().label("label2").build();415 Logger.log("query=%s", query);416 assertEquals(query, "label:label1 -label:label2");417 418 Logger.log("Fail to build query ending with exclude");419 assertThrows("Query is in an intermediate state", function() {420 newQuery().label("label1").exclude().build();421 });422}423function testExact() {424 Logger.log("--- testExact ---");425 var query;426 427 query = newQuery().label("label1").exact().label("label2").build();428 Logger.log("query=%s", query);429 assertEquals(query, "label:label1 +label:label2");430 431 Logger.log("Fail to build query ending with exact");432 assertThrows("Query is in an intermediate state", function() {433 newQuery().label("label1").exact().build();434 });435}436function testFrom() {437 Logger.log("--- testFrom ---");438 var query;439 440 query = newQuery().from("john@foo.com").build();441 Logger.log("query=%s", query);442 assertEquals(query, "from:john@foo.com");443 444 Logger.log("Fail to build query with from: null");445 assertThrows("Sender must be a string", function() {446 newQuery().from(null);447 });448 449 Logger.log("Fail to build query with from: number");450 assertThrows("Sender must be a string", function() {451 newQuery().from(7);452 });453 454 Logger.log("Fail to build query with from: boolean");455 assertThrows("Sender must be a string", function() {456 newQuery().from(true);457 });458 459 Logger.log("Fail to build query with from: undefined");460 assertThrows("Sender must be a string", function() {461 newQuery().from();462 });463}464function testTo() {465 Logger.log("--- testTo ---");466 var query;467 468 query = newQuery().to("john@foo.com").build();469 Logger.log("query=%s", query);470 assertEquals(query, "to:john@foo.com");471 472 Logger.log("Fail to build query with to: null");473 assertThrows("Recipient must be a string", function() {474 newQuery().to(null);475 });476 477 Logger.log("Fail to build query with to: number");478 assertThrows("Recipient must be a string", function() {479 newQuery().to(3.14);480 });481 482 Logger.log("Fail to build query with to: boolean");483 assertThrows("Recipient must be a string", function() {484 newQuery().to(false);485 });486 487 Logger.log("Fail to build query with to: undefined");488 assertThrows("Recipient must be a string", function() {489 newQuery().to();490 });491}492function testCc() {493 Logger.log("--- testCc ---");494 var query;495 496 query = newQuery().cc("john@foo.com").build();497 Logger.log("query=%s", query);498 assertEquals(query, "cc:john@foo.com");499 500 Logger.log("Fail to build query with cc: null");501 assertThrows("Recipient must be a string", function() {502 newQuery().cc(null);503 });504 505 Logger.log("Fail to build query with cc: number");506 assertThrows("Recipient must be a string", function() {507 newQuery().cc(6.18);508 });509 510 Logger.log("Fail to build query with cc: boolean");511 assertThrows("Recipient must be a string", function() {512 newQuery().cc(true);513 });514 515 Logger.log("Fail to build query with cc: undefined");516 assertThrows("Recipient must be a string", function() {517 newQuery().cc();518 });519}520function testBcc() {521 Logger.log("--- testBcc ---");522 var query;523 524 query = newQuery().bcc("john@foo.com").build();525 Logger.log("query=%s", query);526 assertEquals(query, "bcc:john@foo.com");527 528 Logger.log("Fail to build query with bcc: null");529 assertThrows("Recipient must be a string", function() {530 newQuery().bcc(null);531 });532 533 Logger.log("Fail to build query with bcc: number");534 assertThrows("Recipient must be a string", function() {535 newQuery().bcc(10);536 });537 538 Logger.log("Fail to build query with bcc: boolean");539 assertThrows("Recipient must be a string", function() {540 newQuery().bcc(false);541 });542 543 Logger.log("Fail to build query with bcc: undefined");544 assertThrows("Recipient must be a string", function() {545 newQuery().bcc();546 });547}548function testHasAttachment() {549 Logger.log("--- testHasAttachment ---");550 var query;551 552 query = newQuery().hasAttachment().build();553 Logger.log("query=%s", query);554 assertEquals(query, "has:attachment");555}556function testFilename() {557 Logger.log("--- testFilename ---");558 var query;559 560 query = newQuery().fileName("file.ext").build();561 Logger.log("query=%s", query);562 assertEquals(query, "filename:file.ext");563 564 Logger.log("Fail to set filename: number");565 assertThrows("Filename must be a non-empty string", function() {566 newQuery().fileName(1);567 });568 569 Logger.log("Fail to set filename: boolean");570 assertThrows("Filename must be a non-empty string", function() {571 newQuery().fileName(true);572 });573 574 Logger.log("Fail to set filename: null");575 assertThrows("Filename must be a non-empty string", function() {576 newQuery().fileName(null);577 });578 579 Logger.log("Fail to set filename: undefined");580 assertThrows("Filename must be a non-empty string", function() {581 newQuery().fileName();582 });583}584function testLarger() {585 Logger.log("--- testLarger ---");586 var query;587 588 query = newQuery().larger(2,SizeType.B).build();589 Logger.log("query=%s", query);590 assertEquals(query, "larger:2");591 592 query = newQuery().larger(2).build();593 Logger.log("query=%s", query);594 assertEquals(query, "larger:2");595 596 query = newQuery().larger(2,'B').build();597 Logger.log("query=%s", query);598 assertEquals(query, "larger:2");599 600 query = newQuery().larger(2,SizeType.K).build();601 Logger.log("query=%s", query);602 assertEquals(query, "larger:2000");603 604 query = newQuery().larger(2,'K').build();605 Logger.log("query=%s", query);606 assertEquals(query, "larger:2000");607 608 query = newQuery().larger(2,SizeType.KB).build();609 Logger.log("query=%s", query);610 assertEquals(query, "larger:2048");611 612 query = newQuery().larger(2,'KB').build();613 Logger.log("query=%s", query);614 assertEquals(query, "larger:2048");615 616 query = newQuery().larger(2,SizeType.M).build();617 Logger.log("query=%s", query);618 assertEquals(query, "larger:2000000");619 620 query = newQuery().larger(2,'M').build();621 Logger.log("query=%s", query);622 assertEquals(query, "larger:2000000");623 624 query = newQuery().larger(2,SizeType.MB).build();625 Logger.log("query=%s", query);626 assertEquals(query, "larger:" + 2*1024*1024);627 628 query = newQuery().larger(2,'MB').build();629 Logger.log("query=%s", query);630 assertEquals(query, "larger:" + 2*1024*1024);631 632 query = newQuery().larger(2,SizeType.G).build();633 Logger.log("query=%s", query);634 assertEquals(query, "larger:2000000000");635 636 query = newQuery().larger(2,'G').build();637 Logger.log("query=%s", query);638 assertEquals(query, "larger:2000000000");639 640 query = newQuery().larger(2,SizeType.GB).build();641 Logger.log("query=%s", query);642 assertEquals(query, "larger:" + 2*1024*1024*1024);643 644 query = newQuery().larger(2,'GB').build();645 Logger.log("query=%s", query);646 assertEquals(query, "larger:" + 2*1024*1024*1024);647 648 Logger.log("Fail to set larger: size=string");649 assertThrows("Size must be a non negative integer number", function() {650 newQuery().larger('1',SizeType.B);651 });652 653 Logger.log("Fail to set larger: size=float");654 assertThrows("Size must be a non negative integer number", function() {655 newQuery().larger(3.14,SizeType.B);656 });657 658 Logger.log("Fail to set larger: size=negative");659 assertThrows("Size must be a non negative integer number", function() {660 newQuery().larger(-1,SizeType.B);661 });662 663 Logger.log("Fail to set larger: size=null");664 assertThrows("Size must be a non negative integer number", function() {665 newQuery().larger(null,SizeType.B);666 });667 668 Logger.log("Fail to set larger: size=undefined");669 assertThrows("Size must be a non negative integer number", function() {670 newQuery().larger(undefined,SizeType.B);671 });672 673 Logger.log("Fail to set larger: size=boolean");674 assertThrows("Size must be a non negative integer number", function() {675 newQuery().larger(true,SizeType.B);676 });677 678 Logger.log("Fail to set larger: type=string");679 assertThrows("Type must be a valid SizeType value", function() {680 newQuery().larger(1,'blabla');681 });682 683 Logger.log("Fail to set larger: type=number");684 assertThrows("Type must be a valid SizeType value", function() {685 newQuery().larger(1,7);686 });687 688 Logger.log("Fail to set larger: type=boolean");689 assertThrows("Type must be a valid SizeType value", function() {690 newQuery().larger(1,false);691 });692 693 Logger.log("Fail to set larger: type=null");694 assertThrows("Type must be a valid SizeType value", function() {695 newQuery().larger(1,null);696 });697}698function testSmaller() {699 Logger.log("--- testSmaller ---");700 var query;701 702 query = newQuery().smaller(2,SizeType.B).build();703 Logger.log("query=%s", query);704 assertEquals(query, "smaller:2");705 706 query = newQuery().smaller(2).build();707 Logger.log("query=%s", query);708 assertEquals(query, "smaller:2");709 710 query = newQuery().smaller(2,'B').build();711 Logger.log("query=%s", query);712 assertEquals(query, "smaller:2");713 714 query = newQuery().smaller(2,SizeType.K).build();715 Logger.log("query=%s", query);716 assertEquals(query, "smaller:2000");717 718 query = newQuery().smaller(2,'K').build();719 Logger.log("query=%s", query);720 assertEquals(query, "smaller:2000");721 722 query = newQuery().smaller(2,SizeType.KB).build();723 Logger.log("query=%s", query);724 assertEquals(query, "smaller:2048");725 726 query = newQuery().smaller(2,'KB').build();727 Logger.log("query=%s", query);728 assertEquals(query, "smaller:2048");729 730 query = newQuery().smaller(2,SizeType.M).build();731 Logger.log("query=%s", query);732 assertEquals(query, "smaller:2000000");733 734 query = newQuery().smaller(2,'M').build();735 Logger.log("query=%s", query);736 assertEquals(query, "smaller:2000000");737 738 query = newQuery().smaller(2,SizeType.MB).build();739 Logger.log("query=%s", query);740 assertEquals(query, "smaller:" + 2*1024*1024);741 742 query = newQuery().smaller(2,'MB').build();743 Logger.log("query=%s", query);744 assertEquals(query, "smaller:" + 2*1024*1024);745 746 query = newQuery().smaller(2,SizeType.G).build();747 Logger.log("query=%s", query);748 assertEquals(query, "smaller:2000000000");749 750 query = newQuery().smaller(2,'G').build();751 Logger.log("query=%s", query);752 assertEquals(query, "smaller:2000000000");753 754 query = newQuery().smaller(2,SizeType.GB).build();755 Logger.log("query=%s", query);756 assertEquals(query, "smaller:" + 2*1024*1024*1024);757 758 query = newQuery().smaller(2,'GB').build();759 Logger.log("query=%s", query);760 assertEquals(query, "smaller:" + 2*1024*1024*1024);761 762 Logger.log("Fail to set smaller: size=string");763 assertThrows("Size must be a non negative integer number", function() {764 newQuery().smaller('1',SizeType.B);765 });766 767 Logger.log("Fail to set smaller: size=float");768 assertThrows("Size must be a non negative integer number", function() {769 newQuery().smaller(3.14,SizeType.B);770 });771 772 Logger.log("Fail to set smaller: size=negative");773 assertThrows("Size must be a non negative integer number", function() {774 newQuery().smaller(-1,SizeType.B);775 });776 777 Logger.log("Fail to set smaller: size=null");778 assertThrows("Size must be a non negative integer number", function() {779 newQuery().smaller(null,SizeType.B);780 });781 782 Logger.log("Fail to set smaller: size=undefined");783 assertThrows("Size must be a non negative integer number", function() {784 newQuery().smaller(undefined,SizeType.B);785 });786 787 Logger.log("Fail to set smaller: size=boolean");788 assertThrows("Size must be a non negative integer number", function() {789 newQuery().smaller(true,SizeType.B);790 });791 792 Logger.log("Fail to set smaller: type=string");793 assertThrows("Type must be a valid SizeType value", function() {794 newQuery().smaller(1,'blabla');795 });796 797 Logger.log("Fail to set smaller: type=number");798 assertThrows("Type must be a valid SizeType value", function() {799 newQuery().smaller(1,7);800 });801 802 Logger.log("Fail to set smaller: type=boolean");803 assertThrows("Type must be a valid SizeType value", function() {804 newQuery().smaller(1,false);805 });806 807 Logger.log("Fail to set smaller: type=null");808 assertThrows("Type must be a valid SizeType value", function() {809 newQuery().smaller(1,null);810 });811}812function testIn() {813 Logger.log("--- testIn ---");814 var query;815 816 query = newQuery().inInbox().build();817 Logger.log("query=%s", query);818 assertEquals(query, "in:inbox");819 820 query = newQuery().inTrash().build();821 Logger.log("query=%s", query);822 assertEquals(query, "in:trash");823 824 query = newQuery().inSpam().build();825 Logger.log("query=%s", query);826 assertEquals(query, "in:spam");827 828 query = newQuery().inAnywhere().build();829 Logger.log("query=%s", query);830 assertEquals(query, "in:anywhere");831}832function testIs() {833 Logger.log("--- testIs ---");834 var query;835 836 query = newQuery().isStarred().build();837 Logger.log("query=%s", query);838 assertEquals(query, "is:starred");839 840 query = newQuery().isImportant().build();841 Logger.log("query=%s", query);842 assertEquals(query, "is:important");843 844 query = newQuery().isUnread().build();845 Logger.log("query=%s", query);846 assertEquals(query, "is:unread");847 848 query = newQuery().isRead().build();849 Logger.log("query=%s", query);850 assertEquals(query, "is:read");851 852 query = newQuery().isChat().build();853 Logger.log("query=%s", query);854 assertEquals(query, "is:chat");855}856function testSubQuery() {857 Logger.log("--- testSubQuery ---");858 var query;859 860 query = newQuery().words("bla").subQuery("foo").build();861 Logger.log("query=%s", query);862 assertEquals(query, "bla (foo)");863 864 query = newQuery().words("bla").subQuery("foo").words("bar").build();865 Logger.log("query=%s", query);866 assertEquals(query, "bla (foo) bar");867 868 query = newQuery().subQuery("foo").words("bar").build();869 Logger.log("query=%s", query);870 assertEquals(query, "(foo) bar");871 872 query = newQuery().words("bla").subQuery(newQuery().label("a").or().label("b")).words("bar").build();873 Logger.log("query=%s", query);874 assertEquals(query, "bla (label:a OR label:b) bar");875}876function testComplexQuery() {877 Logger.log("--- testComplexQuery ---");878 var query = newQuery()879 .words('bla foo')880 .exclude().subject('bar')881 .exact().subQuery(newQuery().label('a').or().inInbox())882 .isStarred()883 .olderThan(7,DateType.DAY)884 .build();885 Logger.log("query=%s", query);886 assertEquals(query, "bla foo -subject:bar +(label:a OR in:inbox) is:starred older_than:7d");887}888function testSearch() {889 Logger.log("--- testSearch ---");890 var origGmailApp = GmailApp;891 try {892 Logger.log("Search empty query with start and max arguments");893 var start = 7, max = 10;894 GmailApp = {895 search : function() {896 if (arguments.length !== 3 || arguments[0] !== '' || arguments[1] !== start || arguments[2] !== max) {897 throw new Error("Unexpected arguments passed to search: arguments=" + argumentsToString(arguments));898 }899 }900 };901 newQuery().search(start, max);902 903 Logger.log("Search query=words with start and max arguments");904 var start = 7, max = 10;905 GmailApp = {906 search : function() {907 if (arguments.length !== 3 || arguments[0] !== 'words' || arguments[1] !== start || arguments[2] !== max) {908 throw new Error("Unexpected arguments passed to search: arguments=" + argumentsToString(arguments));909 }910 }911 };912 newQuery().words('words').search(start, max);913 914 Logger.log("Search empty query with no arguments");915 GmailApp = {916 search : function() {917 if (arguments.length !== 1 || arguments[0] !== '') {918 throw new Error("Unexpected arguments passed to search: arguments=" + argumentsToString(arguments));919 }920 }921 };922 newQuery().search();923 924 Logger.log("Search query=words with no arguments");925 GmailApp = {926 search : function() {927 if (arguments.length !== 1 || arguments[0] !== 'words') {928 throw new Error("Unexpected arguments passed to search: arguments=" + argumentsToString(arguments));929 }930 }931 };932 newQuery().words('words').search();933 } finally {934 GmailApp = origGmailApp;935 }936}937//###################################################################################################938function assertEquals(actual, expected, message) {939 message = message || Utilities.formatString("Value is not as expected: actual=%s, expected=%s", actual, expected);940 if (actual !== expected) {941 throw new Error(message);942 }943}944function assertThrows(expectedErrorMessage, func) {945 try {946 func();...

Full Screen

Full Screen

stateChangeHeuristics.js

Source:stateChangeHeuristics.js Github

copy

Full Screen

1export default (oldState, newState) => {2 const { query, sessionGranularity } = oldState;3 const defaultGranularity = sessionGranularity || 'day';4 if (newState.query) {5 const oldQuery = query;6 let newQuery = newState.query;7 const { meta } = oldState;8 if (9 (oldQuery.timeDimensions || []).length === 110 && (newQuery.timeDimensions || []).length === 111 && newQuery.timeDimensions[0].granularity12 && oldQuery.timeDimensions[0].granularity !== newQuery.timeDimensions[0].granularity13 ) {14 newState = {15 ...newState,16 sessionGranularity: newQuery.timeDimensions[0].granularity,17 };18 }19 if (20 // eslint-disable-next-line no-mixed-operators21 (oldQuery.measures || []).length === 0 && (newQuery.measures || []).length > 022 // eslint-disable-next-line no-mixed-operators23 || (24 (oldQuery.measures || []).length === 125 && (newQuery.measures || []).length === 126 && oldQuery.measures[0] !== newQuery.measures[0]27 )28 ) {29 const defaultTimeDimension = meta.defaultTimeDimensionNameFor(newQuery.measures[0]);30 newQuery = {31 ...newQuery,32 timeDimensions: defaultTimeDimension ? [{33 dimension: defaultTimeDimension,34 granularity: defaultGranularity,35 dateRange: "Last 30 days"36 }] : [],37 };38 return {39 ...newState,40 query: newQuery,41 chartType: defaultTimeDimension ? 'line' : 'number'42 };43 }44 if (45 (oldQuery.dimensions || []).length === 046 && (newQuery.dimensions || []).length > 047 ) {48 newQuery = {49 ...newQuery,50 timeDimensions: (newQuery.timeDimensions || []).map(td => ({ ...td, granularity: undefined })),51 };52 return {53 ...newState,54 query: newQuery,55 chartType: 'table'56 };57 }58 if (59 (oldQuery.dimensions || []).length > 060 && (newQuery.dimensions || []).length === 061 ) {62 newQuery = {63 ...newQuery,64 timeDimensions: (newQuery.timeDimensions || []).map(td => ({65 ...td, granularity: td.granularity || defaultGranularity66 })),67 };68 return {69 ...newState,70 query: newQuery,71 chartType: (newQuery.timeDimensions || []).length ? 'line' : 'number'72 };73 }74 if (75 (76 (oldQuery.dimensions || []).length > 077 || (oldQuery.measures || []).length > 078 )79 && (newQuery.dimensions || []).length === 080 && (newQuery.measures || []).length === 081 ) {82 newQuery = {83 ...newQuery,84 timeDimensions: [],85 filters: []86 };87 return {88 ...newState,89 query: newQuery,90 sessionGranularity: null91 };92 }93 return newState;94 }95 if (newState.chartType) {96 const newChartType = newState.chartType;97 if (98 (newChartType === 'line' || newChartType === 'area')99 && (query.timeDimensions || []).length === 1100 && !query.timeDimensions[0].granularity101 ) {102 const [td] = query.timeDimensions;103 return {104 ...newState,105 query: {106 ...query,107 timeDimensions: [{ ...td, granularity: defaultGranularity }]108 }109 };110 }111 if (112 (newChartType === 'pie' || newChartType === 'table' || newChartType === 'number')113 && (query.timeDimensions || []).length === 1114 && query.timeDimensions[0].granularity115 ) {116 const [td] = query.timeDimensions;117 return {118 ...newState,119 query: {120 ...query,121 timeDimensions: [{ ...td, granularity: undefined }]122 }123 };124 }125 }126 return newState;...

Full Screen

Full Screen

auctions-search.service.ts

Source:auctions-search.service.ts Github

copy

Full Screen

1import {Injectable} from "@angular/core";2import {BehaviorSubject} from "rxjs";3import {AuctionSearchQuery} from "../models/auctionSearchQuery";4@Injectable({5 providedIn: 'root'6})7export class AuctionsSearchService {8 private auctionsQuerySource = new BehaviorSubject<AuctionSearchQuery>(new AuctionSearchQuery());9 auctionsQuery = this.auctionsQuerySource.asObservable();10 updateSearchKeys(newSearchKeys:string[]) {11 const newQuery = this.cloneCurrentQuery();12 newQuery.searchKeys = Array.from(newSearchKeys);13 this.auctionsQuerySource.next(newQuery);14 }15 updateSelectedCategories(newCategories:string[]) {16 const newQuery = this.cloneCurrentQuery();17 newQuery.categories = Array.from(newCategories);18 this.auctionsQuerySource.next(newQuery);19 }20 updateSelectedCountries(newCountries:string[]) {21 const newQuery = this.cloneCurrentQuery();22 newQuery.countries = Array.from(newCountries);23 this.auctionsQuerySource.next(newQuery);24 }25 selectCategory(category:string) {26 let categories:string[] = Array.from(this.auctionsQuerySource.getValue().categories);27 if (!categories.includes(category)) {28 categories.push(category);29 }30 this.updateSelectedCategories(categories);31 }32 deselectCategory(category:string) {33 let categories:string[] = Array.from(this.auctionsQuerySource.getValue().categories);34 const index = categories.indexOf(category);35 if (index > -1) {36 categories.splice(index, 1);37 }38 this.updateSelectedCategories(categories);39 }40 selectCountry(country:string) {41 let countries:string[] = Array.from(this.auctionsQuerySource.getValue().countries);42 if (!countries.includes(country)) {43 countries.push(country);44 }45 this.updateSelectedCountries(countries);46 }47 deselectCountry(country:string) {48 let countries:string[] = Array.from(this.auctionsQuerySource.getValue().countries);49 const index = countries.indexOf(country);50 if (index > -1) {51 countries.splice(index, 1);52 }53 this.updateSelectedCountries(countries);54 }55 private cloneCurrentQuery() {56 const query = this.auctionsQuerySource.getValue();57 const newQuery = new AuctionSearchQuery();58 newQuery.categories = Array.from(query.categories);59 newQuery.countries = Array.from(query.countries);60 newQuery.searchKeys = Array.from(query.searchKeys);61 return newQuery;62 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestBuy = require('bestbuy');2var bestbuy = new BestBuy('your-api-key');3bestbuy.newQuery()4 .query('search=ipod')5 .show('sku,name,salePrice')6 .format('json')7 .sort('sku.asc')8 .pageSize(5)9 .page(2)10 .get('products')11 .then(function(data) {12 console.log(data);13 })14 .catch(function(err) {15 console.error(err);16 });17var BestBuy = require('bestbuy');18var bestbuy = new BestBuy('your-api-key');19bestbuy.newQuery()20 .query('categoryPath.id=abcat0502000')21 .show('sku,name,salePrice')22 .format('json')23 .sort('sku.asc')24 .pageSize(5)25 .page(2)26 .get('products')27 .then(function(data) {28 console.log(data);29 })30 .catch(function(err) {31 console.error(err);32 });33var BestBuy = require('bestbuy');34var bestbuy = new BestBuy('your-api-key');35bestbuy.newQuery()36 .query('categoryPath.id=abcat0502000')37 .show('sku,name,salePrice')38 .format('json')39 .sort('sku.asc')40 .pageSize(5)41 .page(2)42 .get('products')43 .then(function(data) {44 console.log(data);45 })46 .catch(function(err) {47 console.error(err);48 });49var BestBuy = require('bestbuy');50var bestbuy = new BestBuy('your-api-key');51bestbuy.newQuery()52 .query('categoryPath.id=abcat0502000')53 .show('sku,name,salePrice')54 .format('json')55 .sort('sku.asc')56 .pageSize(5)57 .page(2)58 .get('products')59 .then(function(data) {60 console.log(data);61 })62 .catch(function(err) {63 console.error(err);64 });

Full Screen

Using AI Code Generation

copy

Full Screen

1var bestbuy = require('bestbuy')('my-api-key');2bestbuy.products('(search=ipod&categoryPath.id=abcat0502000)', {show: 'sku,name,salePrice,image,customerReviewAverage'}).then(function(data){3 console.log(data);4});5var bestbuy = require('bestbuy')('my-api-key');6bestbuy.products('(search=ipod&categoryPath.id=abcat0502000)', {show: 'sku,name,salePrice,image,customerReviewAverage'}).then(function(data){7 console.log(data);8});9var bestbuy = require('bestbuy')('my-api-key');10bestbuy.products('(search=ipod&categoryPath.id=abcat0502000)', {show: 'sku,name,salePrice,image,customerReviewAverage'}).then(function(data){11 console.log(data);12});13var bestbuy = require('bestbuy')('my-api-key');14bestbuy.products('(search=ipod&categoryPath.id=abcat0502000)', {show: 'sku,name,salePrice,image,customerReviewAverage'}).then(function(data){15 console.log(data);16});17var bestbuy = require('bestbuy')('my-api-key');18bestbuy.products('(search=ipod&categoryPath.id=abcat0502000)', {show: 'sku,name,salePrice,image,customerReviewAverage'}).then(function(data){19 console.log(data);20});21var bestbuy = require('bestbuy')('my-api-key');22bestbuy.products('(search=ipod&categoryPath.id=abcat0502000)', {show: 'sku,name,salePrice,image,customerReviewAverage'}).then(function(data){23 console.log(data);24});25var bestbuy = require('bestbuy')('my-api-key');26bestbuy.products('(search=ipod&categoryPath.id=abcat0502000)', {show: 'sku,name,salePrice,image,customerReviewAverage'}).then(function(data){27 console.log(data);28});29var bestbuy = require('bestbuy')('my-api-key');

Full Screen

Using AI Code Generation

copy

Full Screen

1var request = require('request');2var querystring = require('querystring');3var http = require('http');4var fs = require('fs');5var path = require('path');6var url = require('url');7var express = require('express');8var bodyParser = require('body-parser');9var mongo = require('mongodb');10var mongoose = require('mongoose');11var session = require('express-session');12var exphbs = require('express-handlebars');13var handlebars = require('handlebars');14var helpers = require('handlebars-helpers')();15var moment = require('moment');16var randomstring = require('randomstring');17var crypto = require('crypto');18var async = require('async');19var multer = require('multer');20var http = require('http');21var fs = require('fs');22var path = require('path');23var url = require('url');24var express = require('express');25var bodyParser = require('body-parser');26var mongo = require('mongodb');27var mongoose = require('mongoose');28var session = require('express-session');29var exphbs = require('express-handlebars');30var handlebars = require('handlebars');

Full Screen

Using AI Code Generation

copy

Full Screen

1var bestMatch = require('best-match');2var query = bestMatch.newQuery(['a', 'b', 'c', 'd', 'e'], 2);3console.log(query('a'));4console.log(query('b'));5console.log(query('c'));6console.log(query('d'));7console.log(query('e'));8console.log(query('f'));9var BestMatch = require('best-match').BestMatch;10var bestMatch = new BestMatch(['a', 'b', 'c', 'd', 'e'], 2);11console.log(bestMatch.query('a'));12console.log(bestMatch.query('b'));13console.log(bestMatch.query('c'));14console.log(bestMatch.query('d'));15console.log(bestMatch.query('e'));16console.log(bestMatch.query('f'));

Full Screen

Using AI Code Generation

copy

Full Screen

1var bb = require('./BestBuy.js');2var query = bb.newQuery();3query.lessThan('price', 1000);4query.exec(function(err, products){5 if(err){6 console.log(err);7 }8 else{9 for(var i = 0; i < products.length; i++){10 console.log(products[i].name);11 }12 }13});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best 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