|
| 1 | +const rule = require('../../../lib/rules/template-no-empty-headings'); |
| 2 | +const RuleTester = require('eslint').RuleTester; |
| 3 | + |
| 4 | +const ruleTester = new RuleTester({ |
| 5 | + parser: require.resolve('ember-eslint-parser'), |
| 6 | + parserOptions: { ecmaVersion: 2022, sourceType: 'module' }, |
| 7 | +}); |
| 8 | + |
| 9 | +ruleTester.run('template-no-empty-headings', rule, { |
| 10 | + valid: [ |
| 11 | + '<template><h1>Title</h1></template>', |
| 12 | + '<template><h2>{{this.title}}</h2></template>', |
| 13 | + '<template><h3><span>Text</span></h3></template>', |
| 14 | + '<template><h4 hidden></h4></template>', |
| 15 | + '<template><h1>Accessible Heading</h1></template>', |
| 16 | + '<template><h1>Accessible Heading</h1></template>', |
| 17 | + '<template><h1 aria-hidden="true">Valid Heading</h1></template>', |
| 18 | + '<template><h1 aria-hidden="true"><span>Valid Heading</span></h1></template>', |
| 19 | + '<template><h1 aria-hidden="false">Accessible Heading</h1></template>', |
| 20 | + '<template><h1 hidden>Valid Heading</h1></template>', |
| 21 | + '<template><h1 hidden><span>Valid Heading</span></h1></template>', |
| 22 | + '<template><h1><span aria-hidden="true">Hidden text</span><span>Visible text</span></h1></template>', |
| 23 | + '<template><h1><span aria-hidden="true">Hidden text</span>Visible text</h1></template>', |
| 24 | + '<template><div role="heading" aria-level="1">Accessible Text</div></template>', |
| 25 | + '<template><div role="heading" aria-level="1"><span>Accessible Text</span></div></template>', |
| 26 | + '<template><div role="heading" aria-level="1"><span aria-hidden="true">Hidden text</span><span>Visible text</span></div></template>', |
| 27 | + '<template><div role="heading" aria-level="1"><span aria-hidden="true">Hidden text</span>Visible text</div></template>', |
| 28 | + '<template><div></div></template>', |
| 29 | + '<template><p></p></template>', |
| 30 | + '<template><span></span></template>', |
| 31 | + '<template><header></header></template>', |
| 32 | + '<template><h2><CustomComponent /></h2></template>', |
| 33 | + '<template><h2>{{@title}}</h2></template>', |
| 34 | + '<template><h2>{{#component}}{{/component}}</h2></template>', |
| 35 | + '<template><h2><span>{{@title}}</span></h2></template>', |
| 36 | + '<template><h2><div><CustomComponent /></div></h2></template>', |
| 37 | + '<template><h2><div></div><CustomComponent /></h2></template>', |
| 38 | + '<template><h2><div><span>{{@title}}</span></div></h2></template>', |
| 39 | + '<template><h2><span>Some text{{@title}}</span></h2></template>', |
| 40 | + '<template><h2><span><div></div>{{@title}}</span></h2></template>', |
| 41 | + ], |
| 42 | + invalid: [ |
| 43 | + { |
| 44 | + code: '<template><h1></h1></template>', |
| 45 | + output: null, |
| 46 | + errors: [{ messageId: 'emptyHeading' }], |
| 47 | + }, |
| 48 | + { |
| 49 | + code: '<template><h2> </h2></template>', |
| 50 | + output: null, |
| 51 | + errors: [{ messageId: 'emptyHeading' }], |
| 52 | + }, |
| 53 | + { |
| 54 | + code: `<template><h1> |
| 55 | + </h1></template>`, |
| 56 | + output: null, |
| 57 | + errors: [{ messageId: 'emptyHeading' }], |
| 58 | + }, |
| 59 | + { |
| 60 | + code: '<template><h1><span></span></h1></template>', |
| 61 | + output: null, |
| 62 | + errors: [{ messageId: 'emptyHeading' }], |
| 63 | + }, |
| 64 | + { |
| 65 | + code: `<template><h1><span> |
| 66 | + </span></h1></template>`, |
| 67 | + output: null, |
| 68 | + errors: [{ messageId: 'emptyHeading' }], |
| 69 | + }, |
| 70 | + { |
| 71 | + code: '<template><h1><div><span></span></div></h1></template>', |
| 72 | + output: null, |
| 73 | + errors: [{ messageId: 'emptyHeading' }], |
| 74 | + }, |
| 75 | + { |
| 76 | + code: '<template><h1><span></span><span></span></h1></template>', |
| 77 | + output: null, |
| 78 | + errors: [{ messageId: 'emptyHeading' }], |
| 79 | + }, |
| 80 | + { |
| 81 | + code: '<template><h1> <div aria-hidden="true">Some hidden text</div></h1></template>', |
| 82 | + output: null, |
| 83 | + errors: [{ messageId: 'emptyHeading' }], |
| 84 | + }, |
| 85 | + { |
| 86 | + code: '<template><h1><span aria-hidden="true">Inaccessible text</span></h1></template>', |
| 87 | + output: null, |
| 88 | + errors: [{ messageId: 'emptyHeading' }], |
| 89 | + }, |
| 90 | + { |
| 91 | + code: '<template><h1><span hidden>Inaccessible text</span></h1></template>', |
| 92 | + output: null, |
| 93 | + errors: [{ messageId: 'emptyHeading' }], |
| 94 | + }, |
| 95 | + { |
| 96 | + code: '<template><h1><span hidden>{{@title}}</span></h1></template>', |
| 97 | + output: null, |
| 98 | + errors: [{ messageId: 'emptyHeading' }], |
| 99 | + }, |
| 100 | + { |
| 101 | + code: '<template><h1><span hidden>{{#component}}Inaccessible text{{/component}}</span></h1></template>', |
| 102 | + output: null, |
| 103 | + errors: [{ messageId: 'emptyHeading' }], |
| 104 | + }, |
| 105 | + { |
| 106 | + code: '<template><h1><span hidden><CustomComponent>Inaccessible text</CustomComponent></span></h1></template>', |
| 107 | + output: null, |
| 108 | + errors: [{ messageId: 'emptyHeading' }], |
| 109 | + }, |
| 110 | + { |
| 111 | + code: '<template><h1><span aria-hidden="true">Hidden text</span><span aria-hidden="true">Hidden text</span></h1></template>', |
| 112 | + output: null, |
| 113 | + errors: [{ messageId: 'emptyHeading' }], |
| 114 | + }, |
| 115 | + { |
| 116 | + code: '<template><div role="heading" aria-level="1"></div></template>', |
| 117 | + output: null, |
| 118 | + errors: [{ messageId: 'emptyHeading' }], |
| 119 | + }, |
| 120 | + { |
| 121 | + code: '<template><div role="heading" aria-level="1"><span aria-hidden="true">Inaccessible text</span></div></template>', |
| 122 | + output: null, |
| 123 | + errors: [{ messageId: 'emptyHeading' }], |
| 124 | + }, |
| 125 | + { |
| 126 | + code: '<template><div role="heading" aria-level="1"><span hidden>Inaccessible text</span></div></template>', |
| 127 | + output: null, |
| 128 | + errors: [{ messageId: 'emptyHeading' }], |
| 129 | + }, |
| 130 | + ], |
| 131 | +}); |
0 commit comments