@instructure/ui-tree-browser 10.16.1 → 10.16.3

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 (32) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/es/TreeBrowser/TreeButton/__new-tests__/TreeButton.test.js +165 -0
  3. package/es/TreeBrowser/TreeCollection/__new-tests__/TreeCollection.test.js +454 -0
  4. package/es/TreeBrowser/{TreeBrowserLocator.js → TreeNode/__new-tests__/TreeNode.test.js} +31 -14
  5. package/es/TreeBrowser/__new-tests__/TreeBrowser.test.js +525 -0
  6. package/lib/TreeBrowser/TreeButton/__new-tests__/TreeButton.test.js +166 -0
  7. package/lib/TreeBrowser/TreeCollection/__new-tests__/TreeCollection.test.js +457 -0
  8. package/lib/TreeBrowser/TreeNode/__new-tests__/TreeNode.test.js +56 -0
  9. package/lib/TreeBrowser/__new-tests__/TreeBrowser.test.js +527 -0
  10. package/package.json +17 -14
  11. package/src/TreeBrowser/TreeButton/__new-tests__/TreeButton.test.tsx +162 -0
  12. package/src/TreeBrowser/TreeCollection/__new-tests__/TreeCollection.test.tsx +423 -0
  13. package/src/TreeBrowser/{TreeBrowserLocator.ts → TreeNode/__new-tests__/TreeNode.test.tsx} +30 -13
  14. package/src/TreeBrowser/__new-tests__/TreeBrowser.test.tsx +575 -0
  15. package/tsconfig.build.json +1 -1
  16. package/tsconfig.build.tsbuildinfo +1 -1
  17. package/types/TreeBrowser/TreeButton/__new-tests__/TreeButton.test.d.ts +2 -0
  18. package/types/TreeBrowser/TreeButton/__new-tests__/TreeButton.test.d.ts.map +1 -0
  19. package/types/TreeBrowser/TreeCollection/__new-tests__/TreeCollection.test.d.ts +2 -0
  20. package/types/TreeBrowser/TreeCollection/__new-tests__/TreeCollection.test.d.ts.map +1 -0
  21. package/types/TreeBrowser/TreeNode/__new-tests__/TreeNode.test.d.ts +2 -0
  22. package/types/TreeBrowser/TreeNode/__new-tests__/TreeNode.test.d.ts.map +1 -0
  23. package/types/TreeBrowser/__new-tests__/TreeBrowser.test.d.ts +2 -0
  24. package/types/TreeBrowser/__new-tests__/TreeBrowser.test.d.ts.map +1 -0
  25. package/es/TreeBrowser/locator.js +0 -26
  26. package/lib/TreeBrowser/TreeBrowserLocator.js +0 -44
  27. package/lib/TreeBrowser/locator.js +0 -37
  28. package/src/TreeBrowser/locator.ts +0 -27
  29. package/types/TreeBrowser/TreeBrowserLocator.d.ts +0 -1065
  30. package/types/TreeBrowser/TreeBrowserLocator.d.ts.map +0 -1
  31. package/types/TreeBrowser/locator.d.ts +0 -4
  32. package/types/TreeBrowser/locator.d.ts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [10.16.3](https://github.com/instructure/instructure-ui/compare/v10.16.1...v10.16.3) (2025-04-30)
7
+
8
+ **Note:** Version bump only for package @instructure/ui-tree-browser
9
+
10
+
11
+
12
+
13
+
14
+ ## [10.16.2](https://github.com/instructure/instructure-ui/compare/v10.16.1...v10.16.2) (2025-04-22)
15
+
16
+ **Note:** Version bump only for package @instructure/ui-tree-browser
17
+
18
+
19
+
20
+
21
+
6
22
  ## [10.16.1](https://github.com/instructure/instructure-ui/compare/v10.16.0...v10.16.1) (2025-04-22)
7
23
 
8
24
  **Note:** Version bump only for package @instructure/ui-tree-browser
@@ -0,0 +1,165 @@
1
+ var _TreeButton, _TreeButton2, _TreeButton3, _svg, _TreeButton4, _TreeButton5, _TreeButton6, _div;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import { render, screen } from '@testing-library/react';
27
+ import { vi } from 'vitest';
28
+ import '@testing-library/jest-dom';
29
+ import { TreeButton } from '../index';
30
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
31
+ describe('<TreeButton />', () => {
32
+ it('should render', async () => {
33
+ const _render = render(_TreeButton || (_TreeButton = _jsx(TreeButton, {
34
+ id: "1"
35
+ }))),
36
+ container = _render.container;
37
+ const treeButton = container.querySelector('button[class$="-treeButton"]');
38
+ expect(treeButton).toBeInTheDocument();
39
+ });
40
+ describe('containerRef', () => {
41
+ it('should call with parent element', async () => {
42
+ const containerRef = vi.fn();
43
+ render(_jsx("div", {
44
+ "data-testid": "1",
45
+ children: _jsx(TreeButton, {
46
+ id: "2",
47
+ containerRef: containerRef
48
+ })
49
+ }));
50
+ const div = screen.getByTestId('1');
51
+ expect(containerRef).toHaveBeenCalledWith(div);
52
+ });
53
+ });
54
+ describe('descriptor', () => {
55
+ it('should not render a descriptor element if no descriptor passed', async () => {
56
+ const _render2 = render(_TreeButton2 || (_TreeButton2 = _jsx(TreeButton, {
57
+ id: "1"
58
+ }))),
59
+ container = _render2.container;
60
+ const descriptor = container.querySelector('[class$="-treeButton__textDescriptor"]');
61
+ expect(descriptor).not.toBeInTheDocument();
62
+ });
63
+ it('should render a descriptor element if descriptor passed', async () => {
64
+ const _render3 = render(_TreeButton3 || (_TreeButton3 = _jsx(TreeButton, {
65
+ id: "1",
66
+ descriptor: "Some Descriptor"
67
+ }))),
68
+ container = _render3.container;
69
+ const descriptor = container.querySelector('[class$="-treeButton__textDescriptor"]');
70
+ expect(descriptor).toBeInTheDocument();
71
+ expect(descriptor).toHaveTextContent('Some Descriptor');
72
+ });
73
+ });
74
+ describe('icons', () => {
75
+ const Icon = _svg || (_svg = _jsxs("svg", {
76
+ height: "100",
77
+ width: "100",
78
+ "data-testid": "custom-icon",
79
+ children: [_jsx("title", {
80
+ "data-testid": "custom-icon-title",
81
+ children: "Test icon"
82
+ }), _jsx("circle", {
83
+ cx: "50",
84
+ cy: "50",
85
+ r: "40"
86
+ })]
87
+ }));
88
+ it('should render a collection icon', async () => {
89
+ render(_jsx(TreeButton, {
90
+ id: "1",
91
+ type: "collection",
92
+ collectionIcon: () => Icon
93
+ }));
94
+ const icon = screen.getByTestId('custom-icon');
95
+ const iconTitle = screen.getByTestId('custom-icon-title');
96
+ expect(icon).toBeInTheDocument();
97
+ expect(icon).toHaveTextContent('Test icon');
98
+ expect(iconTitle).toBeInTheDocument();
99
+ });
100
+ it('should render an item icon', async () => {
101
+ render(_jsx(TreeButton, {
102
+ id: "1",
103
+ type: "item",
104
+ itemIcon: () => Icon
105
+ }));
106
+ const icon = screen.getByTestId('custom-icon');
107
+ expect(icon).toBeInTheDocument();
108
+ expect(icon).toHaveTextContent('Test icon');
109
+ });
110
+ it('should render no icon if no icon prop passed', async () => {
111
+ const _render4 = render(_TreeButton4 || (_TreeButton4 = _jsx(TreeButton, {
112
+ id: "1"
113
+ }))),
114
+ container = _render4.container;
115
+ const icon = container.querySelector('svg');
116
+ expect(icon).not.toBeInTheDocument();
117
+ });
118
+ it('should render a thumbnail instead of an icon if a thumbnail URL is passed', async () => {
119
+ const _render5 = render(_TreeButton5 || (_TreeButton5 = _jsx(TreeButton, {
120
+ id: "1",
121
+ type: "item",
122
+ thumbnail: "data:image/gif;base64,R0lGODlhFAAUAJEAAP/9/fYQEPytrflWViH5BAAAAAAALAAAAAAUABQAQAJKhI+pGe09lnhBnEETfodatVHNh1BR+ZzH9LAOCYrVYpiAfWWJOxrC/5MASbyZT4d6AUIBlUYGoR1FsAXUuTN5YhxAEYbrpKRkQwEAOw=="
123
+ }))),
124
+ container = _render5.container;
125
+ const img = container.querySelector('img');
126
+ expect(img).toBeInTheDocument();
127
+ });
128
+ it('should not render a thumbnail if no thumbnail URL is passed', async () => {
129
+ const _render6 = render(_TreeButton6 || (_TreeButton6 = _jsx(TreeButton, {
130
+ id: "1",
131
+ type: "item"
132
+ }))),
133
+ container = _render6.container;
134
+ const thumbnail = container.querySelector('img');
135
+ expect(thumbnail).not.toBeInTheDocument();
136
+ });
137
+ it('should render a thumbnail if a thumbnail and an icon are passed', async () => {
138
+ const _render7 = render(_jsx(TreeButton, {
139
+ id: "1",
140
+ type: "item",
141
+ itemIcon: () => Icon,
142
+ thumbnail: "data:image/gif;base64,R0lGODlhFAAUAJEAAP/9/fYQEPytrflWViH5BAAAAAAALAAAAAAUABQAQAJKhI+pGe09lnhBnEETfodatVHNh1BR+ZzH9LAOCYrVYpiAfWWJOxrC/5MASbyZT4d6AUIBlUYGoR1FsAXUuTN5YhxAEYbrpKRkQwEAOw=="
143
+ })),
144
+ container = _render7.container;
145
+ const thumbnail = container.querySelector('img');
146
+ const icon = container.querySelector('svg');
147
+ expect(thumbnail).toBeInTheDocument();
148
+ expect(icon).not.toBeInTheDocument();
149
+ });
150
+ });
151
+ describe('renderContent', () => {
152
+ it('should render the content passed to renderContent', async () => {
153
+ const _render8 = render(_jsx(TreeButton, {
154
+ id: "1",
155
+ renderContent: () => _div || (_div = _jsx("div", {
156
+ className: "test1",
157
+ children: "abcd"
158
+ }))
159
+ })),
160
+ container = _render8.container;
161
+ const customElement = container.querySelector('div[class="test1"]');
162
+ expect(customElement).toBeInTheDocument();
163
+ });
164
+ });
165
+ });
@@ -0,0 +1,454 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { render, screen, waitFor } from '@testing-library/react';
26
+ import userEvent from '@testing-library/user-event';
27
+ import { vi } from 'vitest';
28
+ import '@testing-library/jest-dom';
29
+ import { TreeCollection } from '../index';
30
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
31
+ const IconFolder = _jsxs("svg", {
32
+ height: "100",
33
+ width: "100",
34
+ children: [_jsx("title", {
35
+ children: "Folder icon"
36
+ }), _jsx("circle", {
37
+ cx: "50",
38
+ cy: "50",
39
+ r: "40"
40
+ })]
41
+ });
42
+ const IconDocument = _jsxs("svg", {
43
+ height: "100",
44
+ width: "100",
45
+ children: [_jsx("title", {
46
+ children: "Document icon"
47
+ }), _jsx("circle", {
48
+ cx: "50",
49
+ cy: "50",
50
+ r: "40"
51
+ })]
52
+ });
53
+ const IconUser = _jsxs("svg", {
54
+ height: "100",
55
+ width: "100",
56
+ children: [_jsx("title", {
57
+ children: "User icon"
58
+ }), _jsx("circle", {
59
+ cx: "50",
60
+ cy: "50",
61
+ r: "40"
62
+ })]
63
+ });
64
+ describe('<TreeCollection />', () => {
65
+ let consoleWarningMock;
66
+ let consoleErrorMock;
67
+ beforeEach(() => {
68
+ // Mocking console to prevent test output pollution and expect for messages
69
+ consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
70
+ consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
71
+ });
72
+ afterEach(() => {
73
+ consoleWarningMock.mockRestore();
74
+ consoleErrorMock.mockRestore();
75
+ });
76
+ it('should render', async () => {
77
+ const _render = render(_jsx(TreeCollection, {
78
+ level: 1,
79
+ id: 1,
80
+ name: "Coll 1",
81
+ collections: [{
82
+ id: 2,
83
+ name: 'Coll 2',
84
+ descriptor: 'Another Descriptor'
85
+ }],
86
+ items: [{
87
+ id: 1,
88
+ name: 'Item 1'
89
+ }]
90
+ })),
91
+ container = _render.container;
92
+ const collection = container.querySelector('[class$="-treeCollection"]');
93
+ expect(collection).toBeInTheDocument();
94
+ });
95
+ describe('collections', () => {
96
+ it('should render icons on children', async () => {
97
+ render(_jsx(TreeCollection, {
98
+ level: 1,
99
+ id: 1,
100
+ name: "Coll 1",
101
+ collections: [{
102
+ id: 2,
103
+ name: 'Coll 2',
104
+ descriptor: 'Another Descriptor'
105
+ }],
106
+ items: [{
107
+ id: 1,
108
+ name: 'Item 1'
109
+ }],
110
+ collectionIcon: () => IconFolder,
111
+ collectionIconExpanded: () => IconFolder,
112
+ itemIcon: () => IconDocument,
113
+ expanded: true
114
+ }));
115
+ const folderIcons = await screen.findAllByTitle('Folder icon');
116
+ expect(folderIcons.length).toBe(2);
117
+ const documentIcons = await screen.findAllByTitle('Document icon');
118
+ expect(documentIcons.length).toBe(1);
119
+ });
120
+ it('should support the containerRef prop', async () => {
121
+ const containerRef = vi.fn();
122
+ const _render2 = render(_jsx(TreeCollection, {
123
+ level: 1,
124
+ id: 1,
125
+ containerRef: containerRef,
126
+ name: "Coll 1",
127
+ collections: [{
128
+ id: 2,
129
+ name: 'Coll 2',
130
+ descriptor: 'Another Descriptor'
131
+ }],
132
+ items: [{
133
+ id: 1,
134
+ name: 'Item 1'
135
+ }]
136
+ })),
137
+ container = _render2.container;
138
+ const collection = container.querySelector('[class$="-treeCollection"]');
139
+ expect(containerRef).toHaveBeenCalledWith(collection);
140
+ });
141
+ it('should pass an aria-expanded attribute to its list item', async () => {
142
+ render(_jsx(TreeCollection, {
143
+ level: 1,
144
+ id: 1,
145
+ name: "Coll 1",
146
+ collections: [{
147
+ id: 2,
148
+ name: 'Coll 2',
149
+ descriptor: 'Another Descriptor'
150
+ }],
151
+ items: [{
152
+ id: 1,
153
+ name: 'Item 1'
154
+ }]
155
+ }));
156
+ const item = screen.getByRole('treeitem');
157
+ expect(item).toHaveAttribute('aria-expanded');
158
+ });
159
+ it('should pass an aria-selected attribute to its list item', async () => {
160
+ render(_jsx(TreeCollection, {
161
+ level: 1,
162
+ id: 1,
163
+ name: "Coll 1",
164
+ collections: [{
165
+ id: 2,
166
+ name: 'Coll 2',
167
+ descriptor: 'Another Descriptor'
168
+ }],
169
+ items: [{
170
+ id: 1,
171
+ name: 'Item 1'
172
+ }],
173
+ selection: "collection_1"
174
+ }));
175
+ const item = screen.getByRole('treeitem');
176
+ expect(item).toHaveAttribute('aria-selected');
177
+ });
178
+ it('should correctly evaluate `getCollectionProps` for each item', async () => {
179
+ const _render3 = render(_jsx(TreeCollection, {
180
+ level: 1,
181
+ id: 1,
182
+ name: "Coll 1",
183
+ collections: [{
184
+ id: 2,
185
+ name: 'Coll 2',
186
+ descriptor: 'Another Descriptor'
187
+ }],
188
+ items: [{
189
+ id: 1,
190
+ name: 'Item 1',
191
+ icon: () => IconFolder
192
+ }, {
193
+ id: 2,
194
+ name: 'Item 2',
195
+ icon: () => IconUser
196
+ }, {
197
+ id: 2,
198
+ name: 'Item 3'
199
+ }],
200
+ collectionIcon: IconFolder,
201
+ getCollectionProps: ({
202
+ ...props
203
+ }) => {
204
+ let icon = props.collectionIcon;
205
+ if (props.name === 'Coll 2') {
206
+ icon = IconUser;
207
+ }
208
+ return {
209
+ ...props,
210
+ collectionIcon: icon
211
+ };
212
+ },
213
+ expanded: true
214
+ })),
215
+ container = _render3.container;
216
+ const svgIconUser = screen.getByTitle('User icon');
217
+ const item1 = container.querySelectorAll('button')[1];
218
+ expect(svgIconUser).toBeInTheDocument();
219
+ expect(item1).toContainElement(svgIconUser);
220
+ expect(item1).toHaveTextContent('Coll 2');
221
+ });
222
+ describe('onCollectionClick', () => {
223
+ it('should return the correct collection params on click', async () => {
224
+ const onCollectionClick = vi.fn();
225
+ render(_jsx(TreeCollection, {
226
+ level: 1,
227
+ id: 1,
228
+ name: "Coll 1",
229
+ collections: [{
230
+ id: 2,
231
+ name: 'Coll 2',
232
+ descriptor: 'Another Descriptor'
233
+ }],
234
+ items: [{
235
+ id: 1,
236
+ name: 'Item 1'
237
+ }],
238
+ onCollectionClick: onCollectionClick
239
+ }));
240
+ const item = screen.getByRole('treeitem');
241
+ await userEvent.click(item);
242
+ await waitFor(() => {
243
+ const args = onCollectionClick.mock.calls[0][1];
244
+ expect(onCollectionClick).toHaveBeenCalledTimes(1);
245
+ expect(args).toStrictEqual({
246
+ id: 1,
247
+ expanded: true,
248
+ type: 'collection'
249
+ });
250
+ });
251
+ });
252
+ });
253
+ });
254
+ describe('items', () => {
255
+ it('should not pass an aria-expanded attribute to its button', async () => {
256
+ render(_jsx(TreeCollection, {
257
+ level: 1,
258
+ id: 1,
259
+ name: "Coll 1",
260
+ collections: [{
261
+ id: 2,
262
+ name: 'Coll 2',
263
+ descriptor: 'Another Descriptor'
264
+ }],
265
+ items: [{
266
+ id: 1,
267
+ name: 'Item 1'
268
+ }],
269
+ expanded: true
270
+ }));
271
+ const item = screen.getAllByLabelText('Coll 1')[0];
272
+ const button = item.firstChild;
273
+ expect(item).toHaveAttribute('aria-expanded', 'true');
274
+ expect(button.tagName).toBe('BUTTON');
275
+ expect(button).not.toHaveAttribute('aria-expanded');
276
+ });
277
+ it('should call custom functions passed by onItemClick', async () => {
278
+ const onItemClick = vi.fn();
279
+ render(_jsx(TreeCollection, {
280
+ level: 1,
281
+ id: 1,
282
+ name: "Coll 1",
283
+ collections: [{
284
+ id: 2,
285
+ name: 'Coll 2',
286
+ descriptor: 'Another Descriptor'
287
+ }],
288
+ items: [{
289
+ id: 1,
290
+ name: 'Item 1'
291
+ }],
292
+ onItemClick: onItemClick,
293
+ expanded: true
294
+ }));
295
+ const item = screen.getByLabelText('Item 1');
296
+ await userEvent.click(item);
297
+ await waitFor(() => {
298
+ const args = onItemClick.mock.calls[0][1];
299
+ expect(onItemClick).toHaveBeenCalledTimes(1);
300
+ expect(args).toStrictEqual({
301
+ id: 1,
302
+ type: 'item'
303
+ });
304
+ });
305
+ });
306
+ it('should correctly evaluate `getItemProps` for each item', async () => {
307
+ render(_jsx(TreeCollection, {
308
+ level: 1,
309
+ id: 1,
310
+ name: "Coll 1",
311
+ collections: [{
312
+ id: 2,
313
+ name: 'Coll 2',
314
+ descriptor: 'Another Descriptor'
315
+ }],
316
+ items: [{
317
+ id: 1,
318
+ name: 'Item 1',
319
+ icon: () => IconFolder
320
+ }, {
321
+ id: 2,
322
+ name: 'Item 2',
323
+ icon: () => IconUser
324
+ }, {
325
+ id: 2,
326
+ name: 'Item 3'
327
+ }],
328
+ getItemProps: ({
329
+ name,
330
+ ...props
331
+ }) => {
332
+ let itemIcon = IconDocument;
333
+ if (name === 'Item 1') {
334
+ itemIcon = IconFolder;
335
+ }
336
+ if (name === 'Item 2') {
337
+ itemIcon = IconUser;
338
+ }
339
+ return {
340
+ ...props,
341
+ itemIcon,
342
+ name
343
+ };
344
+ },
345
+ expanded: true
346
+ }));
347
+ expect(screen.getByTitle('Folder icon')).toBeInTheDocument();
348
+ expect(screen.getByTitle('User icon')).toBeInTheDocument();
349
+ expect(screen.getByTitle('Document icon')).toBeInTheDocument();
350
+ });
351
+ });
352
+ describe('sorting', () => {
353
+ it('should show the items and subcollections in alphabetical order', async () => {
354
+ const _render4 = render(_jsx(TreeCollection, {
355
+ level: 1,
356
+ id: 1,
357
+ name: "Root",
358
+ collections: [{
359
+ id: 2,
360
+ name: 'A',
361
+ descriptor: 'Collection A'
362
+ }, {
363
+ id: 3,
364
+ name: 'B',
365
+ descriptor: 'Collection B'
366
+ }, {
367
+ id: 4,
368
+ name: 'C',
369
+ descriptor: 'Collection A'
370
+ }],
371
+ items: [{
372
+ id: 1,
373
+ name: 'A1'
374
+ }, {
375
+ id: 2,
376
+ name: 'B1'
377
+ }, {
378
+ id: 2,
379
+ name: 'C1'
380
+ }],
381
+ getItemProps: ({
382
+ name,
383
+ ...props
384
+ }) => {
385
+ const itemIcon = IconDocument;
386
+ return {
387
+ ...props,
388
+ itemIcon,
389
+ name
390
+ };
391
+ },
392
+ expanded: true,
393
+ compareFunc: (a, b) => {
394
+ return a.name.localeCompare(b.name);
395
+ }
396
+ })),
397
+ container = _render4.container;
398
+ const childNames = container.querySelectorAll('span[class$="treeButton__textName"]');
399
+ const childNameArr = Array.from(childNames).map(element => element.textContent).slice(1);
400
+ expect(childNameArr).toEqual(['A', 'A1', 'B', 'B1', 'C', 'C1']);
401
+ });
402
+ it('should show the items before the collections', async () => {
403
+ const _render5 = render(_jsx(TreeCollection, {
404
+ level: 1,
405
+ id: 1,
406
+ name: "Root",
407
+ collections: [{
408
+ id: 2,
409
+ name: 'Coll A',
410
+ descriptor: 'Collection A'
411
+ }, {
412
+ id: 3,
413
+ name: 'Coll B',
414
+ descriptor: 'Collection B'
415
+ }, {
416
+ id: 4,
417
+ name: 'Coll C',
418
+ descriptor: 'Collection A'
419
+ }],
420
+ items: [{
421
+ id: 1,
422
+ name: 'Item A'
423
+ }, {
424
+ id: 2,
425
+ name: 'Item B'
426
+ }, {
427
+ id: 2,
428
+ name: 'Item C'
429
+ }],
430
+ getItemProps: ({
431
+ name,
432
+ ...props
433
+ }) => {
434
+ const itemIcon = IconDocument;
435
+ return {
436
+ ...props,
437
+ itemIcon,
438
+ name
439
+ };
440
+ },
441
+ expanded: true,
442
+ compareFunc: (a, b) => {
443
+ if (a.type === 'item' && b.type === 'collection') return -1;
444
+ if (a.type === 'collection' && b.type === 'item') return 1;
445
+ return 0;
446
+ }
447
+ })),
448
+ container = _render5.container;
449
+ const childNames = container.querySelectorAll('span[class$="treeButton__textName"]');
450
+ const childNameArr = Array.from(childNames).map(element => element.textContent).slice(1);
451
+ expect(childNameArr).toEqual(['Item A', 'Item B', 'Item C', 'Coll A', 'Coll B', 'Coll C']);
452
+ });
453
+ });
454
+ });
@@ -1,7 +1,8 @@
1
+ var _TreeNode, _button;
1
2
  /*
2
3
  * The MIT License (MIT)
3
4
  *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
+ * Copyright (c) 2021 - present Instructure, Inc.
5
6
  *
6
7
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
8
  * of this software and associated documentation files (the "Software"), to deal
@@ -21,18 +22,34 @@
21
22
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
23
  * SOFTWARE.
23
24
  */
24
- import { locator } from '@instructure/ui-test-locator';
25
- import { TreeBrowser } from './index';
26
25
 
27
- // TODO: if we make a TreeBrowserItem component + locator we could use it here.
28
- const TreeBrowserItemLocator = locator('[role="treeitem"]');
29
-
30
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
31
- export const TreeBrowserLocator = locator(TreeBrowser.selector, {
32
- findAllItems: (...args) => {
33
- return TreeBrowserItemLocator.findAll(...args);
34
- },
35
- findItem: (...args) => {
36
- return TreeBrowserItemLocator.find(...args);
37
- }
26
+ import { render, screen } from '@testing-library/react';
27
+ import { vi } from 'vitest';
28
+ import '@testing-library/jest-dom';
29
+ import { TreeNode } from '../index';
30
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
31
+ describe('<TreeNode />', () => {
32
+ it('should render children', async () => {
33
+ render(_TreeNode || (_TreeNode = _jsx(TreeNode, {
34
+ children: _jsx("button", {
35
+ children: "Hello World"
36
+ })
37
+ })));
38
+ const item = screen.getByText('Hello World');
39
+ expect(item).toBeInTheDocument();
40
+ });
41
+ it('supports containerRef prop', async () => {
42
+ const containerRef = vi.fn();
43
+ render(_jsx("div", {
44
+ "data-testid": "1",
45
+ children: _jsx(TreeNode, {
46
+ containerRef: containerRef,
47
+ children: _button || (_button = _jsx("button", {
48
+ children: "Hello World"
49
+ }))
50
+ })
51
+ }));
52
+ const div = screen.getByTestId('1');
53
+ expect(containerRef).toHaveBeenCalledWith(div);
54
+ });
38
55
  });