| 
 | 1 | +'use strict'  | 
 | 2 | + | 
 | 3 | +var rule = require('../../lib/rules/no-repetitive-selectors')  | 
 | 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-selectors', rule, {  | 
 | 10 | +  valid: [  | 
 | 11 | +    toCode([  | 
 | 12 | +      'var MyPage = function () {',  | 
 | 13 | +      '  this.parent = $(".container #parent");',  | 
 | 14 | +      '  this.child1 = this.parent.$("div:first-of-type");',  | 
 | 15 | +      '  this.child2 = this.parent.$("#subcontainer > .add-client");',  | 
 | 16 | +      '}'  | 
 | 17 | +    ]),  | 
 | 18 | +    toCode([  | 
 | 19 | +      'var MyPage = function () {',  | 
 | 20 | +      '  this.elm1 = $(".container #parent");',  | 
 | 21 | +      '  this.elm2 = element(by.css("#parent"));',  | 
 | 22 | +      '}'  | 
 | 23 | +    ]),  | 
 | 24 | +    toCode([  | 
 | 25 | +      'var MyPage = function () {',  | 
 | 26 | +      '  this.elm1 = $(".container > #parent");',  | 
 | 27 | +      '  this.elm2 = element(by.css(".container>#parent"));',  | 
 | 28 | +      '}'  | 
 | 29 | +    ])  | 
 | 30 | +  ],  | 
 | 31 | + | 
 | 32 | +  invalid: [  | 
 | 33 | +    {  | 
 | 34 | +      code: toCode([  | 
 | 35 | +        'var MyPage = function () {',  | 
 | 36 | +        '  this.parent = $(".container");',  | 
 | 37 | +        '  this.child1 = $(".container div:first-of-type");',  | 
 | 38 | +        '}'  | 
 | 39 | +      ]),  | 
 | 40 | +      errors: [  | 
 | 41 | +        {  | 
 | 42 | +          message: 'Repetitive part of a selector detected: ".container"'  | 
 | 43 | +        }  | 
 | 44 | +      ]  | 
 | 45 | +    },  | 
 | 46 | +    {  | 
 | 47 | +      code: toCode([  | 
 | 48 | +        'var MyPage = function () {',  | 
 | 49 | +        '  this.parent = $(".container #parent");',  | 
 | 50 | +        '  this.child1 = $(".container #parent div:first-of-type");',  | 
 | 51 | +        '  this.child2 = $(".container #parent #subcontainer > .add-client");',  | 
 | 52 | +        '}'  | 
 | 53 | +      ]),  | 
 | 54 | +      errors: [  | 
 | 55 | +        {  | 
 | 56 | +          message: 'Repetitive part of a selector detected: ".container #parent"'  | 
 | 57 | +        },  | 
 | 58 | +        {  | 
 | 59 | +          message: 'Repetitive part of a selector detected: ".container #parent"'  | 
 | 60 | +        }  | 
 | 61 | +      ]  | 
 | 62 | +    },  | 
 | 63 | +    {  | 
 | 64 | +      code: toCode([  | 
 | 65 | +        'var MyPage = function () {',  | 
 | 66 | +        '  this.field1 = $(".container #parent div:first-of-type");',  | 
 | 67 | +        '  this.field2 = $(".container div:first-of-type");',  | 
 | 68 | +        '}'  | 
 | 69 | +      ]),  | 
 | 70 | +      errors: [  | 
 | 71 | +        {  | 
 | 72 | +          message: 'Repetitive part of a selector detected: ".container"'  | 
 | 73 | +        }  | 
 | 74 | +      ]  | 
 | 75 | +    },  | 
 | 76 | +    {  | 
 | 77 | +      code: toCode([  | 
 | 78 | +        'var MyPage = function () {',  | 
 | 79 | +        '  this.elm1 = $(".container");',  | 
 | 80 | +        '  this.elm2 = element(by.css(".container"));',  | 
 | 81 | +        '}'  | 
 | 82 | +      ]),  | 
 | 83 | +      errors: [  | 
 | 84 | +        {  | 
 | 85 | +          message: 'Repetitive part of a selector detected: ".container"'  | 
 | 86 | +        }  | 
 | 87 | +      ]  | 
 | 88 | +    }  | 
 | 89 | +  ]  | 
 | 90 | +})  | 
0 commit comments