How to use finder.find method in Appium Base Driver

Best JavaScript code snippet using appium-base-driver

finderTests.js

Source:finderTests.js Github

copy

Full Screen

1/*******************************************************************************2 * @license3 * Copyright (c) 2013, 2014 IBM Corporation and others.4 * All rights reserved. This program and the accompanying materials are made 5 * available under the terms of the Eclipse Public License v1.0 6 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 7 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 8 * 9 * Contributors: IBM Corporation - initial API and implementation10 ******************************************************************************/11/*global console:true describe:true it:true define window*/12define([13 'chai/chai',14 'esprima',15 'javascript/finder',16 'javascript/astManager',17 'orion/Deferred',18 'mocha/mocha' // not a module, leave it at the end19], function(chai, Esprima, Finder, ASTManager, Deferred) {20 var assert = chai.assert;21 describe('Finder Tests', function() {22 var astManager = new ASTManager.ASTManager(Esprima);23 var editorContext = {24 text: "",25 /**26 * get the text27 */28 getText: function() {29 return new Deferred().resolve(this.text);30 }31 };32 /**33 * @description Sets up the test34 * @public35 * @param {String} text The compilation unit text36 */37 function setUp(text) {38 return {39 text: text,40 /**41 * get the text42 */43 getText: function() {44 return new Deferred().resolve(this.text);45 }46 };47 }48 49 /**50 * @name tearDown51 * @description Resets the test state between runs, must explicitly be called per-test52 * @function53 * @public54 */55 function tearDown() {56 editorContext.text = "";57 astManager.updated();58 }59 60 it('test_findWord1', function() {61 var word = Finder.findWord('function(param1, param2)', 12);62 assert.equal(word, 'param1', 'Should have found the word param1');63 });64 it('test_findWord2', function() {65 var word = Finder.findWord('function(param1, param2)', 9);66 assert.equal(word, 'param1', 'Should have found the word param1');67 });68 it('test_findWord3', function() {69 var word = Finder.findWord('function(param1, param2)', 17);70 assert.equal(word, 'param2', 'Should have found the word param2');71 });72 it('test_findWord4', function() {73 var word = Finder.findWord('var foo.bar = function(param1, param2)', 4);74 assert.equal(word, 'foo', 'Should have found the word foo');75 });76 it('test_findWord5', function() {77 var word = Finder.findWord('var foo.bar = function(param1, param2)', 8);78 assert.equal(word, 'bar', 'Should have found the word bar');79 });80 it('test_findWord6', function() {81 var word = Finder.findWord('f =function(p1) {', 3);82 assert.equal(word, 'function', 'Should have found word function');83 });84 it('test_findWord7', function() {85 var word = Finder.findWord('f ={foo:true', 4);86 assert.equal(word, 'foo', 'Should have found word foo');87 });88 it('test_findWord8', function() {89 var word = Finder.findWord('function(param1, param2)', 15);90 assert.equal(word, 'param1', 'Should have found word param1');91 });92 it('test_findWord9', function() {93 var word = Finder.findWord('var foo.bar = function(param1, param2)', 7);94 assert.equal(word, 'foo', 'Should have found word foo');95 });96 it('test_findWord10', function() {97 var word = Finder.findWord(' foo.bar = function(param1, param2)', 4);98 assert.equal(word, 'foo', 'Should have found word foo');99 });100 it('test_findWord11', function() {101 var word = Finder.findWord(' foo.bar = function(param1, param2)', 2);102 assert.equal(word, 'foo', 'Should have found word foo');103 });104 it('test_findNoWord1', function() {105 var word = Finder.findWord('f: function(p1, p2)', 2);106 assert.equal(word, null, 'Should have found no word');107 });108 it('test_findNoWord2', function() {109 var word = Finder.findWord('f: function(p1, p2)', 15);110 assert.equal(word, null, 'Should have found no word');111 });112 it('test_findNoWord3', function() {113 var word = Finder.findWord('f: function(p1) {', 16);114 assert.equal(word, null, 'Should have found no word');115 });116 it('test_findNoWord4', function() {117 var word = Finder.findWord('f: function(p1) {', 17);118 assert.equal(word, null, 'Should have found no word');119 });120 it('test_findNoWord5', function() {121 var word = Finder.findWord('f = function(p1) {', 2);122 assert.equal(word, null, 'Should have found no word');123 });124 it('test_findNoWord6', function() {125 var word = Finder.findWord('f = function(p1) {', 3);126 assert.equal(word, null, 'Should have found no word');127 });128 it('test_findNoWord7', function() {129 var word = Finder.findWord('var a = [1, 2]', 7);130 assert.equal(word, null, 'Should have found no word');131 });132 it('test_findNoWord8', function() {133 var word = Finder.findWord('var a = [1, 2]', 14);134 assert.equal(word, null, 'Should have found no word');135 });136 it('test_findNode1', function() {137 try {138 editorContext.text = "function F1(p1, p2) {\n"+139 "\tvar out = p1;\n"+140 "};";141 return astManager.getAST(editorContext).then(function(ast) {142 var node = Finder.findNode(9, ast);143 if(!node) {144 assert.fail("Should have found a node");145 }146 else {147 assert.equal(node.type, 'FunctionDeclaration', 'Should have found a FunctionDeclaration node');148 }149 });150 }151 finally {152 tearDown();153 }154 });155 it('test_findNode2', function() {156 try {157 editorContext.text = "function F1(p1, p2) {\n"+158 "\tvar out = p1;\n"+159 "};";160 return astManager.getAST(editorContext).then(function(ast) {161 var node = Finder.findNode(12, ast);162 if(!node) {163 assert.fail("Should have found a node");164 }165 else {166 assert.equal(node.type, 'Identifier', 'Should have found a Identifier node');167 }168 });169 }170 finally {171 tearDown();172 }173 });174 it('test_findNode3', function() {175 try {176 editorContext.text = "function F1(p1, p2) {\n"+177 "\tvar out = p1;\n"+178 "};";179 return astManager.getAST(editorContext).then(function(ast) {180 var node = Finder.findNode(14, ast);181 if(!node) {182 assert.fail("Should have found a node");183 }184 else {185 assert.equal(node.type, 'Identifier', 'Should have found a Identifier node');186 }187 });188 }189 finally {190 tearDown();191 }192 });193 194 it('test_findNode4', function() {195 try {196 editorContext.text = "function F1(p1, p2) {\n"+197 "\tvar out = p1;\n"+198 "};";199 return astManager.getAST(editorContext).then(function(ast) {200 var node = Finder.findNode(28, ast);201 if(!node) {202 assert.fail("Should have found a node");203 }204 else {205 assert.equal(node.type, 'Identifier', 'Should have found a Identifier node');206 }207 });208 }209 finally {210 tearDown();211 }212 });213 /**214 * Find a token in a broken AST215 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426399216 */217 it('test_findToken1', function() {218 return astManager.getAST(setUp("(")).then(function(ast) {219 try {220 var token = Finder.findToken(0, ast.tokens);221 if(!token) {222 assert.fail("Should have found a token");223 }224 else {225 assert.equal(token.type, 'Punctuator', 'Should have found a Punctuator token');226 assert.equal(token.value, '(', 'Should have found a ( token');227 }228 }229 finally {230 astManager.updated();231 }232 });233 });234 235 /**236 * Find a token in a broken AST237 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426399238 */239 it('test_findToken2', function() {240 var text = "var function f() {}";241 return astManager.getAST(setUp(text)).then(function(ast) {242 try {243 var token = Finder.findToken(4, ast.tokens);244 if(!token) {245 assert.fail("Should have found a token");246 }247 else {248 assert.equal(token.type, 'Keyword', 'Should have found a Keyword token');249 assert.equal(token.value, 'function', 'Should have found a function token');250 }251 }252 finally {253 astManager.updated();254 }255 });256 });257 258 /**259 * Find a token in a broken AST260 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426399261 */262 it('test_findToken3', function() {263 var text = "(var function f() {}";264 return astManager.getAST(setUp(text)).then(function(ast) {265 try {266 var token = Finder.findToken(21, ast.tokens);267 if(!token) {268 assert.fail("Should have found a token");269 }270 else {271 assert.equal(token.type, 'Punctuator', 'Should have found a Punctuator token');272 assert.equal(token.value, '}', 'Should have found a } token');273 }274 }275 finally {276 astManager.updated();277 }278 });279 });280 281 /**282 * Find a token in a broken AST283 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426399284 */285 it('test_findToken4', function() {286 var text = "(var function f() {}";287 return astManager.getAST(setUp(text)).then(function(ast) {288 try {289 var token = Finder.findToken(1, ast.tokens);290 if(!token) {291 assert.fail("Should have found a token");292 }293 else {294 assert.equal(token.type, 'Keyword', 'Should have found a Keyword token');295 assert.equal(token.value, 'var', 'Should have found a var token');296 }297 }298 finally {299 astManager.updated();300 }301 });302 });303 304 /**305 * Find a token in a broken AST306 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426399307 */308 it('test_findToken5', function() {309 var text = "var foo.baz / = 43;";310 return astManager.getAST(setUp(text)).then(function(ast) {311 try {312 var token = Finder.findToken(12, ast.tokens);313 if(!token) {314 assert.fail("Should have found a token");315 }316 else {317 assert.equal(token.type, 'Punctuator', 'Should have found a Punctuator token');318 assert.equal(token.value, '/', 'Should have found a / token');319 }320 }321 finally {322 astManager.updated();323 }324 });325 });326 327 /**328 * Find a token in a broken AST329 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426399330 */331 it('test_findToken6', function() {332 var text = "var foo.baz / = 43;";333 return astManager.getAST(setUp(text)).then(function(ast) {334 try {335 var token = Finder.findToken(1, ast.tokens);336 if(!token) {337 assert.fail("Should have found a token");338 }339 else {340 assert.equal(token.type, 'Keyword', 'Should have found a Keyword token');341 assert.equal(token.value, 'var', 'Should have found a var token');342 }343 }344 finally {345 astManager.updated();346 }347 });348 });349 350 /**351 * Find a token in a broken AST352 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426399353 */354 it('test_findToken7', function() {355 var text = "var function f1() {";356 return astManager.getAST(setUp(text)).then(function(ast) {357 try {358 var token = Finder.findToken(7, ast.tokens);359 if(!token) {360 assert.fail("Should have found a token");361 }362 else {363 assert.equal(token.type, 'Keyword', 'Should have found a Keyword token');364 assert.equal(token.value, 'function', 'Should have found a function token');365 }366 }367 finally {368 astManager.updated();369 }370 });371 });372 373 /**374 * Find a token in a broken AST375 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426399376 */377 it('test_findToken8', function() {378 var text = "var function f1() {";379 return astManager.getAST(setUp(text)).then(function(ast) {380 try {381 var token = Finder.findToken(7, ast.tokens);382 if(!token) {383 assert.fail("Should have found a token");384 }385 else {386 assert.equal(token.type, 'Keyword', 'Should have found a Keyword token');387 assert.equal(token.value, 'function', 'Should have found a function token');388 }389 }390 finally {391 astManager.updated();392 }393 });394 });395 396 /**397 * Find a token in a broken AST398 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426399399 */400 it('test_findToken9', function() {401 var text = "(var function f() {}";402 return astManager.getAST(setUp(text)).then(function(ast) {403 try {404 var token = Finder.findToken(-1, ast.tokens);405 assert.equal(token, null, "Should not have found a token for out of range");406 }407 finally {408 astManager.updated();409 }410 });411 });412 413 /**414 * Find a token in a correct AST415 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426399416 */417 it('test_findToken10', function() {418 var text = "function f() {}";419 return astManager.getAST(setUp(text)).then(function(ast) {420 try {421 var token = Finder.findToken(9, ast.tokens);422 if(!token) {423 assert.fail("Should have found a token");424 }425 else {426 assert.equal(token.type, 'Identifier', 'Should have found an Identifier token');427 assert.equal(token.value, 'f', 'Should have found a f token');428 }429 }430 finally {431 astManager.updated();432 }433 });434 });435 436 /**437 * Find a token in a broken AST438 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426399439 */440 it('test_findToken11', function() {441 var text = "var foo = {}";442 return astManager.getAST(setUp(text)).then(function(ast) {443 try {444 var token = Finder.findToken(8, ast.tokens);445 if(!token) {446 assert.fail("Should have found a token");447 }448 else {449 assert.equal(token.type, 'Punctuator', 'Should have found an Punctuator token');450 assert.equal(token.value, '=', 'Should have found a = token');451 }452 }453 finally {454 astManager.updated();455 }456 });457 });458 459 /**460 * Find a token in a broken AST461 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426399462 */463 it('test_findToken12', function() {464 var text = "var foo = {f: function() {}}";465 return astManager.getAST(setUp(text)).then(function(ast) {466 try {467 var token = Finder.findToken(11, ast.tokens);468 if(!token) {469 assert.fail("Should have found a token");470 }471 else {472 assert.equal(token.type, 'Identifier', 'Should have found an Identifier token');473 assert.equal(token.value, 'f', 'Should have found a f token');474 }475 }476 finally {477 astManager.updated();478 }479 });480 });481 482 /**483 * Find a token in a broken AST484 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426399485 */486 it('test_findToken13', function() {487 var text = "var foo = {f: function() {}}";488 return astManager.getAST(setUp(text)).then(function(ast) {489 try {490 var token = Finder.findToken(14, ast.tokens);491 if(!token) {492 assert.fail("Should have found a token");493 }494 else {495 assert.equal(token.type, 'Keyword', 'Should have found an Keyword token');496 assert.equal(token.value, 'function', 'Should have found a function token');497 }498 }499 finally {500 astManager.updated();501 }502 });503 });504 505 /**506 * Find a token in a broken AST507 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426399508 */509 it('test_findToken14', function() {510 var text = "var foo = {f: function() {}}";511 return astManager.getAST(setUp(text)).then(function(ast) {512 try {513 var token = Finder.findToken(18, ast.tokens);514 if(!token) {515 assert.fail("Should have found a token");516 }517 else {518 assert.equal(token.type, 'Keyword', 'Should have found an Keyword token');519 assert.equal(token.value, 'function', 'Should have found a function token');520 }521 }522 finally {523 astManager.updated();524 }525 });526 });527 528 /**529 * Find a token in a broken AST530 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426399531 */532 it('test_findToken15', function() {533 var text = "var foo = {f: function() {}}";534 return astManager.getAST(setUp(text)).then(function(ast) {535 try {536 var token = Finder.findToken(23, ast.tokens);537 if(!token) {538 assert.fail("Should have found a token");539 }540 else {541 assert.equal(token.type, 'Punctuator', 'Should have found an Punctuator token');542 assert.equal(token.value, ')', 'Should have found a ) token');543 }544 }545 finally {546 astManager.updated();547 }548 });549 });550 551 /**552 * Find a token in an AST with copious whitespace553 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427931554 */555 it('test_findToken16', function() {556 var text = "var foo = {f: function() {}}";557 return astManager.getAST(setUp(text)).then(function(ast) {558 try {559 var token = Finder.findToken(4, ast.tokens);560 assert.equal(null, token, 'Should not have found a token');561 }562 finally {563 astManager.updated();564 }565 });566 });567 568 /**569 * Find a token in an AST with copious whitespace570 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427931571 */572 it('test_findToken17', function() {573 var text = "var foo = {f: function() {}}";574 return astManager.getAST(setUp(text)).then(function(ast) {575 try {576 var token = Finder.findToken(5, ast.tokens);577 assert.equal(null, token, 'Should not have found a token');578 }579 finally {580 astManager.updated();581 }582 });583 });584 585 /**586 * Find a token in an AST with copious whitespace587 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427931588 */589 it('test_findToken18', function() {590 var text = "var foo = { f: function() {}}";591 return astManager.getAST(setUp(text)).then(function(ast) {592 try {593 var token = Finder.findToken(12, ast.tokens);594 assert.equal(null, token, 'Should not have found a token');595 }596 finally {597 astManager.updated();598 }599 });600 });601 602 /**603 * Find a token in an AST with copious whitespace604 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427931605 */606 it('test_findToken19', function() {607 var text = "var foo = {f: function() {}}";608 return astManager.getAST(setUp(text)).then(function(ast) {609 try {610 var token = Finder.findToken(14, ast.tokens);611 assert.equal(null, token, 'Should not have found a token');612 }613 finally {614 astManager.updated();615 }616 });617 });618 619 /**620 * Find a token in an AST with copious whitespace621 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427931622 */623 it('test_findToken20', function() {624 var text = "var foo = {f: function() {}}";625 return astManager.getAST(setUp(text)).then(function(ast) {626 try {627 var token = Finder.findToken(15, ast.tokens);628 assert.equal(null, token, 'Should not have found a token');629 }630 finally {631 astManager.updated();632 }633 });634 });635 636 /**637 * Find a token in an AST with copious whitespace638 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427931639 */640 it('test_findToken21', function() {641 var text = " var foo = {f: function() {}}";642 return astManager.getAST(setUp(text)).then(function(ast) {643 try {644 var token = Finder.findToken(1, ast.tokens);645 assert.equal(null, token, 'Should not have found a token');646 }647 finally {648 astManager.updated();649 }650 });651 });652 653 /**654 * Find a token in an AST with copious whitespace655 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427931656 */657 it('test_findToken22', function() {658 var text = " var foo = {f: function() {}}";659 return astManager.getAST(setUp(text)).then(function(ast) {660 try {661 var token = Finder.findToken(0, ast.tokens);662 assert.equal(null, token, 'Should not have found a token');663 }664 finally {665 astManager.updated();666 }667 });668 });669 670 /**671 * Find a token in an AST with copious whitespace672 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427931673 */674 it('test_findToken23', function() {675 var text = "function f3( foo , bar , baz) {};";676 return astManager.getAST(setUp(text)).then(function(ast) {677 try {678 var token = Finder.findToken(17, ast.tokens);679 if(!token) {680 assert.fail('Should have found a token');681 }682 else {683 assert.equal(token.type, 'Identifier', 'Should have found an Identifier token');684 assert.equal(token.value, 'foo', 'Should have found a foo token');685 }686 }687 finally {688 astManager.updated();689 }690 });691 });692 693 /**694 * Find a comment695 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426033696 */697 it('test_findComment1', function() {698 var text = "/***/var foo = {f: function() {}}";699 return astManager.getAST(setUp(text)).then(function(ast) {700 try {701 var comment = Finder.findComment(0, ast);702 if(!comment) {703 assert.fail("Should have found a comment");704 }705 }706 finally {707 astManager.updated();708 }709 });710 });711 712 /**713 * Find a comment714 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426033715 */716 it('test_findComment2', function() {717 var text = "/***/var foo = {f: function() {}}";718 return astManager.getAST(setUp(text)).then(function(ast) {719 try {720 var comment = Finder.findComment(4, ast);721 if(!comment) {722 assert.fail("Should have found a comment");723 }724 }725 finally {726 astManager.updated();727 }728 });729 });730 731 /**732 * Find a comment733 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426033734 */735 it('test_findComment3', function() {736 var text = "var foo = {/***/f: function() {}}";737 return astManager.getAST(setUp(text)).then(function(ast) {738 try {739 var comment = Finder.findComment(11, ast);740 if(!comment) {741 assert.fail("Should have found a comment");742 }743 }744 finally {745 astManager.updated();746 }747 });748 });749 750 /**751 * Find a comment752 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426033753 */754 it('test_findComment4', function() {755 var text = "var foo = {/***/f: function() {}}";756 return astManager.getAST(setUp(text)).then(function(ast) {757 try {758 var comment = Finder.findComment(14, ast);759 if(!comment) {760 assert.fail("Should have found a comment");761 }762 }763 finally {764 astManager.updated();765 }766 });767 });768 769 /**770 * Find a comment771 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426033772 */773 it('test_findComment5', function() {774 var text = "/***/function f() {/***/};";775 return astManager.getAST(setUp(text)).then(function(ast) {776 try {777 var comment = Finder.findComment(19, ast);778 if(!comment) {779 assert.fail("Should have found a comment");780 }781 }782 finally {783 astManager.updated();784 }785 });786 });787 788 /**789 * Find a comment790 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=426033791 */792 it('test_findComment6', function() {793 var text = "/***/function f() {/***/};/***/";794 return astManager.getAST(setUp(text)).then(function(ast) {795 try {796 var comment = Finder.findComment(26, ast);797 if(!comment) {798 assert.fail("Should have found a comment");799 }800 }801 finally {802 astManager.updated();803 }804 });805 });806 807 /**808 * Find a token with a bogus offset809 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427141810 */811 it('test_findTokenBadOffset1', function() {812 var text = "if(()) {};";813 return astManager.getAST(setUp(text)).then(function(ast) {814 try {815 var token = Finder.findToken(-1, ast);816 assert.equal(token, null, "Should not have found a token for a negative offset");817 }818 finally {819 astManager.updated();820 }821 });822 });823 824 /**825 * Find a token with a bogus offset826 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427141827 */828 it('test_findTokenBadOffset2', function() {829 var text = "if(()) {};";830 return astManager.getAST(setUp(text)).then(function(ast) {831 try {832 var token = Finder.findToken(null, ast);833 assert.equal(token, null, "Should not have found a token for a null offset");834 }835 finally {836 astManager.updated();837 }838 });839 });840 841 /**842 * Find a token with a bogus offset843 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427141844 */845 it('test_findTokenBadOffset3', function() {846 var text = "if(()) {};";847 return astManager.getAST(setUp(text)).then(function(ast) {848 try {849 var token = Finder.findToken(undefined, ast);850 assert.equal(token, null, "Should not have found a token for an undefined offset");851 }852 finally {853 astManager.updated();854 }855 });856 });857 858 /**859 * Find a node with a bogus offset860 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427141861 */862 it('test_findNodeBadOffset1', function() {863 var text = "if(()) {};";864 return astManager.getAST(setUp(text)).then(function(ast) {865 try {866 var token = Finder.findNode(null, ast);867 assert.equal(token, null, "Should not have found a node for a null offset");868 }869 finally {870 astManager.updated();871 }872 });873 });874 875 /**876 * Find a node with a bogus offset877 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427141878 */879 it('test_findNodeBadOffset2', function() {880 var text = "if(()) {};";881 return astManager.getAST(setUp(text)).then(function(ast) {882 try {883 var token = Finder.findNode(-1, ast);884 assert.equal(token, null, "Should not have found a node for a negative offset");885 }886 finally {887 astManager.updated();888 }889 });890 });891 892 /**893 * Find a node with a bogus offset894 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=427141895 */896 it('test_findNodeBadOffset3', function() {897 var text = "if(()) {};";898 return astManager.getAST(setUp(text)).then(function(ast) {899 try {900 var token = Finder.findNode(undefined, ast);901 assert.equal(token, null, "Should not have found a node for an undefined offset");902 }903 finally {904 astManager.updated();905 }906 });907 });908 909 /**910 * Tests the support for finding script blocks in HTML911 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=430299912 */913 it('test_findScriptBlock1', function() {914 var text = "<!DOCTYPE html><head><script>function f() {}</script></head><html></html>";915 var blocks = Finder.findScriptBlocks(text);916 assert.equal(blocks.length, 1, "Should have found one script block");917 assert.equal(blocks[0].offset, 29);918 assert.equal(blocks[0].text, 'function f() {}');919 });920 921 /**922 * Tests the support for finding script blocks in HTML923 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=430299924 */925 it('test_findScriptBlock2', function() {926 var text = "<!DOCTYPE html><head><scriPt>function f() {}</script></head><html></html>";927 var blocks = Finder.findScriptBlocks(text);928 assert.equal(blocks.length, 1, "Should have found one script block");929 assert.equal(blocks[0].offset, 29);930 assert.equal(blocks[0].text, 'function f() {}');931 });932 933 /**934 * Tests the support for finding script blocks in HTML935 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=430299936 */937 it('test_findScriptBlock3', function() {938 var text = "<!DOCTYPE html><head><script>function f() {}</scriPt></head><html></html>";939 var blocks = Finder.findScriptBlocks(text);940 assert.equal(blocks.length, 1, "Should have found one script block");941 assert.equal(blocks[0].offset, 29);942 assert.equal(blocks[0].text, 'function f() {}');943 });944 945 /**946 * Tests the support for finding script blocks in HTML947 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=430299948 */949 it('test_findScriptBlock4', function() {950 var text = "<!DOCTYPE html><head><scRipt>function f() {}</scripT></head><html></html>";951 var blocks = Finder.findScriptBlocks(text);952 assert.equal(blocks.length, 1, "Should have found one script block");953 assert.equal(blocks[0].offset, 29);954 assert.equal(blocks[0].text, 'function f() {}');955 });956 957 /**958 * Tests the support for finding script blocks in HTML959 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=430299960 */961 it('test_findScriptBlock5', function() {962 var text = "<!DOCTYPE html><head><scriPt >function f() {}</scRIpt></head><html></html>";963 var blocks = Finder.findScriptBlocks(text);964 assert.equal(blocks.length, 1, "Should have found one script block");965 assert.equal(blocks[0].offset, 32);966 assert.equal(blocks[0].text, 'function f() {}');967 });968 969 /**970 * Tests the support for finding script blocks in HTML971 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=430299972 */973 it('test_findScriptBlockMulti1', function() {974 var text = "<!DOCTYPE html><head><script>function f() {}</script><script>function f() {}</script></head><html></html>";975 var blocks = Finder.findScriptBlocks(text);976 assert.equal(blocks.length, 2, "Should have found two script blocks");977 assert.equal(blocks[0].offset, 29);978 assert.equal(blocks[0].text, 'function f() {}');979 assert.equal(blocks[1].offset, 61);980 assert.equal(blocks[1].text, 'function f() {}');981 });982 983 /**984 * Tests the support for finding script blocks in HTML985 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=430299986 */987 it('test_findScriptBlockMulti2', function() {988 var text = "<!DOCTYPE html><head><scrIpt>function f() {}</script><scRipt>function f() {}</script></head><html></html>";989 var blocks = Finder.findScriptBlocks(text);990 assert.equal(blocks.length, 2, "Should have found two script blocks");991 assert.equal(blocks[0].offset, 29);992 assert.equal(blocks[0].text, 'function f() {}');993 assert.equal(blocks[1].offset, 61);994 assert.equal(blocks[1].text, 'function f() {}');995 });996 997 /**998 * Tests the support for finding script blocks in HTML999 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=4302991000 */1001 it('test_findScriptBlockMulti3', function() {1002 var text = "<!DOCTYPE html><head><scripT>function f() {}</scriPt><scRipt>function f() {}</Script></head><html></html>";1003 var blocks = Finder.findScriptBlocks(text);1004 assert.equal(blocks.length, 2, "Should have found two script blocks");1005 assert.equal(blocks[0].offset, 29);1006 assert.equal(blocks[0].text, 'function f() {}');1007 assert.equal(blocks[1].offset, 61);1008 assert.equal(blocks[1].text, 'function f() {}');1009 });1010 1011 /**1012 * Tests the support for finding script blocks in HTML1013 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=4302991014 */1015 it('test_findScriptBlockMulti4', function() {1016 var text = "<!DOCTYPE html><head><script >function f() {}</script><script >function f() {}</script></head><html></html>";1017 var blocks = Finder.findScriptBlocks(text);1018 assert.equal(blocks.length, 2, "Should have found two script blocks");1019 assert.equal(blocks[0].offset, 30);1020 assert.equal(blocks[0].text, 'function f() {}');1021 assert.equal(blocks[1].offset, 64);1022 assert.equal(blocks[1].text, 'function f() {}');1023 });1024 1025 /**1026 * Tests the support for finding script blocks in HTML1027 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=4302991028 */1029 it('test_findScriptBlockMultiWithOffset1', function() {1030 var text = "<!DOCTYPE html><head><script >function f() {}</script><script >function f() {}</script></head><html></html>";1031 var blocks = Finder.findScriptBlocks(text, 39);1032 assert.equal(blocks.length, 1, "Should have found one script block");1033 assert.equal(blocks[0].offset, 30);1034 assert.equal(blocks[0].text, 'function f() {}');1035 });1036 /**1037 * Tests the support for finding script blocks in HTML1038 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=4302991039 */1040 it('test_findScriptBlockMultiWithOffset2', function() {1041 var text = "<!DOCTYPE html><head><script >function f() {}</script><script >function f() {}</script></head><html></html>";1042 var blocks = Finder.findScriptBlocks(text, 71);1043 assert.equal(blocks.length, 1, "Should have found one script block");1044 assert.equal(blocks[0].offset, 64);1045 assert.equal(blocks[0].text, 'function f() {}');1046 });1047 1048 /**1049 * Tests the support for finding script blocks in HTML1050 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=4302991051 */1052 it('test_findScriptBlockWithOffset1', function() {1053 var text = "<!DOCTYPE html><head><script >function f() {}</script></head><html></html>";1054 var blocks = Finder.findScriptBlocks(text, 39);1055 assert.equal(blocks.length, 1, "Should have found one script block");1056 assert.equal(blocks[0].offset, 30);1057 assert.equal(blocks[0].text, 'function f() {}');1058 });1059 1060 /**1061 * Tests the support for finding script blocks in HTML with postamble text1062 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=4332631063 */1064 it('test_findScriptBlockWithSpacePostamble1', function() {1065 var text = "<!DOCTYPE html><head><script type='javascript'>function f() {}</script></head><html></html>";1066 var blocks = Finder.findScriptBlocks(text, 48);1067 assert.equal(blocks.length, 1, "Should have found one script block");1068 assert.equal(blocks[0].offset, 47);1069 assert.equal(blocks[0].text, 'function f() {}');1070 });1071 1072 /**1073 * Tests the support for finding script blocks in HTML with postamble text1074 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=4332631075 */1076 it('test_findScriptBlockWithSpacePostamble2', function() {1077 var text = "<!DOCTYPE html><head><script type=javascript >function f() {}</script></head><html></html>";1078 var blocks = Finder.findScriptBlocks(text, 48);1079 assert.equal(blocks.length, 1, "Should have found one script block");1080 assert.equal(blocks[0].offset, 47);1081 assert.equal(blocks[0].text, 'function f() {}');1082 });1083 1084 /**1085 * Tests the support for finding script blocks in HTML with postamble text1086 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=4332631087 */1088 it('test_findScriptBlockWithSpacePostamble3', function() {1089 var text = "<!DOCTYPE html><head><script source=foo bar >function f() {}</script></head><html></html>";1090 var blocks = Finder.findScriptBlocks(text, 47);1091 assert.equal(blocks.length, 1, "Should have found one script block");1092 assert.equal(blocks[0].offset, 46);1093 assert.equal(blocks[0].text, 'function f() {}');1094 });1095 1096 /**1097 * Tests the support for finding script blocks in HTML with postamble text1098 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=4332631099 */1100 it('test_findScriptBlockWithSpacePostamble4', function() {1101 var text = "<!DOCTYPE html><head><script source=foo bar >function f() {}</script type='javascript' ></head><html></html>";1102 var blocks = Finder.findScriptBlocks(text, 47);1103 assert.equal(blocks.length, 1, "Should have found one script block");1104 assert.equal(blocks[0].offset, 46);1105 assert.equal(blocks[0].text, 'function f() {}');1106 });1107 1108 /**1109 * Tests the support for finding script blocks in HTML with postamble text1110 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=4332631111 */1112 it('test_findScriptBlockWithSpacePostamble5', function() {1113 var text = "<!DOCTYPE html><head><script source=foo bar >function f() {}</script type=javascript ></head><html></html>";1114 var blocks = Finder.findScriptBlocks(text, 47);1115 assert.equal(blocks.length, 1, "Should have found one script block");1116 assert.equal(blocks[0].offset, 46);1117 assert.equal(blocks[0].text, 'function f() {}');1118 });1119 1120 /**1121 * Tests the support for finding script blocks in HTML with postamble text1122 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=4332631123 */1124 it('test_findScriptBlockWithSpacePostamble6', function() {1125 var text = "<!DOCTYPE html><head><script source=foo bar >function f() {}</script type= javas cript ></head><html></html>";1126 var blocks = Finder.findScriptBlocks(text, 47);1127 assert.equal(blocks.length, 1, "Should have found one script block");1128 assert.equal(blocks[0].offset, 46);1129 assert.equal(blocks[0].text, 'function f() {}');1130 });1131 1132 /**1133 * Tests the support for finding script blocks in HTML with postamble text1134 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=4332631135 */1136 it('test_findScriptBlockWithSpacePostamble7', function() {1137 var text = "<!DOCTYPE html><head>< script source=foo bar >function f() {}</script type= javas cript ></head><html></html>";1138 var blocks = Finder.findScriptBlocks(text, 48);1139 assert.equal(blocks.length, 1, "Should have found one script block");1140 assert.equal(blocks[0].offset, 47);1141 assert.equal(blocks[0].text, 'function f() {}');1142 });1143 1144 /**1145 * Tests the support for finding script blocks in HTML with postamble text1146 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=4332631147 */1148 it('test_findScriptBlockWithSpacePostamble8', function() {1149 var text = "<!DOCTYPE html><head>< scrIpt source=foo bar >function f() {}</script type= javas cript ></head><html></html>";1150 var blocks = Finder.findScriptBlocks(text, 50);1151 assert.equal(blocks.length, 1, "Should have found one script block");1152 assert.equal(blocks[0].offset, 49);1153 assert.equal(blocks[0].text, 'function f() {}');1154 });1155 1156 /**1157 * Tests the support for finding script blocks in HTML with postamble text1158 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=4332631159 */1160 it('test_findScriptBlockWithSpacePostamble9', function() {1161 var text = "<!DOCTYPE html><head><script source=foo bar >function f() {}< /scrIpt type= javas cript ></head><html></html>";1162 var blocks = Finder.findScriptBlocks(text, 47);1163 assert.equal(blocks.length, 1, "Should have found one script block");1164 assert.equal(blocks[0].offset, 46);1165 assert.equal(blocks[0].text, 'function f() {}');1166 });1167 1168 /**1169 * Tests the support for finding script blocks in HTML with postamble text1170 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=4332631171 */1172 it('test_findNoScriptBlockWithSpacePostamble1', function() {1173 var text = "<!DOCTYPE html><head><script <source=foo bar >function f() {}</script type= javas cript ></head><html></html>";1174 var blocks = Finder.findScriptBlocks(text, 39);1175 assert.equal(blocks.length, 0, "Should not have found any script blocks");1176 });1177 1178 /**1179 * Tests the support for finding script blocks in HTML with postamble text1180 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=4332631181 */1182 it('test_findNoScriptBlockWithSpacePostamble2', function() {1183 var text = "<!DOCTYPE html><head><script source=foo bar > source='js'>function f() {}</script type= javas cript ></head><html></html>";1184 var blocks = Finder.findScriptBlocks(text, 39);1185 assert.equal(blocks.length, 0, "Should not have found any script blocks");1186 });1187 });...

Full Screen

Full Screen

select.spec.js

Source:select.spec.js Github

copy

Full Screen

...82 }83 expect(error).to.equal(1)84 })85 it('[1.2]组件初始化后,input会显示ngModel的相应内容', () => {86 expect(finder.find('input')[0].value).to.be.equal('beijing');87 })88 })89 describe('[2]测试组件', () => {90 describe('[2.1]组件无数据时展示', () => {91 it('[2.1.1]dropdown里内容应该为无数据', () => {92 $rootScope.model = {};93 element = $compile('<f-select ng-model="model"></f-select>')($rootScope);94 $rootScope.$digest();95 let dropDownEmpty = new ElementFinder(element).dropDownEmpty();96 expect(dropDownEmpty.html()).to.be.equal('无数据');97 });98 });99 describe('[2.2]测试组件默认数据渲染', () => {100 beforeEach(() => {101 $rootScope.city = {};102 $rootScope.data = mockData.getData(false);103 element = $compile('<f-select data="data" ng-model="city"></f-select>')($rootScope);104 finder = new ElementFinder(element);105 $rootScope.$digest();106 })107 it('[2.2.1]测试readonly属性', () => {108 expect(finder.find('input')[0].getAttribute('readonly')).to.equal('readonly');109 var elementRemote = $compile('<f-select is-remote="true" ng-model="city" remote-method="getData($value)"></f-select>')($rootScope);110 expect(new ElementFinder(elementRemote).find('input')[0].getAttribute('readonly')).to.equal(null)111 })112 it('[2.2.2]传入的data的长度,等于页面渲染出来的items 长度', () => {113 let items = finder.items();114 expect(items.length).to.equal($rootScope.data.length);115 });116 it('[2.2.3]默认状态之下(点击之前),dropdown是关闭着的(非打开状态)', () => {117 expect(finder.find('.f-select').hasClass('active')).to.be.false;118 });119 it('[2.2.4]点击input框时,dropdown打开,点击空白处,dropdown关闭', () => {120 finder.find('.f-input').triggerHandler('click');121 expect(finder.find('.f-select').hasClass('active')).to.be.true;122 angular.element(document).triggerHandler('click');123 expect(finder.find('.f-select').hasClass('active')).to.be.false;124 })125 it('[2.2.5]点击input框时,dropdown打开,选择item,高亮item', () => {126 let index = 2;127 let items = finder.items();128 finder.find('.f-input').triggerHandler('click');129 expect(finder.find('.f-select').hasClass('active')).to.be.true;130 let activeItem = angular.element(items[index]);131 activeItem.triggerHandler('click');132 //高亮item133 expect(activeItem.hasClass('active')).to.be.true;134 })135 it('[2.2.6]可以设置ngModel的值,来改变view', () => {136 /**137 * 模拟打开,并且选中一个选项138 */139 let index = 2;140 let items = finder.items();141 finder.find('.f-input').triggerHandler('click');142 expect(finder.find('.f-select').hasClass('active')).to.be.true;143 let activeItem = angular.element(items[index]);144 activeItem.triggerHandler('click');145 /**146 * 选中一个“上海周浦万达广场”147 */148 expect(finder.find('.f-input_inner').val()).to.equal($rootScope.data[index].name);149 /**150 * 设置city.id =1001, name=北京通州万达广场;151 */152 $rootScope.city = $rootScope.data[0];153 $rootScope.$digest()154 /**155 * 期望UI展示的结果是 北京通州广场156 */157 expect(finder.find('.f-input_inner').val()).to.equal($rootScope.data[0].name);158 });159 })160 describe('[2.3]测试group组件', () => {161 beforeEach(inject(() => {162 $rootScope.city = {};163 $rootScope.groupData = mockData.getData(true);164 element = $compile('<f-select data="groupData" is-group="true" ng-model="city"></f-select>')($rootScope);165 finder = new ElementFinder(element);166 $rootScope.$digest();167 }))168 it('[2.3.1]测试组件is-group属性,应该生成group-title', () => {169 let groupTitle = finder.groupTitle();170 expect(groupTitle.length).to.equal($rootScope.groupData.length);171 });172 /** angular 1.5.x browserTrigger 版本不支持浏览器 bubble,无法测试该功能。后议。 173 it('group组件,展开的时候点击group-title 不应该被关闭',inject(($document)=>{174 //加到document里175 angular.element($document[0].body).append(element);176 //点击input 展开177 finder.find('.f-input').triggerHandler('click');178 expect(finder.find('.f-select').hasClass('active')).to.be.true;179 })) */180 })181 describe('[2.4]测试远程异步获取数据的方式,', () => {182 beforeEach(inject(($timeout) => {183 $rootScope.city = {};184 $rootScope.getData = ($value) => {185 let data = mockData.getData(false);186 let deferred = q.defer();187 let returnData = data.filter((d) => {188 return d.name.indexOf($value) > -1;189 })190 /**191 * 远程请求,延迟100ms192 */193 $timeout(function () {194 deferred.resolve(returnData);195 }, 100)196 return deferred.promise;197 }198 element = $compile('<f-select is-remote="true" ng-model="city" remote-method="getData($value)"></f-select>')($rootScope);199 $rootScope.$digest();200 finder = new ElementFinder(element);201 }))202 it('[2.4.1]点击的数据是从remoteMethod获取', inject(($timeout) => {203 finder.find('.f-input').triggerHandler('click');204 $timeout.flush();205 let items = finder.items();206 expect(items.length).to.equal(mockData.getData(false).length);207 }))208 it('[2.4.2]输入值,并触发onChange, 结果值回根据输入值filter', inject(($timeout) => {209 finder.find('.f-input_inner').val('上海');210 finder.find('.f-input_inner').triggerHandler('change');211 $timeout.flush();212 let items = finder.items();213 expect(items.length).to.equal(2);214 }))215 /**216 * https://github.com/ffan-fe/fancyui/issues/43217 */218 it('[2.4.3]输入无结果并且失焦时,input应该显示的是ngModel的值,而并非输入的值', inject(($timeout) => {219 finder.find('.f-input').triggerHandler('click');220 finder.find('.f-input_inner').val('test');221 finder.find('.f-input_inner').triggerHandler('change');222 $timeout.flush();223 angular.element(document).triggerHandler('click');224 expect(finder.find('input')[0].value).not.to.be.equal('test');225 }))226 /**227 * 解决issue:远程数据异步时,会先展示empty状态228 */229 it('[2.4.4]点击获取数据时,直到remoteMethod数据返回时,才打开dropdown', inject(($timeout) => {230 finder.find('.f-input').triggerHandler('click');231 expect(finder.find('.f-select').hasClass('active')).to.be.false;232 let dropDown = finder.dropDown();233 expect(dropDown).be.empty;234 expect(finder.items().length).to.be.equal(0);235 $timeout.flush()236 expect(finder.items().length).to.be.equal(5);237 expect(finder.find('.f-select').hasClass('active')).to.be.true;238 }))239 it('[2.4.5]每次change值的时候,都重新打开drowDown', inject(($timeout) => {240 let selectElement = finder.find('.f-select');241 /**242 * 随便输入一个值,期望的结果是打开菜单.243 */244 finder.find('.f-input_inner').val('希望结果是空的');245 finder.find('.f-input_inner').triggerHandler('change');246 /**247 * 因为是异步数据,所以在flush之前,菜单依然是关闭着的(数据还没回来)248 */249 expect(selectElement.hasClass('active')).to.be.false;250 $timeout.flush();251 /**252 * 异步数据回来之后,应该打开菜单253 */254 expect(selectElement.hasClass('active')).to.be.true;255 /**256 * 点击组件,会再次关闭菜单257 */258 finder.find('.f-input').triggerHandler('click');259 expect(selectElement.hasClass('active')).to.be.false;260 /**261 * 此时再改变输入值,获取结果的时候应该自动打开菜单262 */263 finder.find('.f-input_inner').val('上海');264 finder.find('.f-input_inner').triggerHandler('change');265 $timeout.flush();266 expect(selectElement.hasClass('active')).to.be.true;267 }))268 it('[2.4.6]选中items不应该被高亮', inject(($timeout) => {269 finder.find('.f-input_inner').val('上海');270 finder.find('.f-input_inner').triggerHandler('change');271 $timeout.flush();272 let items = finder.items();273 let activeItem = angular.element(items[0]);274 activeItem.triggerHandler('click');275 expect(activeItem.hasClass('active')).to.be.false;276 }));277 /**278 * dissMissHanlder行为要在remoteMethod数据返回之后绑定279 */280 it('[2.4.7]快速点击两次click,等数据返回之后点击document click,仍然可以顺利关闭', inject(($timeout) => {281 finder.find('.f-input').triggerHandler('click');282 finder.find('.f-input').triggerHandler('click');283 $timeout.flush();284 expect(finder.find('.f-select').hasClass('active')).to.be.true;285 angular.element(document).triggerHandler('click');286 expect(finder.find('.f-select').hasClass('active')).to.be.false;287 }))288 it('[2.4.8]给一个尚未填充数据的remote组件设置ngModel,应该有效',()=>{289 $rootScope.city = mockData.getData(false)[0];290 $rootScope.$digest();291 expect(finder.find('.f-input_inner').val()).to.equal($rootScope.city.name); 292 })293 })294 describe('[2.5]测试 is-multiple', () => {295 let finder;296 beforeEach((inject($document => {297 $rootScope.data = new MockData().getData(false);298 $rootScope.city = {};299 element = $compile('<f-select data="data" ng-models="city" is-multiple="true" ></f-select>')($rootScope);300 finder = new ElementFinder(element);301 angular.element($document[0].body).append(element);302 $rootScope.$digest();303 })))304 it('[2.5.1]页面上应该有f-select_tags元素', () => {305 expect(finder.find('.f-select_tags').length > 0).to.be.true;306 })307 it('[2.5.2]f-select元素应该有class multiple', () => {308 expect(finder.find('.f-select').hasClass('multiple')).to.be.true;309 })310 it('[2.5.3]当点击标签区域(f-select_tags)时,聚焦输入框,并且打开菜单', () => {311 finder.find('.f-select_tags').triggerHandler('click');312 expect(angular.element(document.activeElement).hasClass('f-select_input')).to.be.true;313 expect(finder.find('.f-select').hasClass('active')).to.be.true;314 })315 })316 describe('[2.6]测试 allow-create', () => {317 let finder;318 beforeEach(() => {319 $rootScope.data = new MockData().getData(false);320 $rootScope.city = {};321 element = $compile('<f-select data="data" ng-models="city" allow-create="true" is-multiple="true" ></f-select>')($rootScope);322 finder = new ElementFinder(element);323 $rootScope.$digest();324 })325 it('[2.6.1]输入不存在的值,列表长度应为1,并且可添加', inject(($timeout) => {326 let inputValue = '2222222';327 finder.find('.f-input').triggerHandler('click');328 finder.find('.f-select_input').val(inputValue);329 finder.find('.f-select_input').triggerHandler('change');330 expect(finder.find('.f-select-dropdown_item').length).to.equal(1);331 angular.element(finder.find('.f-select-dropdown_item')[0]).triggerHandler('click');332 $timeout.flush();333 expect($rootScope.city[0].name).to.be.equal(inputValue);334 }))335 })336 describe ('[2.7]测试 is-disabled',()=>{337 let finder;338 beforeEach(() => {339 $rootScope.data = new MockData().getData(false);340 $rootScope.city = $rootScope.data[0];341 element = $compile('<f-select data="data" ng-model="city" is-disabled="true" ></f-select>')($rootScope);342 finder = new ElementFinder(element);343 $rootScope.$digest();344 })345 it('禁用不可点击',()=>{346 finder.find('.f-input').triggerHandler('click');347 expect(finder.find('.f-select').hasClass('active')).to.be.false;348 })349 })350 });351 describe('[3]测试directive', () => {352 describe('[3.1]测试calculate-style', () => {353 let finder;354 beforeEach(inject(($timeout, $document) => {355 $rootScope.data = new MockData().getData(false);356 $rootScope.city = {};357 element = $compile('<f-select data="data" ng-models="city" is-multiple="true" ></f-select>')($rootScope);358 finder = new ElementFinder(element);359 angular.element($document[0].body).append(element);360 $rootScope.$digest();361 $timeout.flush();362 $rootScope.$digest();363 }))364 it('[3.1.1]当is-multiple时,自动计算input框的max-width', () => {365 expect(finder.find('.f-select_tags')[0].style.maxWidth).to.not.be.empty;366 });367 it('[3.1.2]当选中多个item时,高度在增加', inject($timeout => {368 finder.find('.f-input').triggerHandler('click');369 let height = finder.find('.f-input input')[0].clientHeight;370 angular.element(finder.find('.f-select-dropdown_item')[0]).triggerHandler('click');371 $timeout.flush();372 angular.element(finder.find('.f-select-dropdown_item')[1]).triggerHandler('click');373 $timeout.flush();374 angular.element(finder.find('.f-select-dropdown_item')[2]).triggerHandler('click');375 $timeout.flush();376 expect(finder.find('.f-input input')[0].clientHeight > height).to.be.true;377 }))378 })379 })...

Full Screen

Full Screen

threshold-finder_test.js

Source:threshold-finder_test.js Github

copy

Full Screen

1"use strict";2const expect = require("chai").expect;3const LightnessFinder = require("../lib/threshold-finder").LightnessFinder;4const BrightnessFinder = require("../lib/threshold-finder").BrightnessFinder;5const Checker = require("../lib/contrast-checker").ContrastChecker;6const Calc = require("../lib/color-contrast-calc").ColorContrastCalc;7const higherLuminanceThan = (mainRgb, otherRgb) => {8 const mainLum = Checker.relativeLuminance(mainRgb);9 const otherLum = Checker.relativeLuminance(otherRgb);10 return mainLum > otherLum;11};12describe("LightnessFinder", function() {13 const orange = Calc.colorFrom("orange").rgb;14 const blueviolet = Calc.colorFrom("blueviolet").rgb;15 const blue = Calc.colorFrom("blue").rgb;16 const black = Calc.colorFrom("black").rgb;17 const white = Calc.colorFrom("white").rgb;18 const darkgreen = Calc.colorFrom("darkgreen").rgb;19 const green = Calc.colorFrom("green").rgb;20 const springgreen = Calc.colorFrom("springgreen").rgb;21 const mintcream = Calc.colorFrom("mintcream").rgb;22 const yellow = Calc.colorFrom("yellow").rgb;23 const fuchsia = Calc.colorFrom("fuchsia").rgb;24 const azure = Calc.colorFrom("azure").rgb;25 describe("binarySearchWidth", function() {26 it("expects to return a smaller value for each iteration", function() {27 let ds = [];28 for (let d of LightnessFinder.binarySearchWidth(100, 1)) {29 ds.push(d);30 }31 expect(ds).to.deep.equal([50, 25, 12.5, 6.25, 3.125, 1.5625]);32 });33 });34 describe("find", function() {35 context("when the required level is A", function() {36 it("expects to return a darker color when azure is passed to fuchsia", function() {37 const newRgb = LightnessFinder.find(fuchsia, azure, "A");38 const ratio = Checker.contrastRatio(fuchsia, newRgb);39 expect(higherLuminanceThan(azure, fuchsia)).to.be.true;40 expect(higherLuminanceThan(azure, newRgb)).to.be.true;41 expect(ratio).to.be.above(3.0);42 expect(ratio).to.be.closeTo(3.0, 0.5);43 expect(newRgb).to.deep.equal([233, 255, 255]);44 });45 it("expects to return a lighter green when both colors are darkgreen", function() {46 const contrast_with_white = Checker.contrastRatio(darkgreen, white);47 const contrast_with_black = Checker.contrastRatio(darkgreen, black);48 const newRgb = LightnessFinder.find(darkgreen, darkgreen, "A");49 const ratio = Checker.contrastRatio(darkgreen, newRgb);50 expect(Checker.isLightColor(darkgreen)).to.be.false;51 expect(contrast_with_white).to.be.greaterThan(contrast_with_black);52 expect(higherLuminanceThan(newRgb, darkgreen)).to.be.true;53 expect(ratio).to.be.above(3.0);54 expect(ratio).to.be.closeTo(3.0, 0.1);55 expect(newRgb).to.deep.equal([0, 192, 0]);56 });57 });58 context("when the required level is AA", function() {59 it("expects to return a darker orange when orange is passed to white", function() {60 const newRgb = LightnessFinder.find(white, orange, "AA");61 const ratio = Checker.contrastRatio(white, newRgb);62 expect(ratio).to.be.above(4.5);63 expect(ratio).to.be.closeTo(4.5, 0.1);64 expect(newRgb).to.deep.equal([165, 106, 0]);65 });66 it("expects to return a darker green when green is passed to white", function() {67 const newRgb = LightnessFinder.find(white, green, "AA");68 const ratio = Checker.contrastRatio(white, newRgb);69 expect(ratio).to.be.above(4.5);70 expect(ratio).to.be.closeTo(4.5, 0.1);71 expect(newRgb).to.deep.equal([0, 138, 0]);72 });73 it("expects to return a lighter orange when orange is passed to blueviolet", function() {74 const newRgb = LightnessFinder.find(blueviolet, orange, "AA");75 const ratio = Checker.contrastRatio(blueviolet, newRgb);76 expect(ratio).to.be.above(4.5);77 expect(ratio).to.be.closeTo(4.5, 0.1);78 expect(newRgb).to.deep.equal([255, 220, 154]);79 });80 it("expects to return a darker green when both colors are springgreen", function() {81 const contrast_with_white = Checker.contrastRatio(springgreen, white);82 const contrast_with_black = Checker.contrastRatio(springgreen, black);83 const newRgb = LightnessFinder.find(springgreen, springgreen, "AA");84 const ratio = Checker.contrastRatio(springgreen, newRgb);85 expect(Checker.isLightColor(springgreen)).to.be.true;86 expect(contrast_with_white).to.be.lessThan(contrast_with_black);87 expect(higherLuminanceThan(newRgb, springgreen)).to.be.false;88 expect(ratio).to.be.above(4.5);89 expect(ratio).to.be.closeTo(4.5, 0.1);90 expect(newRgb).to.deep.equal([0, 114, 57]);91 });92 it("expects to return white when yellow is passed to orange", function() {93 const newRgb = LightnessFinder.find(orange, yellow, "AA");94 const ratio = Checker.contrastRatio(orange, newRgb);95 expect(ratio).to.be.lessThan(4.5);96 expect(newRgb).to.deep.equal(white);97 });98 it("expects to return white when mintcream is passed to yellow", function() {99 const newRgb = LightnessFinder.find(yellow, mintcream, "AA");100 const ratio = Checker.contrastRatio(yellow, newRgb);101 expect(ratio).to.be.lessThan(4.5);102 expect(newRgb).to.deep.equal(white);103 });104 });105 context("when the required level is AAA", function() {106 it("expects to return a darker orange when orange is passed to white", function() {107 const newRgb = LightnessFinder.find(white, green, "AAA");108 const ratio = Checker.contrastRatio(white, newRgb);109 expect(ratio).to.be.above(7.0);110 expect(ratio).to.be.closeTo(7.0, 0.1);111 expect(newRgb).to.deep.equal([0, 104, 0]);112 });113 it("expects to return a darker green when green is passed to white", function() {114 const newRgb = LightnessFinder.find(white, orange, "AAA");115 const ratio = Checker.contrastRatio(white, newRgb);116 expect(ratio).to.be.above(7.0);117 expect(ratio).to.be.closeTo(7.0, 0.1);118 expect(newRgb).to.deep.equal([123, 80, 0]);119 });120 it("expects to return black when blue is passed to green", function() {121 const newRgb = LightnessFinder.find(green, blue, "AA");122 const ratio = Checker.contrastRatio(green, newRgb);123 expect(ratio).to.be.lessThan(7.0);124 expect(newRgb).to.deep.equal(black);125 });126 });127 context("when the required level is specified by a ratio", function() {128 it("expects to return a darker orange when orange is passed to white", function() {129 const newRgb = LightnessFinder.find(white, orange, 6.5);130 const ratio = Checker.contrastRatio(white, newRgb);131 expect(ratio).to.be.above(6.5);132 expect(ratio).to.be.closeTo(6.5, 0.1);133 expect(newRgb).to.deep.equal([130, 84, 0]);134 });135 it("expects to return a darker green when green is passed to white", function() {136 const newRgb = LightnessFinder.find(white, green, 6.5);137 const ratio = Checker.contrastRatio(white, newRgb);138 expect(ratio).to.be.above(6.5);139 expect(ratio).to.be.closeTo(6.5, 0.1);140 expect(newRgb).to.deep.equal([0, 110, 0]);141 });142 it("expects to return black when blue is passed to green", function() {143 const newRgb = LightnessFinder.find(green, blue, 6.5);144 const ratio = Checker.contrastRatio(green, newRgb);145 expect(ratio).to.be.lessThan(6.5);146 expect(newRgb).to.deep.equal(black);147 });148 });149 });150});151describe("BrightnessFinder", function() {152 const orange = Calc.colorFrom("orange").rgb;153 const blueviolet = Calc.colorFrom("blueviolet").rgb;154 const blue = Calc.colorFrom("blue").rgb;155 const brown = Calc.colorFrom("brown").rgb;156 const black = Calc.colorFrom("black").rgb;157 const white = Calc.colorFrom("white").rgb;158 const darkgreen = Calc.colorFrom("darkgreen").rgb;159 const green = Calc.colorFrom("green").rgb;160 const mintcream = Calc.colorFrom("mintcream").rgb;161 const yellow = Calc.colorFrom("yellow").rgb;162 const springgreen = Calc.colorFrom("springgreen").rgb;163 const fuchsia = Calc.colorFrom("fuchsia").rgb;164 const azure = Calc.colorFrom("azure").rgb;165 describe("find", function() {166 it("expects to return a darker orange if orange is passed", function() {167 const threshold = BrightnessFinder.find(orange, orange);168 const ratio = Checker.contrastRatio(orange, threshold);169 expect(Checker.contrastRatio(orange, orange)).to.be.below(4.5);170 expect(ratio).to.be.above(4.5);171 expect(ratio).to.be.closeTo(4.5, 0.5);172 expect(threshold).to.deep.equal([103, 66, 0]);173 });174 it("expects to return a more darker color when a darker color is passed", function() {175 const threshold = BrightnessFinder.find(orange, blueviolet);176 const ratio = Checker.contrastRatio(orange, threshold);177 expect(Checker.contrastRatio(orange, blueviolet)).to.be.below(4.5);178 expect(ratio).to.be.above(4.5);179 expect(ratio).to.be.closeTo(4.5, 0.5);180 expect(threshold).to.deep.equal([103, 32, 169]);181 });182 it("expects to return a brighter orange if blueviolet is combined with orange", function() {183 const threshold = BrightnessFinder.find(blueviolet, orange);184 const ratio = Checker.contrastRatio(blueviolet, threshold);185 expect(Checker.contrastRatio(blueviolet, orange)).to.be.below(4.5);186 expect(ratio).to.be.above(4.5);187 expect(ratio).to.be.closeTo(4.5, 0.5);188 expect(threshold).to.deep.equal([255, 224, 0]);189 });190 it("expects to return a brigher color if brown is passed to brown", function() {191 const threshold = BrightnessFinder.find(brown, brown);192 const ratio = Checker.contrastRatio(brown, threshold);193 expect(Checker.contrastRatio(brown, black)).to.be.below(4.5);194 expect(ratio).to.be.above(4.5);195 expect(ratio).to.be.closeTo(4.5, 0.5);196 expect(threshold).to.deep.equal([255, 190, 190]);197 });198 it("expects to return a darker green if darkgreen is passed to white - AA", function() {199 const threshold = BrightnessFinder.find(white, darkgreen);200 const ratio = Checker.contrastRatio(white, threshold);201 expect(ratio).to.be.above(4.5);202 expect(ratio).to.be.closeTo(4.5, 0.5);203 });204 it("expects to return a darker green if darkgreen is passed to white - AA", function() {205 const threshold = BrightnessFinder.find(white, darkgreen, "AAA");206 const ratio = Checker.contrastRatio(white, threshold);207 expect(ratio).to.be.above(7.0);208 expect(ratio).to.be.closeTo(7.0, 0.5);209 });210 it("expects to return black for AAA if blue is passed to green", function() {211 const newColor = BrightnessFinder.find(green, blue, "AAA");212 expect(Checker.contrastRatio(newColor, black)).to.be.below(7.0);213 expect(newColor).to.deep.equal(black);214 });215 it("expects to return white when mintcream is passed to yellow", function() {216 const a = BrightnessFinder.find(yellow, mintcream, "A");217 const aa = BrightnessFinder.find(yellow, mintcream, "AA");218 const aaa = BrightnessFinder.find(yellow, mintcream, "AAA");219 expect(BrightnessFinder.calcUpperRatioLimit(mintcream)).to.equal(105);220 expect(a).to.deep.equal(white);221 expect(aa).to.deep.equal(white);222 expect(aaa).to.deep.equal(white);223 });224 it("expects to return darker green when springgreen is passed to green", function() {225 const newColor = BrightnessFinder.find(green, springgreen, "A");226 const springgreenLum = Checker.relativeLuminance(springgreen);227 const newLum = Checker.relativeLuminance(newColor);228 const ratio = Checker.contrastRatio(green, newColor);229 expect(springgreenLum).to.be.greaterThan(newLum);230 expect(ratio).to.be.above(3.0);231 expect(ratio).to.be.closeTo(3.0, 0.5);232 });233 it("expects to return a darker color when azure is passed to fuchsia", function() {234 const threshold = BrightnessFinder.find(fuchsia, azure, "A");235 const azureLum = Checker.relativeLuminance(azure);236 const newLum = Checker.relativeLuminance(threshold);237 const ratio = Checker.contrastRatio(fuchsia, threshold);238 expect(azureLum).to.be.greaterThan(newLum);239 expect(ratio).to.be.above(3.0);240 expect(ratio).to.be.closeTo(3.0, 0.5);241 });242 });243 describe("calcUpperRatioLimit", function() {244 it("expects to return 155 for orange", function() {245 expect(BrightnessFinder.calcUpperRatioLimit(orange)).to.equal(155);246 });247 it("expects to return 594 for blueviolet", function() {248 expect(BrightnessFinder.calcUpperRatioLimit(blueviolet)).to.equal(594);249 });250 it("expects to return 100 for black", function() {251 expect(BrightnessFinder.calcUpperRatioLimit(black)).to.equal(100);252 });253 });...

Full Screen

Full Screen

checkout.js

Source:checkout.js Github

copy

Full Screen

1///////////////////////////2// checkout 3///////////////////////////4$(function() { 5 if ($('.checkout').length > 0) { 6 showHideDelivery(true); //check shipping radios on load7 $('#ship_to_billing,#ship_to_delivery').click(function() {8 showHideDelivery(false);9 });10 ////////////////////////////11 //start Address Finder12 ////////////////////////////13 //enable finder section if we have JS (otherwise show vanilla form) // - find a better way to hand n number of these14 $('.js-co-badd-finder').removeClass('hidden');15 $('.js-co-badd-fields').addClass('hidden'); 16 $('.js-co-badd-manual').click(function() { // If enter address manually is clicked17 var addressFinder = $(this).closest("*[data-address-type]");18 var addressFields = addressFinder.data("address-fields");19 var addressFieldPrefix = addressFinder.data("address-field-prefix");20 //$('.js-co-badd-finder').addClass('hidden');21 addressFinder.find('.js-co-badd-wrapper').addClass('disable');22 $('.' + addressFields).removeClass('hidden');23 addressFinder.find('.js-co-badd-manual').addClass('hidden');24 addressFinder.find('.js-co-badd-search-again').removeClass('hidden');25 addressFinder.find('#b_pc_lookup').val('');26 addressFinder.find("#b_pc_lookup").attr('disabled', 'disabled');27 28 $("#checkout").validate().resetForm();29 30 });31 $('.js-co-badd-search-again').click(function() { // If search again is clicked32 var addressFinder = $(this).closest("*[data-address-type]");33 var addressFields = addressFinder.data("address-fields");34 var addressFieldPrefix = addressFinder.data("address-field-prefix");35 $('.' + addressFields).addClass('hidden');36 //$('.js-co-badd-finder').addClass('hidden');37 addressFinder.find('.js-co-badd-wrapper').removeClass('disable');38 addressFinder.find('.js-co-badd-manual').removeClass('hidden');39 addressFinder.find('.js-co-badd-search-again').addClass('hidden');40 addressFinder.find('.js-co-badd-results').addClass('hidden');41 addressFinder.find("#b_pc_lookup").removeAttr('disabled')42 resetFields(addressFieldPrefix);43 });44 $('.js-co-badd-pc-lookup').click(function() { //if find address button is clicked45 //get the context for the address lookup that was clicked46 var addressFinder = $(this).closest("*[data-address-type]");47 var addressType = addressFinder.data("address-type");48 var postCode = addressFinder.find('#b_pc_lookup').val().trim();49 50 addressFinder.find('.co_address-no-results').addClass('hidden');51 addressFinder.find('.js-co-badd-results').addClass('js-co-badd-results--loading'); //show a loading bar52 $.ajaxSetup({53 cache: false54 });55 $.ajax({56 url: 'address-list',57 method:'post',58 data: { postCode: postCode }59 }).done(function (data) {60 if (data) {61 addressFinder.find('.js-co-badd-results').removeClass('hidden');62 63 addressFinder.find('.js-co-badd-results').removeClass('js-co-badd-results--loading');64 if (data.AddressData.length > 0) {65 //remove any previous entries66 addressFinder.find('.js-co-badd-results-list option[value!=""]').remove();67 //write the new ones out68 $.each(data.AddressData, function (i, item) {69 addressFinder.find('.js-co-badd-results-list').append($('<option>').text(item.AddressText).attr('value', item.AddressKey));70 });71 //reset text72 addressFinder.find('.js-co-badd-manual').text('Enter address manually');73 }74 else {75 noResults();76 }77 } else {78 //no results returns - allow the user to enter an address manually79 addressFinder.find('.js-co-badd-fields').removeClass('hidden');80 }81 }).fail(function () {82 noResults(addressFinder);83 });84 resetFields();85 }); 86 $('.js-co-badd-results-list').change(function () { //is select menu option is changed87 var addressFinder = $(this).closest("*[data-address-type]");88 var addressFields = addressFinder.data("address-fields");89 var addressFieldPrefix = addressFinder.data("address-field-prefix");90 91 //disable look-up92 addressFinder.find('.js-co-badd-wrapper').addClass('disable');93 addressFinder.find('.js-co-badd-manual').addClass('hidden');94 addressFinder.find('.js-co-badd-search-again').removeClass('hidden');95 //show address form96 $('.' + addressFields).removeClass('hidden');97 //get the addressKey98 var addressKey = addressFinder.find('.js-co-badd-results-list option:selected').val();99 //get the address details object using the key100 $.ajaxSetup({101 cache: false102 });103 $.ajax({104 url: 'address-details',105 method: 'post',106 data: { addressKey: addressKey }107 }).done(function (data) {108 if (data) {109 resetFields(addressFieldPrefix);110 $('#' + addressFieldPrefix + 'company').val(data.Company);111 $('#' + addressFieldPrefix + 'street').val(data.Address1);112 $('#' + addressFieldPrefix + 'street1').val(data.Address2);113 $('#' + addressFieldPrefix + 'city').val(data.City);114 $('#' + addressFieldPrefix + 'state').val(data.State);115 $('#' + addressFieldPrefix + 'zip').val(data.ZipCode);116 }117 });118 });119 function resetFields(fieldPrefix) {120 $('#' + fieldPrefix + 'street').val('');121 $('#' + fieldPrefix + 'street1').val('');122 $('#' + fieldPrefix + 'city').val('');123 $('#' + fieldPrefix + 'state').val('');124 $('#' + fieldPrefix + 'zip').val('');125 }126 function noResults(addressFinder) {127 addressFinder.find('.js-co-badd-results').removeClass('js-co-badd-results--loading'); //show a loading bar128 //remove any previous entries and hide the list129 addressFinder.find('.js-co-badd-results-list option[value!=""]').remove();130 addressFinder.find('.js-co-badd-results').addClass('hidden');131 //no results returns - allow the user to enter an address manually132 addressFinder.find('.js-co-badd-fields').removeClass('hidden');133 addressFinder.find('.co_address-no-results').removeClass('hidden');134 addressFinder.find('.js-co-badd-manual').removeClass('hidden');135 }136 ////////////////////////////137 //end Address recall138 ////////////////////////////139 }140 $('.form-textfield,.form-selectmenu').focus(function() {141 //$(this).parent().parent().find('.form-label').addClass('active');142 resetActiveRows();143 $(this).closest('.form-row').addClass('form-row--active');144 });145 $('.form-textfield,.form-selectmenu').blur(function() {146 resetActiveRows();147 });148 function resetActiveRows() {149 $('.form-row').removeClass('form-row--active');150 }151 152 function showHideDelivery(init) {153 //reset labels154 $('.js-shipping-label').removeClass('active');155 //check active radio156 if ($('#ship_to_billing').is(':checked')) {157 if (init) { //initial page load so hide rather than slide up158 $('.js-delivery-wrapper').hide();159 } else {160 $('.js-delivery-wrapper').slideUp();161 }162 //set label status163 $('#ship_to_billing').parent().parent().find('.js-shipping-label').addClass('active');164 } 165 if ($('#ship_to_delivery').is(':checked')) {166 $('.js-delivery-wrapper').slideDown();167 //set label status168 $('#ship_to_delivery').parent().parent().find('.js-shipping-label').addClass('active');169 } 170 //console.log(shipToBilling + " | " + shipToDelivery);171 }172 //SIMS ON PLACE ORDER PAGE173 if ($('.place-order-sims').length > 0) { 174 $('.js-bconfig__tariff-select').each(function( index ) { //iterate through each item175 176 var sku = $(this).data('contract-id');177 $(this).html('<a href="/uk/basket/add?i=' + sku + '">Select Tariff ></a>');178 });179 }180 //END SIMS ON PLACE ORDER PAGE...

Full Screen

Full Screen

110_dom_1c_match.t.js

Source:110_dom_1c_match.t.js Github

copy

Full Screen

1StartTest(function(t) {2 3 var finder = new Ariadne.DomQueryFinder()4 5 var body6 7 t.beforeEach(function () {8 body = document.body9 10 body.className = ''11 body.parentNode.clasName = ''12 })13 14 var unique = function (selector) { return body.querySelectorAll(selector)[ 0 ] }15 t.it('basic query', function (t) {16 t.isDeeply(finder.findQueries(body), [ 'body' ])17 t.isDeeply(finder.findQueries(body.parentNode), [ 'html' ])18 19 body.innerHTML = 20 '<a>' +21 '<b>' +22 '<c></c>' +23 '</b>' +24 '</a>'25 26 t.isDeeply(finder.findQueries(unique('c')), [ 'c' ])27 t.isDeeply(finder.findQueries(unique('b')), [ 'b' ])28 t.isDeeply(finder.findQueries(unique('a')), [ 'a' ])29 30 t.isDeeply(finder.findQueries(unique('b'), unique('a')), [ 'b' ])31 })32 33 34 t.it('basic query', function (t) {35 36 body.innerHTML = 37 '<a>' +38 '<b>' +39 '<c></c>' +40 '</b>' +41 '</a>' +42 '<b>' +43 '<c></c>' +44 '</b>'45 46 t.isDeeply(finder.findQueries(unique('a c')), [ 'a c' ])47 48 t.isDeeply(finder.findQueries(unique('a c'), unique('a')), [ 'c' ])49 50 body.innerHTML = 51 '<a>' +52 '<b>' +53 '<c>' +54 '<d></d>' +55 '</c>' +56 '<d></d>' +57 '</b>' +58 '<b></b>' +59 '</a>' +60 '<c>' +61 '<d></d>' +62 '</c>' +63 '<b>' +64 '<d></d>' +65 '</b>'66 67 t.isDeeply(finder.findQueries(unique('a c d')), [ 'a c d' ])68 69 body.innerHTML = 70 '<a>' +71 '<b>' +72 '<c id="c1"></c>' +73 '</b>' +74 '</a>' +75 '<b>' +76 '<c></c>' +77 '</b>'78 79 t.isDeeply(finder.findQueries(unique('#c1')), [ '#c1' ])80 })81 82 83 t.it('Mandatory Id', function (t) {84 body.innerHTML = 85 '<a>' +86 '<b id="b1">' +87 '<c></c>' +88 '</b>' +89 '</a>'90 91 t.isDeeply(finder.findQueries(unique('c')), [ '#b1 c' ])92 93 var finder2 = new Ariadne.DomQueryFinder({ enableMandatoryId : false })94 95 t.isDeeply(finder2.findQueries(unique('c')), [ 'c' ])96 })97 98 99 t.it('Correct path weight even if some segment is re-used in the query because of the partial match', function (t) {100 101 body.innerHTML = 102 '<a>' +103 '<b>' +104 '<c>' +105 '<d></d>' +106 '</c>' +107 '<d></d>' +108 '</b>' +109 '<c></c>' +110 '</a>' +111 '<a></a>' +112 '<b></b>' +113 '<c></c>'114 115 var queries = finder.findQueries(unique('c d'), null, { detailed : true })116 117 t.isDeeply(queries, [ t.any() ], "One query")118 119 t.isDeeply(queries[ 0 ].query, 'c d', "Correct query found")120 121 t.isDeeply(queries[ 0 ].weight, 2000, "Correct path weight")122 }) 123 124 125 t.it('Non-unique results filtering', function (t) {126 127 body.innerHTML = 128 '<c class="z">' +129 '<d>' +130 '<e class="z">' +131 '<f target=true></f>' +132 '</e>' +133 '<e>' +134 '<f></f>' +135 '</e>' +136 '<e>' +137 '<f></f>' +138 '</e>' +139 '</d>' +140 '</c>' +141 '<d></d>' +142 '<c></c>'143 144 var queries = finder.findQueries(unique('[target=true]'))145 146 // should not find naive ".z f" query147 t.isDeeply(queries, [ 'e.z f' ], 'Correct queries found')148 }) 149 150 151 t.it('Non-unique results filtering', function (t) {152 body.innerHTML = 153 '<e>' +154 '<e>' +155 '<f target=true></f>' +156 '</e>' +157 '<e>' +158 '<f></f>' +159 '</e>' +160 '<e>' +161 '<f></f>' +162 '</e>' +163 '</e>'164 165 var queries = finder.findQueries(unique('[target=true]'))166 167 t.isDeeply(queries, [ 'e e:nth-of-type(1) f' ], 'Correct queries found')168 })169 170 t.it('Non-unique results filtering', function (t) {171 body.innerHTML = 172 '<e class="z">' +173 '<e class="z">' +174 '<f target=true></f>' +175 '</e>' +176 '<e>' +177 '<f></f>' +178 '</e>' +179 '<e>' +180 '<f></f>' +181 '</e>' +182 '</e>'183 184 var queries = finder.findQueries(unique('[target=true]'))185 186 t.isDeeply(queries, [ '.z .z f', 'e .z f' ], 'Correct queries found')187 }) 188 189 190 t.it('Should prefer just a tag name for <body> and <html>', function (t) {191 body.innerHTML = ''192 body.className = 'z'193 194 var queries = finder.findQueries(document.body)195 196 t.isDeeply(queries, [ 'body' ], 'Correct queries found')197 })198 199 200 t.it('Should prefer just a tag name for <body> and <html>', function (t) {201 body.innerHTML = ''202 body.parentNode.className = 'z'203 204 var queries = finder.findQueries(document.documentElement)205 206 t.isDeeply(queries, [ 'html' ], 'Correct queries found')207 }) ...

Full Screen

Full Screen

finder.js

Source:finder.js Github

copy

Full Screen

1describe('RcFinder', function () {2 var RcFinder = require('../');3 var path = require('path');4 var expect = require('expect.js');5 var fs = require('fs');6 var fixtures = {7 root: path.resolve(__dirname, 'fixtures/foo/foo/foo/foo/'),8 json: path.resolve(__dirname, 'fixtures/foo/foo/bar.json'),9 text: path.resolve(__dirname, 'fixtures/foo/foo/.baz'),10 checkCount: 4,11 config: {12 baz: 'bog'13 }14 };15 it('looks for config files', function () {16 var rcFinder = new RcFinder('bar.json');17 var config = rcFinder.find(path.resolve(__dirname, 'fixtures/foo/foo/foo/foo/'));18 expect(config).to.eql(fixtures.config);19 });20 it('can be run async by using a callback', function (done) {21 var rcFinder = new RcFinder('bar.json');22 var count = 0;23 rcFinder.find(fixtures.root, function (err, config) {24 expect(count).to.eql(1); // prove async25 expect(config).to.eql(fixtures.config);26 done();27 });28 count ++;29 });30 it('caches config objects', function () {31 var count = 0;32 var rcFinder = new RcFinder('bar.json', {33 loader: function (path) {34 count ++;35 return JSON.parse(fs.readFileSync(path));36 }37 });38 var config = rcFinder.find(fixtures.root);39 expect(count).to.eql(1);40 expect(config).to.eql(fixtures.config);41 // it should only be loaded once42 config = rcFinder.find(fixtures.root);43 expect(count).to.eql(1);44 expect(config).to.eql(fixtures.config);45 });46 it('caches config objects from async calls', function (done) {47 var count = 0;48 var rcFinder = new RcFinder('bar.json', {49 loader: function (path, cb) {50 count ++;51 fs.readFile(path, function (err, file) {52 var config;53 if (!err) {54 try {55 config = JSON.parse(file);56 } catch(e) {57 err = cb(new Error(path + ' is not valid JSON: ' + e.message));58 }59 }60 cb(err, config);61 });62 }63 });64 rcFinder.find(fixtures.root, function (err, config) {65 expect(count).to.eql(1);66 expect(config).to.eql(fixtures.config);67 rcFinder.find(fixtures.root, function (err, config) {68 expect(count).to.eql(1);69 expect(config).to.eql(fixtures.config);70 done();71 });72 });73 });74 it('throws an error when called without a callback by an async loader is in use', function () {75 expect(function () {76 var rcFinder = new RcFinder('bar.json', {77 loader: 'async'78 });79 rcFinder.find(fixtures.root);80 }).to.throwException();81 });82 it('properly caches sync lookups when a config file is not found', function () {83 var count = 0;84 var expectedCount = fixtures.checkCount;85 var rcFinder = new RcFinder('bar.json', {86 _syncCheck: function (path) {87 count++;88 return fs.existsSync(path);89 }90 });91 expect(count).to.eql(0);92 rcFinder.find(fixtures.root);93 expect(count).to.eql(expectedCount);94 rcFinder.find(fixtures.root);95 // it should still equal previous count96 expect(count).to.eql(expectedCount);97 });98 it('properly caches async lookups when a config file is not found', function () {99 var count = 0;100 var expectedCount = fixtures.checkCount;101 var rcFinder = new RcFinder('bar.json', {102 _asyncCheck: function (path, cb) {103 count++;104 fs.stat(path, function (err, exists) {105 if (err && err.code !== 'ENOENT') return cb(err);106 cb(void 0, !err);107 });108 }109 });110 expect(count).to.eql(0);111 rcFinder.find(fixtures.root, function (err, config) {112 expect(count).to.eql(expectedCount);113 rcFinder.find(fixtures.root, function (err, config) {114 // it should still equal previous count115 expect(count).to.eql(expectedCount);116 });117 });118 });119 it('throws errors from loader when loading and calling synchronously', function() {120 var rcFinder = new RcFinder('bar.json', {121 loader: function(path) {122 return JSON.parse('{not really json');123 }124 });125 expect(function () {126 var config = rcFinder.find(fixtures.root);127 }).to.throwException('Unexpected token n');128 });129 it('propagates errors from loader when loading synchronously and calling async', function(done) {130 var rcFinder = new RcFinder('bar.json', {131 loader: function(path) {132 return JSON.parse('{not really json');133 }134 });135 rcFinder.find(fixtures.root, function(err, config) {136 expect(err).to.be.an(Error);137 expect(err.message).to.be('Unexpected token n');138 expect(config).to.be(undefined);139 done();140 });141 });142 it('propagates error from loader when loading asynchronously', function(done) {143 var rcFinder = new RcFinder('bar.json', {144 loader: function(path, callback) {145 process.nextTick(function() {146 var err, body;147 try {148 body = JSON.parse('{not really json');149 } catch (e) {150 err = e;151 } finally {152 callback(err, body);153 }154 });155 }156 });157 rcFinder.find(fixtures.root, function(err, config) {158 expect(err).to.be.an(Error);159 expect(err.message).to.be('Unexpected token n');160 expect(config).to.be(undefined);161 done();162 });163 });...

Full Screen

Full Screen

anagram_finder_spec.js

Source:anagram_finder_spec.js Github

copy

Full Screen

1const assert = require('assert');2const AnagramFinder = require('./anagram_finder.js');3describe('AnagramFinder', function () {4 it('should be able to detect an anagram', function () {5 const anagramFinder = new AnagramFinder('act');6 assert.deepStrictEqual(anagramFinder.findAnagrams(['cat', 'dog']), ['cat']);7 });8 it('should be able to detect a non-anagram', function () {9 const anagramFinder = new AnagramFinder('potato');10 assert.deepStrictEqual(anagramFinder.findAnagrams(['tomato']), []);11 })12 it('should not detect words with too few letters as an anagram', function () {13 const anagramFinder = new AnagramFinder('good');14 assert.deepStrictEqual(anagramFinder.findAnagrams(['dog']), []);15 });16 it('should not detect words with too many letters as an anagram', function () {17 const anagramFinder = new AnagramFinder('dog');18 assert.deepStrictEqual(anagramFinder.findAnagrams(['good']), []);19 });20 it('should detect an anagram regardless of case', function () {21 const anagramFinder = new AnagramFinder('DeduCTionS');22 assert.deepStrictEqual(anagramFinder.findAnagrams(['DiscOUnteD']), ['DiscOUnteD']);23 });24 it('should not detect a word as it\'s own anagram', function () {25 const anagramFinder = new AnagramFinder('javascript');26 assert.deepStrictEqual(anagramFinder.findAnagrams(['javascript']), []);27 });28 it('should not detect an empty string as an anagram', function () {29 const anagramFinder = new AnagramFinder('word');30 assert.deepStrictEqual(anagramFinder.findAnagrams(['']), []);31 });...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1const propFinder = require("../index");2const object = {3 value: 1,4 two: {5 value: 2,6 three: {7 value: "this is a string",8 four: {9 value: [0, 1, 2, 3, [[0, 1, 2, 3], [3.14, 3.1416]]]10 }11 }12 }13};14//#region empty check15// propFinder.find()16// propFinder.find(object)17//#endregion empty check18//#region type check19// propFinder.find('', null)20// propFinder.find(false, false)21//#endregion type check22//#region falsy check23// propFinder.find(null, '')24//#endregion falsy check25const result1 = propFinder.find(object, "three");26console.log(result1);27const result2 = propFinder.findAll(object, "value", { array: true });28console.log(result2);29const result3 = propFinder.findAll(object, "value");...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { AppiumDriver } = require('appium-base-driver');2const { AndroidUiautomator2Driver } = require('appium-uiautomator2-driver');3const { AndroidDriver } = require('appium-android-driver');4const { UiAutomator2Server } = require('appium-uiautomator2-server');5const { server } = require('appium-base-driver');6const { androidHelpers } = require('appium-android-driver');7const { util } = require('appium-support');8const adb = androidHelpers.createADB();9const uiautomator2Server = new UiAutomator2Server(adb);10const driver = new AndroidUiautomator2Driver({adb, uiautomator2Server});11const appiumDriver = new AppiumDriver({driver});12appiumDriver.find(locator).then((el) => {13console.log('Element found', el);14});15const { AppiumDriver } = require('appium-base-driver');16const { AndroidUiautomator2Driver } = require('appium-uiautomator2-driver');17const { AndroidDriver } = require('appium-android-driver');18const { UiAutomator2Server } = require('appium-uiautomator2-server');19const { server } = require('appium-base-driver');20const { androidHelpers } = require('appium-android-driver');21const { util } = require('appium-support');22const adb = androidHelpers.createADB();23const uiautomator2Server = new UiAutomator2Server(adb);24const driver = new AndroidDriver({adb});25const appiumDriver = new AppiumDriver({driver});26appiumDriver.find(locator).then((el) => {27console.log('Element found', el);28});

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = new webdriver.Builder()2 .withCapabilities({3 })4 .build();5driver.findElement(By.name("Animation")).click();6driver.findElement(By.name("Bouncing Balls")).click();7driver.quit();8driver.context("WEBVIEW_com.google.android.apps.maps");

Full Screen

Using AI Code Generation

copy

Full Screen

1const { BaseDriver } = require('appium-base-driver');2const { AppiumDriver } = require('appium-android-driver');3const { AndroidUiautomator2Driver } = require('appium-uiautomator2-driver');4const driver = new AndroidUiautomator2Driver();5driver.find('accessibility id', 'someId');6const { BaseDriver } = require('appium-base-driver');7const { AndroidUiautomator2Driver } = require('appium-uiautomator2-driver');8const driver = new AndroidUiautomator2Driver();9driver.find('accessibility id', 'someId');10const { BaseDriver } = require('appium-base-driver');11const { AndroidUiautomator2Driver } = require('appium-uiautomator2-driver');12const driver = new AndroidUiautomator2Driver();13driver.find('accessibility id', 'someId');14const { BaseDriver } = require('appium-base-driver');15const { AndroidUiautomator2Driver } = require('appium-uiautomator2-driver');16const driver = new AndroidUiautomator2Driver();17driver.find('accessibility id', 'someId');18const { BaseDriver } = require('appium-base-driver');19const { AndroidUiautomator2Driver } = require('appium-uiautomator2-driver');20const driver = new AndroidUiautomator2Driver();21driver.find('accessibility id', 'someId');22const { BaseDriver } = require('appium-base-driver');23const { AndroidUiautomator2Driver } = require('appium-uiautomator2-driver');24const driver = new AndroidUiautomator2Driver();

Full Screen

Using AI Code Generation

copy

Full Screen

1var appiumBaseDriver = require('appium-base-driver');2var finder = new appiumBaseDriver.Finder();3var driver = new appiumBaseDriver.AppiumDriver();4driver.find = finder.find;5 console.log(element);6});7var appiumBaseDriver = require('appium-base-driver');8var driver = new appiumBaseDriver.AppiumDriver();9 console.log(element);10});

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 Appium Base Driver 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