Skip to content

Commit d832fc5

Browse files
chore(content-picker): Add visual regression tests (#4000)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 80cb2e5 commit d832fc5

File tree

1 file changed

+97
-1
lines changed

1 file changed

+97
-1
lines changed

src/elements/content-picker/stories/tests/ContentPicker-visual.stories.js

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import React from 'react';
12
import { expect, userEvent, waitFor, within } from '@storybook/test';
23
import { http, HttpResponse } from 'msw';
34
import ContentPicker from '../../ContentPicker';
4-
import { mockRootFolder } from '../../../common/__mocks__/mockRootFolder';
5+
import { mockRootFolder, mockEmptyRootFolder } from '../../../common/__mocks__/mockRootFolder';
56

67
import { DEFAULT_HOSTNAME_API } from '../../../../constants';
78

@@ -22,6 +23,95 @@ export const selectedEmptyState = {
2223
},
2324
};
2425

26+
export const singleSelect = {
27+
args: {
28+
maxSelectable: 1,
29+
},
30+
play: async ({ canvasElement }) => {
31+
const canvas = within(canvasElement);
32+
await waitFor(() => {
33+
expect(canvas.getByText('An Ordered Folder')).toBeInTheDocument();
34+
});
35+
36+
const rows = canvas.getAllByRole('row');
37+
await userEvent.click(rows[3]);
38+
await waitFor(() => {
39+
expect(canvas.getByRole('button', { name: 'Choose' })).not.toBeDisabled();
40+
});
41+
},
42+
};
43+
44+
export const multipleSelect = {
45+
args: {
46+
maxSelectable: 3,
47+
},
48+
play: async ({ canvasElement }) => {
49+
const canvas = within(canvasElement);
50+
await waitFor(() => {
51+
expect(canvas.getByText('An Ordered Folder')).toBeInTheDocument();
52+
});
53+
54+
const rows = canvas.getAllByRole('row');
55+
await userEvent.click(rows[3]);
56+
await userEvent.click(rows[4]);
57+
58+
await waitFor(() => {
59+
expect(canvas.getByText('2 Selected')).toBeInTheDocument();
60+
});
61+
},
62+
};
63+
64+
export const fileTypeFilter = {
65+
args: {
66+
extensions: ['doc', 'docx'],
67+
},
68+
};
69+
70+
export const emptyState = {
71+
args: {
72+
rootFolderId: '74729718131',
73+
},
74+
play: async ({ canvasElement }) => {
75+
const canvas = within(canvasElement);
76+
await waitFor(() => {
77+
expect(canvas.getByText('There are no items in this folder.')).toBeInTheDocument();
78+
});
79+
},
80+
};
81+
82+
export const errorEmptyState = {
83+
args: {
84+
rootFolderId: '191354690948',
85+
},
86+
play: async ({ canvasElement }) => {
87+
const canvas = within(canvasElement);
88+
await waitFor(() => {
89+
expect(canvas.getByText('A network error has occurred while trying to load.')).toBeInTheDocument();
90+
});
91+
},
92+
};
93+
94+
export const searchEmptyState = {
95+
args: {
96+
rootFolderId: '74729718131',
97+
},
98+
play: async ({ canvasElement }) => {
99+
const canvas = within(canvasElement);
100+
const searchBar = canvas.getByRole('searchbox', { name: 'Search files and folders' });
101+
await userEvent.type(searchBar, 'foo');
102+
103+
expect(canvas.getByText("Sorry, we couldn't find what you're looking for.")).toBeInTheDocument();
104+
},
105+
};
106+
107+
export const customActionButtons = {
108+
args: {
109+
renderCustomActionButtons: ({ selectedCount }) => (
110+
<button type="button">Custom Action ({selectedCount} items)</button>
111+
),
112+
},
113+
};
114+
25115
export default {
26116
title: 'Elements/ContentPicker/tests/visual',
27117
component: ContentPicker,
@@ -36,6 +126,12 @@ export default {
36126
http.get(`${DEFAULT_HOSTNAME_API}/2.0/folders/69083462919`, () => {
37127
return HttpResponse.json(mockRootFolder);
38128
}),
129+
http.get(`${DEFAULT_HOSTNAME_API}/2.0/folders/74729718131`, () => {
130+
return HttpResponse.json(mockEmptyRootFolder);
131+
}),
132+
http.get(`${DEFAULT_HOSTNAME_API}/2.0/folders/191354690948`, () => {
133+
return new HttpResponse('Internal Server Error', { status: 500 });
134+
}),
39135
],
40136
},
41137
},

0 commit comments

Comments
 (0)