@squiz/resource-browser 1.69.2 → 2.1.9-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +89 -38
- package/LICENSE.md +15 -0
- package/README.md +9 -0
- package/jest.config.ts +22 -21
- package/lib/Hooks/useSelectedState.d.ts +15 -0
- package/lib/Hooks/useSelectedState.js +16 -0
- package/lib/Hooks/useSources.d.ts +6 -6
- package/lib/Hooks/useSources.js +26 -1
- package/lib/MainContainer/MainContainer.d.ts +17 -0
- package/lib/MainContainer/MainContainer.js +61 -0
- package/lib/Plugin/Plugin.d.ts +13 -0
- package/lib/Plugin/Plugin.js +17 -0
- package/lib/ResourceBrowserContext/ResourceBrowserContext.d.ts +2 -3
- package/lib/ResourceBrowserContext/ResourceBrowserContext.js +4 -17
- package/lib/ResourceBrowserInput/ResourceBrowserInput.d.ts +24 -0
- package/lib/ResourceBrowserInput/ResourceBrowserInput.js +16 -0
- package/lib/ResourcePicker/ResourcePicker.d.ts +6 -4
- package/lib/ResourcePicker/ResourcePicker.js +14 -8
- package/lib/ResourcePicker/States/Selected.d.ts +10 -4
- package/lib/ResourcePicker/States/Selected.js +11 -32
- package/lib/SourceDropdown/SourceDropdown.d.ts +5 -11
- package/lib/SourceDropdown/SourceDropdown.js +20 -99
- package/lib/SourceList/SourceList.d.ts +5 -16
- package/lib/SourceList/SourceList.js +14 -75
- package/lib/index.css +42 -202
- package/lib/index.d.ts +7 -7
- package/lib/index.js +69 -13
- package/lib/types.d.ts +41 -59
- package/package.json +82 -80
- package/src/Hooks/useSelectedState.spec.ts +46 -0
- package/src/Hooks/useSelectedState.ts +22 -0
- package/src/Hooks/useSources.spec.ts +60 -13
- package/src/Hooks/useSources.ts +35 -5
- package/src/Icons/CircledLoopIcon.tsx +8 -8
- package/src/MainContainer/MainContainer.spec.tsx +203 -0
- package/src/MainContainer/MainContainer.stories.tsx +62 -0
- package/src/MainContainer/MainContainer.tsx +101 -0
- package/src/Plugin/Plugin.spec.tsx +46 -0
- package/src/Plugin/Plugin.tsx +20 -0
- package/src/ResourceBrowserContext/ResourceBrowserContext.spec.tsx +65 -106
- package/src/ResourceBrowserContext/ResourceBrowserContext.tsx +24 -39
- package/src/ResourceBrowserInput/ResourceBrowserInput.spec.tsx +192 -0
- package/src/ResourceBrowserInput/ResourceBrowserInput.tsx +81 -0
- package/src/ResourcePicker/ResourcePicker.spec.tsx +159 -116
- package/src/ResourcePicker/ResourcePicker.stories.tsx +28 -24
- package/src/ResourcePicker/ResourcePicker.tsx +79 -59
- package/src/ResourcePicker/States/Error.tsx +8 -8
- package/src/ResourcePicker/States/Loading.tsx +3 -3
- package/src/ResourcePicker/States/Selected.tsx +66 -73
- package/src/ResourcePicker/mock-image-resource.json +25 -47
- package/src/ResourcePicker/mock-resource.json +11 -13
- package/src/ResourcePicker/resource-picker.scss +13 -13
- package/src/SourceDropdown/SourceDropdown.spec.tsx +65 -391
- package/src/SourceDropdown/SourceDropdown.stories.tsx +21 -24
- package/src/SourceDropdown/SourceDropdown.tsx +80 -258
- package/src/SourceList/SourceList.spec.tsx +37 -430
- package/src/SourceList/SourceList.stories.tsx +17 -37
- package/src/SourceList/SourceList.tsx +28 -155
- package/src/__mocks__/MockModels.ts +56 -25
- package/src/__mocks__/PluginExample.tsx +98 -0
- package/src/__mocks__/StorybookHelpers.tsx +141 -0
- package/src/__mocks__/renderWithContext.tsx +14 -18
- package/src/__mocks__/sample-sources.json +32 -0
- package/src/index.scss +18 -8
- package/src/index.spec.tsx +277 -99
- package/src/index.stories.tsx +65 -39
- package/src/index.tsx +119 -57
- package/src/types.ts +54 -63
- package/tailwind.config.cjs +92 -92
- package/vite.config.js +12 -12
- package/lib/Hooks/useCategorisedSources.d.ts +0 -14
- package/lib/Hooks/useCategorisedSources.js +0 -38
- package/lib/Hooks/useChildResources.d.ts +0 -16
- package/lib/Hooks/useChildResources.js +0 -13
- package/lib/Hooks/usePreselectedResourcePath.d.ts +0 -20
- package/lib/Hooks/usePreselectedResourcePath.js +0 -31
- package/lib/Hooks/useRecentLocations.d.ts +0 -5
- package/lib/Hooks/useRecentLocations.js +0 -38
- package/lib/Hooks/useRecentResourcesPaths.d.ts +0 -20
- package/lib/Hooks/useRecentResourcesPaths.js +0 -30
- package/lib/Hooks/useResource.d.ts +0 -28
- package/lib/Hooks/useResource.js +0 -25
- package/lib/Hooks/useResourcePath.d.ts +0 -16
- package/lib/Hooks/useResourcePath.js +0 -64
- package/lib/Icons/HistoryIcon.d.ts +0 -4
- package/lib/Icons/HistoryIcon.js +0 -13
- package/lib/PreviewPanel/PreviewPanel.d.ts +0 -5
- package/lib/PreviewPanel/PreviewPanel.js +0 -8
- package/lib/PreviewPanel/details/MatrixResource.d.ts +0 -7
- package/lib/PreviewPanel/details/MatrixResource.js +0 -35
- package/lib/ResourceBreadcrumb/ResourceBreadcrumb.d.ts +0 -9
- package/lib/ResourceBreadcrumb/ResourceBreadcrumb.js +0 -54
- package/lib/ResourceList/ResourceList.d.ts +0 -18
- package/lib/ResourceList/ResourceList.js +0 -49
- package/lib/ResourcePickerContainer/ResourcePickerContainer.d.ts +0 -17
- package/lib/ResourcePickerContainer/ResourcePickerContainer.js +0 -166
- package/lib/StatusIndicator/StatusIndicator.d.ts +0 -8
- package/lib/StatusIndicator/StatusIndicator.js +0 -27
- package/lib/utils/findBestMatchLineage.d.ts +0 -2
- package/lib/utils/findBestMatchLineage.js +0 -28
- package/lib/utils/uuid.d.ts +0 -1
- package/lib/utils/uuid.js +0 -6
- package/src/Hooks/useCategorisedSources.spec.ts +0 -39
- package/src/Hooks/useCategorisedSources.ts +0 -46
- package/src/Hooks/useChildResources.spec.ts +0 -29
- package/src/Hooks/useChildResources.ts +0 -21
- package/src/Hooks/usePreselectedResourcePath.ts +0 -54
- package/src/Hooks/useRecentLocations.spec.ts +0 -81
- package/src/Hooks/useRecentLocations.ts +0 -44
- package/src/Hooks/useRecentResourcesPaths.ts +0 -54
- package/src/Hooks/useResource.spec.ts +0 -61
- package/src/Hooks/useResource.ts +0 -40
- package/src/Hooks/useResourcePath.spec.ts +0 -120
- package/src/Hooks/useResourcePath.ts +0 -76
- package/src/Icons/HistoryIcon.tsx +0 -17
- package/src/PreviewPanel/PreviewPanel.spec.tsx +0 -198
- package/src/PreviewPanel/PreviewPanel.stories.tsx +0 -76
- package/src/PreviewPanel/PreviewPanel.tsx +0 -6
- package/src/PreviewPanel/details/MatrixResource.tsx +0 -54
- package/src/PreviewPanel/details/matrix-resource.scss +0 -16
- package/src/ResourceBreadcrumb/ResourceBreadcrumb.spec.tsx +0 -133
- package/src/ResourceBreadcrumb/ResourceBreadcrumb.stories.tsx +0 -24
- package/src/ResourceBreadcrumb/ResourceBreadcrumb.tsx +0 -79
- package/src/ResourceBreadcrumb/resource-breadcrumb.scss +0 -28
- package/src/ResourceBreadcrumb/sample-hierarchy.json +0 -27
- package/src/ResourceList/ResourceList.spec.tsx +0 -202
- package/src/ResourceList/ResourceList.stories.tsx +0 -40
- package/src/ResourceList/ResourceList.tsx +0 -83
- package/src/ResourceList/sample-resources.json +0 -851
- package/src/ResourcePickerContainer/ResourcePickerContainer.spec.tsx +0 -780
- package/src/ResourcePickerContainer/ResourcePickerContainer.stories.tsx +0 -45
- package/src/ResourcePickerContainer/ResourcePickerContainer.tsx +0 -290
- package/src/SourceList/sample-sources.json +0 -251
- package/src/StatusIndicator/StatusIndicator.stories.tsx +0 -83
- package/src/StatusIndicator/StatusIndicator.tsx +0 -38
- package/src/__mocks__/JestHelpers.ts +0 -65
- package/src/__mocks__/StorybookHelpers.ts +0 -128
- package/src/__mocks__/jestHelpers.spec.ts +0 -38
- package/src/utils/findBestMatchLineage.spec.ts +0 -81
- package/src/utils/findBestMatchLineage.ts +0 -30
- package/src/utils/uuid.ts +0 -5
@@ -1,433 +1,107 @@
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-empty-function */
|
2
1
|
import React from 'react';
|
3
|
-
import { screen, render, waitFor } from '@testing-library/react';
|
2
|
+
import { screen, render, waitFor, act, fireEvent } from '@testing-library/react';
|
4
3
|
import userEvent from '@testing-library/user-event';
|
5
4
|
import SourceDropdown from './SourceDropdown';
|
6
|
-
import {
|
7
|
-
import {
|
8
|
-
import { RecentResourcesPaths } from '../Hooks/useRecentResourcesPaths';
|
9
|
-
|
10
|
-
const mockRecentSources: RecentResourcesPaths[] = [
|
11
|
-
{
|
12
|
-
source: mockSource({
|
13
|
-
id: '1',
|
14
|
-
name: 'Source 1',
|
15
|
-
nodes: [
|
16
|
-
{
|
17
|
-
id: '1',
|
18
|
-
type: {
|
19
|
-
code: 'site',
|
20
|
-
name: 'Site',
|
21
|
-
},
|
22
|
-
name: 'Node 1',
|
23
|
-
childCount: 21,
|
24
|
-
},
|
25
|
-
{
|
26
|
-
id: '2',
|
27
|
-
type: {
|
28
|
-
code: 'site',
|
29
|
-
name: 'Site',
|
30
|
-
},
|
31
|
-
name: 'Node 2',
|
32
|
-
childCount: 13,
|
33
|
-
},
|
34
|
-
],
|
35
|
-
}),
|
36
|
-
path: [mockResource()],
|
37
|
-
},
|
38
|
-
];
|
39
|
-
|
40
|
-
const sources: Source[] = [
|
41
|
-
mockSource({
|
42
|
-
id: '1',
|
43
|
-
name: 'Source 1',
|
44
|
-
nodes: [
|
45
|
-
{
|
46
|
-
id: '1',
|
47
|
-
type: {
|
48
|
-
code: 'site',
|
49
|
-
name: 'Site',
|
50
|
-
},
|
51
|
-
name: 'Node 1',
|
52
|
-
childCount: 21,
|
53
|
-
},
|
54
|
-
{
|
55
|
-
id: '2',
|
56
|
-
type: {
|
57
|
-
code: 'site',
|
58
|
-
name: 'Site',
|
59
|
-
},
|
60
|
-
name: 'Node 2',
|
61
|
-
childCount: 13,
|
62
|
-
},
|
63
|
-
],
|
64
|
-
}),
|
65
|
-
mockSource({
|
66
|
-
id: '2',
|
67
|
-
name: 'Source 2',
|
68
|
-
nodes: [
|
69
|
-
{
|
70
|
-
id: '3',
|
71
|
-
type: {
|
72
|
-
code: 'site',
|
73
|
-
name: 'Site',
|
74
|
-
},
|
75
|
-
name: 'Node 3',
|
76
|
-
childCount: 15,
|
77
|
-
},
|
78
|
-
{
|
79
|
-
id: '4',
|
80
|
-
type: {
|
81
|
-
code: 'site',
|
82
|
-
name: 'Site',
|
83
|
-
},
|
84
|
-
name: 'Node 4',
|
85
|
-
childCount: 10,
|
86
|
-
},
|
87
|
-
],
|
88
|
-
}),
|
89
|
-
];
|
5
|
+
import { mockSource } from '../__mocks__/MockModels';
|
6
|
+
import { ResourceBrowserSource } from '../types';
|
90
7
|
|
91
8
|
describe('SourceDropdown', () => {
|
92
|
-
|
93
|
-
|
94
|
-
<SourceDropdown
|
95
|
-
sources={sources}
|
96
|
-
selectedSource={null}
|
97
|
-
isLoading={false}
|
98
|
-
onRootSelect={() => {}}
|
99
|
-
onSourceSelect={() => {}}
|
100
|
-
setSource={() => {}}
|
101
|
-
currentResource={mockResource()}
|
102
|
-
recentSources={mockRecentSources}
|
103
|
-
/>,
|
104
|
-
);
|
105
|
-
|
106
|
-
await waitFor(() => {
|
107
|
-
expect(screen.getByRole('button', { name: 'Source quick select' })).toHaveTextContent(
|
108
|
-
'view All available sources',
|
109
|
-
);
|
110
|
-
});
|
111
|
-
});
|
112
|
-
|
113
|
-
it('Show loading state if isLoading true', async () => {
|
114
|
-
render(
|
115
|
-
<SourceDropdown
|
116
|
-
sources={sources}
|
117
|
-
selectedSource={null}
|
118
|
-
isLoading={true}
|
119
|
-
onRootSelect={() => {}}
|
120
|
-
onSourceSelect={() => {}}
|
121
|
-
setSource={() => {}}
|
122
|
-
currentResource={mockResource()}
|
123
|
-
recentSources={mockRecentSources}
|
124
|
-
/>,
|
125
|
-
);
|
126
|
-
|
127
|
-
await waitFor(() => {
|
128
|
-
expect(screen.getByLabelText('Loading sources')).toBeTruthy();
|
129
|
-
});
|
130
|
-
});
|
9
|
+
it('Render empty fragment if no sources are provided', async () => {
|
10
|
+
const sources: Array<ResourceBrowserSource> = [];
|
131
11
|
|
132
|
-
|
133
|
-
render(
|
134
|
-
<SourceDropdown
|
135
|
-
sources={sources}
|
136
|
-
selectedSource={mockScopedSource({
|
137
|
-
source: {
|
138
|
-
name: 'Active source',
|
139
|
-
},
|
140
|
-
resource: {
|
141
|
-
name: 'Active scoped resource',
|
142
|
-
},
|
143
|
-
})}
|
144
|
-
isLoading={false}
|
145
|
-
onRootSelect={() => {}}
|
146
|
-
onSourceSelect={() => {}}
|
147
|
-
setSource={() => {}}
|
148
|
-
currentResource={mockResource()}
|
149
|
-
recentSources={mockRecentSources}
|
150
|
-
/>,
|
151
|
-
);
|
12
|
+
const { baseElement } = render(<SourceDropdown sources={sources} selectedSource={mockSource()} onSourceSelect={() => {}} />);
|
152
13
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
14
|
+
await waitFor(() => {
|
15
|
+
const button = baseElement.querySelector(`button[aria-label="Source quick select"]`) as HTMLButtonElement;
|
16
|
+
expect(button).toBeFalsy();
|
17
|
+
});
|
157
18
|
});
|
158
|
-
});
|
159
19
|
|
160
|
-
|
161
|
-
|
162
|
-
<SourceDropdown
|
163
|
-
sources={sources}
|
164
|
-
selectedSource={null}
|
165
|
-
isLoading={false}
|
166
|
-
onRootSelect={() => {}}
|
167
|
-
onSourceSelect={() => {}}
|
168
|
-
setSource={() => {}}
|
169
|
-
currentResource={mockResource()}
|
170
|
-
recentSources={mockRecentSources}
|
171
|
-
/>,
|
172
|
-
);
|
20
|
+
it('Render title of the selected source', async () => {
|
21
|
+
const sources = [mockSource(), mockSource({ id: '2', name: 'Selected source' })];
|
173
22
|
|
174
|
-
|
175
|
-
user.click(screen.getByRole('button', { name: 'Source quick select' }));
|
23
|
+
render(<SourceDropdown sources={sources} selectedSource={sources[1]} onSourceSelect={() => {}} />);
|
176
24
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
expect(screen.getByRole('button', { name: 'Site Node 2' })).toBeTruthy();
|
181
|
-
expect(screen.getByRole('button', { name: 'Site Node 3' })).toBeTruthy();
|
182
|
-
expect(screen.getByRole('button', { name: 'Site Node 4' })).toBeTruthy();
|
25
|
+
await waitFor(() => {
|
26
|
+
expect(screen.getByRole('button', { name: 'Source quick select' })).toHaveTextContent('Selected source');
|
27
|
+
});
|
183
28
|
});
|
184
|
-
});
|
185
29
|
|
186
|
-
|
187
|
-
|
188
|
-
<div>
|
189
|
-
<SourceDropdown
|
190
|
-
sources={sources}
|
191
|
-
selectedSource={null}
|
192
|
-
isLoading={false}
|
193
|
-
onRootSelect={() => {}}
|
194
|
-
onSourceSelect={() => {}}
|
195
|
-
setSource={() => {}}
|
196
|
-
currentResource={mockResource()}
|
197
|
-
recentSources={mockRecentSources}
|
198
|
-
/>
|
199
|
-
<input />
|
200
|
-
</div>,
|
201
|
-
);
|
30
|
+
it('Sources are rendered when dropdown clicked', async () => {
|
31
|
+
const sources = [mockSource({ name: 'Source 1' }), mockSource({ id: '2', name: 'Source 2' })];
|
202
32
|
|
203
|
-
|
204
|
-
const buttonDropdown = screen.getByRole('button', { name: 'Source quick select' });
|
205
|
-
user.click(buttonDropdown);
|
33
|
+
render(<SourceDropdown sources={sources} selectedSource={sources[0]} onSourceSelect={() => {}} />);
|
206
34
|
|
207
|
-
|
208
|
-
expect(screen.getByRole('button', { name: 'All available sources' })).toBeTruthy();
|
209
|
-
expect(screen.getByRole('button', { name: 'Site Node 1' })).toBeTruthy();
|
210
|
-
expect(screen.getByRole('button', { name: 'Site Node 2' })).toBeTruthy();
|
211
|
-
expect(screen.getByRole('button', { name: 'Site Node 3' })).toBeTruthy();
|
212
|
-
expect(screen.getByRole('button', { name: 'Site Node 4' })).toBeTruthy();
|
213
|
-
});
|
35
|
+
const user = userEvent.setup();
|
214
36
|
|
215
|
-
|
216
|
-
user.type(buttonDropdown, '{tab}');
|
217
|
-
user.type(buttonDropdown, '{tab}');
|
218
|
-
user.type(buttonDropdown, '{tab}');
|
219
|
-
user.type(buttonDropdown, '{tab}');
|
37
|
+
await act(() => user.click(screen.getByRole('button', { name: 'Source quick select' })));
|
220
38
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
expect(screen.queryByRole('button', { name: 'site Node 3' })).toBeFalsy();
|
226
|
-
expect(screen.queryByRole('button', { name: 'site Node 4' })).toBeFalsy();
|
39
|
+
await waitFor(() => {
|
40
|
+
expect(screen.getByRole('button', { name: 'dam Source 1 selected' })).toBeTruthy();
|
41
|
+
expect(screen.getByRole('button', { name: 'dam Source 2' })).toBeTruthy();
|
42
|
+
});
|
227
43
|
});
|
228
|
-
});
|
229
44
|
|
230
|
-
|
231
|
-
|
232
|
-
<div>
|
233
|
-
<SourceDropdown
|
234
|
-
sources={sources}
|
235
|
-
selectedSource={null}
|
236
|
-
isLoading={false}
|
237
|
-
onRootSelect={() => {}}
|
238
|
-
onSourceSelect={() => {}}
|
239
|
-
setSource={() => {}}
|
240
|
-
currentResource={mockResource()}
|
241
|
-
recentSources={mockRecentSources}
|
242
|
-
/>
|
243
|
-
<input />
|
244
|
-
</div>,
|
245
|
-
);
|
45
|
+
it('Source menu closes on focus loss', async () => {
|
46
|
+
const sources = [mockSource({ name: 'Source 1' }), mockSource({ id: '2', name: 'Source 2' })];
|
246
47
|
|
247
|
-
|
248
|
-
const buttonDropdown = screen.getByRole('button', { name: 'Source quick select' });
|
249
|
-
user.click(buttonDropdown);
|
48
|
+
render(<SourceDropdown sources={sources} selectedSource={sources[0]} onSourceSelect={() => {}} />);
|
250
49
|
|
251
|
-
|
252
|
-
|
253
|
-
expect(screen.getByRole('button', { name: 'Site Node 1' })).toBeTruthy();
|
254
|
-
expect(screen.getByRole('button', { name: 'Site Node 2' })).toBeTruthy();
|
255
|
-
expect(screen.getByRole('button', { name: 'Site Node 3' })).toBeTruthy();
|
256
|
-
expect(screen.getByRole('button', { name: 'Site Node 4' })).toBeTruthy();
|
257
|
-
});
|
50
|
+
const user = userEvent.setup();
|
51
|
+
const buttonDropdown = screen.getByRole('button', { name: 'Source quick select' });
|
258
52
|
|
259
|
-
|
53
|
+
await act(() => user.click(buttonDropdown));
|
260
54
|
|
261
|
-
|
55
|
+
await waitFor(() => {
|
56
|
+
expect(screen.queryByRole('button', { name: 'dam Source 1 selected' })).toBeTruthy();
|
57
|
+
expect(screen.queryByRole('button', { name: 'dam Source 2' })).toBeTruthy();
|
58
|
+
});
|
262
59
|
|
263
|
-
|
60
|
+
await act(() => fireEvent.blur(buttonDropdown));
|
264
61
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
expect(screen.queryByRole('button', { name: 'Site Node 3' })).toBeFalsy();
|
270
|
-
expect(screen.queryByRole('button', { name: 'Site Node 4' })).toBeFalsy();
|
62
|
+
await waitFor(() => {
|
63
|
+
expect(screen.queryByRole('button', { name: 'dam Source 1 selected' })).toBeFalsy();
|
64
|
+
expect(screen.queryByRole('button', { name: 'dam Source 2' })).toBeFalsy();
|
65
|
+
});
|
271
66
|
});
|
272
|
-
});
|
273
67
|
|
274
|
-
|
275
|
-
|
68
|
+
it('Source menu closes on {esc}', async () => {
|
69
|
+
const sources = [mockSource({ name: 'Source 1' }), mockSource({ id: '2', name: 'Source 2' })];
|
276
70
|
|
277
|
-
|
278
|
-
<SourceDropdown
|
279
|
-
sources={sources}
|
280
|
-
selectedSource={null}
|
281
|
-
isLoading={false}
|
282
|
-
onRootSelect={onRootSelect}
|
283
|
-
onSourceSelect={() => {}}
|
284
|
-
setSource={() => {}}
|
285
|
-
currentResource={mockResource()}
|
286
|
-
recentSources={mockRecentSources}
|
287
|
-
/>,
|
288
|
-
);
|
71
|
+
render(<SourceDropdown sources={sources} selectedSource={sources[0]} onSourceSelect={() => {}} />);
|
289
72
|
|
290
|
-
|
291
|
-
|
292
|
-
await user.click(screen.getByRole('button', { name: 'All available sources' }));
|
293
|
-
|
294
|
-
await waitFor(() => {
|
295
|
-
expect(onRootSelect).toHaveBeenCalled();
|
296
|
-
expect(screen.queryByRole('button', { name: 'All available sources' })).toBeFalsy();
|
297
|
-
});
|
298
|
-
});
|
73
|
+
const user = userEvent.setup();
|
74
|
+
const buttonDropdown = screen.getByRole('button', { name: 'Source quick select' });
|
299
75
|
|
300
|
-
|
301
|
-
const onSourceSelect = jest.fn();
|
76
|
+
await act(() => user.click(buttonDropdown));
|
302
77
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
isLoading={false}
|
308
|
-
onRootSelect={() => {}}
|
309
|
-
onSourceSelect={onSourceSelect}
|
310
|
-
setSource={() => {}}
|
311
|
-
currentResource={mockResource()}
|
312
|
-
recentSources={mockRecentSources}
|
313
|
-
/>,
|
314
|
-
);
|
78
|
+
await waitFor(() => {
|
79
|
+
expect(screen.queryByRole('button', { name: 'dam Source 1 selected' })).toBeTruthy();
|
80
|
+
expect(screen.queryByRole('button', { name: 'dam Source 2' })).toBeTruthy();
|
81
|
+
});
|
315
82
|
|
316
|
-
|
317
|
-
await user.click(screen.getByRole('button', { name: 'Source quick select' }));
|
318
|
-
await user.click(screen.getByRole('button', { name: 'Site Node 1' }));
|
83
|
+
await act(() => userEvent.keyboard('{escape}'));
|
319
84
|
|
320
|
-
|
321
|
-
|
322
|
-
|
85
|
+
await waitFor(() => {
|
86
|
+
expect(screen.queryByRole('button', { name: 'dam Source 1 selected' })).toBeFalsy();
|
87
|
+
expect(screen.queryByRole('button', { name: 'dam Source 2' })).toBeFalsy();
|
88
|
+
});
|
323
89
|
});
|
324
|
-
});
|
325
90
|
|
326
|
-
|
327
|
-
|
328
|
-
<SourceDropdown
|
329
|
-
sources={sources}
|
330
|
-
selectedSource={null}
|
331
|
-
isLoading={false}
|
332
|
-
onRootSelect={() => {}}
|
333
|
-
onSourceSelect={() => {}}
|
334
|
-
setSource={() => {}}
|
335
|
-
currentResource={mockResource()}
|
336
|
-
recentSources={mockRecentSources}
|
337
|
-
/>,
|
338
|
-
);
|
339
|
-
|
340
|
-
const user = userEvent.setup();
|
341
|
-
user.click(screen.getByRole('button', { name: 'Source quick select' }));
|
342
|
-
|
343
|
-
await waitFor(() => {
|
344
|
-
expect(screen.getByText('Test resource')).toBeInTheDocument();
|
345
|
-
});
|
346
|
-
});
|
91
|
+
it('Selecting node calls onSourceSelect ', async () => {
|
92
|
+
const onSourceSelect = jest.fn();
|
347
93
|
|
348
|
-
|
349
|
-
const onSourceSelect = jest.fn();
|
350
|
-
const setSource = jest.fn();
|
94
|
+
const sources = [mockSource({ name: 'Source 1' }), mockSource({ id: '2', name: 'Source 2' })];
|
351
95
|
|
352
|
-
|
353
|
-
<SourceDropdown
|
354
|
-
sources={sources}
|
355
|
-
selectedSource={null}
|
356
|
-
isLoading={false}
|
357
|
-
onRootSelect={() => {}}
|
358
|
-
onSourceSelect={onSourceSelect}
|
359
|
-
setSource={setSource}
|
360
|
-
currentResource={mockResource()}
|
361
|
-
recentSources={mockRecentSources}
|
362
|
-
/>,
|
363
|
-
);
|
96
|
+
render(<SourceDropdown sources={sources} selectedSource={sources[0]} onSourceSelect={onSourceSelect} />);
|
364
97
|
|
365
|
-
|
366
|
-
await user.click(screen.getByRole('button', { name: 'Source quick select' }));
|
367
|
-
await user.click(screen.getByText('Test resource'));
|
98
|
+
const user = userEvent.setup();
|
368
99
|
|
369
|
-
|
370
|
-
|
371
|
-
{
|
372
|
-
resource: {
|
373
|
-
childCount: 0,
|
374
|
-
id: '1',
|
375
|
-
lineages: [],
|
376
|
-
name: 'Test resource',
|
377
|
-
status: {
|
378
|
-
code: 'live',
|
379
|
-
name: 'Live',
|
380
|
-
},
|
381
|
-
type: {
|
382
|
-
code: 'folder',
|
383
|
-
name: 'Folder',
|
384
|
-
},
|
385
|
-
url: 'https://no-where.com',
|
386
|
-
urls: [],
|
387
|
-
},
|
388
|
-
source: {
|
389
|
-
id: '1',
|
390
|
-
name: 'Source 1',
|
391
|
-
nodes: [
|
392
|
-
{
|
393
|
-
childCount: 21,
|
394
|
-
id: '1',
|
395
|
-
lineages: [],
|
396
|
-
name: 'Node 1',
|
397
|
-
status: {
|
398
|
-
code: 'live',
|
399
|
-
name: 'Live',
|
400
|
-
},
|
401
|
-
type: {
|
402
|
-
code: 'site',
|
403
|
-
name: 'Site',
|
404
|
-
},
|
405
|
-
url: 'https://no-where.com',
|
406
|
-
urls: [],
|
407
|
-
},
|
408
|
-
{
|
409
|
-
childCount: 13,
|
410
|
-
id: '2',
|
411
|
-
lineages: [],
|
412
|
-
name: 'Node 2',
|
413
|
-
status: {
|
414
|
-
code: 'live',
|
415
|
-
name: 'Live',
|
416
|
-
},
|
417
|
-
type: {
|
418
|
-
code: 'site',
|
419
|
-
name: 'Site',
|
420
|
-
},
|
421
|
-
url: 'https://no-where.com',
|
422
|
-
urls: [],
|
423
|
-
},
|
424
|
-
],
|
425
|
-
},
|
426
|
-
},
|
427
|
-
[],
|
428
|
-
);
|
100
|
+
await act(() => user.click(screen.getByRole('button', { name: 'Source quick select' })));
|
101
|
+
await act(() => user.click(screen.getByRole('button', { name: 'dam Source 2' })));
|
429
102
|
|
430
|
-
|
103
|
+
await waitFor(() => {
|
104
|
+
expect(onSourceSelect).toHaveBeenCalledWith(sources[1]);
|
105
|
+
});
|
431
106
|
});
|
432
|
-
});
|
433
107
|
});
|
@@ -1,33 +1,30 @@
|
|
1
|
-
import React from 'react';
|
1
|
+
import React, { useState } from 'react';
|
2
2
|
import { StoryFn, Meta } from '@storybook/react';
|
3
|
-
|
4
3
|
import SourceDropdown from './SourceDropdown';
|
5
|
-
import sampleSources from '../
|
4
|
+
import sampleSources from '../__mocks__/sample-sources.json';
|
5
|
+
import { ResourceBrowserSource } from '../types';
|
6
6
|
|
7
7
|
export default {
|
8
|
-
|
9
|
-
|
8
|
+
title: 'Source dropdown',
|
9
|
+
component: SourceDropdown,
|
10
10
|
} as Meta<typeof SourceDropdown>;
|
11
11
|
|
12
|
-
const Template: StoryFn<typeof SourceDropdown> = (
|
13
|
-
|
14
|
-
sources={sources}
|
15
|
-
selectedSource={selectedSource}
|
16
|
-
isLoading={isLoading}
|
17
|
-
onSourceSelect={({ source, id }) => alert(`Source Select: ${source} - ${id}`)}
|
18
|
-
onRootSelect={() => alert(`Root Select`)}
|
19
|
-
/>
|
20
|
-
);
|
12
|
+
const Template: StoryFn<typeof SourceDropdown> = (props) => {
|
13
|
+
const sources = sampleSources as ResourceBrowserSource[];
|
21
14
|
|
22
|
-
|
23
|
-
Primary.args = {
|
24
|
-
sources: sampleSources,
|
25
|
-
selectedSource: { source: sampleSources[0], resource: sampleSources[0].nodes[0] },
|
26
|
-
isLoading: false,
|
27
|
-
};
|
15
|
+
const [selectedSource, setSelectedSource] = useState<ResourceBrowserSource>(sources[0]);
|
28
16
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
17
|
+
return (
|
18
|
+
<div className="m-3">
|
19
|
+
<SourceDropdown
|
20
|
+
selectedSource={selectedSource}
|
21
|
+
sources={sources}
|
22
|
+
onSourceSelect={(source) => setSelectedSource(source)}
|
23
|
+
></SourceDropdown>
|
24
|
+
</div>
|
25
|
+
);
|
33
26
|
};
|
27
|
+
|
28
|
+
export const Primary = Template.bind({});
|
29
|
+
|
30
|
+
Primary.args = {};
|