|
| 1 | +//------------------------------------------------------------------------------ |
| 2 | +// Requirements |
| 3 | +//------------------------------------------------------------------------------ |
| 4 | + |
| 5 | +const rule = require('../../../lib/rules/template-no-invalid-link-title'); |
| 6 | +const RuleTester = require('eslint').RuleTester; |
| 7 | + |
| 8 | +const ruleTester = new RuleTester({ |
| 9 | + parser: require.resolve('ember-eslint-parser'), |
| 10 | + parserOptions: { ecmaVersion: 2022, sourceType: 'module' }, |
| 11 | +}); |
| 12 | + |
| 13 | +ruleTester.run('template-no-invalid-link-title', rule, { |
| 14 | + valid: [ |
| 15 | + '<template><a href="/page" title="More information about page">Page</a></template>', |
| 16 | + '<template><a href="/page">Page</a></template>', |
| 17 | + '<template><a href="/page" title={{dynamic}}>Page</a></template>', |
| 18 | + |
| 19 | + '<template><a href="https://myurl.com">Click here to read more about this amazing adventure</a></template>', |
| 20 | + '<template>{{#link-to}} click here to read more about our company{{/link-to}}</template>', |
| 21 | + '<template><LinkTo>Read more about ways semantic HTML can make your code more accessible.</LinkTo></template>', |
| 22 | + '<template><LinkTo>{{foo}} more</LinkTo></template>', |
| 23 | + '<template><LinkTo @title="nice title">Something else</LinkTo></template>', |
| 24 | + '<template><LinkTo title="great titles!">Whatever, don\'t judge me</LinkTo></template>', |
| 25 | + '<template><LinkTo title="Download the video">Download</LinkTo></template>', |
| 26 | + '<template><a href="https://myurl.com" title="New to Ember? Read the full tutorial for the best experience">Read the Tutorial</a></template>', |
| 27 | + '<template><a href="./whatever" title={{foo}}>Hello!</a></template>', |
| 28 | + '<template>{{#link-to "blah.route.here" title="awesome title"}}Some thing else here{{/link-to}}</template>', |
| 29 | + `<template> |
| 30 | + <LinkTo @query={{hash page=@pagination.prevPage}} local-class="prev" @rel="prev" @title="previous page" data-test-pagination-prev> |
| 31 | + {{svg-jar "left-pag"}} |
| 32 | + </LinkTo> |
| 33 | + </template>`, |
| 34 | + ], |
| 35 | + invalid: [ |
| 36 | + { |
| 37 | + code: '<template><a href="/page" title="">Page</a></template>', |
| 38 | + output: null, |
| 39 | + errors: [{ messageId: 'noInvalidLinkTitle' }], |
| 40 | + }, |
| 41 | + { |
| 42 | + code: '<template><a href="/page" title="Page">Page</a></template>', |
| 43 | + output: null, |
| 44 | + errors: [{ messageId: 'noInvalidLinkTitle' }], |
| 45 | + }, |
| 46 | + |
| 47 | + { |
| 48 | + code: '<template><a href="https://myurl.com" title="read the tutorial">Read the Tutorial</a></template>', |
| 49 | + output: null, |
| 50 | + errors: [{ messageId: 'noInvalidLinkTitle' }], |
| 51 | + }, |
| 52 | + { |
| 53 | + code: '<template><LinkTo title="quickstart">Quickstart</LinkTo></template>', |
| 54 | + output: null, |
| 55 | + errors: [{ messageId: 'noInvalidLinkTitle' }], |
| 56 | + }, |
| 57 | + { |
| 58 | + code: '<template><LinkTo @title="foo" title="blah">derp</LinkTo></template>', |
| 59 | + output: null, |
| 60 | + errors: [{ messageId: 'noInvalidLinkTitle' }], |
| 61 | + }, |
| 62 | + { |
| 63 | + code: '<template>{{#link-to title="Do the things"}}Do the things{{/link-to}}</template>', |
| 64 | + output: null, |
| 65 | + errors: [{ messageId: 'noInvalidLinkTitle' }], |
| 66 | + }, |
| 67 | + { |
| 68 | + code: '<template><LinkTo @route="some.route" @title="Do the things">Do the things</LinkTo></template>', |
| 69 | + output: null, |
| 70 | + errors: [{ messageId: 'noInvalidLinkTitle' }], |
| 71 | + }, |
| 72 | + { |
| 73 | + code: '<template><a href="https://myurl.com" title="Tutorial">Read the Tutorial</a></template>', |
| 74 | + output: null, |
| 75 | + errors: [{ messageId: 'noInvalidLinkTitle' }], |
| 76 | + }, |
| 77 | + { |
| 78 | + code: '<template><LinkTo title="Tutorial">Read the Tutorial</LinkTo></template>', |
| 79 | + output: null, |
| 80 | + errors: [{ messageId: 'noInvalidLinkTitle' }], |
| 81 | + }, |
| 82 | + { |
| 83 | + code: '<template>{{#link-to title="Tutorial"}}Read the Tutorial{{/link-to}}</template>', |
| 84 | + output: null, |
| 85 | + errors: [{ messageId: 'noInvalidLinkTitle' }], |
| 86 | + }, |
| 87 | + ], |
| 88 | +}); |
| 89 | + |
| 90 | +const hbsRuleTester = new RuleTester({ |
| 91 | + parser: require.resolve('ember-eslint-parser/hbs'), |
| 92 | + parserOptions: { |
| 93 | + ecmaVersion: 2022, |
| 94 | + sourceType: 'module', |
| 95 | + }, |
| 96 | +}); |
| 97 | + |
| 98 | +hbsRuleTester.run('template-no-invalid-link-title', rule, { |
| 99 | + valid: [ |
| 100 | + '<a href="https://myurl.com">Click here to read more about this amazing adventure</a>', |
| 101 | + '{{#link-to}} click here to read more about our company{{/link-to}}', |
| 102 | + '<LinkTo>Read more about ways semantic HTML can make your code more accessible.</LinkTo>', |
| 103 | + '<LinkTo>{{foo}} more</LinkTo>', |
| 104 | + '<LinkTo @title="nice title">Something else</LinkTo>', |
| 105 | + '<LinkTo title="great titles!">Whatever, don\'t judge me</LinkTo>', |
| 106 | + '<LinkTo title="Download the video">Download</LinkTo>', |
| 107 | + '<a href="https://myurl.com" title="New to Ember? Read the full tutorial for the best experience">Read the Tutorial</a>', |
| 108 | + '<a href="./whatever" title={{foo}}>Hello!</a>', |
| 109 | + '{{#link-to "blah.route.here" title="awesome title"}}Some thing else here{{/link-to}}', |
| 110 | + ` |
| 111 | + <LinkTo @query={{hash page=@pagination.prevPage}} local-class="prev" @rel="prev" @title="previous page" data-test-pagination-prev> |
| 112 | + {{svg-jar "left-pag"}} |
| 113 | + </LinkTo> |
| 114 | + `, |
| 115 | + '<template><LinkTo>Quickstart</LinkTo></template>', |
| 116 | + ], |
| 117 | + invalid: [ |
| 118 | + { |
| 119 | + code: '<a href="https://myurl.com" title="read the tutorial">Read the Tutorial</a>', |
| 120 | + output: null, |
| 121 | + errors: [{ message: 'Link title attribute should not be the same as link text or empty.' }], |
| 122 | + }, |
| 123 | + { |
| 124 | + code: '<LinkTo title="quickstart">Quickstart</LinkTo>', |
| 125 | + output: null, |
| 126 | + errors: [{ message: 'Link title attribute should not be the same as link text or empty.' }], |
| 127 | + }, |
| 128 | + { |
| 129 | + code: '<LinkTo @title="foo" title="blah">derp</LinkTo>', |
| 130 | + output: null, |
| 131 | + errors: [{ message: 'Link title attribute should not be the same as link text or empty.' }], |
| 132 | + }, |
| 133 | + { |
| 134 | + code: '{{#link-to title="Do the things"}}Do the things{{/link-to}}', |
| 135 | + output: null, |
| 136 | + errors: [{ message: 'Link title attribute should not be the same as link text or empty.' }], |
| 137 | + }, |
| 138 | + { |
| 139 | + code: '<LinkTo @route="some.route" @title="Do the things">Do the things</LinkTo>', |
| 140 | + output: null, |
| 141 | + errors: [{ message: 'Link title attribute should not be the same as link text or empty.' }], |
| 142 | + }, |
| 143 | + { |
| 144 | + code: '<a href="https://myurl.com" title="Tutorial">Read the Tutorial</a>', |
| 145 | + output: null, |
| 146 | + errors: [{ message: 'Link title attribute should not be the same as link text or empty.' }], |
| 147 | + }, |
| 148 | + { |
| 149 | + code: '<LinkTo title="Tutorial">Read the Tutorial</LinkTo>', |
| 150 | + output: null, |
| 151 | + errors: [{ message: 'Link title attribute should not be the same as link text or empty.' }], |
| 152 | + }, |
| 153 | + { |
| 154 | + code: '{{#link-to title="Tutorial"}}Read the Tutorial{{/link-to}}', |
| 155 | + output: null, |
| 156 | + errors: [{ message: 'Link title attribute should not be the same as link text or empty.' }], |
| 157 | + }, |
| 158 | + ], |
| 159 | +}); |
0 commit comments