@availity/mui-spaces 0.2.5 → 0.3.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.
@@ -0,0 +1,605 @@
1
+ import { render, waitFor, cleanup } from '@testing-library/react';
2
+ import dayjs from 'dayjs';
3
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
4
+ import { SpacesLink } from './SpacesLink';
5
+ import { Spaces } from '../Spaces';
6
+ import { FileIcon, NavigateTopIcon } from '@availity/mui-icon';
7
+
8
+ describe('SpacesLink', () => {
9
+ afterEach(() => {
10
+ jest.clearAllMocks();
11
+ cleanup();
12
+ });
13
+
14
+ it('renders link card from space', async () => {
15
+ const space = {
16
+ id: 'encoded1',
17
+ configurationId: '1',
18
+ type: 'APPLICATION',
19
+ name: 'An application',
20
+ description: 'This is an application',
21
+ link: {
22
+ url: '/path/to/url',
23
+ text: 'the link',
24
+ target: '_self',
25
+ },
26
+ };
27
+ const queryClient = new QueryClient();
28
+ const { container } = render(
29
+ <QueryClientProvider client={queryClient}>
30
+ <Spaces clientId="my-client-id" spaces={[space]}>
31
+ <SpacesLink
32
+ id="application-link-1"
33
+ titleTag="h5"
34
+ space={space}
35
+ linkAttributes={{
36
+ spaceId: '1',
37
+ }}
38
+ clientId="my-client-id"
39
+ variant="card"
40
+ title={space.link.text}
41
+ description
42
+ analytics={{
43
+ 'data-av-analytics-application-id': space.configurationId,
44
+ 'data-av-analytics-action': 'click',
45
+ 'data-av-analytics-value': space.link?.url,
46
+ 'data-av-analytics-label': space.name,
47
+ }}
48
+ />
49
+ </Spaces>
50
+ </QueryClientProvider>
51
+ );
52
+
53
+ expect(container.tagName).toBe('DIV');
54
+
55
+ const linkHeader = await waitFor(() => container.querySelector('#app-title-1'));
56
+ expect(linkHeader?.attributes.getNamedItem('variant')?.value).toBe('h6');
57
+ expect(linkHeader?.attributes.getNamedItem('role')?.value).toBe('link');
58
+ expect(linkHeader?.attributes.getNamedItem('data-av-analytics-application-id')?.value).toBe('1');
59
+ expect(linkHeader?.attributes.getNamedItem('data-av-analytics-action')?.value).toBe('click');
60
+ expect(linkHeader?.attributes.getNamedItem('data-av-analytics-value')?.value).toBe('/path/to/url');
61
+ expect(linkHeader?.attributes.getNamedItem('data-av-analytics-label')?.value).toBe('An application');
62
+ expect(linkHeader?.textContent).toBe('An application');
63
+
64
+ const linkDescription = await waitFor(() => container.querySelector('#app-description-1'));
65
+ expect(linkDescription?.textContent).toBe('This is an application');
66
+ });
67
+
68
+ it('renders link card from space with custom link tag', async () => {
69
+ const space = {
70
+ id: 'encoded2',
71
+ configurationId: '2',
72
+ type: 'APPLICATION',
73
+ name: 'An application',
74
+ description: 'This is an application',
75
+ link: {
76
+ url: '/path/to/url',
77
+ text: 'the link',
78
+ target: '_self',
79
+ },
80
+ };
81
+ const queryClient = new QueryClient();
82
+ const { container } = render(
83
+ <QueryClientProvider client={queryClient}>
84
+ <Spaces clientId="my-client-id" spaces={[space]}>
85
+ <SpacesLink
86
+ id="application-link-2"
87
+ titleTag="h5"
88
+ tag="li"
89
+ space={space}
90
+ linkAttributes={{
91
+ spaceId: '2',
92
+ }}
93
+ clientId="my-client-id"
94
+ title={space.link.text}
95
+ />
96
+ </Spaces>
97
+ </QueryClientProvider>
98
+ );
99
+
100
+ const link2 = await waitFor(() => container.querySelector('#application-link-2'));
101
+
102
+ expect(link2?.tagName).toBe('LI');
103
+ });
104
+
105
+ it('renders link card from space with no titleTag', async () => {
106
+ const space = {
107
+ id: 'encoded3',
108
+ configurationId: '3',
109
+ type: 'APPLICATION',
110
+ name: 'An application',
111
+ description: 'This is an application',
112
+ link: {
113
+ url: '/path/to/url',
114
+ text: 'the link',
115
+ target: '_self',
116
+ },
117
+ };
118
+ const queryClient = new QueryClient();
119
+ const { container } = render(
120
+ <QueryClientProvider client={queryClient}>
121
+ <Spaces clientId="my-client-id" spaces={[space]}>
122
+ <SpacesLink
123
+ id="application-link-3"
124
+ space={space}
125
+ linkAttributes={{
126
+ spaceId: '3',
127
+ }}
128
+ clientId="my-client-id"
129
+ title={space.link.text}
130
+ />
131
+ </Spaces>
132
+ </QueryClientProvider>
133
+ );
134
+
135
+ const link3_header = await waitFor(() => container.querySelector('#app-title-3'));
136
+
137
+ expect(link3_header?.tagName).toBe('DIV');
138
+ });
139
+
140
+ it('renders link card from space with custom title class', async () => {
141
+ const space = {
142
+ id: 'encoded3',
143
+ configurationId: '3',
144
+ type: 'APPLICATION',
145
+ name: 'An application',
146
+ description: 'This is an application',
147
+ link: {
148
+ url: '/path/to/url',
149
+ text: 'the link',
150
+ target: '_self',
151
+ },
152
+ };
153
+ const queryClient = new QueryClient();
154
+ const { container } = render(
155
+ <QueryClientProvider client={queryClient}>
156
+ <Spaces clientId="my-client-id" spaces={[space]}>
157
+ <SpacesLink
158
+ id="application-link-3"
159
+ titleClassName="custom_class"
160
+ space={space}
161
+ linkAttributes={{
162
+ spaceId: '3',
163
+ }}
164
+ clientId="my-client-id"
165
+ title={space.link.text}
166
+ />
167
+ </Spaces>
168
+ </QueryClientProvider>
169
+ );
170
+
171
+ const link3_title = await waitFor(() => container.querySelector('#app-title-3'));
172
+
173
+ expect(link3_title?.className).toContain('custom_class');
174
+ });
175
+
176
+ it('renders link card from new space with new badge', async () => {
177
+ const space = {
178
+ id: 'encoded7',
179
+ configurationId: '7',
180
+ type: 'NAVIGATION',
181
+ name: 'A navigation',
182
+ description: 'This is a navigation',
183
+ link: {
184
+ url: '/path/to/url',
185
+ text: 'the link',
186
+ target: '_self',
187
+ },
188
+ isNew: true,
189
+ };
190
+ const queryClient = new QueryClient();
191
+ const { container } = render(
192
+ <QueryClientProvider client={queryClient}>
193
+ <Spaces clientId="my-client-id" spaces={[space]}>
194
+ <SpacesLink
195
+ id="navigation-link-7"
196
+ space={space}
197
+ linkAttributes={{
198
+ spaceId: '7',
199
+ }}
200
+ clientId="my-client-id"
201
+ title={space.link.text}
202
+ showNew
203
+ />
204
+ </Spaces>
205
+ </QueryClientProvider>
206
+ );
207
+
208
+ const link7_newBadge = await waitFor(() => container.querySelector('#app-new-badge-7'));
209
+
210
+ expect(link7_newBadge?.className.includes('MuiChip-colorDefault')).toBeTruthy();
211
+ expect(link7_newBadge?.textContent).toBe('New!');
212
+ });
213
+
214
+ it('renders link card from new space with date', async () => {
215
+ const space = {
216
+ id: 'encoded8',
217
+ configurationId: '8',
218
+ type: 'NAVIGATION',
219
+ name: 'A navigation',
220
+ description: 'This is a navigation',
221
+ link: {
222
+ url: '/path/to/url',
223
+ text: 'the link',
224
+ target: '_self',
225
+ },
226
+ activeDate: dayjs('01/01/2022').format(),
227
+ };
228
+ const queryClient = new QueryClient();
229
+ const { container } = render(
230
+ <QueryClientProvider client={queryClient}>
231
+ <Spaces clientId="my-client-id" spaces={[space]}>
232
+ <SpacesLink
233
+ id="navigation-link-8"
234
+ space={space}
235
+ linkAttributes={{
236
+ spaceId: '8',
237
+ }}
238
+ clientId="my-client-id"
239
+ title={space.link.text}
240
+ showDate
241
+ />
242
+ </Spaces>
243
+ </QueryClientProvider>
244
+ );
245
+
246
+ const link8_date = await waitFor(() => container.querySelector('#app-date-badge-8'));
247
+
248
+ expect(link8_date?.tagName).toBe('SPAN');
249
+ expect(link8_date?.className.includes('MuiTypography-caption')).toBeTruthy();
250
+ expect(link8_date?.textContent).toBe('01/01/2022');
251
+ });
252
+
253
+ it('renders link card from space with children', async () => {
254
+ const space = {
255
+ id: 'encoded9',
256
+ configurationId: '9',
257
+ type: 'NAVIGATION',
258
+ name: 'A navigation',
259
+ description: 'This is a navigation',
260
+ link: {
261
+ url: '/path/to/url',
262
+ text: 'the link',
263
+ target: '_self',
264
+ },
265
+ };
266
+ const queryClient = new QueryClient();
267
+ const { container } = render(
268
+ <QueryClientProvider client={queryClient}>
269
+ <Spaces clientId="my-client-id" spaces={[space]}>
270
+ <SpacesLink
271
+ id="navigation-link-9"
272
+ space={space}
273
+ linkAttributes={{
274
+ spaceId: '9',
275
+ }}
276
+ clientId="my-client-id"
277
+ title={space.link.text}
278
+ analytics={{
279
+ 'data-av-analytics-application-id': space.configurationId,
280
+ 'data-av-analytics-action': 'click',
281
+ 'data-av-analytics-value': space.link?.url,
282
+ 'data-av-analytics-label': space.name,
283
+ }}
284
+ >
285
+ <span id="space-link-child-1">{space.name}</span>
286
+ </SpacesLink>
287
+ </Spaces>
288
+ </QueryClientProvider>
289
+ );
290
+
291
+ const link9_child = await waitFor(() => container.querySelector('#space-link-child-1'));
292
+
293
+ expect(link9_child?.tagName).toBe('SPAN');
294
+ expect(link9_child?.attributes.getNamedItem('role')?.value).toBe('link');
295
+ expect(link9_child?.attributes.getNamedItem('data-av-analytics-application-id')?.value).toBe('9');
296
+ expect(link9_child?.attributes.getNamedItem('data-av-analytics-action')?.value).toBe('click');
297
+ expect(link9_child?.attributes.getNamedItem('data-av-analytics-value')?.value).toBe('/path/to/url');
298
+ expect(link9_child?.attributes.getNamedItem('data-av-analytics-label')?.value).toBe('A navigation');
299
+ });
300
+
301
+ it('renders link card from space with children function', async () => {
302
+ const space = {
303
+ id: 'encoded10',
304
+ configurationId: '10',
305
+ type: 'NAVIGATION',
306
+ name: 'A navigation',
307
+ description: 'This is a navigation',
308
+ link: {
309
+ url: '/path/to/url',
310
+ text: 'the link',
311
+ target: '_self',
312
+ },
313
+ };
314
+ const children = ({ name }: { name: string }) => <span id="space-link-child-2">{name}</span>;
315
+ const queryClient = new QueryClient();
316
+ const { container } = render(
317
+ <QueryClientProvider client={queryClient}>
318
+ <Spaces clientId="my-client-id" spaces={[space]}>
319
+ <SpacesLink
320
+ id="navigation-link-10"
321
+ space={space}
322
+ linkAttributes={{
323
+ spaceId: '10',
324
+ }}
325
+ clientId="my-client-id"
326
+ title={space.link.text}
327
+ >
328
+ {children}
329
+ </SpacesLink>
330
+ </Spaces>
331
+ </QueryClientProvider>
332
+ );
333
+
334
+ const link10_child = await waitFor(() => container.querySelector('#space-link-child-2'));
335
+
336
+ expect(link10_child?.tagName).toBe('SPAN');
337
+ expect(link10_child?.textContent).toBe('A navigation');
338
+ });
339
+
340
+ it('renders title with link role when url is provided', async () => {
341
+ const space = {
342
+ id: 'encoded11',
343
+ configurationId: '11',
344
+ type: 'APPLICATION',
345
+ name: 'application with link',
346
+ description: 'This is a application',
347
+ link: {
348
+ url: '/path/to/url',
349
+ text: 'title',
350
+ target: '_self',
351
+ },
352
+ };
353
+ const queryClient = new QueryClient();
354
+ const { container } = render(
355
+ <QueryClientProvider client={queryClient}>
356
+ <Spaces clientId="my-client-id" spaces={[space]}>
357
+ <SpacesLink
358
+ id="application-link-11"
359
+ space={space}
360
+ linkAttributes={{
361
+ spaceId: '11',
362
+ }}
363
+ role="listitem"
364
+ clientId="my-client-id"
365
+ title={space.link.text}
366
+ />
367
+ </Spaces>
368
+ </QueryClientProvider>
369
+ );
370
+
371
+ const link11_title = await waitFor(() => container.querySelector('#app-title-11'));
372
+
373
+ expect(link11_title?.getAttribute('role')).toBe('link');
374
+ });
375
+
376
+ it('renders title without link role when no url is provided', async () => {
377
+ const space = {
378
+ id: 'encoded12',
379
+ configurationId: '12',
380
+ type: 'APPLICATION',
381
+ name: 'no link application',
382
+ description: 'This is a application',
383
+ link: {
384
+ text: 'title',
385
+ target: '_self',
386
+ },
387
+ };
388
+ const queryClient = new QueryClient();
389
+ const { container } = render(
390
+ <QueryClientProvider client={queryClient}>
391
+ <Spaces clientId="my-client-id" spaces={[space]}>
392
+ <SpacesLink
393
+ id="application-link-12"
394
+ space={space}
395
+ linkAttributes={{
396
+ spaceId: '12',
397
+ }}
398
+ role="listitem"
399
+ clientId="my-client-id"
400
+ title={space.link.text}
401
+ />
402
+ </Spaces>
403
+ </QueryClientProvider>
404
+ );
405
+
406
+ const link12_title = await waitFor(() => container.querySelector('#app-title-12'));
407
+
408
+ expect(link12_title?.getAttribute('role')).toBe('listitem');
409
+ });
410
+
411
+ it('renders title without link role when isGhosted', async () => {
412
+ const space = {
413
+ id: 'encoded13',
414
+ configurationId: '13',
415
+ type: 'APPLICATION',
416
+ name: 'no link application',
417
+ description: 'This is a application',
418
+ link: {
419
+ url: '/path/to/url',
420
+ text: 'title',
421
+ target: '_self',
422
+ },
423
+ isGhosted: true,
424
+ };
425
+ const queryClient = new QueryClient();
426
+ const { container } = render(
427
+ <QueryClientProvider client={queryClient}>
428
+ <Spaces clientId="my-client-id" spaces={[space]}>
429
+ <SpacesLink
430
+ id="application-link-13"
431
+ space={space}
432
+ linkAttributes={{
433
+ spaceId: '13',
434
+ }}
435
+ role="listitem"
436
+ clientId="my-client-id"
437
+ title={space.link.text}
438
+ />
439
+ </Spaces>
440
+ </QueryClientProvider>
441
+ );
442
+
443
+ const link13_title = await waitFor(() => container.querySelector('#app-title-13'));
444
+
445
+ expect(link13_title?.getAttribute('role')).toBe('listitem');
446
+ });
447
+
448
+ it('renders title with link role when url is provided and isGhosted = false', async () => {
449
+ const space = {
450
+ id: 'encoded14',
451
+ configurationId: '14',
452
+ type: 'APPLICATION',
453
+ name: 'application with link',
454
+ description: 'This is a application',
455
+ link: {
456
+ url: '/path/to/url',
457
+ text: 'title',
458
+ target: '_self',
459
+ },
460
+ isGhosted: false,
461
+ };
462
+ const queryClient = new QueryClient();
463
+ const { container } = render(
464
+ <QueryClientProvider client={queryClient}>
465
+ <Spaces clientId="my-client-id" spaces={[space]}>
466
+ <SpacesLink
467
+ id="application-link-14"
468
+ space={space}
469
+ linkAttributes={{
470
+ spaceId: '14',
471
+ }}
472
+ role="listitem"
473
+ clientId="my-client-id"
474
+ title={space.link.text}
475
+ />
476
+ </Spaces>
477
+ </QueryClientProvider>
478
+ );
479
+
480
+ const link14_title = await waitFor(() => container.querySelector('#app-title-14'));
481
+
482
+ expect(link14_title?.getAttribute('role')).toBe('link');
483
+ });
484
+
485
+ it('renders title with link role when url is provided and isGhosted is undefined', async () => {
486
+ const space = {
487
+ id: 'encoded14',
488
+ configurationId: '14',
489
+ type: 'APPLICATION',
490
+ name: 'application with link',
491
+ description: 'This is a application',
492
+ link: {
493
+ url: '/path/to/url',
494
+ text: 'title',
495
+ target: '_self',
496
+ },
497
+ };
498
+ const queryClient = new QueryClient();
499
+ const { container } = render(
500
+ <QueryClientProvider client={queryClient}>
501
+ <Spaces clientId="my-client-id" spaces={[space]}>
502
+ <SpacesLink
503
+ id="application-link-14"
504
+ space={space}
505
+ linkAttributes={{
506
+ spaceId: '14',
507
+ }}
508
+ role="listitem"
509
+ clientId="my-client-id"
510
+ title={space.link.text}
511
+ />
512
+ </Spaces>
513
+ </QueryClientProvider>
514
+ );
515
+
516
+ const link14_title = await waitFor(() => container.querySelector('#app-title-14'));
517
+
518
+ expect(link14_title?.getAttribute('role')).toBe('link');
519
+ });
520
+
521
+ it('renders link with icon for type file when icon is true', async () => {
522
+ const space = {
523
+ id: 'encoded14',
524
+ configurationId: '14',
525
+ type: 'FILE',
526
+ url: '/path/to/url',
527
+ name: 'file with link',
528
+ metadataPairs: [{ name: 'icon', value: 'file-archive' }],
529
+ description: 'This is a file',
530
+ link: {
531
+ url: '/path/to/url',
532
+ text: 'title',
533
+ target: '_self',
534
+ },
535
+ };
536
+ const queryClient = new QueryClient();
537
+ const { container } = render(
538
+ <QueryClientProvider client={queryClient}>
539
+ <Spaces clientId="my-client-id" spaces={[space]}>
540
+ <SpacesLink
541
+ id="application-link-14"
542
+ icon
543
+ space={space}
544
+ linkAttributes={{
545
+ spaceId: '14',
546
+ }}
547
+ role="listitem"
548
+ clientId="my-client-id"
549
+ title={space.link.text}
550
+ />
551
+ </Spaces>
552
+ </QueryClientProvider>
553
+ );
554
+
555
+ const link = await waitFor(() => container.getElementsByTagName('a'));
556
+ expect(link[0]?.getAttribute('href')).toContain('/public/apps/home/#!/loadApp?appUrl=%2Fpath%2Fto%2Furl');
557
+ const icon = await waitFor(() => container.getElementsByTagName('svg')[1]);
558
+
559
+ const { container: testContainer } = render(<FileIcon data-testid="icon" />);
560
+
561
+ expect(icon).toStrictEqual(testContainer.getElementsByTagName('svg')[0]);
562
+ });
563
+
564
+ it('renders icon for non file type when icon is true', async () => {
565
+ const space = {
566
+ id: 'encoded14',
567
+ configurationId: '14',
568
+ type: 'LINK',
569
+ name: 'file with link',
570
+ url: '/path/to/url',
571
+ icons: {
572
+ navigation: 'desktop',
573
+ },
574
+ description: 'This is a file',
575
+ link: {
576
+ url: '/path/to/url',
577
+ text: 'title',
578
+ target: '_self',
579
+ },
580
+ };
581
+ const queryClient = new QueryClient();
582
+ const { container } = render(
583
+ <QueryClientProvider client={queryClient}>
584
+ <Spaces clientId="my-client-id" spaces={[space]}>
585
+ <SpacesLink
586
+ id="application-link-14"
587
+ space={space}
588
+ linkAttributes={{
589
+ spaceId: '14',
590
+ }}
591
+ role="listitem"
592
+ clientId="my-client-id"
593
+ title={space.link.text}
594
+ />
595
+ </Spaces>
596
+ </QueryClientProvider>
597
+ );
598
+
599
+ const icon = await waitFor(() => container.getElementsByTagName('svg')[0]);
600
+
601
+ const { container: testContainer } = render(<NavigateTopIcon data-testid="icon" />);
602
+
603
+ expect(icon).toStrictEqual(testContainer.getElementsByTagName('svg')[0]);
604
+ });
605
+ });