|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const {RuleTester} = require('eslint') |
| 4 | +const rule = require('../no-deprecated-props') |
| 5 | + |
| 6 | +const ruleTester = new RuleTester({ |
| 7 | + parserOptions: { |
| 8 | + ecmaVersion: 'latest', |
| 9 | + sourceType: 'module', |
| 10 | + ecmaFeatures: { |
| 11 | + jsx: true, |
| 12 | + }, |
| 13 | + }, |
| 14 | +}) |
| 15 | + |
| 16 | +ruleTester.run('no-deprecated-props', rule, { |
| 17 | + valid: [ |
| 18 | + `import {ActionList} from '@primer/react'; |
| 19 | + <ActionList> |
| 20 | + <ActionList.Group> |
| 21 | + <ActionList.GroupHeading as="h3">Group heading 1</ActionList.GroupHeading> |
| 22 | + <ActionList.Item>Item</ActionList.Item> |
| 23 | + </ActionList.Group> |
| 24 | + <ActionList.Group> |
| 25 | + <ActionList.GroupHeading as="h3">Group heading 2</ActionList.GroupHeading> |
| 26 | + <ActionList.Item>Item 2</ActionList.Item> |
| 27 | + </ActionList.Group> |
| 28 | + </ActionList>`, |
| 29 | + `import {ActionList} from '@primer/react'; |
| 30 | + <ActionList> |
| 31 | + <ActionList.Group> |
| 32 | + <ActionList.GroupHeading>Group heading 1</ActionList.GroupHeading> |
| 33 | + <ActionList.Item>Item</ActionList.Item> |
| 34 | + </ActionList.Group> |
| 35 | + <ActionList.Group> |
| 36 | + <ActionList.GroupHeading>Group heading 2</ActionList.GroupHeading> |
| 37 | + <ActionList.Item>Item 2</ActionList.Item> |
| 38 | + </ActionList.Group> |
| 39 | + </ActionList>`, |
| 40 | + `import {ActionList} from '@primer/react'; |
| 41 | + <ActionList> |
| 42 | + <ActionList.Group> |
| 43 | + <ActionList.GroupHeading as="h3">Group heading</ActionList.GroupHeading> |
| 44 | + <ActionList.Item>Item</ActionList.Item> |
| 45 | + </ActionList.Group> |
| 46 | + <ActionList.Item>Item 2</ActionList.Item> |
| 47 | + </ActionList>`, |
| 48 | + `import {ActionList} from '@primer/react'; |
| 49 | + <ActionList role="listbox"> |
| 50 | + <ActionList.Group> |
| 51 | + <ActionList.GroupHeading>Group heading</ActionList.GroupHeading> |
| 52 | + <ActionList.Item>Item</ActionList.Item> |
| 53 | + </ActionList.Group> |
| 54 | + <ActionList.Item>Item 2</ActionList.Item> |
| 55 | + </ActionList>`, |
| 56 | + `import {ActionList} from '@primer/react'; |
| 57 | + <ActionList role="menu"> |
| 58 | + <ActionList.Item>Item</ActionList.Item> |
| 59 | + <ActionList.Group> |
| 60 | + <ActionList.GroupHeading>Group heading</ActionList.GroupHeading> |
| 61 | + <ActionList.Item>Group item</ActionList.Item> |
| 62 | + </ActionList.Group> |
| 63 | + </ActionList>`, |
| 64 | + ], |
| 65 | + invalid: [ |
| 66 | + { |
| 67 | + code: `<ActionList.Group title="Group heading 1"></ActionList.Group>`, |
| 68 | + output: `<ActionList.Group><ActionList.GroupHeading>Group heading 1</ActionList.GroupHeading></ActionList.Group>`, |
| 69 | + errors: [ |
| 70 | + { |
| 71 | + messageId: 'titlePropDeprecated', |
| 72 | + }, |
| 73 | + ], |
| 74 | + }, |
| 75 | + { |
| 76 | + code: `<ActionList.Group title="Group heading 1" sx={{padding: 2}}></ActionList.Group>`, |
| 77 | + output: `<ActionList.Group sx={{padding: 2}}><ActionList.GroupHeading>Group heading 1</ActionList.GroupHeading></ActionList.Group>`, |
| 78 | + errors: [ |
| 79 | + { |
| 80 | + messageId: 'titlePropDeprecated', |
| 81 | + }, |
| 82 | + ], |
| 83 | + }, |
| 84 | + { |
| 85 | + code: `<ActionList.Group variant="filled" title="Group heading 1"></ActionList.Group>`, |
| 86 | + output: `<ActionList.Group variant="filled"><ActionList.GroupHeading>Group heading 1</ActionList.GroupHeading></ActionList.Group>`, |
| 87 | + errors: [ |
| 88 | + { |
| 89 | + messageId: 'titlePropDeprecated', |
| 90 | + }, |
| 91 | + ], |
| 92 | + }, |
| 93 | + { |
| 94 | + code: `<ActionList.Group title={titleVariable}></ActionList.Group>`, |
| 95 | + output: `<ActionList.Group><ActionList.GroupHeading>{titleVariable}</ActionList.GroupHeading></ActionList.Group>`, |
| 96 | + errors: [ |
| 97 | + { |
| 98 | + messageId: 'titlePropDeprecated', |
| 99 | + }, |
| 100 | + ], |
| 101 | + }, |
| 102 | + { |
| 103 | + code: `<ActionList.Group title={'Title'}></ActionList.Group>`, |
| 104 | + output: `<ActionList.Group><ActionList.GroupHeading>{'Title'}</ActionList.GroupHeading></ActionList.Group>`, |
| 105 | + errors: [ |
| 106 | + { |
| 107 | + messageId: 'titlePropDeprecated', |
| 108 | + }, |
| 109 | + ], |
| 110 | + }, |
| 111 | + { |
| 112 | + code: `<ActionList.Group title={condition ? 'Title' : undefined}></ActionList.Group>`, |
| 113 | + output: `<ActionList.Group><ActionList.GroupHeading>{condition ? 'Title' : undefined}</ActionList.GroupHeading></ActionList.Group>`, |
| 114 | + errors: [ |
| 115 | + { |
| 116 | + messageId: 'titlePropDeprecated', |
| 117 | + }, |
| 118 | + ], |
| 119 | + }, |
| 120 | + ], |
| 121 | +}) |
0 commit comments