|
| 1 | +'use strict' |
| 2 | + |
| 3 | +var rule = require('../../lib/rules/no-repetitive-locators') |
| 4 | +var RuleTester = require('eslint').RuleTester |
| 5 | +var toCode = require('../lib/join-multiline-code') |
| 6 | + |
| 7 | +var eslintTester = new RuleTester() |
| 8 | + |
| 9 | +eslintTester.run('no-repetitive-locators', rule, { |
| 10 | + valid: [ |
| 11 | + toCode([ |
| 12 | + 'var MyPage = function () {', |
| 13 | + ' this.grids = element.all(by.css(".mygrid"));', |
| 14 | + ' this.firstGrid = this.grids.first();', |
| 15 | + '}' |
| 16 | + ]), |
| 17 | + toCode([ |
| 18 | + 'var MyPage = function () {', |
| 19 | + ' this.parent = $(".container #parent");', |
| 20 | + ' this.child1 = this.parent.$("div:first-of-type");', |
| 21 | + ' this.child2 = this.parent.$("#subcontainer > .add-client");', |
| 22 | + '}' |
| 23 | + ]) |
| 24 | + ], |
| 25 | + |
| 26 | + invalid: [ |
| 27 | + { |
| 28 | + code: toCode([ |
| 29 | + 'var MyPage = function () {', |
| 30 | + ' this.grids = element.all(by.css(".mygrid"));', |
| 31 | + ' this.firstGrid = element.all(by.css(".mygrid")).first();', |
| 32 | + '}' |
| 33 | + ]), |
| 34 | + errors: [ |
| 35 | + { |
| 36 | + message: 'Repetitive locator detected' |
| 37 | + } |
| 38 | + ] |
| 39 | + }, |
| 40 | + { |
| 41 | + code: toCode([ |
| 42 | + 'var MyPage = function () {', |
| 43 | + ' this.grids = $$(".mygrid");', |
| 44 | + ' this.firstGrid = $$(".mygrid").first();', |
| 45 | + '}' |
| 46 | + ]), |
| 47 | + errors: [ |
| 48 | + { |
| 49 | + message: 'Repetitive locator detected' |
| 50 | + } |
| 51 | + ] |
| 52 | + }, |
| 53 | + { |
| 54 | + code: toCode([ |
| 55 | + 'var MyPage = function () {', |
| 56 | + ' this.grids = $$(".mygrid");', |
| 57 | + ' this.firstGrid = $(".mygrid")', |
| 58 | + '}' |
| 59 | + ]), |
| 60 | + errors: [ |
| 61 | + { |
| 62 | + message: 'Repetitive locator detected' |
| 63 | + } |
| 64 | + ] |
| 65 | + }, |
| 66 | + { |
| 67 | + code: toCode([ |
| 68 | + 'var MyPage = function () {', |
| 69 | + ' this.grids = element.all(by.css(".mygrid"));', |
| 70 | + ' this.firstGrid = $(".mygrid")', |
| 71 | + '}' |
| 72 | + ]), |
| 73 | + errors: [ |
| 74 | + { |
| 75 | + message: 'Repetitive locator detected' |
| 76 | + } |
| 77 | + ] |
| 78 | + }, |
| 79 | + { |
| 80 | + code: toCode([ |
| 81 | + 'var MyPage = function () {', |
| 82 | + ' this.grids = $$(".mygrid");', |
| 83 | + ' this.firstGrid = element(by.css(".mygrid"))', |
| 84 | + '}' |
| 85 | + ]), |
| 86 | + errors: [ |
| 87 | + { |
| 88 | + message: 'Repetitive locator detected' |
| 89 | + } |
| 90 | + ] |
| 91 | + }, |
| 92 | + { |
| 93 | + code: toCode([ |
| 94 | + 'var MyPage = function () {', |
| 95 | + ' this.grids = element.all(by.className("test"));', |
| 96 | + ' this.firstGrid = element(by.css(".container")).all(by.className("test")).first()', |
| 97 | + '}' |
| 98 | + ]), |
| 99 | + errors: [ |
| 100 | + { |
| 101 | + message: 'Repetitive locator detected' |
| 102 | + } |
| 103 | + ] |
| 104 | + } |
| 105 | + ] |
| 106 | +}) |
0 commit comments