Skip to content

Commit ed86013

Browse files
test(advanced-color-picker): refine testing suite
1 parent 37fbfd1 commit ed86013

File tree

2 files changed

+29
-269
lines changed

2 files changed

+29
-269
lines changed

src/components/advanced-color-picker/advanced-color-picker.interaction.stories.tsx

Lines changed: 29 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -58,42 +58,6 @@ async function ensurePickerIsOpen(trigger: HTMLElement) {
5858
await waitFor(() => expect(radiosCount()).toBeGreaterThan(0));
5959
}
6060

61-
export const ColorSelection: Story = {
62-
render: () => (
63-
<Box mb={3}>
64-
<AdvancedColorPickerWithState />
65-
</Box>
66-
),
67-
play: async ({ canvasElement }) => {
68-
if (!allowInteractions()) return;
69-
70-
const canvas = within(canvasElement);
71-
72-
const trigger = canvas.getByRole("button", { name: /change colo(u)?r/i });
73-
await userEvent.click(trigger);
74-
75-
const portal = within(document.body);
76-
77-
const blue = await portal.findByLabelText(/blue/i);
78-
await userEvent.click(blue);
79-
80-
await portal.findByLabelText(/blue/i, { selector: "input:checked" });
81-
82-
await ensurePickerIsOpen(trigger);
83-
},
84-
decorators: [
85-
(StoryToRender) => (
86-
<DefaultDecorator>
87-
<StoryToRender />
88-
</DefaultDecorator>
89-
),
90-
],
91-
};
92-
ColorSelection.storyName = "Color Selection";
93-
ColorSelection.parameters = {
94-
chromatic: { disableSnapshot: true },
95-
};
96-
9761
export const ColorPreviewInteraction: Story = {
9862
render: () => (
9963
<Box mb={3}>
@@ -147,9 +111,6 @@ export const DialogOpenAndCloseStates: Story = {
147111
<AdvancedColorPickerWithState />
148112
</Box>
149113
),
150-
parameters: {
151-
chromatic: { disableSnapshot: true },
152-
},
153114
play: async ({ canvasElement }) => {
154115
if (!allowInteractions()) return;
155116

@@ -163,17 +124,40 @@ export const DialogOpenAndCloseStates: Story = {
163124
const blueRadioOption = await portal.findByLabelText(/blue/i);
164125
expect(blueRadioOption).toBeInTheDocument();
165126

166-
await userEvent.click(blueRadioOption);
167-
await userEvent.keyboard("{Enter}");
127+
blueRadioOption.focus();
128+
await waitFor(() => expect(blueRadioOption).toHaveFocus());
129+
130+
await userEvent.keyboard("{ArrowLeft}");
131+
const colorBlack = await portal.findByLabelText(/black/i);
132+
await expect(colorBlack).toHaveFocus();
133+
134+
await userEvent.keyboard("{ArrowRight}");
135+
const colorBlue = await portal.findByLabelText(/blue/i);
136+
await expect(colorBlue).toHaveFocus();
137+
138+
await userEvent.keyboard("{ArrowDown}");
139+
const colorDesert = await portal.findByLabelText(/desert/i);
140+
await expect(colorDesert).toHaveFocus();
168141

142+
await userEvent.keyboard("{ArrowUp}");
143+
await expect(colorBlue).toHaveFocus();
144+
145+
await userEvent.keyboard("{Escape}");
169146
await waitFor(() =>
170147
expect(portal.queryByLabelText(/blue/i)).not.toBeInTheDocument(),
171148
);
172-
173149
await userEvent.click(trigger);
174150
await portal.findByLabelText(/blue/i);
175151

176152
await ensurePickerIsOpen(trigger);
153+
154+
const blueForTab = await portal.findByLabelText(/blue/i);
155+
blueForTab.focus();
156+
await waitFor(() => expect(blueForTab).toHaveFocus());
157+
158+
await userEvent.tab();
159+
const closeButton = await portal.findByRole("button", { name: /close/i });
160+
await expect(closeButton).toHaveFocus();
177161
},
178162
decorators: [
179163
(StoryToRender) => (
@@ -185,7 +169,7 @@ export const DialogOpenAndCloseStates: Story = {
185169
};
186170
DialogOpenAndCloseStates.storyName = "Dialog Open And Close States";
187171
DialogOpenAndCloseStates.parameters = {
188-
chromatic: { disableSnapshot: true },
172+
chromatic: { disableSnapshot: false },
189173
};
190174

191175
export const FocusManagement: Story = {
@@ -284,54 +268,6 @@ export const RestoreOnFocus: Story = {
284268
],
285269
};
286270
RestoreOnFocus.storyName = "Restore On Focus";
287-
288-
export const ColorGridNavigation: Story = {
289-
render: () => (
290-
<Box mb={3}>
291-
<AdvancedColorPickerWithState />
292-
</Box>
293-
),
294-
play: async ({ canvasElement }) => {
295-
if (!allowInteractions()) return;
296-
297-
const canvas = within(canvasElement);
298-
const trigger = canvas.getByRole("button", { name: /change colo(u)?r/i });
299-
await userEvent.click(trigger);
300-
301-
const portal = within(document.body);
302-
const labels = ["white", "blue", "pink", "turquoise", "mint"] as const;
303-
304-
for (const label of labels) {
305-
const option = await portal.findByLabelText(
306-
new RegExp(`^${label}$`, "i"),
307-
);
308-
await userEvent.click(option);
309-
await portal.findByLabelText(new RegExp(`^${label}$`, "i"), {
310-
selector: "input:checked",
311-
});
312-
}
313-
314-
const lastOption = portal.getByLabelText(/mint/i);
315-
lastOption.focus();
316-
await userEvent.keyboard(" ");
317-
await waitFor(() => expect(portal.queryByRole("radio")).toBeNull());
318-
319-
await ensurePickerIsOpen(trigger);
320-
const mintForSnapshot = await within(document.body).findByLabelText(
321-
/mint/i,
322-
);
323-
mintForSnapshot.focus();
324-
await waitFor(() => expect(mintForSnapshot).toHaveFocus());
325-
},
326-
decorators: [
327-
(StoryToRender) => (
328-
<DefaultDecorator>
329-
<StoryToRender />
330-
</DefaultDecorator>
331-
),
332-
],
333-
};
334-
ColorGridNavigation.storyName = "Color Grid Navigation";
335-
ColorGridNavigation.parameters = {
336-
chromatic: { disableSnapshot: true },
271+
RestoreOnFocus.parameters = {
272+
chromatic: { disableSnapshot: false },
337273
};

src/components/advanced-color-picker/advanced-color-picker.pw.tsx

Lines changed: 0 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import {
55
currentColorDescription,
66
advancedColorPickerCell,
77
simpleColorPickerInput,
8-
simpleColorPickerComponent,
9-
advancedColorPickerPreview,
108
} from "../../../playwright/components/advanced-color-picker";
119
import {
1210
dialog as advancedColorPickerParent,
@@ -16,25 +14,6 @@ import { closeIconButton } from "../../../playwright/components/index";
1614
import { CHARACTERS } from "../../../playwright/support/constants";
1715
import { checkAccessibility } from "../../../playwright/support/helper";
1816

19-
// TODO: Skipped due to flaky focus behaviour. To review in FE-6428
20-
test.skip("should have the expected styling when focused", async ({
21-
mount,
22-
page,
23-
}) => {
24-
await mount(<AdvancedColorPickerCustom open />);
25-
26-
const icon = closeIconButton(page);
27-
await icon.focus();
28-
await expect(closeIconButton(page)).toHaveCSS(
29-
"box-shadow",
30-
"rgb(255, 188, 25) 0px 0px 0px 3px, rgba(0, 0, 0, 0.9) 0px 0px 0px 6px",
31-
);
32-
await expect(closeIconButton(page)).toHaveCSS(
33-
"outline",
34-
"rgba(0, 0, 0, 0) solid 3px",
35-
);
36-
});
37-
3817
test("when AdvancedColorPicker is opened and then closed, with the `restoreFocusOnClose` prop passed as `false`, the call to action element should not be focused", async ({
3918
mount,
4019
page,
@@ -57,38 +36,6 @@ test("when AdvancedColorPicker is opened and then closed, with the `restoreFocus
5736
});
5837

5938
test.describe("should render AdvancedColorPicker component and check functionality", () => {
60-
(
61-
[
62-
["ArrowUp", 2],
63-
["ArrowLeft", 6],
64-
["ArrowRight", 8],
65-
] as [string, number][]
66-
).forEach(([key, index]) => {
67-
test(`should use ${key} key and move selection`, async ({
68-
mount,
69-
page,
70-
}) => {
71-
await mount(<AdvancedColorPickerCustom />);
72-
73-
const picker = simpleColorPickerInput(page, 7);
74-
await picker.press(key);
75-
await expect(simpleColorPickerInput(page, index)).toBeChecked();
76-
});
77-
});
78-
79-
test("should move selection down using downarrow", async ({
80-
mount,
81-
page,
82-
}) => {
83-
await mount(<AdvancedColorPickerCustom />);
84-
85-
const picker = simpleColorPickerInput(page, 7);
86-
await picker.press("ArrowUp");
87-
const newPicker = simpleColorPickerInput(page, 2);
88-
await newPicker.press("ArrowDown");
89-
await expect(simpleColorPickerInput(page, 7)).toBeChecked();
90-
});
91-
9239
test("should regain focus on color after second tab", async ({
9340
mount,
9441
page,
@@ -103,40 +50,10 @@ test.describe("should render AdvancedColorPicker component and check functionali
10350

10451
await expect(simpleColorPickerInput(page, 7)).toBeFocused();
10552
});
106-
107-
(["Space", "Enter"] as const).forEach((key) => {
108-
test(`should close AdvancedColorPicker using ${key} on selected color`, async ({
109-
mount,
110-
page,
111-
}) => {
112-
await mount(<AdvancedColorPickerCustom />);
113-
114-
const picker = simpleColorPickerInput(page, 7);
115-
await picker.press(key);
116-
await expect(simpleColorPickerComponent(page)).toBeHidden();
117-
});
118-
});
119-
120-
[1, 2, 3].forEach((index) => {
121-
test(`should confirm dedicated ${index} color was selected`, async ({
122-
mount,
123-
page,
124-
}) => {
125-
await mount(<AdvancedColorPickerCustom />);
126-
127-
const input = simpleColorPickerInput(page, index);
128-
await input.click();
129-
await expect(simpleColorPickerInput(page, index)).toBeChecked();
130-
});
131-
});
13253
});
13354

13455
test.describe("should render AdvancedColorPicker component and check props", () => {
13556
const testPropValue = CHARACTERS.STANDARD;
136-
const colors = [
137-
{ value: "#111222", label: "superBlack" },
138-
{ value: "#333555", label: "black" },
139-
];
14057

14158
test("should render AdvancedColorPicker with aria-describedby prop", async ({
14259
mount,
@@ -210,88 +127,6 @@ test.describe("should render AdvancedColorPicker component and check props", ()
210127
);
211128
});
212129

213-
test("should render AdvancedColorPicker with availableColors prop", async ({
214-
mount,
215-
page,
216-
}) => {
217-
await mount(
218-
<AdvancedColorPickerCustom
219-
availableColors={colors}
220-
selectedColor="#111222"
221-
/>,
222-
);
223-
224-
await expect(simpleColorPickerInput(page, 0)).toHaveAttribute(
225-
"value",
226-
colors[0].value,
227-
);
228-
await expect(simpleColorPickerInput(page, 0)).toHaveAttribute(
229-
"aria-label",
230-
colors[0].label,
231-
);
232-
await expect(simpleColorPickerInput(page, 1)).toHaveAttribute(
233-
"value",
234-
colors[1].value,
235-
);
236-
await expect(simpleColorPickerInput(page, 1)).toHaveAttribute(
237-
"aria-label",
238-
colors[1].label,
239-
);
240-
});
241-
242-
test("should render AdvancedColorPicker with selectedColor prop", async ({
243-
mount,
244-
page,
245-
}) => {
246-
await mount(
247-
<AdvancedColorPickerCustom
248-
availableColors={colors}
249-
selectedColor="#333555"
250-
/>,
251-
);
252-
253-
await expect(simpleColorPickerInput(page, 1)).toHaveAttribute(
254-
"value",
255-
colors[1].value,
256-
);
257-
await expect(simpleColorPickerInput(page, 1)).toHaveAttribute(
258-
"aria-label",
259-
colors[1].label,
260-
);
261-
});
262-
263-
test("should render AdvancedColorPicker with defaultColor prop", async ({
264-
mount,
265-
page,
266-
}) => {
267-
await mount(
268-
<AdvancedColorPickerCustom
269-
availableColors={colors}
270-
selectedColor="#111222"
271-
/>,
272-
);
273-
274-
await expect(advancedColorPickerPreview(page)).toHaveAttribute(
275-
"color",
276-
colors[0].value,
277-
);
278-
});
279-
280-
[true, false].forEach((bool) => {
281-
test(`should render AdvancedColorPicker with open prop set to ${bool}`, async ({
282-
mount,
283-
page,
284-
}) => {
285-
await mount(<AdvancedColorPickerCustom open={bool} />);
286-
287-
if (bool) {
288-
await expect(advancedColorPickerParent(page)).toBeVisible();
289-
} else {
290-
await expect(advancedColorPickerParent(page)).toBeHidden();
291-
}
292-
});
293-
});
294-
295130
test("should render AdvancedColorPicker with correct description when color is selected", async ({
296131
mount,
297132
page,
@@ -314,14 +149,3 @@ test.describe("Accessibility tests for AdvancedColorPicker component", () => {
314149
await checkAccessibility(page);
315150
});
316151
});
317-
318-
test("color picker preview should have the expected border radius styling", async ({
319-
mount,
320-
page,
321-
}) => {
322-
await mount(<AdvancedColorPickerCustom />);
323-
await expect(advancedColorPickerPreview(page)).toHaveCSS(
324-
"border-radius",
325-
"4px",
326-
);
327-
});

0 commit comments

Comments
 (0)