11const ruleTester = require ( "../../ruletester" ) ;
22import * as rule from "./enable-animations" ;
33
4+ const valid = [
5+ // Components not in target list should be ignored
6+ "<AlertGroup />" ,
7+ "import { AlertGroup } from '@patternfly/react-core'; <AlertGroup hasAnimations />" ,
8+ "import { AlertGroup } from '@patternfly/react-core'; <AlertGroup hasAnimations={true} />" ,
9+ "import { Table } from '@patternfly/react-table'; <Table hasAnimations />" ,
10+ // Component not in target components
11+ "import { Button } from '@patternfly/react-core'; <Button />" ,
12+ // DualListSelector without isTree should not get hasAnimations
13+ "import { DualListSelector } from '@patternfly/react-core'; <DualListSelector />" ,
14+ // DualListSelector with isTree={false} should not get hasAnimations
15+ "import { DualListSelector } from '@patternfly/react-core'; <DualListSelector isTree={false} />" ,
16+ // DualListSelector with isTree and hasAnimations already present
17+ "import { DualListSelector } from '@patternfly/react-core'; <DualListSelector isTree hasAnimations />" ,
18+ ] ;
19+
20+ const invalid = [
21+ {
22+ code : "import { AlertGroup } from '@patternfly/react-core'; <AlertGroup />" ,
23+ output : "import { AlertGroup } from '@patternfly/react-core'; <AlertGroup hasAnimations />" ,
24+ errors : [
25+ {
26+ message : "Consider adding hasAnimations prop to enable component animations." ,
27+ type : "JSXOpeningElement"
28+ }
29+ ]
30+ } ,
31+ {
32+ code : "import { DualListSelector } from '@patternfly/react-core'; <DualListSelector isTree />" ,
33+ output : "import { DualListSelector } from '@patternfly/react-core'; <DualListSelector isTree hasAnimations />" ,
34+ errors : [
35+ {
36+ message : "Consider adding hasAnimations prop to enable component animations." ,
37+ type : "JSXOpeningElement"
38+ }
39+ ]
40+ } ,
41+ {
42+ code : "import { DualListSelector } from '@patternfly/react-core'; <DualListSelector isTree={true} />" ,
43+ output : "import { DualListSelector } from '@patternfly/react-core'; <DualListSelector isTree={true} hasAnimations />" ,
44+ errors : [
45+ {
46+ message : "Consider adding hasAnimations prop to enable component animations." ,
47+ type : "JSXOpeningElement"
48+ }
49+ ]
50+ } ,
51+ {
52+ code : "import { TreeView } from '@patternfly/react-core'; <TreeView />" ,
53+ output : "import { TreeView } from '@patternfly/react-core'; <TreeView hasAnimations />" ,
54+ errors : [
55+ {
56+ message : "Consider adding hasAnimations prop to enable component animations." ,
57+ type : "JSXOpeningElement"
58+ }
59+ ]
60+ } ,
61+ {
62+ code : "import { SearchInputExpandable } from '@patternfly/react-core'; <SearchInputExpandable />" ,
63+ output : "import { SearchInputExpandable } from '@patternfly/react-core'; <SearchInputExpandable hasAnimations />" ,
64+ errors : [
65+ {
66+ message : "Consider adding hasAnimations prop to enable component animations." ,
67+ type : "JSXOpeningElement"
68+ }
69+ ]
70+ } ,
71+ {
72+ code : "import { FormFieldGroupExpandable } from '@patternfly/react-core'; <FormFieldGroupExpandable />" ,
73+ output : "import { FormFieldGroupExpandable } from '@patternfly/react-core'; <FormFieldGroupExpandable hasAnimations />" ,
74+ errors : [
75+ {
76+ message : "Consider adding hasAnimations prop to enable component animations." ,
77+ type : "JSXOpeningElement"
78+ }
79+ ]
80+ } ,
81+ {
82+ code : "import { Table } from '@patternfly/react-table'; <Table />" ,
83+ output : "import { Table } from '@patternfly/react-table'; <Table hasAnimations />" ,
84+ errors : [
85+ {
86+ message : "Consider adding hasAnimations prop to enable component animations." ,
87+ type : "JSXOpeningElement"
88+ }
89+ ]
90+ } ,
91+ {
92+ code : `import { AlertGroup, TreeView } from '@patternfly/react-core';
93+ <>
94+ <AlertGroup />
95+ <TreeView />
96+ </>` ,
97+ output : `import { AlertGroup, TreeView } from '@patternfly/react-core';
98+ <>
99+ <AlertGroup hasAnimations />
100+ <TreeView hasAnimations />
101+ </>` ,
102+ errors : [
103+ {
104+ message : "Consider adding hasAnimations prop to enable component animations." ,
105+ type : "JSXOpeningElement"
106+ } ,
107+ {
108+ message : "Consider adding hasAnimations prop to enable component animations." ,
109+ type : "JSXOpeningElement"
110+ }
111+ ]
112+ } ,
113+ {
114+ code : "import { AlertGroup } from '@patternfly/react-core'; <AlertGroup isLiveRegion />" ,
115+ output : "import { AlertGroup } from '@patternfly/react-core'; <AlertGroup isLiveRegion hasAnimations />" ,
116+ errors : [
117+ {
118+ message : "Consider adding hasAnimations prop to enable component animations." ,
119+ type : "JSXOpeningElement"
120+ }
121+ ]
122+ }
123+ ] ;
124+
4125ruleTester . run ( "enable-animations" , rule , {
5- valid : [
6- // No imports, should not trigger
7- {
8- code : `<AlertGroup />` ,
9- } ,
10- // Already has hasAnimations prop
11- {
12- code : `import { AlertGroup } from '@patternfly/react-core'; <AlertGroup hasAnimations />` ,
13- } ,
14- // Already has hasAnimations with value
15- {
16- code : `import { AlertGroup } from '@patternfly/react-core'; <AlertGroup hasAnimations={true} />` ,
17- } ,
18- // Table already has hasAnimations
19- {
20- code : `import { Table } from '@patternfly/react-table'; <Table hasAnimations />` ,
21- } ,
22- // Non-target component should not be affected
23- {
24- code : `import { Button } from '@patternfly/react-core'; <Button />` ,
25- } ,
26- ] ,
27- invalid : [
28- // AlertGroup without hasAnimations
29- {
30- code : `import { AlertGroup } from '@patternfly/react-core'; <AlertGroup />` ,
31- output : `import { AlertGroup } from '@patternfly/react-core'; <AlertGroup hasAnimations />` ,
32- errors : [
33- {
34- message : "Consider adding hasAnimations prop to enable component animations." ,
35- type : "JSXOpeningElement" ,
36- } ,
37- ] ,
38- } ,
39- // DualListSelector without hasAnimations
40- {
41- code : `import { DualListSelector } from '@patternfly/react-core'; <DualListSelector />` ,
42- output : `import { DualListSelector } from '@patternfly/react-core'; <DualListSelector hasAnimations />` ,
43- errors : [
44- {
45- message : "Consider adding hasAnimations prop to enable component animations." ,
46- type : "JSXOpeningElement" ,
47- } ,
48- ] ,
49- } ,
50- // TreeView without hasAnimations
51- {
52- code : `import { TreeView } from '@patternfly/react-core'; <TreeView />` ,
53- output : `import { TreeView } from '@patternfly/react-core'; <TreeView hasAnimations />` ,
54- errors : [
55- {
56- message : "Consider adding hasAnimations prop to enable component animations." ,
57- type : "JSXOpeningElement" ,
58- } ,
59- ] ,
60- } ,
61- // SearchInput without hasAnimations
62- {
63- code : `import { SearchInput } from '@patternfly/react-core'; <SearchInput />` ,
64- output : `import { SearchInput } from '@patternfly/react-core'; <SearchInput hasAnimations />` ,
65- errors : [
66- {
67- message : "Consider adding hasAnimations prop to enable component animations." ,
68- type : "JSXOpeningElement" ,
69- } ,
70- ] ,
71- } ,
72- // FormFieldGroupExpandable without hasAnimations
73- {
74- code : `import { FormFieldGroupExpandable } from '@patternfly/react-core'; <FormFieldGroupExpandable />` ,
75- output : `import { FormFieldGroupExpandable } from '@patternfly/react-core'; <FormFieldGroupExpandable hasAnimations />` ,
76- errors : [
77- {
78- message : "Consider adding hasAnimations prop to enable component animations." ,
79- type : "JSXOpeningElement" ,
80- } ,
81- ] ,
82- } ,
83- // Table from react-table without hasAnimations
84- {
85- code : `import { Table } from '@patternfly/react-table'; <Table />` ,
86- output : `import { Table } from '@patternfly/react-table'; <Table hasAnimations />` ,
87- errors : [
88- {
89- message : "Consider adding hasAnimations prop to enable component animations." ,
90- type : "JSXOpeningElement" ,
91- } ,
92- ] ,
93- } ,
94- // Multiple components in one file
95- {
96- code : `import { AlertGroup, TreeView } from '@patternfly/react-core';
97- <>
98- <AlertGroup />
99- <TreeView />
100- </>` ,
101- output : `import { AlertGroup, TreeView } from '@patternfly/react-core';
102- <>
103- <AlertGroup hasAnimations />
104- <TreeView hasAnimations />
105- </>` ,
106- errors : [
107- {
108- message : "Consider adding hasAnimations prop to enable component animations." ,
109- type : "JSXOpeningElement" ,
110- } ,
111- {
112- message : "Consider adding hasAnimations prop to enable component animations." ,
113- type : "JSXOpeningElement" ,
114- } ,
115- ] ,
116- } ,
117- // Component with existing props
118- {
119- code : `import { AlertGroup } from '@patternfly/react-core'; <AlertGroup isLiveRegion />` ,
120- output : `import { AlertGroup } from '@patternfly/react-core'; <AlertGroup hasAnimations isLiveRegion />` ,
121- errors : [
122- {
123- message : "Consider adding hasAnimations prop to enable component animations." ,
124- type : "JSXOpeningElement" ,
125- } ,
126- ] ,
127- } ,
128- // Self-closing and regular tags
129- {
130- code : `import { DualListSelector } from '@patternfly/react-core';
131- <>
132- <DualListSelector />
133- <DualListSelector></DualListSelector>
134- </>` ,
135- output : `import { DualListSelector } from '@patternfly/react-core';
136- <>
137- <DualListSelector hasAnimations />
138- <DualListSelector hasAnimations></DualListSelector>
139- </>` ,
140- errors : [
141- {
142- message : "Consider adding hasAnimations prop to enable component animations." ,
143- type : "JSXOpeningElement" ,
144- } ,
145- {
146- message : "Consider adding hasAnimations prop to enable component animations." ,
147- type : "JSXOpeningElement" ,
148- } ,
149- ] ,
150- } ,
151- ] ,
126+ valid : valid ,
127+ invalid : invalid ,
152128} ) ;
0 commit comments