1+ const ruleTester = require ( "../../ruletester" ) ;
2+ import * as rule from "./enable-animations" ;
3+
4+ ruleTester . 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+ ] ,
152+ } ) ;
0 commit comments