Skip to content

Commit ff6271f

Browse files
committed
have --components include related components
1 parent 48f1768 commit ff6271f

File tree

11 files changed

+492
-31
lines changed

11 files changed

+492
-31
lines changed

packages/dev/codemods/src/s1-to-s2/__tests__/__snapshots__/dialog.test.ts.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ exports[`Replaces type="fullscreen" with FullscreenDialog component 1`] = `
127127
<Button>Test</Button>
128128
<FullscreenDialog isKeyboardDismissDisabled>
129129
<Heading>Test</Heading>
130-
<Divider />
130+
131131
<Content>Content</Content>
132132
</FullscreenDialog>
133133
</DialogTrigger>"
@@ -147,12 +147,12 @@ exports[`Replaces type="fullscreen" with FullscreenDialog component in DialogCon
147147
<DialogContainer>
148148
{showDialog1 && <FullscreenDialog isKeyboardDismissDisabled>
149149
<Heading>Test</Heading>
150-
<Divider />
150+
151151
<Content>Content</Content>
152152
</FullscreenDialog>}
153153
{showDialog2 && <FullscreenDialog isKeyboardDismissDisabled>
154154
<Heading>Test</Heading>
155-
<Divider />
155+
156156
<Content>Content</Content>
157157
</FullscreenDialog>}
158158
</DialogContainer>"
@@ -165,7 +165,7 @@ exports[`Replaces type="fullscreenTakeover" with FullscreenDialog component 1`]
165165
<Button>Test</Button>
166166
<FullscreenDialog variant="fullscreenTakeover">
167167
<Heading>Test</Heading>
168-
<Divider />
168+
169169
<Content>Content</Content>
170170
</FullscreenDialog>
171171
</DialogTrigger>"
@@ -195,7 +195,7 @@ exports[`Replaces type="popover" with Popover component 1`] = `
195195
<Button>Test</Button>
196196
<Popover hideArrow>
197197
<Heading>Test</Heading>
198-
<Divider />
198+
199199
<Content>Content</Content>
200200
</Popover>
201201
</DialogTrigger>"

packages/dev/codemods/src/s1-to-s2/__tests__/__snapshots__/subset.test.ts.snap

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@ exports[`Should not update components that are not provided to --components opti
1010
</div>"
1111
`;
1212

13+
exports[`Should only update ComboBox related shared components provided to --components option 1`] = `
14+
"import { ComboBoxSection, ComboBoxItem, ComboBox } from "@react-spectrum/s2";
15+
import { Menu, MenuTrigger, Button, Section, Item } from '@adobe/react-spectrum';
16+
17+
<>
18+
<ComboBox>
19+
<ComboBoxSection><Header>Animals</Header>
20+
<ComboBoxItem id="dog">Dog</ComboBoxItem>
21+
<ComboBoxItem id="cat">Cat</ComboBoxItem>
22+
</ComboBoxSection>
23+
</ComboBox>
24+
<MenuTrigger>
25+
<Button>Open</Button>
26+
<Menu>
27+
<Section title="Actions">
28+
<Item key="cut">Cut</Item>
29+
</Section>
30+
</Menu>
31+
</MenuTrigger>
32+
</>"
33+
`;
34+
1335
exports[`Should only update components provided to --components option 1`] = `
1436
"import { TextArea } from '@adobe/react-spectrum';
1537
@@ -22,6 +44,92 @@ import { Button } from "@react-spectrum/s2";
2244
</div>"
2345
`;
2446

47+
exports[`Should update ActionGroup related components provided to --components option 1`] = `
48+
"import { ActionButtonGroup, ActionButton } from "@react-spectrum/s2";
49+
50+
<ActionButtonGroup>
51+
<ActionButton key="add" onPress={() => onAction("add")}>Add</ActionButton>
52+
<ActionButton key="delete" onPress={() => onAction("delete")}>Delete</ActionButton>
53+
<ActionButton key="edit" onPress={() => onAction("edit")}>Edit</ActionButton>
54+
</ActionButtonGroup>"
55+
`;
56+
57+
exports[`Should update DialogTrigger related components provided to --components option 1`] = `
58+
"import { Button, Heading, Content } from '@adobe/react-spectrum';
59+
60+
import { DialogTrigger, Dialog } from "@react-spectrum/s2";
61+
62+
<DialogTrigger>
63+
<Button>Test</Button>
64+
<Dialog>
65+
<Heading>Test</Heading>
66+
67+
<Content>Content</Content>
68+
</Dialog>
69+
</DialogTrigger>"
70+
`;
71+
72+
exports[`Should update Menu related components provided to --components option 1`] = `
73+
"import {
74+
UnavailableMenuItemTrigger,
75+
ContextualHelpPopover,
76+
MenuItem,
77+
MenuSection,
78+
Menu,
79+
MenuTrigger,
80+
SubmenuTrigger,
81+
} from "@react-spectrum/s2";
82+
83+
import { Breadcrumbs, Item, Button, Heading, Content } from '@adobe/react-spectrum';
84+
85+
<>
86+
<MenuTrigger>
87+
<Button>Edit</Button>
88+
<Menu>
89+
<MenuItem id="undo">Undo</MenuItem>
90+
<SubmenuTrigger>
91+
<MenuItem id="share">Share</MenuItem>
92+
<Menu>
93+
<MenuItem id="sms">SMS</MenuItem>
94+
</Menu>
95+
</SubmenuTrigger>
96+
<MenuSection><Header>Help</Header>
97+
<UnavailableMenuItemTrigger isUnavailable>
98+
<MenuItem id="cut">Cut</MenuItem>
99+
<ContextualHelpPopover>
100+
<Heading>Cut</Heading>
101+
<Content>Please select text for Cut to be enabled.</Content>
102+
</ContextualHelpPopover>
103+
</UnavailableMenuItemTrigger>
104+
</MenuSection>
105+
</Menu>
106+
</MenuTrigger>
107+
<Breadcrumbs>
108+
<Item key="home">Home</Item>
109+
</Breadcrumbs>
110+
</>"
111+
`;
112+
113+
exports[`Should update Tabs related components provided to --components option 1`] = `
114+
"import { Tab, TabPanel, Tabs, TabList } from "@react-spectrum/s2";
115+
116+
<Tabs aria-label="History of Ancient Rome"><TabList>
117+
<Tab id="FoR">Founding of Rome</Tab>
118+
<Tab id="MaR">Monarchy and Republic</Tab>
119+
</TabList><TabPanel id="FoR">Arma virumque cano, Troiae qui primus ab oris.</TabPanel><TabPanel id="MaR">Senatus Populusque Romanus.</TabPanel></Tabs>"
120+
`;
121+
122+
exports[`Should update TooltipTrigger related components provided to --components option 1`] = `
123+
"import { ActionButton } from '@adobe/react-spectrum';
124+
125+
import { TooltipTrigger, Tooltip } from "@react-spectrum/s2";
126+
127+
<TooltipTrigger placement="bottom">
128+
<ActionButton aria-label="Edit Name"><Edit /></ActionButton>
129+
<Tooltip>Change Name</Tooltip>
130+
</TooltipTrigger>"
131+
`;
132+
25133
exports[`Should update multiple components provided to --components option 1`] = `
26134
"import { Button, TextArea } from "@react-spectrum/s2";
27135
@@ -31,3 +139,24 @@ exports[`Should update multiple components provided to --components option 1`] =
31139
<TextArea />
32140
</div>"
33141
`;
142+
143+
exports[`Should update related TableView components provided to --components option 1`] = `
144+
"import { Cell, Column, Row, TableBody, TableHeader, TableView } from "@react-spectrum/s2";
145+
146+
<TableView>
147+
<TableHeader>
148+
<Column id="test" isRowHeader={true}>Test</Column>
149+
<Column id="blah">Blah</Column>
150+
</TableHeader>
151+
<TableBody>
152+
<Row>
153+
<Cell>Test1</Cell>
154+
<Cell>One</Cell>
155+
</Row>
156+
<Row>
157+
<Cell>Test2</Cell>
158+
<Cell>One</Cell>
159+
</Row>
160+
</TableBody>
161+
</TableView>"
162+
`;

packages/dev/codemods/src/s1-to-s2/__tests__/cli.e2e.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,22 @@ test('runs the shipped assistant in agent mode', async () => {
226226
expectProjectToMatchFixture(result.projectDir, 'full-project');
227227
});
228228

229+
test('respects --components in agent mode', async () => {
230+
let result = await runFixtureCLI({
231+
fixtureName: 'subset-project',
232+
args: ['--agent', '--components', 'Button']
233+
});
234+
235+
expect(result.exitCode).toBe(0);
236+
expect(result.stderr).toBe('');
237+
expect(result.stdout).toContain('Running s1-to-s2 in agent mode (non-interactive, transform-only).');
238+
expect(result.stdout).toContain('Upgrade complete!');
239+
expect(result.stdout).not.toContain(PROMPT_TO_START);
240+
expect(result.stdout).not.toContain(PROMPT_TO_UPGRADE);
241+
expect(result.packageManagerCalls).toEqual([]);
242+
expectProjectToMatchFixture(result.projectDir, 'subset-project');
243+
});
244+
229245
test('runs the interactive assistant flow against a real project fixture', async () => {
230246
let result = await runFixtureCLI({
231247
fixtureName: 'full-project',

packages/dev/codemods/src/s1-to-s2/__tests__/subset.test.ts

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,123 @@ import {Button, TextArea} from '@adobe/react-spectrum';
3535
<TextArea isQuiet />
3636
</div>
3737
`, 'TableView');
38+
39+
testSubset('Should update related TableView components provided to --components option', `
40+
import {Cell, Column, Row, TableBody, TableHeader, TableView} from '@adobe/react-spectrum';
41+
42+
<TableView>
43+
<TableHeader>
44+
<Column key="test">Test</Column>
45+
<Column key="blah">Blah</Column>
46+
</TableHeader>
47+
<TableBody>
48+
<Row>
49+
<Cell>Test1</Cell>
50+
<Cell>One</Cell>
51+
</Row>
52+
<Row>
53+
<Cell>Test2</Cell>
54+
<Cell>One</Cell>
55+
</Row>
56+
</TableBody>
57+
</TableView>
58+
`, 'TableView');
59+
60+
testSubset('Should only update ComboBox related shared components provided to --components option', `
61+
import {ComboBox, Menu, MenuTrigger, Button, Section, Item} from '@adobe/react-spectrum';
62+
63+
<>
64+
<ComboBox>
65+
<Section title="Animals">
66+
<Item key="dog">Dog</Item>
67+
<Item key="cat">Cat</Item>
68+
</Section>
69+
</ComboBox>
70+
<MenuTrigger>
71+
<Button>Open</Button>
72+
<Menu>
73+
<Section title="Actions">
74+
<Item key="cut">Cut</Item>
75+
</Section>
76+
</Menu>
77+
</MenuTrigger>
78+
</>
79+
`, 'ComboBox');
80+
81+
testSubset('Should update Menu related components provided to --components option', `
82+
import {Breadcrumbs, Menu, MenuTrigger, SubmenuTrigger, ContextualHelpTrigger, Item, Section, Button, Dialog, Heading, Content} from '@adobe/react-spectrum';
83+
84+
<>
85+
<MenuTrigger>
86+
<Button>Edit</Button>
87+
<Menu>
88+
<Item key="undo">Undo</Item>
89+
<SubmenuTrigger>
90+
<Item key="share">Share</Item>
91+
<Menu>
92+
<Item key="sms">SMS</Item>
93+
</Menu>
94+
</SubmenuTrigger>
95+
<Section title="Help">
96+
<ContextualHelpTrigger isUnavailable>
97+
<Item key="cut">Cut</Item>
98+
<Dialog>
99+
<Heading>Cut</Heading>
100+
<Content>Please select text for Cut to be enabled.</Content>
101+
</Dialog>
102+
</ContextualHelpTrigger>
103+
</Section>
104+
</Menu>
105+
</MenuTrigger>
106+
<Breadcrumbs>
107+
<Item key="home">Home</Item>
108+
</Breadcrumbs>
109+
</>
110+
`, 'Menu');
111+
112+
testSubset('Should update Tabs related components provided to --components option', `
113+
import {Tabs, TabList, TabPanels, Item} from '@adobe/react-spectrum';
114+
115+
<Tabs aria-label="History of Ancient Rome">
116+
<TabList>
117+
<Item key="FoR">Founding of Rome</Item>
118+
<Item key="MaR">Monarchy and Republic</Item>
119+
</TabList>
120+
<TabPanels>
121+
<Item key="FoR">Arma virumque cano, Troiae qui primus ab oris.</Item>
122+
<Item key="MaR">Senatus Populusque Romanus.</Item>
123+
</TabPanels>
124+
</Tabs>
125+
`, 'Tabs');
126+
127+
testSubset('Should update DialogTrigger related components provided to --components option', `
128+
import {DialogTrigger, Button, Dialog, Heading, Content, Divider} from '@adobe/react-spectrum';
129+
130+
<DialogTrigger>
131+
<Button>Test</Button>
132+
<Dialog>
133+
<Heading>Test</Heading>
134+
<Divider />
135+
<Content>Content</Content>
136+
</Dialog>
137+
</DialogTrigger>
138+
`, 'DialogTrigger');
139+
140+
testSubset('Should update TooltipTrigger related components provided to --components option', `
141+
import {ActionButton, TooltipTrigger, Tooltip} from '@adobe/react-spectrum';
142+
143+
<TooltipTrigger>
144+
<ActionButton aria-label="Edit Name"><Edit /></ActionButton>
145+
<Tooltip placement="bottom left" showIcon>Change Name</Tooltip>
146+
</TooltipTrigger>
147+
`, 'TooltipTrigger');
148+
149+
testSubset('Should update ActionGroup related components provided to --components option', `
150+
import {ActionGroup, Item} from '@adobe/react-spectrum';
151+
152+
<ActionGroup onAction={onAction}>
153+
<Item key="add">Add</Item>
154+
<Item key="delete">Delete</Item>
155+
<Item key="edit">Edit</Item>
156+
</ActionGroup>
157+
`, 'ActionGroup');

0 commit comments

Comments
 (0)