|
| 1 | +const rule = require('../a11y-tooltip-non-interactive-trigger') |
| 2 | +const {RuleTester} = require('eslint') |
| 3 | + |
| 4 | +const ruleTester = new RuleTester({ |
| 5 | + parserOptions: { |
| 6 | + ecmaVersion: 'latest', |
| 7 | + sourceType: 'module', |
| 8 | + ecmaFeatures: { |
| 9 | + jsx: true |
| 10 | + } |
| 11 | + } |
| 12 | +}) |
| 13 | + |
| 14 | +ruleTester.run('non-interactive-tooltip-trigger', rule, { |
| 15 | + valid: [ |
| 16 | + `import {Tooltip, Button} from '@primer/react'; |
| 17 | + <Tooltip aria-label="Filter vegetarian options" direction="e"> |
| 18 | + <Button>🥦</Button> |
| 19 | + </Tooltip>`, |
| 20 | + |
| 21 | + `import {Tooltip, Button} from '@primer/react'; |
| 22 | + <Tooltip aria-label="Supplementary text" direction="e"> |
| 23 | + <Button>Save</Button> |
| 24 | + </Tooltip>`, |
| 25 | + |
| 26 | + `import {Tooltip, IconButton} from '@primer/react'; |
| 27 | + import {SearchIcon} from '@primer/octicons-react'; |
| 28 | + <Tooltip aria-label="Supplementary text" direction="e"> |
| 29 | + <IconButton icon={SearchIcon} aria-label="Search" /> |
| 30 | + </Tooltip>`, |
| 31 | + |
| 32 | + `import {Tooltip, Button} from '@primer/react'; |
| 33 | + <Tooltip aria-label="Supplementary text" direction="e"> |
| 34 | + <div> |
| 35 | + <Button>Save</Button> |
| 36 | + </div> |
| 37 | + </Tooltip>`, |
| 38 | + |
| 39 | + `import {Tooltip, Button} from '@primer/react'; |
| 40 | + <Tooltip aria-label="Supplementary text" direction="e"> |
| 41 | + <div> |
| 42 | + <a href="https://gthub.com">Save</a> |
| 43 | + </div> |
| 44 | + </Tooltip>`, |
| 45 | + |
| 46 | + `import {Tooltip} from '@primer/react'; |
| 47 | + <Tooltip aria-label="Supplementary text" direction="e"> |
| 48 | + <a href="https://github.com">see commit message</a> |
| 49 | + </Tooltip>`, |
| 50 | + |
| 51 | + `import {Tooltip, Link} from '@primer/react'; |
| 52 | + <Tooltip aria-label="Supplementary text" direction="e"> |
| 53 | + <Link href="https://github.com">Link</Link> |
| 54 | + </Tooltip>` |
| 55 | + ], |
| 56 | + invalid: [ |
| 57 | + { |
| 58 | + code: `import {Tooltip} from '@primer/react';<Tooltip type="description" text="supportive text" direction="e"><button>button1</button><button>button2</button></Tooltip> |
| 59 | + `, |
| 60 | + errors: [ |
| 61 | + { |
| 62 | + messageId: 'singleChild' |
| 63 | + } |
| 64 | + ] |
| 65 | + }, |
| 66 | + { |
| 67 | + code: ` |
| 68 | + import {Tooltip} from '@primer/react'; |
| 69 | + <Tooltip aria-label="Filter vegetarian options" direction="e"> |
| 70 | + <span>non interactive element</span> |
| 71 | + </Tooltip> |
| 72 | + `, |
| 73 | + errors: [ |
| 74 | + { |
| 75 | + messageId: 'nonInteractiveTrigger' |
| 76 | + } |
| 77 | + ] |
| 78 | + }, |
| 79 | + { |
| 80 | + code: ` |
| 81 | + import {Tooltip, Button} from '@primer/react'; |
| 82 | + <Tooltip aria-label="Supplementary text" direction="e"> |
| 83 | + <h1>Save</h1> |
| 84 | + </Tooltip>`, |
| 85 | + errors: [ |
| 86 | + { |
| 87 | + messageId: 'nonInteractiveTrigger' |
| 88 | + } |
| 89 | + ] |
| 90 | + }, |
| 91 | + { |
| 92 | + code: ` |
| 93 | + import {Tooltip} from '@primer/react'; |
| 94 | + <Tooltip aria-label="Supplementary text" direction="e"> |
| 95 | + <a>see commit message</a> |
| 96 | + </Tooltip>`, |
| 97 | + errors: [ |
| 98 | + { |
| 99 | + messageId: 'anchorTagWithoutHref' |
| 100 | + } |
| 101 | + ] |
| 102 | + }, |
| 103 | + { |
| 104 | + code: ` |
| 105 | + import {Tooltip, Link} from '@primer/react'; |
| 106 | + <Tooltip aria-label="Supplementary text" direction="e"> |
| 107 | + <Link>see commit message</Link> |
| 108 | + </Tooltip>`, |
| 109 | + errors: [ |
| 110 | + { |
| 111 | + messageId: 'anchorTagWithoutHref' |
| 112 | + } |
| 113 | + ] |
| 114 | + }, |
| 115 | + { |
| 116 | + code: ` |
| 117 | + import {Tooltip} from '@primer/react'; |
| 118 | + <Tooltip aria-label="Supplementary text" direction="e"> |
| 119 | + <input type="hidden" /> |
| 120 | + </Tooltip>`, |
| 121 | + errors: [ |
| 122 | + { |
| 123 | + messageId: 'hiddenInput' |
| 124 | + } |
| 125 | + ] |
| 126 | + }, |
| 127 | + { |
| 128 | + code: ` |
| 129 | + import {Tooltip, TextInput} from '@primer/react'; |
| 130 | + <Tooltip aria-label="Supplementary text" direction="e"> |
| 131 | + <TextInput type="hidden" aria-label="Zipcode" name="zipcode" placeholder="Zipcode" autoComplete="postal-code" /> |
| 132 | + </Tooltip>`, |
| 133 | + errors: [ |
| 134 | + { |
| 135 | + messageId: 'hiddenInput' |
| 136 | + } |
| 137 | + ] |
| 138 | + }, |
| 139 | + { |
| 140 | + code: ` |
| 141 | + import {Tooltip, Button} from '@primer/react'; |
| 142 | + <Tooltip aria-label="Supplementary text" direction="e"> |
| 143 | + <header> |
| 144 | + <span>Save</span> |
| 145 | + </header> |
| 146 | + </Tooltip>`, |
| 147 | + errors: [ |
| 148 | + { |
| 149 | + messageId: 'nonInteractiveTrigger' |
| 150 | + } |
| 151 | + ] |
| 152 | + }, |
| 153 | + { |
| 154 | + code: `import {Tooltip, Button} from '@primer/react'; |
| 155 | + <Tooltip aria-label="Supplementary text" direction="e"> |
| 156 | + <h1> |
| 157 | + <a>Save</a> |
| 158 | + </h1> |
| 159 | + </Tooltip>`, |
| 160 | + errors: [ |
| 161 | + { |
| 162 | + messageId: 'anchorTagWithoutHref' |
| 163 | + } |
| 164 | + ] |
| 165 | + } |
| 166 | + ] |
| 167 | +}) |
0 commit comments