Skip to content

Commit 44fa255

Browse files
fix(content-picker): improve folder navigation
Co-Authored-By: [email protected] <[email protected]>
1 parent b95ee73 commit 44fa255

File tree

1 file changed

+95
-16
lines changed

1 file changed

+95
-16
lines changed

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

Lines changed: 95 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { http, HttpResponse } from 'msw';
55
import ContentPicker from '../../ContentPicker';
66
import { mockRootFolder, mockEmptyRootFolder } from '../../../content-explorer/stories/__mocks__/mockRootFolder';
77
import mockSubFolder from '../../../content-explorer/stories/__mocks__/mockSubFolder';
8+
import { SLEEP_TIMEOUT } from '../../../../utils/storybook';
89
import { DEFAULT_HOSTNAME_API } from '../../../../constants';
910

1011
export const basic = {
@@ -69,19 +70,33 @@ export const emptyFolder = {
6970
},
7071
play: async ({ canvasElement }) => {
7172
const canvas = within(canvasElement);
72-
await waitFor(() => {
73-
expect(canvas.getByText('There are no items in this folder.')).toBeInTheDocument();
74-
expect(canvas.queryByRole('progressbar')).not.toBeInTheDocument();
75-
});
73+
74+
await waitFor(
75+
() => {
76+
// Verify empty folder state
77+
expect(canvas.getByText('This folder is empty')).toBeInTheDocument();
78+
},
79+
{
80+
timeout: SLEEP_TIMEOUT,
81+
},
82+
);
83+
},
84+
parameters: {
85+
msw: {
86+
handlers: [
87+
http.get(`${DEFAULT_HOSTNAME_API}/2.0/folders/74729718131`, () => {
88+
return HttpResponse.json(mockEmptyRootFolder);
89+
}),
90+
],
91+
},
7692
},
7793
};
7894

7995
export const emptySelectionMode = {
8096
play: async ({ canvasElement }) => {
8197
const canvas = within(canvasElement);
82-
const emptyModeChooseButton = canvas.getByLabelText('Choose');
83-
await userEvent.click(emptyModeChooseButton);
84-
expect(emptyModeChooseButton).toBeDisabled();
98+
const chooseButton = canvas.getByLabelText('Choose');
99+
expect(chooseButton).toBeDisabled();
85100
},
86101
};
87102

@@ -91,21 +106,54 @@ export const withError = {
91106
},
92107
play: async ({ canvasElement }) => {
93108
const canvas = within(canvasElement);
94-
await waitFor(() => {
95-
expect(canvas.getByText('A network error has occurred while trying to load.')).toBeInTheDocument();
96-
expect(canvas.queryByRole('progressbar')).not.toBeInTheDocument();
97-
});
109+
110+
await waitFor(
111+
() => {
112+
// Verify error state is displayed
113+
expect(canvas.getByText('A network error has occurred while trying to load.')).toBeInTheDocument();
114+
},
115+
{
116+
timeout: SLEEP_TIMEOUT * 3, // Increase timeout to allow for retries
117+
},
118+
);
119+
},
120+
parameters: {
121+
msw: {
122+
handlers: [
123+
http.get(`${DEFAULT_HOSTNAME_API}/2.0/folders/69083462919`, () => {
124+
return new HttpResponse('Internal Server Error', { status: 500 });
125+
}),
126+
],
127+
},
98128
},
99129
};
100130

101131
export const hitSelectionLimit = {
102132
args: {
103133
maxSelectable: 2,
104134
},
135+
parameters: {
136+
msw: {
137+
handlers: [
138+
http.get(`${DEFAULT_HOSTNAME_API}/2.0/folders/69083462919`, () => {
139+
return HttpResponse.json(mockRootFolder);
140+
}),
141+
http.get(`${DEFAULT_HOSTNAME_API}/2.0/folders/73426618530`, () => {
142+
return HttpResponse.json(mockSubFolder);
143+
}),
144+
],
145+
},
146+
},
105147
play: async ({ canvasElement }) => {
106148
const canvas = within(canvasElement);
107149

108-
// Wait for items to load and verify initial state
150+
// Wait for root folder to load and navigate into "An Ordered Folder"
151+
await waitFor(() => {
152+
expect(canvas.getByText('An Ordered Folder')).toBeInTheDocument();
153+
});
154+
await userEvent.dblClick(canvas.getByText('An Ordered Folder'));
155+
156+
// Wait for subfolder items to load
109157
await waitFor(() => {
110158
const items = canvas.getAllByRole('row');
111159
expect(items.length).toBeGreaterThan(1); // Header row + at least one item
@@ -174,10 +222,28 @@ export const hitSelectionLimit = {
174222
};
175223

176224
export const cancelUnselectsItems = {
225+
parameters: {
226+
msw: {
227+
handlers: [
228+
http.get(`${DEFAULT_HOSTNAME_API}/2.0/folders/69083462919`, () => {
229+
return HttpResponse.json(mockRootFolder);
230+
}),
231+
http.get(`${DEFAULT_HOSTNAME_API}/2.0/folders/73426618530`, () => {
232+
return HttpResponse.json(mockSubFolder);
233+
}),
234+
],
235+
},
236+
},
177237
play: async ({ canvasElement }) => {
178238
const canvas = within(canvasElement);
179239

180-
// Wait for items to load
240+
// Wait for root folder to load and navigate into "An Ordered Folder"
241+
await waitFor(() => {
242+
expect(canvas.getByText('An Ordered Folder')).toBeInTheDocument();
243+
});
244+
await userEvent.click(canvas.getByText('An Ordered Folder'));
245+
246+
// Wait for subfolder items to load
181247
await waitFor(() => {
182248
const items = canvas.getAllByRole('row');
183249
expect(items.length).toBeGreaterThan(1); // Header row + at least one item
@@ -239,15 +305,28 @@ export const singleSelectWithItems = {
239305
args: {
240306
maxSelectable: 1,
241307
},
308+
parameters: {
309+
msw: {
310+
handlers: [
311+
http.get(`${DEFAULT_HOSTNAME_API}/2.0/folders/69083462919`, () => {
312+
return HttpResponse.json(mockRootFolder);
313+
}),
314+
http.get(`${DEFAULT_HOSTNAME_API}/2.0/folders/73426618530`, () => {
315+
return HttpResponse.json(mockSubFolder);
316+
}),
317+
],
318+
},
319+
},
242320
play: async ({ canvasElement }) => {
243321
const canvas = within(canvasElement);
244322

245-
// Wait for initial loading state
323+
// Wait for root folder to load and navigate into "An Ordered Folder"
246324
await waitFor(() => {
247-
expect(canvas.getByRole('progressbar')).toBeInTheDocument();
325+
expect(canvas.getByText('An Ordered Folder')).toBeInTheDocument();
248326
});
327+
await userEvent.dblClick(canvas.getByText('An Ordered Folder'));
249328

250-
// Wait for items to load
329+
// Wait for subfolder items to load
251330
await waitFor(() => {
252331
expect(canvas.queryByRole('progressbar')).not.toBeInTheDocument();
253332
const items = canvas.getAllByRole('row');

0 commit comments

Comments
 (0)