|
| 1 | +const ruleTester = require("../../ruletester"); |
| 2 | +import * as rule from "./button-support-favorite-variant"; |
| 3 | + |
| 4 | +ruleTester.run("button-support-favorite-variant", rule, { |
| 5 | + valid: [ |
| 6 | + { |
| 7 | + code: `<Button isFavorite={true} />`, |
| 8 | + }, |
| 9 | + { |
| 10 | + code: `<Button isFavorited={true} />`, |
| 11 | + }, |
| 12 | + { |
| 13 | + code: `<Button isFavorite={true} isFavorited={false} />`, |
| 14 | + }, |
| 15 | + { |
| 16 | + code: `import { Button } from '@patternfly/react-core'; <Button>Some text</Button>`, |
| 17 | + }, |
| 18 | + { |
| 19 | + code: `import { Button } from '@patternfly/react-core'; import { SomeIcon } from '@patternfly/react-icons'; <Button><SomeIcon /></Button>`, |
| 20 | + }, |
| 21 | + { |
| 22 | + code: `import { Button } from '@patternfly/react-core'; <Button icon={<SomeIcon />} />`, |
| 23 | + }, |
| 24 | + ], |
| 25 | + invalid: [ |
| 26 | + // Simple case - StarIcon as child |
| 27 | + { |
| 28 | + code: `import { Button } from '@patternfly/react-core'; import { StarIcon } from '@patternfly/react-icons'; <Button><StarIcon /></Button>`, |
| 29 | + errors: [ |
| 30 | + { |
| 31 | + message: "It looks like you are trying to create a custom favorites button. Use `isFavorite` and `isFavorited` button properties instead to apply the correct styling.", |
| 32 | + type: "JSXElement", |
| 33 | + }, |
| 34 | + ], |
| 35 | + }, |
| 36 | + // StarIcon in icon prop |
| 37 | + { |
| 38 | + code: `import { Button } from '@patternfly/react-core'; import { StarIcon } from '@patternfly/react-icons'; <Button icon={<StarIcon />} />`, |
| 39 | + errors: [ |
| 40 | + { |
| 41 | + message: "It looks like you are trying to create a custom favorites button. Use `isFavorite` and `isFavorited` button properties instead to apply the correct styling.", |
| 42 | + type: "JSXElement", |
| 43 | + }, |
| 44 | + ], |
| 45 | + }, |
| 46 | + // StarIcon with aliased import |
| 47 | + { |
| 48 | + code: `import { Button } from '@patternfly/react-core'; import { StarIcon as Star } from '@patternfly/react-icons'; <Button><Star /></Button>`, |
| 49 | + errors: [ |
| 50 | + { |
| 51 | + message: "It looks like you are trying to create a custom favorites button. Use `isFavorite` and `isFavorited` button properties instead to apply the correct styling.", |
| 52 | + type: "JSXElement", |
| 53 | + }, |
| 54 | + ], |
| 55 | + }, |
| 56 | + // Button with aliased import |
| 57 | + { |
| 58 | + code: `import { Button as PFButton } from '@patternfly/react-core'; import { StarIcon } from '@patternfly/react-icons'; <PFButton><StarIcon /></PFButton>`, |
| 59 | + errors: [ |
| 60 | + { |
| 61 | + message: "It looks like you are trying to create a custom favorites button. Use `isFavorite` and `isFavorited` button properties instead to apply the correct styling.", |
| 62 | + type: "JSXElement", |
| 63 | + }, |
| 64 | + ], |
| 65 | + }, |
| 66 | + // StarIcon with text |
| 67 | + { |
| 68 | + code: `import { Button } from '@patternfly/react-core'; import { StarIcon } from '@patternfly/react-icons'; <Button>Favorite <StarIcon /></Button>`, |
| 69 | + errors: [ |
| 70 | + { |
| 71 | + message: "It looks like you are trying to create a custom favorites button. Use `isFavorite` and `isFavorited` button properties instead to apply the correct styling.", |
| 72 | + type: "JSXElement", |
| 73 | + }, |
| 74 | + ], |
| 75 | + }, |
| 76 | + // StarIcon with other icon |
| 77 | + { |
| 78 | + code: `import { Button } from '@patternfly/react-core'; import { StarIcon, SomeIcon } from '@patternfly/react-icons'; <Button><SomeIcon /><StarIcon /></Button>`, |
| 79 | + errors: [ |
| 80 | + { |
| 81 | + message: "It looks like you are trying to create a custom favorites button. Use `isFavorite` and `isFavorited` button properties instead to apply the correct styling.", |
| 82 | + type: "JSXElement", |
| 83 | + }, |
| 84 | + ], |
| 85 | + }, |
| 86 | + // StarIcon in fragment with text |
| 87 | + { |
| 88 | + code: `import { Button } from '@patternfly/react-core'; import { StarIcon } from '@patternfly/react-icons'; <Button><>Favorite <StarIcon /></></Button>`, |
| 89 | + errors: [ |
| 90 | + { |
| 91 | + message: "It looks like you are trying to create a custom favorites button. Use `isFavorite` and `isFavorited` button properties instead to apply the correct styling.", |
| 92 | + type: "JSXElement", |
| 93 | + }, |
| 94 | + ], |
| 95 | + }, |
| 96 | + // StarIcon with existing props |
| 97 | + { |
| 98 | + code: `import { Button } from '@patternfly/react-core'; import { StarIcon } from '@patternfly/react-icons'; <Button variant="primary"><StarIcon /></Button>`, |
| 99 | + errors: [ |
| 100 | + { |
| 101 | + message: "It looks like you are trying to create a custom favorites button. Use `isFavorite` and `isFavorited` button properties instead to apply the correct styling.", |
| 102 | + type: "JSXElement", |
| 103 | + }, |
| 104 | + ], |
| 105 | + }, |
| 106 | + ], |
| 107 | +}); |
0 commit comments