@aarhus-university/au-lib-react-components 12.6.2 → 12.6.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.
- package/.eslintrc.js +35 -35
- package/.storybook/main.js +34 -34
- package/.storybook/preview.js +17 -17
- package/README.md +19 -19
- package/__tests__/jest/AUButtonComponent.test.tsx +165 -165
- package/__tests__/jest/AUDynamicContentComponent.test.tsx +386 -386
- package/__tests__/jest/AUErrorComponent.test.tsx +142 -142
- package/__tests__/jest/AUModalComponent.test.tsx +186 -186
- package/__tests__/jest/AUNotificationComponent.test.tsx +115 -115
- package/__tests__/jest/AUSpinnerComponent.test.tsx +57 -57
- package/__tests__/jest/AUToolbarComponent.test.tsx +46 -46
- package/__tests__/jest/context.test.ts +25 -25
- package/__tests__/jest/helpers.test.ts +15 -15
- package/__tests__/jest/setupTests.ts +2 -2
- package/babel.config.js +8 -8
- package/build/umd/all.css +2 -2
- package/build/umd/all.js +1 -1
- package/build/umd/alphabox.js +1 -1
- package/build/umd/databox.js +1 -1
- package/build/umd/diagramme.js +1 -1
- package/build/umd/flowbox.js +1 -1
- package/build/umd/flowbox.js.map +1 -1
- package/build/umd/universe.js +1 -1
- package/build-storybook.log +386 -386
- package/esbuild.mjs +22 -22
- package/package.json +107 -107
- package/src/components/AUAlertComponent.tsx +128 -128
- package/src/components/AUAutoSuggestComponent.js +148 -148
- package/src/components/AUButtonComponent.tsx +99 -99
- package/src/components/AUCalendarComponent.tsx +497 -497
- package/src/components/AUCharacterCountComponent.tsx +56 -56
- package/src/components/AUComboBoxComponent.tsx +195 -195
- package/src/components/AUContentToggleComponent.tsx +50 -50
- package/src/components/AUDatepickerComponent.tsx +124 -124
- package/src/components/AUDialogModalComponent.tsx +124 -124
- package/src/components/AUDynamicContentComponent.tsx +137 -137
- package/src/components/AUEditorComponent.tsx +126 -126
- package/src/components/AUErrorComponent.tsx +73 -73
- package/src/components/AUMobilePrefixComponent.tsx +20 -20
- package/src/components/AUModalComponent.tsx +72 -72
- package/src/components/AUNotificationComponent.tsx +44 -44
- package/src/components/AUReceiptComponent.tsx +34 -34
- package/src/components/AUSpinnerComponent.tsx +40 -40
- package/src/components/AUStepComponent.tsx +75 -75
- package/src/components/AUSubNavComponent.tsx +57 -57
- package/src/components/AUSubmitButtonContainerComponent.tsx +38 -38
- package/src/components/AUTabbedContentComponent.tsx +154 -154
- package/src/components/AUTableComponent.tsx +29 -29
- package/src/components/AUToastComponent.tsx +104 -104
- package/src/components/AUToolbarComponent.tsx +108 -108
- package/src/components/AUTruncatorComponent.tsx +141 -141
- package/src/components/wrapping/AUEmbedComponent.js +47 -47
- package/src/layout-2016/components/alphabox/AlphaBoxComponent.js +142 -142
- package/src/layout-2016/components/alphabox/AlphaBoxContentComponent.js +136 -136
- package/src/layout-2016/components/common/AUCollapsibleComponent.js +152 -152
- package/src/layout-2016/components/common/AUSpinnerComponent.js +103 -103
- package/src/layout-2016/components/databox/DataBoxAlphabetComponent.js +144 -144
- package/src/layout-2016/components/databox/DataBoxAssociationComponent.js +122 -122
- package/src/layout-2016/components/databox/DataBoxButtonComponent.js +157 -157
- package/src/layout-2016/components/databox/DataBoxComponent.js +297 -297
- package/src/layout-2016/components/databox/DataBoxGroupingComponent.js +64 -64
- package/src/layout-2016/components/databox/DataBoxSearchResultComponent.js +36 -36
- package/src/layout-2016/components/databox/DataBoxStackedAssociationComponent.js +54 -54
- package/src/layout-2016/components/databox/DataBoxSuggestionComponent.js +39 -39
- package/src/layout-2016/components/diagramme/AUDiagrammeComponent.js +309 -309
- package/src/layout-2016/components/flowbox/FlowBoxComponent.js +126 -126
- package/src/layout-2016/components/flowbox/FlowBoxPhoneComponent.js +104 -104
- package/src/layout-2016/lib/all.js +3 -3
- package/src/layout-2016/lib/au-alphabox.js +99 -99
- package/src/layout-2016/lib/au-databox.js +399 -399
- package/src/layout-2016/lib/au-diagramme.js +85 -85
- package/src/layout-2016/lib/au-flowbox.js +116 -119
- package/src/lib/context.tsx +59 -59
- package/src/lib/dates.ts +52 -52
- package/src/lib/helpers.ts +208 -208
- package/src/lib/hooks.ts +157 -157
- package/src/lib/i18n.ts +600 -600
- package/src/lib/portals.tsx +150 -150
- package/src/lib/tinymce.ts +84 -84
- package/src/lib/wrapping.ts +21 -21
- package/src/styles/_settings.scss +10 -10
- package/src/styles/alphabox.scss +222 -222
- package/src/styles/app.scss +7 -7
- package/src/styles/autosuggest.scss +57 -57
- package/src/styles/databox.scss +563 -563
- package/src/styles/diagramme.scss +119 -119
- package/src/styles/flowbox.scss +72 -72
- package/src/styles/maps.scss +395 -395
- package/stories/AUAlertComponent.stories.tsx +133 -133
- package/stories/AUAutoSuggestComponent.stories.tsx +95 -95
- package/stories/AUButtonComponent.stories.tsx +139 -139
- package/stories/AUCharacterCountComponent.stories.tsx +121 -121
- package/stories/AUComboBoxComponent.stories.tsx +101 -101
- package/stories/AUContentToggleComponent.stories.tsx +87 -87
- package/stories/AUDialogModalComponent.stories.tsx +75 -75
- package/stories/AUDynamicContentComponent.stories.tsx +119 -119
- package/stories/AUEditorComponent.stories.tsx +66 -66
- package/stories/AUErrorComponent.stories.tsx +132 -132
- package/stories/AUModalComponent.stories.tsx +160 -160
- package/stories/AUNotificationComponent.stories.tsx +151 -151
- package/stories/AUSpinnerComponent.stories.tsx +44 -44
- package/stories/AUStepComponent.stories.tsx +91 -91
- package/stories/AUToolbarComponent.stories.tsx +389 -389
- package/stories/AUTruncatorComponent.stories.tsx +123 -123
- package/stories/lib/helpers.tsx +146 -146
- package/tsconfig.json +46 -46
- package/webpack.config.js +88 -88
- package/.claude/settings.local.json +0 -12
- package/.vscode/settings.json +0 -22
|
@@ -1,386 +1,386 @@
|
|
|
1
|
-
/* eslint-disable react/jsx-props-no-spreading */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { render, screen } from '@testing-library/react';
|
|
5
|
-
import '@testing-library/jest-dom';
|
|
6
|
-
import AUDynamicContentComponent, {
|
|
7
|
-
IDynamicContentProps,
|
|
8
|
-
IDynamicContentVideo,
|
|
9
|
-
IDynamicContentImage,
|
|
10
|
-
IDynamicContentInfoBox,
|
|
11
|
-
} from '../../src/components/AUDynamicContentComponent';
|
|
12
|
-
|
|
13
|
-
describe('<AUDynamicContentComponent />', () => {
|
|
14
|
-
const baseProps: IDynamicContentProps = {
|
|
15
|
-
name: 'Dynamic Content Section',
|
|
16
|
-
featuredContentDescription: '<p>This is a description</p>',
|
|
17
|
-
links: [
|
|
18
|
-
{
|
|
19
|
-
title: 'System Link',
|
|
20
|
-
description: 'A system link description',
|
|
21
|
-
url: 'https://example.com/system',
|
|
22
|
-
linkType: 'system',
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
title: 'Information Link',
|
|
26
|
-
description: 'An information link description',
|
|
27
|
-
url: 'https://example.com/info',
|
|
28
|
-
linkType: 'information',
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
featuredContent: {
|
|
32
|
-
type: 'image',
|
|
33
|
-
url: 'https://example.com/image.jpg',
|
|
34
|
-
altText: 'Example image',
|
|
35
|
-
} as IDynamicContentImage,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
describe('basic rendering', () => {
|
|
39
|
-
it('renders the component with all required props', () => {
|
|
40
|
-
const { container } = render(<AUDynamicContentComponent {...baseProps} />);
|
|
41
|
-
|
|
42
|
-
expect(screen.getByText('Dynamic Content Section')).toBeInTheDocument();
|
|
43
|
-
expect(screen.getByText('System Link')).toBeInTheDocument();
|
|
44
|
-
expect(container.querySelector('.dynamic-content')).toBeInTheDocument();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('applies correct ARIA attributes', () => {
|
|
48
|
-
render(<AUDynamicContentComponent {...baseProps} />);
|
|
49
|
-
|
|
50
|
-
const section = screen.getByRole('region');
|
|
51
|
-
expect(section).toHaveAttribute('aria-labelledby', 'dynamic-content-heading');
|
|
52
|
-
expect(screen.getByRole('heading', { level: 3 })).toHaveAttribute(
|
|
53
|
-
'id',
|
|
54
|
-
'dynamic-content-heading',
|
|
55
|
-
);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('renders the featured content description as HTML', () => {
|
|
59
|
-
const { container } = render(<AUDynamicContentComponent {...baseProps} />);
|
|
60
|
-
|
|
61
|
-
const description = container.querySelector('.dynamic-content__featured p');
|
|
62
|
-
expect(description).toBeInTheDocument();
|
|
63
|
-
expect(description?.textContent).toBe('This is a description');
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('featured content variants', () => {
|
|
68
|
-
it('renders a video featured content', () => {
|
|
69
|
-
// Note: Backend/admin panel validates that video URLs are from Panopto or YouTube-nocookie
|
|
70
|
-
// This component is a thin client that renders what the backend provides
|
|
71
|
-
const videoContent: IDynamicContentVideo = {
|
|
72
|
-
type: 'video',
|
|
73
|
-
url: 'https://aarhusuniversitet.cloud.panopto.eu/Panopto/Pages/Embed.aspx?id=test-video-id',
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const { container } = render(
|
|
77
|
-
<AUDynamicContentComponent
|
|
78
|
-
{...baseProps}
|
|
79
|
-
featuredContent={videoContent}
|
|
80
|
-
/>,
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
const iframe = container.querySelector('iframe');
|
|
84
|
-
expect(iframe).toBeInTheDocument();
|
|
85
|
-
expect(iframe).toHaveAttribute('src', 'https://aarhusuniversitet.cloud.panopto.eu/Panopto/Pages/Embed.aspx?id=test-video-id');
|
|
86
|
-
expect(iframe).toHaveAttribute('title', 'Video player: Dynamic Content Section');
|
|
87
|
-
expect(iframe).toHaveAttribute('loading', 'lazy');
|
|
88
|
-
expect(iframe).toHaveAttribute('allowfullscreen');
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('renders an image featured content without optional fields', () => {
|
|
92
|
-
const imageContent: IDynamicContentImage = {
|
|
93
|
-
type: 'image',
|
|
94
|
-
url: 'https://example.com/image.jpg',
|
|
95
|
-
altText: 'Test image',
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const { container } = render(
|
|
99
|
-
<AUDynamicContentComponent
|
|
100
|
-
{...baseProps}
|
|
101
|
-
featuredContent={imageContent}
|
|
102
|
-
/>,
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
const img = container.querySelector('img');
|
|
106
|
-
expect(img).toBeInTheDocument();
|
|
107
|
-
expect(img).toHaveAttribute('src', 'https://example.com/image.jpg');
|
|
108
|
-
expect(img).toHaveAttribute('alt', 'Test image');
|
|
109
|
-
expect(img).toHaveAttribute('loading', 'lazy');
|
|
110
|
-
expect(container.querySelector('figcaption')).not.toBeInTheDocument();
|
|
111
|
-
// Check that the image is not wrapped in a link (only links in links section)
|
|
112
|
-
const featuredDiv = container.querySelector('.dynamic-content__featured');
|
|
113
|
-
expect(featuredDiv?.querySelector('a')).not.toBeInTheDocument();
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('renders an image with caption', () => {
|
|
117
|
-
const imageContent: IDynamicContentImage = {
|
|
118
|
-
type: 'image',
|
|
119
|
-
url: 'https://example.com/image.jpg',
|
|
120
|
-
altText: 'Test image',
|
|
121
|
-
caption: 'This is a caption',
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
render(
|
|
125
|
-
<AUDynamicContentComponent
|
|
126
|
-
{...baseProps}
|
|
127
|
-
featuredContent={imageContent}
|
|
128
|
-
/>,
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
const caption = screen.getByText('This is a caption');
|
|
132
|
-
expect(caption).toBeInTheDocument();
|
|
133
|
-
expect(caption.tagName).toBe('FIGCAPTION');
|
|
134
|
-
expect(caption).toHaveClass('text--small');
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('renders an image wrapped in a link when linkUrl is provided', () => {
|
|
138
|
-
const imageContent: IDynamicContentImage = {
|
|
139
|
-
type: 'image',
|
|
140
|
-
url: 'https://example.com/image.jpg',
|
|
141
|
-
altText: 'Test image',
|
|
142
|
-
linkUrl: 'https://example.com/destination',
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const { container } = render(
|
|
146
|
-
<AUDynamicContentComponent
|
|
147
|
-
{...baseProps}
|
|
148
|
-
featuredContent={imageContent}
|
|
149
|
-
/>,
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
const link = container.querySelector('.dynamic-content__featured a');
|
|
153
|
-
expect(link).toBeInTheDocument();
|
|
154
|
-
expect(link).toHaveAttribute('href', 'https://example.com/destination');
|
|
155
|
-
expect(link?.querySelector('img')).toBeInTheDocument();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('renders an infoBox featured content', () => {
|
|
159
|
-
const infoBoxContent: IDynamicContentInfoBox = {
|
|
160
|
-
type: 'infoBox',
|
|
161
|
-
htmlContent: '<div class="info">Important information</div>',
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const { container } = render(
|
|
165
|
-
<AUDynamicContentComponent
|
|
166
|
-
{...baseProps}
|
|
167
|
-
featuredContent={infoBoxContent}
|
|
168
|
-
/>,
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
const infoBox = container.querySelector('.dynamic-content__infobox');
|
|
172
|
-
expect(infoBox).toBeInTheDocument();
|
|
173
|
-
expect(infoBox?.querySelector('.info')).toBeInTheDocument();
|
|
174
|
-
expect(screen.getByText('Important information')).toBeInTheDocument();
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
describe('links rendering', () => {
|
|
179
|
-
it('renders multiple links with correct styling', () => {
|
|
180
|
-
render(<AUDynamicContentComponent {...baseProps} />);
|
|
181
|
-
|
|
182
|
-
const systemLink = screen.getByText('System Link').closest('a');
|
|
183
|
-
const infoLink = screen.getByText('Information Link').closest('a');
|
|
184
|
-
|
|
185
|
-
expect(systemLink).toHaveClass('button', 'button--block');
|
|
186
|
-
expect(systemLink).not.toHaveClass('button--dimmed');
|
|
187
|
-
|
|
188
|
-
expect(infoLink).toHaveClass('button', 'button--block', 'button--dimmed');
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('renders link titles and descriptions', () => {
|
|
192
|
-
render(<AUDynamicContentComponent {...baseProps} />);
|
|
193
|
-
|
|
194
|
-
expect(screen.getByText('System Link')).toHaveClass('card__title');
|
|
195
|
-
expect(screen.getByText('A system link description')).toHaveClass('card__subtitle');
|
|
196
|
-
expect(screen.getByText('Information Link')).toHaveClass('card__title');
|
|
197
|
-
expect(screen.getByText('An information link description')).toHaveClass('card__subtitle');
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it('renders correct href attributes', () => {
|
|
201
|
-
render(<AUDynamicContentComponent {...baseProps} />);
|
|
202
|
-
|
|
203
|
-
const systemLink = screen.getByText('System Link').closest('a');
|
|
204
|
-
const infoLink = screen.getByText('Information Link').closest('a');
|
|
205
|
-
|
|
206
|
-
expect(systemLink).toHaveAttribute('href', 'https://example.com/system');
|
|
207
|
-
expect(infoLink).toHaveAttribute('href', 'https://example.com/info');
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it('does not render links when array is empty', () => {
|
|
211
|
-
const { container } = render(
|
|
212
|
-
<AUDynamicContentComponent
|
|
213
|
-
{...baseProps}
|
|
214
|
-
links={[]}
|
|
215
|
-
/>,
|
|
216
|
-
);
|
|
217
|
-
|
|
218
|
-
const linksContainer = container.querySelector('.dynamic-content__links');
|
|
219
|
-
expect(linksContainer).toBeInTheDocument();
|
|
220
|
-
expect(linksContainer?.querySelector('a')).not.toBeInTheDocument();
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it('renders a single link', () => {
|
|
224
|
-
const singleLinkProps = {
|
|
225
|
-
...baseProps,
|
|
226
|
-
links: [baseProps.links[0]],
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
render(<AUDynamicContentComponent {...singleLinkProps} />);
|
|
230
|
-
|
|
231
|
-
expect(screen.getByText('System Link')).toBeInTheDocument();
|
|
232
|
-
expect(screen.queryByText('Information Link')).not.toBeInTheDocument();
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
describe('defensive coding - null/undefined handling', () => {
|
|
237
|
-
it('handles undefined links array gracefully', () => {
|
|
238
|
-
const { container } = render(
|
|
239
|
-
<AUDynamicContentComponent
|
|
240
|
-
{...baseProps}
|
|
241
|
-
links={undefined as any}
|
|
242
|
-
/>,
|
|
243
|
-
);
|
|
244
|
-
|
|
245
|
-
expect(container.querySelector('.dynamic-content')).toBeInTheDocument();
|
|
246
|
-
expect(container.querySelector('.dynamic-content__links a')).not.toBeInTheDocument();
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
it('handles null links array gracefully', () => {
|
|
250
|
-
const { container } = render(
|
|
251
|
-
<AUDynamicContentComponent
|
|
252
|
-
{...baseProps}
|
|
253
|
-
links={null as any}
|
|
254
|
-
/>,
|
|
255
|
-
);
|
|
256
|
-
|
|
257
|
-
expect(container.querySelector('.dynamic-content')).toBeInTheDocument();
|
|
258
|
-
expect(container.querySelector('.dynamic-content__links a')).not.toBeInTheDocument();
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it('handles undefined name gracefully', () => {
|
|
262
|
-
const { container } = render(
|
|
263
|
-
<AUDynamicContentComponent
|
|
264
|
-
{...baseProps}
|
|
265
|
-
name={undefined as any}
|
|
266
|
-
/>,
|
|
267
|
-
);
|
|
268
|
-
|
|
269
|
-
expect(container.querySelector('.dynamic-content')).toBeInTheDocument();
|
|
270
|
-
expect(container.querySelector('h3')).not.toBeInTheDocument();
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
it('handles empty string name gracefully', () => {
|
|
274
|
-
const { container } = render(
|
|
275
|
-
<AUDynamicContentComponent
|
|
276
|
-
{...baseProps}
|
|
277
|
-
name=""
|
|
278
|
-
/>,
|
|
279
|
-
);
|
|
280
|
-
|
|
281
|
-
expect(container.querySelector('.dynamic-content')).toBeInTheDocument();
|
|
282
|
-
expect(container.querySelector('h3')).not.toBeInTheDocument();
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
it('handles undefined featuredContent gracefully', () => {
|
|
286
|
-
const { container } = render(
|
|
287
|
-
<AUDynamicContentComponent
|
|
288
|
-
{...baseProps}
|
|
289
|
-
featuredContent={undefined as any}
|
|
290
|
-
/>,
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
expect(container.querySelector('.dynamic-content')).toBeInTheDocument();
|
|
294
|
-
expect(container.querySelector('iframe')).not.toBeInTheDocument();
|
|
295
|
-
expect(container.querySelector('img')).not.toBeInTheDocument();
|
|
296
|
-
expect(container.querySelector('.dynamic-content__infobox')).not.toBeInTheDocument();
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
it('handles null featuredContent gracefully', () => {
|
|
300
|
-
const { container } = render(
|
|
301
|
-
<AUDynamicContentComponent
|
|
302
|
-
{...baseProps}
|
|
303
|
-
featuredContent={null as any}
|
|
304
|
-
/>,
|
|
305
|
-
);
|
|
306
|
-
|
|
307
|
-
expect(container.querySelector('.dynamic-content')).toBeInTheDocument();
|
|
308
|
-
expect(container.querySelector('iframe')).not.toBeInTheDocument();
|
|
309
|
-
expect(container.querySelector('img')).not.toBeInTheDocument();
|
|
310
|
-
expect(container.querySelector('.dynamic-content__infobox')).not.toBeInTheDocument();
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
it('handles undefined featuredContentDescription gracefully', () => {
|
|
314
|
-
const { container } = render(
|
|
315
|
-
<AUDynamicContentComponent
|
|
316
|
-
{...baseProps}
|
|
317
|
-
featuredContentDescription={undefined as any}
|
|
318
|
-
/>,
|
|
319
|
-
);
|
|
320
|
-
|
|
321
|
-
expect(container.querySelector('.dynamic-content')).toBeInTheDocument();
|
|
322
|
-
const featuredDiv = container.querySelector('.dynamic-content__featured');
|
|
323
|
-
expect(featuredDiv).toBeInTheDocument();
|
|
324
|
-
// Should not have a child div with dangerouslySetInnerHTML
|
|
325
|
-
const childDivs = Array.from(featuredDiv?.children || []).filter(
|
|
326
|
-
(child) => child.tagName === 'DIV' && child !== featuredDiv,
|
|
327
|
-
);
|
|
328
|
-
expect(childDivs.length).toBe(0);
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
it('handles empty string featuredContentDescription gracefully', () => {
|
|
332
|
-
const { container } = render(
|
|
333
|
-
<AUDynamicContentComponent
|
|
334
|
-
{...baseProps}
|
|
335
|
-
featuredContentDescription=""
|
|
336
|
-
/>,
|
|
337
|
-
);
|
|
338
|
-
|
|
339
|
-
expect(container.querySelector('.dynamic-content')).toBeInTheDocument();
|
|
340
|
-
const featuredDiv = container.querySelector('.dynamic-content__featured');
|
|
341
|
-
expect(featuredDiv).toBeInTheDocument();
|
|
342
|
-
// Should not render the description div when empty
|
|
343
|
-
const childDivs = Array.from(featuredDiv?.children || []).filter(
|
|
344
|
-
(child) => child.tagName === 'DIV' && child !== featuredDiv,
|
|
345
|
-
);
|
|
346
|
-
expect(childDivs.length).toBe(0);
|
|
347
|
-
});
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
describe('edge cases', () => {
|
|
351
|
-
it('renders with minimal valid props', () => {
|
|
352
|
-
const minimalProps: IDynamicContentProps = {
|
|
353
|
-
name: 'Minimal',
|
|
354
|
-
featuredContentDescription: '<p>Description</p>',
|
|
355
|
-
links: [],
|
|
356
|
-
featuredContent: {
|
|
357
|
-
type: 'image',
|
|
358
|
-
url: 'https://example.com/img.jpg',
|
|
359
|
-
altText: 'Image',
|
|
360
|
-
},
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
const { container } = render(<AUDynamicContentComponent {...minimalProps} />);
|
|
364
|
-
|
|
365
|
-
expect(screen.getByText('Minimal')).toBeInTheDocument();
|
|
366
|
-
expect(container.querySelector('img')).toBeInTheDocument();
|
|
367
|
-
expect(container.querySelector('.dynamic-content__links a')).not.toBeInTheDocument();
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
it('handles all link types correctly', () => {
|
|
371
|
-
const allTypesProps = {
|
|
372
|
-
...baseProps,
|
|
373
|
-
links: [
|
|
374
|
-
{ ...baseProps.links[0], linkType: 'system' as const },
|
|
375
|
-
{ ...baseProps.links[1], linkType: 'information' as const },
|
|
376
|
-
],
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
render(<AUDynamicContentComponent {...allTypesProps} />);
|
|
380
|
-
|
|
381
|
-
const links = screen.getAllByRole('link');
|
|
382
|
-
expect(links[0]).not.toHaveClass('button--dimmed');
|
|
383
|
-
expect(links[1]).toHaveClass('button--dimmed');
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
});
|
|
1
|
+
/* eslint-disable react/jsx-props-no-spreading */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
|
+
import '@testing-library/jest-dom';
|
|
6
|
+
import AUDynamicContentComponent, {
|
|
7
|
+
IDynamicContentProps,
|
|
8
|
+
IDynamicContentVideo,
|
|
9
|
+
IDynamicContentImage,
|
|
10
|
+
IDynamicContentInfoBox,
|
|
11
|
+
} from '../../src/components/AUDynamicContentComponent';
|
|
12
|
+
|
|
13
|
+
describe('<AUDynamicContentComponent />', () => {
|
|
14
|
+
const baseProps: IDynamicContentProps = {
|
|
15
|
+
name: 'Dynamic Content Section',
|
|
16
|
+
featuredContentDescription: '<p>This is a description</p>',
|
|
17
|
+
links: [
|
|
18
|
+
{
|
|
19
|
+
title: 'System Link',
|
|
20
|
+
description: 'A system link description',
|
|
21
|
+
url: 'https://example.com/system',
|
|
22
|
+
linkType: 'system',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
title: 'Information Link',
|
|
26
|
+
description: 'An information link description',
|
|
27
|
+
url: 'https://example.com/info',
|
|
28
|
+
linkType: 'information',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
featuredContent: {
|
|
32
|
+
type: 'image',
|
|
33
|
+
url: 'https://example.com/image.jpg',
|
|
34
|
+
altText: 'Example image',
|
|
35
|
+
} as IDynamicContentImage,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
describe('basic rendering', () => {
|
|
39
|
+
it('renders the component with all required props', () => {
|
|
40
|
+
const { container } = render(<AUDynamicContentComponent {...baseProps} />);
|
|
41
|
+
|
|
42
|
+
expect(screen.getByText('Dynamic Content Section')).toBeInTheDocument();
|
|
43
|
+
expect(screen.getByText('System Link')).toBeInTheDocument();
|
|
44
|
+
expect(container.querySelector('.dynamic-content')).toBeInTheDocument();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('applies correct ARIA attributes', () => {
|
|
48
|
+
render(<AUDynamicContentComponent {...baseProps} />);
|
|
49
|
+
|
|
50
|
+
const section = screen.getByRole('region');
|
|
51
|
+
expect(section).toHaveAttribute('aria-labelledby', 'dynamic-content-heading');
|
|
52
|
+
expect(screen.getByRole('heading', { level: 3 })).toHaveAttribute(
|
|
53
|
+
'id',
|
|
54
|
+
'dynamic-content-heading',
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('renders the featured content description as HTML', () => {
|
|
59
|
+
const { container } = render(<AUDynamicContentComponent {...baseProps} />);
|
|
60
|
+
|
|
61
|
+
const description = container.querySelector('.dynamic-content__featured p');
|
|
62
|
+
expect(description).toBeInTheDocument();
|
|
63
|
+
expect(description?.textContent).toBe('This is a description');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('featured content variants', () => {
|
|
68
|
+
it('renders a video featured content', () => {
|
|
69
|
+
// Note: Backend/admin panel validates that video URLs are from Panopto or YouTube-nocookie
|
|
70
|
+
// This component is a thin client that renders what the backend provides
|
|
71
|
+
const videoContent: IDynamicContentVideo = {
|
|
72
|
+
type: 'video',
|
|
73
|
+
url: 'https://aarhusuniversitet.cloud.panopto.eu/Panopto/Pages/Embed.aspx?id=test-video-id',
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const { container } = render(
|
|
77
|
+
<AUDynamicContentComponent
|
|
78
|
+
{...baseProps}
|
|
79
|
+
featuredContent={videoContent}
|
|
80
|
+
/>,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const iframe = container.querySelector('iframe');
|
|
84
|
+
expect(iframe).toBeInTheDocument();
|
|
85
|
+
expect(iframe).toHaveAttribute('src', 'https://aarhusuniversitet.cloud.panopto.eu/Panopto/Pages/Embed.aspx?id=test-video-id');
|
|
86
|
+
expect(iframe).toHaveAttribute('title', 'Video player: Dynamic Content Section');
|
|
87
|
+
expect(iframe).toHaveAttribute('loading', 'lazy');
|
|
88
|
+
expect(iframe).toHaveAttribute('allowfullscreen');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('renders an image featured content without optional fields', () => {
|
|
92
|
+
const imageContent: IDynamicContentImage = {
|
|
93
|
+
type: 'image',
|
|
94
|
+
url: 'https://example.com/image.jpg',
|
|
95
|
+
altText: 'Test image',
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const { container } = render(
|
|
99
|
+
<AUDynamicContentComponent
|
|
100
|
+
{...baseProps}
|
|
101
|
+
featuredContent={imageContent}
|
|
102
|
+
/>,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const img = container.querySelector('img');
|
|
106
|
+
expect(img).toBeInTheDocument();
|
|
107
|
+
expect(img).toHaveAttribute('src', 'https://example.com/image.jpg');
|
|
108
|
+
expect(img).toHaveAttribute('alt', 'Test image');
|
|
109
|
+
expect(img).toHaveAttribute('loading', 'lazy');
|
|
110
|
+
expect(container.querySelector('figcaption')).not.toBeInTheDocument();
|
|
111
|
+
// Check that the image is not wrapped in a link (only links in links section)
|
|
112
|
+
const featuredDiv = container.querySelector('.dynamic-content__featured');
|
|
113
|
+
expect(featuredDiv?.querySelector('a')).not.toBeInTheDocument();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('renders an image with caption', () => {
|
|
117
|
+
const imageContent: IDynamicContentImage = {
|
|
118
|
+
type: 'image',
|
|
119
|
+
url: 'https://example.com/image.jpg',
|
|
120
|
+
altText: 'Test image',
|
|
121
|
+
caption: 'This is a caption',
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
render(
|
|
125
|
+
<AUDynamicContentComponent
|
|
126
|
+
{...baseProps}
|
|
127
|
+
featuredContent={imageContent}
|
|
128
|
+
/>,
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const caption = screen.getByText('This is a caption');
|
|
132
|
+
expect(caption).toBeInTheDocument();
|
|
133
|
+
expect(caption.tagName).toBe('FIGCAPTION');
|
|
134
|
+
expect(caption).toHaveClass('text--small');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('renders an image wrapped in a link when linkUrl is provided', () => {
|
|
138
|
+
const imageContent: IDynamicContentImage = {
|
|
139
|
+
type: 'image',
|
|
140
|
+
url: 'https://example.com/image.jpg',
|
|
141
|
+
altText: 'Test image',
|
|
142
|
+
linkUrl: 'https://example.com/destination',
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const { container } = render(
|
|
146
|
+
<AUDynamicContentComponent
|
|
147
|
+
{...baseProps}
|
|
148
|
+
featuredContent={imageContent}
|
|
149
|
+
/>,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
const link = container.querySelector('.dynamic-content__featured a');
|
|
153
|
+
expect(link).toBeInTheDocument();
|
|
154
|
+
expect(link).toHaveAttribute('href', 'https://example.com/destination');
|
|
155
|
+
expect(link?.querySelector('img')).toBeInTheDocument();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('renders an infoBox featured content', () => {
|
|
159
|
+
const infoBoxContent: IDynamicContentInfoBox = {
|
|
160
|
+
type: 'infoBox',
|
|
161
|
+
htmlContent: '<div class="info">Important information</div>',
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const { container } = render(
|
|
165
|
+
<AUDynamicContentComponent
|
|
166
|
+
{...baseProps}
|
|
167
|
+
featuredContent={infoBoxContent}
|
|
168
|
+
/>,
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
const infoBox = container.querySelector('.dynamic-content__infobox');
|
|
172
|
+
expect(infoBox).toBeInTheDocument();
|
|
173
|
+
expect(infoBox?.querySelector('.info')).toBeInTheDocument();
|
|
174
|
+
expect(screen.getByText('Important information')).toBeInTheDocument();
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe('links rendering', () => {
|
|
179
|
+
it('renders multiple links with correct styling', () => {
|
|
180
|
+
render(<AUDynamicContentComponent {...baseProps} />);
|
|
181
|
+
|
|
182
|
+
const systemLink = screen.getByText('System Link').closest('a');
|
|
183
|
+
const infoLink = screen.getByText('Information Link').closest('a');
|
|
184
|
+
|
|
185
|
+
expect(systemLink).toHaveClass('button', 'button--block');
|
|
186
|
+
expect(systemLink).not.toHaveClass('button--dimmed');
|
|
187
|
+
|
|
188
|
+
expect(infoLink).toHaveClass('button', 'button--block', 'button--dimmed');
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('renders link titles and descriptions', () => {
|
|
192
|
+
render(<AUDynamicContentComponent {...baseProps} />);
|
|
193
|
+
|
|
194
|
+
expect(screen.getByText('System Link')).toHaveClass('card__title');
|
|
195
|
+
expect(screen.getByText('A system link description')).toHaveClass('card__subtitle');
|
|
196
|
+
expect(screen.getByText('Information Link')).toHaveClass('card__title');
|
|
197
|
+
expect(screen.getByText('An information link description')).toHaveClass('card__subtitle');
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('renders correct href attributes', () => {
|
|
201
|
+
render(<AUDynamicContentComponent {...baseProps} />);
|
|
202
|
+
|
|
203
|
+
const systemLink = screen.getByText('System Link').closest('a');
|
|
204
|
+
const infoLink = screen.getByText('Information Link').closest('a');
|
|
205
|
+
|
|
206
|
+
expect(systemLink).toHaveAttribute('href', 'https://example.com/system');
|
|
207
|
+
expect(infoLink).toHaveAttribute('href', 'https://example.com/info');
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('does not render links when array is empty', () => {
|
|
211
|
+
const { container } = render(
|
|
212
|
+
<AUDynamicContentComponent
|
|
213
|
+
{...baseProps}
|
|
214
|
+
links={[]}
|
|
215
|
+
/>,
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
const linksContainer = container.querySelector('.dynamic-content__links');
|
|
219
|
+
expect(linksContainer).toBeInTheDocument();
|
|
220
|
+
expect(linksContainer?.querySelector('a')).not.toBeInTheDocument();
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('renders a single link', () => {
|
|
224
|
+
const singleLinkProps = {
|
|
225
|
+
...baseProps,
|
|
226
|
+
links: [baseProps.links[0]],
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
render(<AUDynamicContentComponent {...singleLinkProps} />);
|
|
230
|
+
|
|
231
|
+
expect(screen.getByText('System Link')).toBeInTheDocument();
|
|
232
|
+
expect(screen.queryByText('Information Link')).not.toBeInTheDocument();
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
describe('defensive coding - null/undefined handling', () => {
|
|
237
|
+
it('handles undefined links array gracefully', () => {
|
|
238
|
+
const { container } = render(
|
|
239
|
+
<AUDynamicContentComponent
|
|
240
|
+
{...baseProps}
|
|
241
|
+
links={undefined as any}
|
|
242
|
+
/>,
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
expect(container.querySelector('.dynamic-content')).toBeInTheDocument();
|
|
246
|
+
expect(container.querySelector('.dynamic-content__links a')).not.toBeInTheDocument();
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('handles null links array gracefully', () => {
|
|
250
|
+
const { container } = render(
|
|
251
|
+
<AUDynamicContentComponent
|
|
252
|
+
{...baseProps}
|
|
253
|
+
links={null as any}
|
|
254
|
+
/>,
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
expect(container.querySelector('.dynamic-content')).toBeInTheDocument();
|
|
258
|
+
expect(container.querySelector('.dynamic-content__links a')).not.toBeInTheDocument();
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('handles undefined name gracefully', () => {
|
|
262
|
+
const { container } = render(
|
|
263
|
+
<AUDynamicContentComponent
|
|
264
|
+
{...baseProps}
|
|
265
|
+
name={undefined as any}
|
|
266
|
+
/>,
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
expect(container.querySelector('.dynamic-content')).toBeInTheDocument();
|
|
270
|
+
expect(container.querySelector('h3')).not.toBeInTheDocument();
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('handles empty string name gracefully', () => {
|
|
274
|
+
const { container } = render(
|
|
275
|
+
<AUDynamicContentComponent
|
|
276
|
+
{...baseProps}
|
|
277
|
+
name=""
|
|
278
|
+
/>,
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
expect(container.querySelector('.dynamic-content')).toBeInTheDocument();
|
|
282
|
+
expect(container.querySelector('h3')).not.toBeInTheDocument();
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('handles undefined featuredContent gracefully', () => {
|
|
286
|
+
const { container } = render(
|
|
287
|
+
<AUDynamicContentComponent
|
|
288
|
+
{...baseProps}
|
|
289
|
+
featuredContent={undefined as any}
|
|
290
|
+
/>,
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
expect(container.querySelector('.dynamic-content')).toBeInTheDocument();
|
|
294
|
+
expect(container.querySelector('iframe')).not.toBeInTheDocument();
|
|
295
|
+
expect(container.querySelector('img')).not.toBeInTheDocument();
|
|
296
|
+
expect(container.querySelector('.dynamic-content__infobox')).not.toBeInTheDocument();
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('handles null featuredContent gracefully', () => {
|
|
300
|
+
const { container } = render(
|
|
301
|
+
<AUDynamicContentComponent
|
|
302
|
+
{...baseProps}
|
|
303
|
+
featuredContent={null as any}
|
|
304
|
+
/>,
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
expect(container.querySelector('.dynamic-content')).toBeInTheDocument();
|
|
308
|
+
expect(container.querySelector('iframe')).not.toBeInTheDocument();
|
|
309
|
+
expect(container.querySelector('img')).not.toBeInTheDocument();
|
|
310
|
+
expect(container.querySelector('.dynamic-content__infobox')).not.toBeInTheDocument();
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it('handles undefined featuredContentDescription gracefully', () => {
|
|
314
|
+
const { container } = render(
|
|
315
|
+
<AUDynamicContentComponent
|
|
316
|
+
{...baseProps}
|
|
317
|
+
featuredContentDescription={undefined as any}
|
|
318
|
+
/>,
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
expect(container.querySelector('.dynamic-content')).toBeInTheDocument();
|
|
322
|
+
const featuredDiv = container.querySelector('.dynamic-content__featured');
|
|
323
|
+
expect(featuredDiv).toBeInTheDocument();
|
|
324
|
+
// Should not have a child div with dangerouslySetInnerHTML
|
|
325
|
+
const childDivs = Array.from(featuredDiv?.children || []).filter(
|
|
326
|
+
(child) => child.tagName === 'DIV' && child !== featuredDiv,
|
|
327
|
+
);
|
|
328
|
+
expect(childDivs.length).toBe(0);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it('handles empty string featuredContentDescription gracefully', () => {
|
|
332
|
+
const { container } = render(
|
|
333
|
+
<AUDynamicContentComponent
|
|
334
|
+
{...baseProps}
|
|
335
|
+
featuredContentDescription=""
|
|
336
|
+
/>,
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
expect(container.querySelector('.dynamic-content')).toBeInTheDocument();
|
|
340
|
+
const featuredDiv = container.querySelector('.dynamic-content__featured');
|
|
341
|
+
expect(featuredDiv).toBeInTheDocument();
|
|
342
|
+
// Should not render the description div when empty
|
|
343
|
+
const childDivs = Array.from(featuredDiv?.children || []).filter(
|
|
344
|
+
(child) => child.tagName === 'DIV' && child !== featuredDiv,
|
|
345
|
+
);
|
|
346
|
+
expect(childDivs.length).toBe(0);
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
describe('edge cases', () => {
|
|
351
|
+
it('renders with minimal valid props', () => {
|
|
352
|
+
const minimalProps: IDynamicContentProps = {
|
|
353
|
+
name: 'Minimal',
|
|
354
|
+
featuredContentDescription: '<p>Description</p>',
|
|
355
|
+
links: [],
|
|
356
|
+
featuredContent: {
|
|
357
|
+
type: 'image',
|
|
358
|
+
url: 'https://example.com/img.jpg',
|
|
359
|
+
altText: 'Image',
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const { container } = render(<AUDynamicContentComponent {...minimalProps} />);
|
|
364
|
+
|
|
365
|
+
expect(screen.getByText('Minimal')).toBeInTheDocument();
|
|
366
|
+
expect(container.querySelector('img')).toBeInTheDocument();
|
|
367
|
+
expect(container.querySelector('.dynamic-content__links a')).not.toBeInTheDocument();
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it('handles all link types correctly', () => {
|
|
371
|
+
const allTypesProps = {
|
|
372
|
+
...baseProps,
|
|
373
|
+
links: [
|
|
374
|
+
{ ...baseProps.links[0], linkType: 'system' as const },
|
|
375
|
+
{ ...baseProps.links[1], linkType: 'information' as const },
|
|
376
|
+
],
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
render(<AUDynamicContentComponent {...allTypesProps} />);
|
|
380
|
+
|
|
381
|
+
const links = screen.getAllByRole('link');
|
|
382
|
+
expect(links[0]).not.toHaveClass('button--dimmed');
|
|
383
|
+
expect(links[1]).toHaveClass('button--dimmed');
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
});
|