@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.
Files changed (141) hide show
  1. package/CHANGELOG.md +89 -38
  2. package/LICENSE.md +15 -0
  3. package/README.md +9 -0
  4. package/jest.config.ts +22 -21
  5. package/lib/Hooks/useSelectedState.d.ts +15 -0
  6. package/lib/Hooks/useSelectedState.js +16 -0
  7. package/lib/Hooks/useSources.d.ts +6 -6
  8. package/lib/Hooks/useSources.js +26 -1
  9. package/lib/MainContainer/MainContainer.d.ts +17 -0
  10. package/lib/MainContainer/MainContainer.js +61 -0
  11. package/lib/Plugin/Plugin.d.ts +13 -0
  12. package/lib/Plugin/Plugin.js +17 -0
  13. package/lib/ResourceBrowserContext/ResourceBrowserContext.d.ts +2 -3
  14. package/lib/ResourceBrowserContext/ResourceBrowserContext.js +4 -17
  15. package/lib/ResourceBrowserInput/ResourceBrowserInput.d.ts +24 -0
  16. package/lib/ResourceBrowserInput/ResourceBrowserInput.js +16 -0
  17. package/lib/ResourcePicker/ResourcePicker.d.ts +6 -4
  18. package/lib/ResourcePicker/ResourcePicker.js +14 -8
  19. package/lib/ResourcePicker/States/Selected.d.ts +10 -4
  20. package/lib/ResourcePicker/States/Selected.js +11 -32
  21. package/lib/SourceDropdown/SourceDropdown.d.ts +5 -11
  22. package/lib/SourceDropdown/SourceDropdown.js +20 -99
  23. package/lib/SourceList/SourceList.d.ts +5 -16
  24. package/lib/SourceList/SourceList.js +14 -75
  25. package/lib/index.css +42 -202
  26. package/lib/index.d.ts +7 -7
  27. package/lib/index.js +69 -13
  28. package/lib/types.d.ts +41 -59
  29. package/package.json +82 -80
  30. package/src/Hooks/useSelectedState.spec.ts +46 -0
  31. package/src/Hooks/useSelectedState.ts +22 -0
  32. package/src/Hooks/useSources.spec.ts +60 -13
  33. package/src/Hooks/useSources.ts +35 -5
  34. package/src/Icons/CircledLoopIcon.tsx +8 -8
  35. package/src/MainContainer/MainContainer.spec.tsx +203 -0
  36. package/src/MainContainer/MainContainer.stories.tsx +62 -0
  37. package/src/MainContainer/MainContainer.tsx +101 -0
  38. package/src/Plugin/Plugin.spec.tsx +46 -0
  39. package/src/Plugin/Plugin.tsx +20 -0
  40. package/src/ResourceBrowserContext/ResourceBrowserContext.spec.tsx +65 -106
  41. package/src/ResourceBrowserContext/ResourceBrowserContext.tsx +24 -39
  42. package/src/ResourceBrowserInput/ResourceBrowserInput.spec.tsx +192 -0
  43. package/src/ResourceBrowserInput/ResourceBrowserInput.tsx +81 -0
  44. package/src/ResourcePicker/ResourcePicker.spec.tsx +159 -116
  45. package/src/ResourcePicker/ResourcePicker.stories.tsx +28 -24
  46. package/src/ResourcePicker/ResourcePicker.tsx +79 -59
  47. package/src/ResourcePicker/States/Error.tsx +8 -8
  48. package/src/ResourcePicker/States/Loading.tsx +3 -3
  49. package/src/ResourcePicker/States/Selected.tsx +66 -73
  50. package/src/ResourcePicker/mock-image-resource.json +25 -47
  51. package/src/ResourcePicker/mock-resource.json +11 -13
  52. package/src/ResourcePicker/resource-picker.scss +13 -13
  53. package/src/SourceDropdown/SourceDropdown.spec.tsx +65 -391
  54. package/src/SourceDropdown/SourceDropdown.stories.tsx +21 -24
  55. package/src/SourceDropdown/SourceDropdown.tsx +80 -258
  56. package/src/SourceList/SourceList.spec.tsx +37 -430
  57. package/src/SourceList/SourceList.stories.tsx +17 -37
  58. package/src/SourceList/SourceList.tsx +28 -155
  59. package/src/__mocks__/MockModels.ts +56 -25
  60. package/src/__mocks__/PluginExample.tsx +98 -0
  61. package/src/__mocks__/StorybookHelpers.tsx +141 -0
  62. package/src/__mocks__/renderWithContext.tsx +14 -18
  63. package/src/__mocks__/sample-sources.json +32 -0
  64. package/src/index.scss +18 -8
  65. package/src/index.spec.tsx +277 -99
  66. package/src/index.stories.tsx +65 -39
  67. package/src/index.tsx +119 -57
  68. package/src/types.ts +54 -63
  69. package/tailwind.config.cjs +92 -92
  70. package/vite.config.js +12 -12
  71. package/lib/Hooks/useCategorisedSources.d.ts +0 -14
  72. package/lib/Hooks/useCategorisedSources.js +0 -38
  73. package/lib/Hooks/useChildResources.d.ts +0 -16
  74. package/lib/Hooks/useChildResources.js +0 -13
  75. package/lib/Hooks/usePreselectedResourcePath.d.ts +0 -20
  76. package/lib/Hooks/usePreselectedResourcePath.js +0 -31
  77. package/lib/Hooks/useRecentLocations.d.ts +0 -5
  78. package/lib/Hooks/useRecentLocations.js +0 -38
  79. package/lib/Hooks/useRecentResourcesPaths.d.ts +0 -20
  80. package/lib/Hooks/useRecentResourcesPaths.js +0 -30
  81. package/lib/Hooks/useResource.d.ts +0 -28
  82. package/lib/Hooks/useResource.js +0 -25
  83. package/lib/Hooks/useResourcePath.d.ts +0 -16
  84. package/lib/Hooks/useResourcePath.js +0 -64
  85. package/lib/Icons/HistoryIcon.d.ts +0 -4
  86. package/lib/Icons/HistoryIcon.js +0 -13
  87. package/lib/PreviewPanel/PreviewPanel.d.ts +0 -5
  88. package/lib/PreviewPanel/PreviewPanel.js +0 -8
  89. package/lib/PreviewPanel/details/MatrixResource.d.ts +0 -7
  90. package/lib/PreviewPanel/details/MatrixResource.js +0 -35
  91. package/lib/ResourceBreadcrumb/ResourceBreadcrumb.d.ts +0 -9
  92. package/lib/ResourceBreadcrumb/ResourceBreadcrumb.js +0 -54
  93. package/lib/ResourceList/ResourceList.d.ts +0 -18
  94. package/lib/ResourceList/ResourceList.js +0 -49
  95. package/lib/ResourcePickerContainer/ResourcePickerContainer.d.ts +0 -17
  96. package/lib/ResourcePickerContainer/ResourcePickerContainer.js +0 -166
  97. package/lib/StatusIndicator/StatusIndicator.d.ts +0 -8
  98. package/lib/StatusIndicator/StatusIndicator.js +0 -27
  99. package/lib/utils/findBestMatchLineage.d.ts +0 -2
  100. package/lib/utils/findBestMatchLineage.js +0 -28
  101. package/lib/utils/uuid.d.ts +0 -1
  102. package/lib/utils/uuid.js +0 -6
  103. package/src/Hooks/useCategorisedSources.spec.ts +0 -39
  104. package/src/Hooks/useCategorisedSources.ts +0 -46
  105. package/src/Hooks/useChildResources.spec.ts +0 -29
  106. package/src/Hooks/useChildResources.ts +0 -21
  107. package/src/Hooks/usePreselectedResourcePath.ts +0 -54
  108. package/src/Hooks/useRecentLocations.spec.ts +0 -81
  109. package/src/Hooks/useRecentLocations.ts +0 -44
  110. package/src/Hooks/useRecentResourcesPaths.ts +0 -54
  111. package/src/Hooks/useResource.spec.ts +0 -61
  112. package/src/Hooks/useResource.ts +0 -40
  113. package/src/Hooks/useResourcePath.spec.ts +0 -120
  114. package/src/Hooks/useResourcePath.ts +0 -76
  115. package/src/Icons/HistoryIcon.tsx +0 -17
  116. package/src/PreviewPanel/PreviewPanel.spec.tsx +0 -198
  117. package/src/PreviewPanel/PreviewPanel.stories.tsx +0 -76
  118. package/src/PreviewPanel/PreviewPanel.tsx +0 -6
  119. package/src/PreviewPanel/details/MatrixResource.tsx +0 -54
  120. package/src/PreviewPanel/details/matrix-resource.scss +0 -16
  121. package/src/ResourceBreadcrumb/ResourceBreadcrumb.spec.tsx +0 -133
  122. package/src/ResourceBreadcrumb/ResourceBreadcrumb.stories.tsx +0 -24
  123. package/src/ResourceBreadcrumb/ResourceBreadcrumb.tsx +0 -79
  124. package/src/ResourceBreadcrumb/resource-breadcrumb.scss +0 -28
  125. package/src/ResourceBreadcrumb/sample-hierarchy.json +0 -27
  126. package/src/ResourceList/ResourceList.spec.tsx +0 -202
  127. package/src/ResourceList/ResourceList.stories.tsx +0 -40
  128. package/src/ResourceList/ResourceList.tsx +0 -83
  129. package/src/ResourceList/sample-resources.json +0 -851
  130. package/src/ResourcePickerContainer/ResourcePickerContainer.spec.tsx +0 -780
  131. package/src/ResourcePickerContainer/ResourcePickerContainer.stories.tsx +0 -45
  132. package/src/ResourcePickerContainer/ResourcePickerContainer.tsx +0 -290
  133. package/src/SourceList/sample-sources.json +0 -251
  134. package/src/StatusIndicator/StatusIndicator.stories.tsx +0 -83
  135. package/src/StatusIndicator/StatusIndicator.tsx +0 -38
  136. package/src/__mocks__/JestHelpers.ts +0 -65
  137. package/src/__mocks__/StorybookHelpers.ts +0 -128
  138. package/src/__mocks__/jestHelpers.spec.ts +0 -38
  139. package/src/utils/findBestMatchLineage.spec.ts +0 -81
  140. package/src/utils/findBestMatchLineage.ts +0 -30
  141. package/src/utils/uuid.ts +0 -5
@@ -1,448 +1,55 @@
1
- /* eslint-disable @typescript-eslint/no-empty-function */
2
1
  import React from 'react';
3
- import { screen, render, waitFor, within } from '@testing-library/react';
4
- import userEvent from '@testing-library/user-event';
5
- import { mockResource, mockSource } from '../__mocks__/MockModels';
6
- import { useOverlayTriggerState, OverlayTriggerState } from 'react-stately';
2
+ import { render, screen, act, fireEvent } from '@testing-library/react';
7
3
  import SourceList from './SourceList';
8
- import { Source } from '../types';
9
- import { RecentResourcesPaths } from '../Hooks/useRecentResourcesPaths';
10
4
 
11
- const mockRecentSources: RecentResourcesPaths[] = [
12
- {
13
- source: mockSource({
14
- id: '1',
15
- name: 'Source 1',
16
- nodes: [
17
- {
18
- id: '1',
19
- type: {
20
- code: 'site',
21
- name: 'Site',
22
- },
23
- name: 'Node 1',
24
- childCount: 21,
25
- },
26
- {
27
- id: '2',
28
- type: {
29
- code: 'site',
30
- name: 'Site',
31
- },
32
- name: 'Node 2',
33
- childCount: 13,
34
- },
35
- ],
36
- }),
37
- path: [mockResource()],
38
- },
39
- ];
5
+ import { mockSource } from '../__mocks__/MockModels';
40
6
 
41
- const sources: Source[] = [
42
- mockSource({
43
- id: '1',
44
- name: 'Source 1',
45
- nodes: [
46
- {
47
- id: '1',
48
- type: {
49
- code: 'site',
50
- name: 'Site',
51
- },
52
- name: 'Node 1',
53
- childCount: 21,
54
- },
55
- {
56
- id: '2',
57
- type: {
58
- code: 'site',
59
- name: 'Site',
60
- },
61
- name: 'Node 2',
62
- childCount: 13,
63
- },
64
- ],
65
- }),
66
- mockSource({
67
- id: '2',
68
- name: 'Source 2',
69
- nodes: [
70
- {
71
- id: '3',
72
- type: {
73
- code: 'site',
74
- name: 'Site',
75
- },
76
- name: 'Node 3',
77
- childCount: 15,
78
- },
79
- {
80
- id: '4',
81
- type: {
82
- code: 'site',
83
- name: 'Site',
84
- },
85
- name: 'Node 4',
86
- childCount: 10,
87
- },
88
- ],
89
- }),
90
- ];
91
-
92
- function SourceListTestWrapper({
93
- constructFunction,
94
- }: {
95
- constructFunction: (previewModalState: OverlayTriggerState) => JSX.Element;
96
- }) {
97
- const previewModalState = useOverlayTriggerState({});
98
- return constructFunction(previewModalState);
99
- }
7
+ import GenericBrowserLib from '@squiz/generic-browser-lib'; // Import Functional Component
8
+ jest.mock('@squiz/generic-browser-lib', () => {
9
+ return {
10
+ ...jest.requireActual('@squiz/generic-browser-lib'),
11
+ };
12
+ });
100
13
 
101
14
  describe('SourceList', () => {
102
- it('Shows loading when isLoading is true', async () => {
103
- const reload = jest.fn();
104
-
105
- render(
106
- <SourceListTestWrapper
107
- constructFunction={(previewModalState) => {
108
- return (
109
- <SourceList
110
- sources={sources}
111
- previewModalState={previewModalState}
112
- isLoading={true}
113
- onSourceSelect={() => {}}
114
- onSourceDrilldown={() => {}}
115
- error={null}
116
- handleReload={reload}
117
- setSource={() => {}}
118
- recentSources={mockRecentSources}
119
- />
120
- );
121
- }}
122
- />,
123
- );
124
-
125
- await waitFor(() => {
126
- expect(screen.getByLabelText('loading Source list')).toBeTruthy();
127
- });
128
- });
129
-
130
- it('Source list render each source', async () => {
131
- const reload = jest.fn();
132
-
133
- render(
134
- <SourceListTestWrapper
135
- constructFunction={(previewModalState) => {
136
- return (
137
- <SourceList
138
- sources={sources}
139
- previewModalState={previewModalState}
140
- isLoading={false}
141
- onSourceSelect={() => {}}
142
- onSourceDrilldown={() => {}}
143
- error={null}
144
- handleReload={reload}
145
- setSource={() => {}}
146
- recentSources={mockRecentSources}
147
- />
148
- );
149
- }}
150
- />,
151
- );
152
-
153
- await waitFor(() => {
154
- expect(screen.queryByText('Source 1')).toBeTruthy();
155
- expect(screen.queryByText('Source 2')).toBeTruthy();
156
- });
157
- });
158
-
159
- it('Focus is moved to the source list', async () => {
160
- const reload = jest.fn();
161
-
162
- render(
163
- <SourceListTestWrapper
164
- constructFunction={(previewModalState) => {
165
- return (
166
- <SourceList
167
- sources={sources}
168
- previewModalState={previewModalState}
169
- isLoading={false}
170
- onSourceSelect={() => {}}
171
- onSourceDrilldown={() => {}}
172
- error={null}
173
- handleReload={reload}
174
- setSource={() => {}}
175
- recentSources={mockRecentSources}
176
- />
177
- );
178
- }}
179
- />,
180
- );
181
-
182
- await waitFor(() => {
183
- expect(screen.queryByLabelText('Source list')).toHaveFocus();
184
- });
185
- });
186
-
187
- it('Source list renders each sources nodes', async () => {
188
- const reload = jest.fn();
189
-
190
- render(
191
- <SourceListTestWrapper
192
- constructFunction={(previewModalState) => {
193
- return (
194
- <SourceList
195
- sources={sources}
196
- previewModalState={previewModalState}
197
- isLoading={false}
198
- onSourceSelect={() => {}}
199
- onSourceDrilldown={() => {}}
200
- error={null}
201
- handleReload={reload}
202
- setSource={() => {}}
203
- recentSources={mockRecentSources}
204
- />
205
- );
206
- }}
207
- />,
208
- );
15
+ it('should render <li> for each provided source', () => {
16
+ const sources = [mockSource(), mockSource({ id: '2' })];
17
+ const onSourceSelect = jest.fn();
18
+ render(<SourceList sources={sources} onSourceSelect={onSourceSelect} />);
209
19
 
210
- await waitFor(() => {
211
- const source1 = screen.getByLabelText('Source 1 nodes');
212
- expect(within(source1).queryByText('Node 1')).toBeTruthy();
213
- expect(within(source1).queryByText('Node 2')).toBeTruthy();
214
-
215
- const source2 = screen.getByLabelText('Source 2 nodes');
216
- expect(within(source2).queryByText('Node 3')).toBeTruthy();
217
- expect(within(source2).queryByText('Node 4')).toBeTruthy();
20
+ expect(screen.getByLabelText('environment list')).toBeInTheDocument();
21
+ expect(screen.getByLabelText('environment list').children.length).toEqual(2);
218
22
  });
219
- });
220
-
221
- it('Clicking node body triggers correct onSourceSelect', async () => {
222
- const onSourceSelect = jest.fn();
223
- const reload = jest.fn();
224
-
225
- render(
226
- <SourceListTestWrapper
227
- constructFunction={(previewModalState) => {
228
- return (
229
- <SourceList
230
- sources={sources}
231
- previewModalState={previewModalState}
232
- isLoading={false}
233
- onSourceSelect={onSourceSelect}
234
- onSourceDrilldown={() => {}}
235
- error={null}
236
- handleReload={reload}
237
- setSource={() => {}}
238
- recentSources={mockRecentSources}
239
- />
240
- );
241
- }}
242
- />,
243
- );
244
-
245
- const user = userEvent.setup();
246
- const itemButton = screen.getByRole('button', { name: 'site Node 1' });
247
- user.click(itemButton);
248
23
 
249
- await waitFor(() => {
250
- // Provides the item that was clicked and an id reference to the button that was clicked
251
- expect(onSourceSelect).toHaveBeenCalledWith(
252
- {
253
- source: sources[0],
254
- resource: sources[0].nodes[0],
255
- },
256
- { id: expect.any(String) },
257
- );
24
+ it('should render Icon based on source type', () => {
25
+ jest.spyOn(GenericBrowserLib, 'Icon');
26
+ const sources = [mockSource({ type: 'dam' })];
27
+ const onSourceSelect = jest.fn();
28
+ render(<SourceList sources={sources} onSourceSelect={onSourceSelect} />);
29
+ expect(GenericBrowserLib.Icon).toHaveBeenCalledWith(expect.objectContaining({ icon: 'dam' }), {});
258
30
  });
259
- });
260
31
 
261
- it('Clicking node child count button triggers correct onSourceDrilldown', async () => {
262
- const onSourceDrilldown = jest.fn();
263
- const reload = jest.fn();
264
-
265
- render(
266
- <SourceListTestWrapper
267
- constructFunction={(previewModalState) => {
268
- return (
269
- <SourceList
270
- sources={sources}
271
- previewModalState={previewModalState}
272
- isLoading={false}
273
- onSourceSelect={() => {}}
274
- onSourceDrilldown={onSourceDrilldown}
275
- error={null}
276
- handleReload={reload}
277
- setSource={() => {}}
278
- recentSources={mockRecentSources}
279
- />
280
- );
281
- }}
282
- />,
283
- );
284
-
285
- const user = userEvent.setup();
286
- const itemButton = screen.getByRole('button', { name: 'Drill down to Node 1 children' });
287
- user.click(itemButton);
288
-
289
- await waitFor(() => {
290
- // Provides the item that was clicked and an id reference to the button that was clicked
291
- expect(onSourceDrilldown).toHaveBeenCalledWith({
292
- source: sources[0],
293
- resource: sources[0].nodes[0],
294
- });
32
+ it('should render using source name', () => {
33
+ const sources = [mockSource({ type: 'dam', name: 'mySource' })];
34
+ const onSourceSelect = jest.fn();
35
+ render(<SourceList sources={sources} onSourceSelect={onSourceSelect} />);
36
+ expect(screen.getByText('mySource')).toBeInTheDocument();
295
37
  });
296
- });
297
-
298
- it('Renders error state when an error occurs loading source list', async () => {
299
- const reload = jest.fn();
300
38
 
301
- const { getByText } = render(
302
- <SourceListTestWrapper
303
- constructFunction={(previewModalState) => {
304
- return (
305
- <SourceList
306
- sources={sources}
307
- previewModalState={previewModalState}
308
- isLoading={false}
309
- onSourceSelect={() => {}}
310
- onSourceDrilldown={() => {}}
311
- error={new Error('Source list error!')}
312
- handleReload={reload}
313
- setSource={() => {}}
314
- recentSources={mockRecentSources}
315
- />
316
- );
317
- }}
318
- />,
319
- );
320
-
321
- await waitFor(() => {
322
- const errorMessage = getByText('Source list error!');
323
- expect(errorMessage).toBeInTheDocument();
39
+ it('should render using source id if name not provided', () => {
40
+ const sources = [mockSource({ type: 'dam', name: undefined, id: '1115544' })];
41
+ const onSourceSelect = jest.fn();
42
+ render(<SourceList sources={sources} onSourceSelect={onSourceSelect} />);
43
+ expect(screen.getByText('1115544')).toBeInTheDocument();
44
+ expect(screen.queryByText('mySource')).not.toBeInTheDocument();
324
45
  });
325
- });
326
-
327
- it('Renders recent locations section when local storage has data present', async () => {
328
- const reload = jest.fn();
329
- const setSource = jest.fn();
330
-
331
- render(
332
- <SourceListTestWrapper
333
- constructFunction={(previewModalState) => {
334
- return (
335
- <SourceList
336
- sources={sources}
337
- previewModalState={previewModalState}
338
- isLoading={false}
339
- onSourceSelect={() => {}}
340
- onSourceDrilldown={() => {}}
341
- error={null}
342
- handleReload={reload}
343
- setSource={setSource}
344
- recentSources={mockRecentSources}
345
- />
346
- );
347
- }}
348
- />,
349
- );
350
-
351
- await waitFor(() => {
352
- expect(screen.getByText('Recent locations')).toBeInTheDocument();
353
- expect(screen.getByText('Test resource')).toBeInTheDocument();
354
- });
355
- });
356
-
357
- it('Handles setSource on click of recent locations item', async () => {
358
- const reload = jest.fn();
359
- const setSource = jest.fn();
360
-
361
- render(
362
- <SourceListTestWrapper
363
- constructFunction={(previewModalState) => {
364
- return (
365
- <SourceList
366
- sources={sources}
367
- previewModalState={previewModalState}
368
- isLoading={false}
369
- onSourceSelect={() => {}}
370
- onSourceDrilldown={() => {}}
371
- error={null}
372
- handleReload={reload}
373
- setSource={setSource}
374
- recentSources={mockRecentSources}
375
- />
376
- );
377
- }}
378
- />,
379
- );
380
46
 
381
- const user = userEvent.setup();
382
- const itemButton = screen.getByRole('button', { name: 'Drill down to Test resource children' });
383
- user.click(itemButton);
47
+ it('should call onSourceSelect with source object when clicked', async () => {
48
+ const sources = [mockSource(), mockSource({ type: 'dam', name: 'mySource', id: '1115544' })];
49
+ const onSourceSelect = jest.fn();
50
+ render(<SourceList sources={sources} onSourceSelect={onSourceSelect} />);
384
51
 
385
- await waitFor(() => {
386
- // Provides the item that was clicked and an id reference to the button that was clicked
387
- expect(setSource).toHaveBeenCalledWith(
388
- {
389
- resource: {
390
- childCount: 0,
391
- id: '1',
392
- lineages: [],
393
- name: 'Test resource',
394
- status: {
395
- code: 'live',
396
- name: 'Live',
397
- },
398
- type: {
399
- code: 'folder',
400
- name: 'Folder',
401
- },
402
- url: 'https://no-where.com',
403
- urls: [],
404
- },
405
- source: {
406
- id: '1',
407
- name: 'Source 1',
408
- nodes: [
409
- {
410
- childCount: 21,
411
- id: '1',
412
- lineages: [],
413
- name: 'Node 1',
414
- status: {
415
- code: 'live',
416
- name: 'Live',
417
- },
418
- type: {
419
- code: 'site',
420
- name: 'Site',
421
- },
422
- url: 'https://no-where.com',
423
- urls: [],
424
- },
425
- {
426
- childCount: 13,
427
- id: '2',
428
- lineages: [],
429
- name: 'Node 2',
430
- status: {
431
- code: 'live',
432
- name: 'Live',
433
- },
434
- type: {
435
- code: 'site',
436
- name: 'Site',
437
- },
438
- url: 'https://no-where.com',
439
- urls: [],
440
- },
441
- ],
442
- },
443
- },
444
- [],
445
- );
52
+ await act(() => fireEvent.click(screen.getByRole('button', { name: 'mySource' })));
53
+ expect(onSourceSelect).toHaveBeenCalledWith(sources[1]);
446
54
  });
447
- });
448
55
  });
@@ -1,48 +1,28 @@
1
1
  import React from 'react';
2
2
  import { StoryFn, Meta } from '@storybook/react';
3
- import { useOverlayTriggerState } from 'react-stately';
4
-
5
3
  import SourceList from './SourceList';
6
- import sampleSources from './sample-sources.json';
4
+ import sampleSources from '../__mocks__/sample-sources.json';
5
+ import { ResourceBrowserSource } from '../types';
7
6
 
8
7
  export default {
9
- title: 'Source List',
10
- component: SourceList,
8
+ title: 'Source list',
9
+ component: SourceList,
11
10
  } as Meta<typeof SourceList>;
12
11
 
13
- const Template: StoryFn<typeof SourceList> = ({ sources, isLoading }) => {
14
- const previewModalState = useOverlayTriggerState({});
15
-
16
- return (
17
- <SourceList
18
- sources={sources}
19
- previewModalState={previewModalState}
20
- isLoading={isLoading}
21
- onSourceSelect={({ source, resource }) =>
22
- alert(`Resource Select: ${source.name} - ${resource?.name}[${resource?.id}]`)
23
- }
24
- onSourceDrilldown={({ source, resource }) =>
25
- alert(`Child Drill Down: ${source.name} - ${resource?.name}[${resource?.id}]`)
26
- }
27
- handleReload={() => {
28
- console.log('Handle reload');
29
- }}
30
- setSource={() => {
31
- alert(`Recent Location Selected`);
32
- }}
33
- error={null}
34
- />
35
- );
12
+ const Template: StoryFn<typeof SourceList> = (props) => {
13
+ const sources = sampleSources as ResourceBrowserSource[];
14
+ return (
15
+ <div className="flex justify-center m-3">
16
+ <SourceList
17
+ sources={sources}
18
+ onSourceSelect={(source) => {
19
+ console.log(`Source ${source?.name} / ${source.id} was selected`);
20
+ }}
21
+ ></SourceList>
22
+ </div>
23
+ );
36
24
  };
37
25
 
38
26
  export const Primary = Template.bind({});
39
- Primary.args = {
40
- sources: sampleSources,
41
- isLoading: false,
42
- };
43
27
 
44
- export const Loading = Template.bind({});
45
- Loading.args = {
46
- ...Primary.args,
47
- isLoading: true,
48
- };
28
+ Primary.args = {};