@classic-homes/theme-svelte 1.22.0 → 1.22.1

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 (77) hide show
  1. package/dist/lib/components/Alert.svelte +8 -10
  2. package/dist/lib/components/DataPanel.svelte +19 -5
  3. package/dist/lib/components/HeaderSearch.svelte +18 -10
  4. package/dist/lib/components/Skeleton.svelte.d.ts +1 -1
  5. package/dist/lib/components/layout/AppShell.svelte +1 -1
  6. package/dist/lib/components/layout/DashboardLayout.svelte +15 -6
  7. package/dist/lib/components/layout/Footer.svelte +6 -6
  8. package/dist/lib/components/layout/FormPageLayout.svelte +4 -3
  9. package/dist/lib/components/layout/Sidebar.svelte +25 -21
  10. package/dist/lib/components/media/Image.svelte.d.ts +1 -1
  11. package/dist/lib/components/media/Lightbox.svelte +13 -9
  12. package/dist/lib/components/media/MediaCarousel.svelte +5 -0
  13. package/dist/lib/components/media/MediaGrid.svelte +4 -1
  14. package/dist/lib/components/notifications/NotificationDialog.svelte +8 -5
  15. package/dist/lib/components/notifications/NotificationItem.svelte +16 -6
  16. package/dist/lib/components/studio/InsertPalette.svelte +4 -1
  17. package/dist/lib/components/studio/StudioCanvas.svelte +23 -2
  18. package/dist/lib/components/studio/StudioCanvas.svelte.d.ts +5 -1
  19. package/dist/lib/composables/useFocusTrap.svelte.js +9 -2
  20. package/dist/lib/notices/sanitize.js +10 -3
  21. package/dist/lib/notices/store.d.ts +3 -3
  22. package/dist/lib/notices/store.js +14 -2
  23. package/dist/lib/notices/types.d.ts +8 -8
  24. package/dist/lib/notices/types.js +5 -1
  25. package/dist/lib/stores/sidebar.svelte.d.ts +6 -0
  26. package/dist/lib/stores/sidebar.svelte.js +61 -26
  27. package/dist/lib/utils/media.js +4 -3
  28. package/dist/lib/utils/url.d.ts +10 -0
  29. package/dist/lib/utils/url.js +21 -0
  30. package/dist/lib/utils.js +14 -1
  31. package/package.json +5 -4
  32. package/dist/__tests__/FileUpload.test.js +0 -45
  33. package/dist/__tests__/a11y/Alert.a11y.test.js +0 -84
  34. package/dist/__tests__/a11y/AlertDialog.a11y.test.js +0 -126
  35. package/dist/__tests__/a11y/Button.a11y.test.js +0 -66
  36. package/dist/__tests__/a11y/Card.a11y.test.js +0 -77
  37. package/dist/__tests__/a11y/Combobox.a11y.test.js +0 -209
  38. package/dist/__tests__/a11y/Dialog.a11y.test.js +0 -103
  39. package/dist/__tests__/a11y/DropdownMenu.a11y.test.js +0 -132
  40. package/dist/__tests__/a11y/FileUpload.a11y.test.js +0 -158
  41. package/dist/__tests__/a11y/FilterToolbar.a11y.test.js +0 -62
  42. package/dist/__tests__/a11y/Icon.a11y.test.js +0 -119
  43. package/dist/__tests__/a11y/Input.a11y.test.js +0 -96
  44. package/dist/__tests__/a11y/LiveRegion.a11y.test.js +0 -102
  45. package/dist/__tests__/a11y/Media.a11y.test.js +0 -145
  46. package/dist/__tests__/a11y/PublicLayout.a11y.test.js +0 -139
  47. package/dist/__tests__/a11y/SegmentedControl.a11y.test.js +0 -50
  48. package/dist/__tests__/a11y/Switch.a11y.test.js +0 -95
  49. package/dist/__tests__/a11y/Tabs.a11y.test.js +0 -116
  50. package/dist/__tests__/a11y/Textarea.a11y.test.js +0 -111
  51. package/dist/__tests__/a11y/Toolbar.a11y.test.js +0 -31
  52. package/dist/__tests__/a11y/ViewToggle.a11y.test.js +0 -40
  53. package/dist/__tests__/action-header.test.js +0 -150
  54. package/dist/__tests__/alert-dialog-dismiss.test.js +0 -54
  55. package/dist/__tests__/code-field.test.js +0 -65
  56. package/dist/__tests__/control-text-color.test.js +0 -29
  57. package/dist/__tests__/data-panel-card-gestures.test.js +0 -138
  58. package/dist/__tests__/data-panel-viewport.test.js +0 -45
  59. package/dist/__tests__/dropdown-trigger.test.js +0 -39
  60. package/dist/__tests__/header-search.test.js +0 -90
  61. package/dist/__tests__/media-components.test.js +0 -206
  62. package/dist/__tests__/media-hls.test.js +0 -273
  63. package/dist/__tests__/media-matterport.test.js +0 -296
  64. package/dist/__tests__/media-players.test.js +0 -244
  65. package/dist/__tests__/media-scrubber.test.js +0 -44
  66. package/dist/__tests__/media-utils.test.js +0 -427
  67. package/dist/__tests__/nav-access.test.js +0 -145
  68. package/dist/__tests__/page-header.test.js +0 -36
  69. package/dist/__tests__/public-layout-drawer.test.js +0 -116
  70. package/dist/__tests__/setup.js +0 -56
  71. package/dist/__tests__/sidebar-collapse.test.js +0 -58
  72. package/dist/__tests__/sidebar-docs-parity.test.js +0 -134
  73. package/dist/__tests__/sidebar-expansion.test.js +0 -59
  74. package/dist/__tests__/sidebar-items.test.js +0 -59
  75. package/dist/__tests__/sidebar-mobile.test.js +0 -86
  76. package/dist/__tests__/studio-canvas-item.svelte.test.js +0 -98
  77. package/dist/__tests__/studio.test.js +0 -240
@@ -1,427 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { buildEmbedSrc, clamp, cloudflareStream, cloudflareStreamHost, cloudflareStreamThumbnail, cloudflareStreamUrls, formatDuration, formatDurationSpoken, getEmbedThumbnail, getFileExtension, getMediaLabel, getMediaThumbnail, inferMediaKind, isHlsSource, isTimeBasedMedia, parseEmbedUrl, resolveAspectRatio, timeRangesToArray, toMediaSources, } from '../lib/utils/media.js';
3
- describe('formatDuration', () => {
4
- it('formats under a minute with a padded seconds field', () => {
5
- expect(formatDuration(0)).toBe('0:00');
6
- expect(formatDuration(9)).toBe('0:09');
7
- expect(formatDuration(59)).toBe('0:59');
8
- });
9
- it('formats minutes and seconds', () => {
10
- expect(formatDuration(60)).toBe('1:00');
11
- expect(formatDuration(83)).toBe('1:23');
12
- expect(formatDuration(599)).toBe('9:59');
13
- });
14
- it('adds an hours field past an hour and pads the minutes', () => {
15
- expect(formatDuration(3600)).toBe('1:00:00');
16
- expect(formatDuration(3723)).toBe('1:02:03');
17
- });
18
- it('collapses non-finite and negative input to zero', () => {
19
- // `video.duration` is NaN until metadata loads, and a player must not
20
- // render "NaN:NaN" in the meantime.
21
- expect(formatDuration(NaN)).toBe('0:00');
22
- expect(formatDuration(Infinity)).toBe('0:00');
23
- expect(formatDuration(-5)).toBe('0:00');
24
- });
25
- it('truncates fractional seconds rather than rounding up', () => {
26
- expect(formatDuration(59.9)).toBe('0:59');
27
- });
28
- });
29
- describe('formatDurationSpoken', () => {
30
- it('spells out each unit', () => {
31
- expect(formatDurationSpoken(83)).toBe('1 minute 23 seconds');
32
- expect(formatDurationSpoken(3723)).toBe('1 hour 2 minutes 3 seconds');
33
- });
34
- it('singularises correctly', () => {
35
- expect(formatDurationSpoken(1)).toBe('1 second');
36
- expect(formatDurationSpoken(60)).toBe('1 minute');
37
- });
38
- it('always says something for zero', () => {
39
- expect(formatDurationSpoken(0)).toBe('0 seconds');
40
- expect(formatDurationSpoken(NaN)).toBe('0 seconds');
41
- });
42
- });
43
- describe('getFileExtension', () => {
44
- it('ignores query strings and fragments', () => {
45
- expect(getFileExtension('/clip.mp4?token=abc')).toBe('mp4');
46
- expect(getFileExtension('/clip.MP4#t=10')).toBe('mp4');
47
- });
48
- it('returns an empty string when there is no extension', () => {
49
- expect(getFileExtension('/asset')).toBe('');
50
- expect(getFileExtension('/asset.')).toBe('');
51
- expect(getFileExtension('https://example.com/path.with.dots/file')).toBe('');
52
- });
53
- });
54
- describe('inferMediaKind', () => {
55
- it('prefers the MIME type over the URL', () => {
56
- expect(inferMediaKind('/asset', 'image/png')).toBe('image');
57
- expect(inferMediaKind('/asset.mp4', 'audio/mpeg')).toBe('audio');
58
- });
59
- it('falls back to the file extension', () => {
60
- expect(inferMediaKind('/photo.webp')).toBe('image');
61
- expect(inferMediaKind('/clip.webm')).toBe('video');
62
- expect(inferMediaKind('/track.flac')).toBe('audio');
63
- });
64
- it('recognises provider URLs as embeds', () => {
65
- expect(inferMediaKind('https://youtu.be/dQw4w9WgXcQ')).toBe('embed');
66
- expect(inferMediaKind('https://vimeo.com/123456789')).toBe('embed');
67
- });
68
- it('returns null when nothing can be inferred', () => {
69
- expect(inferMediaKind('/unknown.xyz')).toBeNull();
70
- expect(inferMediaKind('')).toBeNull();
71
- });
72
- });
73
- describe('parseEmbedUrl', () => {
74
- it('parses every common YouTube URL shape', () => {
75
- const expected = { provider: 'youtube', videoId: 'dQw4w9WgXcQ' };
76
- expect(parseEmbedUrl('https://www.youtube.com/watch?v=dQw4w9WgXcQ')).toEqual(expected);
77
- expect(parseEmbedUrl('https://youtu.be/dQw4w9WgXcQ')).toEqual(expected);
78
- expect(parseEmbedUrl('https://www.youtube.com/embed/dQw4w9WgXcQ')).toEqual(expected);
79
- expect(parseEmbedUrl('https://www.youtube.com/shorts/dQw4w9WgXcQ')).toEqual(expected);
80
- expect(parseEmbedUrl('https://www.youtube.com/live/dQw4w9WgXcQ')).toEqual(expected);
81
- expect(parseEmbedUrl('https://m.youtube.com/watch?v=dQw4w9WgXcQ')).toEqual(expected);
82
- });
83
- it('parses Vimeo URLs, including the player and channel forms', () => {
84
- expect(parseEmbedUrl('https://vimeo.com/123456789')).toEqual({
85
- provider: 'vimeo',
86
- videoId: '123456789',
87
- });
88
- expect(parseEmbedUrl('https://player.vimeo.com/video/123456789')).toEqual({
89
- provider: 'vimeo',
90
- videoId: '123456789',
91
- });
92
- expect(parseEmbedUrl('https://vimeo.com/channels/staffpicks/123456789')).toEqual({
93
- provider: 'vimeo',
94
- videoId: '123456789',
95
- });
96
- });
97
- it('reads the start offset in both numeric and hms form', () => {
98
- expect(parseEmbedUrl('https://youtu.be/dQw4w9WgXcQ?t=30')?.start).toBe(30);
99
- expect(parseEmbedUrl('https://youtu.be/dQw4w9WgXcQ?t=1m30s')?.start).toBe(90);
100
- expect(parseEmbedUrl('https://youtu.be/dQw4w9WgXcQ?t=1h2m3s')?.start).toBe(3723);
101
- expect(parseEmbedUrl('https://www.youtube.com/watch?v=dQw4w9WgXcQ&start=45')?.start).toBe(45);
102
- });
103
- it('rejects malformed ids rather than building a broken embed', () => {
104
- expect(parseEmbedUrl('https://www.youtube.com/watch?v=short')).toBeNull();
105
- expect(parseEmbedUrl('https://youtu.be/way-too-long-an-id')).toBeNull();
106
- expect(parseEmbedUrl('https://vimeo.com/not-a-number')).toBeNull();
107
- });
108
- it('returns null for unsupported hosts and empty input', () => {
109
- expect(parseEmbedUrl('https://example.com/video.mp4')).toBeNull();
110
- expect(parseEmbedUrl('https://dailymotion.com/video/x123')).toBeNull();
111
- expect(parseEmbedUrl('')).toBeNull();
112
- });
113
- });
114
- describe('buildEmbedSrc', () => {
115
- it('routes YouTube through the no-cookie domain by default', () => {
116
- expect(buildEmbedSrc('youtube', 'abc')).toContain('youtube-nocookie.com');
117
- });
118
- it('uses the standard domain when privacy is turned off', () => {
119
- const src = buildEmbedSrc('youtube', 'abc', { privacy: false });
120
- expect(src).toContain('www.youtube.com');
121
- expect(src).not.toContain('nocookie');
122
- });
123
- it('adds autoplay and start parameters only when requested', () => {
124
- expect(buildEmbedSrc('youtube', 'abc')).not.toContain('autoplay');
125
- const src = buildEmbedSrc('youtube', 'abc', { autoplay: true, start: 30.7 });
126
- expect(src).toContain('autoplay=1');
127
- // Providers reject fractional offsets.
128
- expect(src).toContain('start=30');
129
- });
130
- it('suppresses related videos by default', () => {
131
- expect(buildEmbedSrc('youtube', 'abc')).toContain('rel=0');
132
- expect(buildEmbedSrc('youtube', 'abc', { showRelated: true })).not.toContain('rel=0');
133
- });
134
- it('builds a Vimeo player URL with do-not-track set', () => {
135
- const src = buildEmbedSrc('vimeo', '123');
136
- expect(src).toContain('player.vimeo.com/video/123');
137
- expect(src).toContain('dnt=1');
138
- });
139
- });
140
- describe('getEmbedThumbnail', () => {
141
- it('derives a YouTube thumbnail URL', () => {
142
- expect(getEmbedThumbnail('youtube', 'abc')).toBe('https://i.ytimg.com/vi/abc/hqdefault.jpg');
143
- });
144
- it('returns null for Vimeo, which needs an oEmbed lookup', () => {
145
- expect(getEmbedThumbnail('vimeo', '123')).toBeNull();
146
- });
147
- });
148
- describe('getMediaThumbnail', () => {
149
- const base = { id: '1', thumbnail: undefined };
150
- it('prefers an explicit thumbnail over anything derived', () => {
151
- const item = { ...base, kind: 'image', src: '/a.jpg', alt: '', thumbnail: '/t.jpg' };
152
- expect(getMediaThumbnail(item)).toBe('/t.jpg');
153
- });
154
- it('falls back per kind', () => {
155
- expect(getMediaThumbnail({ ...base, kind: 'image', src: '/a.jpg', alt: '' })).toBe('/a.jpg');
156
- expect(getMediaThumbnail({ ...base, kind: 'video', src: '/a.mp4', poster: '/p.jpg' })).toBe('/p.jpg');
157
- expect(getMediaThumbnail({ ...base, kind: 'audio', src: '/a.mp3', artwork: '/w.jpg' })).toBe('/w.jpg');
158
- expect(getMediaThumbnail({ ...base, kind: 'embed', provider: 'youtube', videoId: 'abc' })).toContain('i.ytimg.com');
159
- });
160
- it('returns null when there is nothing to show', () => {
161
- expect(getMediaThumbnail({ ...base, kind: 'video', src: '/a.mp4' })).toBeNull();
162
- expect(getMediaThumbnail({ ...base, kind: 'audio', src: '/a.mp3' })).toBeNull();
163
- expect(getMediaThumbnail({ ...base, kind: 'embed', provider: 'vimeo', videoId: '1' })).toBeNull();
164
- });
165
- });
166
- describe('getMediaLabel', () => {
167
- it('prefers the title, then image alt text', () => {
168
- expect(getMediaLabel({ id: '1', kind: 'image', src: '/a.jpg', alt: 'A cat', title: 'Cat' })).toBe('Cat');
169
- expect(getMediaLabel({ id: '1', kind: 'image', src: '/a.jpg', alt: 'A cat' })).toBe('A cat');
170
- });
171
- it('falls back to a positional name so a tile is never unlabelled', () => {
172
- expect(getMediaLabel({ id: '1', kind: 'video', src: '/a.mp4' }, 2)).toBe('Video 3');
173
- expect(getMediaLabel({ id: '1', kind: 'video', src: '/a.mp4' })).toBe('Untitled video');
174
- });
175
- it('describes embeds as videos rather than "embed"', () => {
176
- expect(getMediaLabel({ id: '1', kind: 'embed', provider: 'youtube', videoId: 'a' }, 0)).toBe('Video 1');
177
- });
178
- });
179
- describe('isTimeBasedMedia', () => {
180
- it('is true for anything with a timeline', () => {
181
- expect(isTimeBasedMedia({ id: '1', kind: 'video', src: '/a.mp4' })).toBe(true);
182
- expect(isTimeBasedMedia({ id: '1', kind: 'audio', src: '/a.mp3' })).toBe(true);
183
- expect(isTimeBasedMedia({ id: '1', kind: 'embed', provider: 'vimeo', videoId: '1' })).toBe(true);
184
- expect(isTimeBasedMedia({ id: '1', kind: 'image', src: '/a.jpg', alt: '' })).toBe(false);
185
- });
186
- });
187
- describe('toMediaSources', () => {
188
- it('passes an explicit source list through untouched', () => {
189
- const sources = [{ src: '/a.webm', type: 'video/webm' }];
190
- expect(toMediaSources(sources)).toBe(sources);
191
- });
192
- it('wraps a single URL and guesses its MIME type', () => {
193
- expect(toMediaSources('/a.mp4')).toEqual([{ src: '/a.mp4', type: 'video/mp4' }]);
194
- expect(toMediaSources('/a.mp3')).toEqual([{ src: '/a.mp3', type: 'audio/mpeg' }]);
195
- });
196
- it('omits the type when the extension is unknown', () => {
197
- expect(toMediaSources('/stream')).toEqual([{ src: '/stream', type: undefined }]);
198
- });
199
- });
200
- describe('resolveAspectRatio', () => {
201
- it('maps named ratios to numbers and passes numbers through', () => {
202
- expect(resolveAspectRatio('square')).toBe(1);
203
- expect(resolveAspectRatio('video')).toBeCloseTo(16 / 9);
204
- expect(resolveAspectRatio(2.35)).toBe(2.35);
205
- });
206
- });
207
- describe('timeRangesToArray', () => {
208
- it('flattens the opaque TimeRanges object into plain pairs', () => {
209
- const ranges = {
210
- length: 2,
211
- start: (i) => [0, 30][i],
212
- end: (i) => [10, 45][i],
213
- };
214
- expect(timeRangesToArray(ranges)).toEqual([
215
- { start: 0, end: 10 },
216
- { start: 30, end: 45 },
217
- ]);
218
- });
219
- it('handles a null ranges object', () => {
220
- expect(timeRangesToArray(null)).toEqual([]);
221
- });
222
- });
223
- describe('isHlsSource', () => {
224
- it('detects HLS by declared MIME type', () => {
225
- expect(isHlsSource({ src: '/stream', type: 'application/vnd.apple.mpegurl' })).toBe(true);
226
- expect(isHlsSource({ src: '/stream', type: 'application/x-mpegURL' })).toBe(true);
227
- });
228
- it('detects HLS by extension when no type is declared', () => {
229
- expect(isHlsSource('/manifest/video.m3u8')).toBe(true);
230
- expect(isHlsSource('/manifest/video.m3u8?protocol=llhls')).toBe(true);
231
- });
232
- it('trusts an explicit type over the extension', () => {
233
- // A progressive MP4 must not be routed through hls.js just because the
234
- // URL happens to mention a playlist.
235
- expect(isHlsSource({ src: '/video.m3u8', type: 'video/mp4' })).toBe(false);
236
- });
237
- it('is false for ordinary files', () => {
238
- expect(isHlsSource('/clip.mp4')).toBe(false);
239
- expect(isHlsSource('/manifest/video.mpd')).toBe(false);
240
- });
241
- });
242
- describe('cloudflareStreamHost', () => {
243
- it('builds the customer subdomain', () => {
244
- expect(cloudflareStreamHost({ customerCode: 'abc123' })).toBe('customer-abc123.cloudflarestream.com');
245
- });
246
- it('prefers a custom domain and strips scheme and trailing slash', () => {
247
- expect(cloudflareStreamHost({ domain: 'https://video.example.com/', customerCode: 'abc' })).toBe('video.example.com');
248
- });
249
- it('returns null when the account cannot be resolved', () => {
250
- expect(cloudflareStreamHost({})).toBeNull();
251
- });
252
- });
253
- describe('cloudflareStreamUrls', () => {
254
- const account = { customerCode: 'abc123' };
255
- it('builds every playback URL from the video id', () => {
256
- const urls = cloudflareStreamUrls('a1b2c3', account);
257
- const base = 'https://customer-abc123.cloudflarestream.com/a1b2c3';
258
- expect(urls.hls).toBe(`${base}/manifest/video.m3u8`);
259
- expect(urls.dash).toBe(`${base}/manifest/video.mpd`);
260
- expect(urls.iframe).toBe(`${base}/iframe`);
261
- expect(urls.thumbnail).toBe(`${base}/thumbnails/thumbnail.jpg`);
262
- expect(urls.download).toBe(`${base}/downloads/default.mp4`);
263
- });
264
- it('requests the low-latency variant on demand', () => {
265
- expect(cloudflareStreamUrls('a1b2c3', { ...account, lowLatency: true }).hls).toContain('protocol=llhls');
266
- expect(cloudflareStreamUrls('a1b2c3', account).hls).not.toContain('protocol');
267
- });
268
- it('passes a bandwidth hint through', () => {
269
- expect(cloudflareStreamUrls('a1b2c3', { ...account, clientBandwidthHint: 3.5 }).hls).toContain('clientBandwidthHint=3.5');
270
- });
271
- it('accepts a signed token in place of the video id', () => {
272
- // Stream substitutes the whole JWT wherever the UID would go, so no
273
- // separate code path should be needed for private videos.
274
- const token = 'eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhMWIyYzMifQ.signature';
275
- expect(cloudflareStreamUrls(token, account).hls).toBe(`https://customer-abc123.cloudflarestream.com/${token}/manifest/video.m3u8`);
276
- });
277
- it('returns null without an account or a video id', () => {
278
- expect(cloudflareStreamUrls('a1b2c3', {})).toBeNull();
279
- expect(cloudflareStreamUrls('', account)).toBeNull();
280
- });
281
- });
282
- describe('cloudflareStreamThumbnail', () => {
283
- const account = { customerCode: 'abc123' };
284
- it('builds a still thumbnail with its options', () => {
285
- expect(cloudflareStreamThumbnail('a1b2c3', { ...account, time: '1s', height: 600 })).toBe('https://customer-abc123.cloudflarestream.com/a1b2c3/thumbnails/thumbnail.jpg?time=1s&height=600');
286
- });
287
- it('supports width and fit', () => {
288
- const url = cloudflareStreamThumbnail('a1b2c3', { ...account, width: 320, fit: 'scale' });
289
- expect(url).toContain('width=320');
290
- expect(url).toContain('fit=scale');
291
- });
292
- it('builds an animated thumbnail with its extra options', () => {
293
- const url = cloudflareStreamThumbnail('a1b2c3', {
294
- ...account,
295
- animated: true,
296
- duration: '4s',
297
- fps: 8,
298
- });
299
- expect(url).toContain('/thumbnails/thumbnail.gif');
300
- expect(url).toContain('duration=4s');
301
- expect(url).toContain('fps=8');
302
- });
303
- it('omits GIF-only options from a still thumbnail', () => {
304
- const url = cloudflareStreamThumbnail('a1b2c3', { ...account, duration: '4s', fps: 8 });
305
- expect(url).toContain('thumbnail.jpg');
306
- expect(url).not.toContain('duration');
307
- expect(url).not.toContain('fps');
308
- });
309
- it('returns null without an account', () => {
310
- expect(cloudflareStreamThumbnail('a1b2c3', {})).toBeNull();
311
- });
312
- });
313
- describe('cloudflareStream', () => {
314
- const account = { customerCode: 'abc123' };
315
- it('builds a playable video item with a derived poster', () => {
316
- const item = cloudflareStream('a1b2c3', { ...account, title: 'Product tour' });
317
- expect(item.kind).toBe('video');
318
- expect(item.id).toBe('a1b2c3');
319
- expect(item.title).toBe('Product tour');
320
- // Typed as HLS so the player routes it through hls.js where needed.
321
- expect(item.src).toEqual([
322
- {
323
- src: 'https://customer-abc123.cloudflarestream.com/a1b2c3/manifest/video.m3u8',
324
- type: 'application/vnd.apple.mpegurl',
325
- },
326
- ]);
327
- expect(item.poster).toContain('/thumbnails/thumbnail.jpg?time=1s&height=720');
328
- // The thumbnail is reused for grids and lightbox strips.
329
- expect(item.thumbnail).toBe(item.poster);
330
- });
331
- it('honours an explicit poster and poster timing', () => {
332
- expect(cloudflareStream('a1b2c3', { ...account, poster: '/own.jpg' }).poster).toBe('/own.jpg');
333
- expect(cloudflareStream('a1b2c3', { ...account, posterTime: '30s', posterHeight: 400 }).poster).toContain('time=30s&height=400');
334
- });
335
- it('only exposes a download URL when downloads are requested', () => {
336
- expect(cloudflareStream('a1b2c3', account).downloadUrl).toBeUndefined();
337
- expect(cloudflareStream('a1b2c3', { ...account, downloadable: true }).downloadUrl).toContain('/downloads/default.mp4');
338
- });
339
- it('throws a directed error when the account is missing', () => {
340
- expect(() => cloudflareStream('a1b2c3', {})).toThrow(/customerCode/);
341
- });
342
- it('produces an item the media helpers understand', () => {
343
- const item = cloudflareStream('a1b2c3', { ...account, title: 'Tour' });
344
- expect(isTimeBasedMedia(item)).toBe(true);
345
- expect(getMediaLabel(item, 0)).toBe('Tour');
346
- expect(getMediaThumbnail(item)).toBe(item.poster);
347
- expect(isHlsSource(toMediaSources(item.src)[0])).toBe(true);
348
- });
349
- });
350
- describe('parseEmbedUrl - Cloudflare Stream', () => {
351
- it('parses every Stream asset URL shape', () => {
352
- const expected = { provider: 'cloudflare', videoId: 'a1b2c3', customerCode: 'abc' };
353
- expect(parseEmbedUrl('https://customer-abc.cloudflarestream.com/a1b2c3/iframe')).toEqual(expected);
354
- expect(parseEmbedUrl('https://customer-abc.cloudflarestream.com/a1b2c3/watch')).toEqual(expected);
355
- expect(parseEmbedUrl('https://customer-abc.cloudflarestream.com/a1b2c3/manifest/video.m3u8')).toEqual(expected);
356
- });
357
- it('reads the Stream player start offset', () => {
358
- expect(parseEmbedUrl('https://customer-abc.cloudflarestream.com/a1b2c3/iframe?startTime=1m30s')
359
- ?.start).toBe(90);
360
- });
361
- it('recognises the legacy videodelivery.net hosts without a customer code', () => {
362
- expect(parseEmbedUrl('https://iframe.videodelivery.net/a1b2c3')).toEqual({
363
- provider: 'cloudflare',
364
- videoId: 'a1b2c3',
365
- });
366
- });
367
- it('accepts a signed token as the id, since it has no fixed shape', () => {
368
- const token = 'eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhMWIyYzMifQ.sig';
369
- expect(parseEmbedUrl(`https://customer-abc.cloudflarestream.com/${token}/iframe`)).toEqual({
370
- provider: 'cloudflare',
371
- videoId: token,
372
- customerCode: 'abc',
373
- });
374
- });
375
- it('rejects a Stream host with no video id', () => {
376
- expect(parseEmbedUrl('https://customer-abc.cloudflarestream.com/')).toBeNull();
377
- });
378
- });
379
- describe('buildEmbedSrc - Cloudflare Stream', () => {
380
- const account = { customerCode: 'abc' };
381
- it('builds the player iframe URL', () => {
382
- expect(buildEmbedSrc('cloudflare', 'a1b2c3', account)).toBe('https://customer-abc.cloudflarestream.com/a1b2c3/iframe');
383
- });
384
- it('mutes automatically when autoplaying, as browsers require', () => {
385
- const src = buildEmbedSrc('cloudflare', 'a1b2c3', { ...account, autoplay: true });
386
- expect(src).toContain('autoplay=true');
387
- expect(src).toContain('muted=true');
388
- });
389
- it('maps the remaining player options', () => {
390
- const src = buildEmbedSrc('cloudflare', 'a1b2c3', {
391
- ...account,
392
- start: 90,
393
- loop: true,
394
- controls: false,
395
- preload: 'metadata',
396
- primaryColor: '#c00',
397
- defaultTextTrack: 'en',
398
- });
399
- expect(src).toContain('startTime=90s');
400
- expect(src).toContain('loop=true');
401
- expect(src).toContain('controls=false');
402
- expect(src).toContain('preload=metadata');
403
- expect(src).toContain(`primaryColor=${encodeURIComponent('#c00')}`);
404
- expect(src).toContain('defaultTextTrack=en');
405
- });
406
- it('throws a directed error when the account is missing', () => {
407
- expect(() => buildEmbedSrc('cloudflare', 'a1b2c3')).toThrow(/customerCode/);
408
- });
409
- });
410
- describe('getEmbedThumbnail - Cloudflare Stream', () => {
411
- it('derives a Stream thumbnail, unlike Vimeo', () => {
412
- expect(getEmbedThumbnail('cloudflare', 'a1b2c3', { customerCode: 'abc' })).toContain('https://customer-abc.cloudflarestream.com/a1b2c3/thumbnails/thumbnail.jpg');
413
- });
414
- it('returns null without an account rather than a malformed URL', () => {
415
- expect(getEmbedThumbnail('cloudflare', 'a1b2c3')).toBeNull();
416
- });
417
- });
418
- describe('clamp', () => {
419
- it('bounds the value inclusively', () => {
420
- expect(clamp(5, 0, 10)).toBe(5);
421
- expect(clamp(-1, 0, 10)).toBe(0);
422
- expect(clamp(11, 0, 10)).toBe(10);
423
- });
424
- it('resolves NaN to the minimum, so a seek never writes NaN to the element', () => {
425
- expect(clamp(NaN, 0, 10)).toBe(0);
426
- });
427
- });
@@ -1,145 +0,0 @@
1
- /**
2
- * Navigation Access Filtering Tests
3
- *
4
- * Covers which navigation items a user sees given the roles and permissions
5
- * they hold — including the nested case, where a restricted child sits under
6
- * an unrestricted parent.
7
- */
8
- import { describe, it, expect } from 'vitest';
9
- import { filterNavItems, isNavItemVisible, matchesAccess } from '../lib/utils/nav-access.js';
10
- function item(partial) {
11
- return { name: partial.id, ...partial };
12
- }
13
- const ids = (items) => items.map((i) => i.id);
14
- describe('matchesAccess', () => {
15
- it('matches when nothing is required', () => {
16
- expect(matchesAccess(undefined, [])).toBe(true);
17
- expect(matchesAccess([], [])).toBe(true);
18
- });
19
- it('does not match a requirement when the user holds nothing', () => {
20
- expect(matchesAccess(['admin'], undefined)).toBe(false);
21
- expect(matchesAccess(['admin'], [])).toBe(false);
22
- });
23
- it('matches any by default', () => {
24
- expect(matchesAccess(['admin', 'manager'], ['manager'])).toBe(true);
25
- expect(matchesAccess(['admin', 'manager'], ['agent'])).toBe(false);
26
- });
27
- it('can require all', () => {
28
- expect(matchesAccess(['admin', 'manager'], ['admin'], true)).toBe(false);
29
- expect(matchesAccess(['admin', 'manager'], ['admin', 'manager'], true)).toBe(true);
30
- });
31
- });
32
- describe('isNavItemVisible', () => {
33
- it('shows unrestricted items to anyone', () => {
34
- expect(isNavItemVisible(item({ id: 'a' }), {})).toBe(true);
35
- });
36
- it('matches against every role held, not just one', () => {
37
- const nav = item({ id: 'a', roles: ['agent'] });
38
- expect(isNavItemVisible(nav, { userRoles: ['manager', 'agent'] })).toBe(true);
39
- });
40
- it('does not imply roles from one another', () => {
41
- // Mirrors the auth package: holding admin does not imply agent, so the UI
42
- // cannot offer something the server would reject.
43
- const nav = item({ id: 'a', roles: ['agent'] });
44
- expect(isNavItemVisible(nav, { userRoles: ['admin'] })).toBe(false);
45
- });
46
- it('combines roles and permissions as AND', () => {
47
- const nav = item({ id: 'a', roles: ['manager'], permissions: ['users:write'] });
48
- expect(isNavItemVisible(nav, { userRoles: ['manager'], userPermissions: ['users:write'] })).toBe(true);
49
- expect(isNavItemVisible(nav, { userRoles: ['manager'], userPermissions: ['users:read'] })).toBe(false);
50
- expect(isNavItemVisible(nav, { userRoles: ['agent'], userPermissions: ['users:write'] })).toBe(false);
51
- });
52
- it('gates on permissions alone', () => {
53
- const nav = item({ id: 'a', permissions: ['settings:read'] });
54
- expect(isNavItemVisible(nav, { userPermissions: ['settings:read'] })).toBe(true);
55
- expect(isNavItemVisible(nav, { userRoles: ['admin'] })).toBe(false);
56
- });
57
- });
58
- describe('filterNavItems', () => {
59
- it('shows the union across a multi-role user', () => {
60
- const items = [
61
- item({ id: 'dashboard' }),
62
- item({ id: 'users', roles: ['manager'] }),
63
- item({ id: 'homes', roles: ['agent'] }),
64
- item({ id: 'system', roles: ['admin'] }),
65
- ];
66
- expect(ids(filterNavItems(items, { userRoles: ['manager', 'agent'] }))).toEqual([
67
- 'dashboard',
68
- 'users',
69
- 'homes',
70
- ]);
71
- });
72
- it('filters a restricted child under an unrestricted parent', () => {
73
- // The parent passes on its own merits; without recursion nothing would ever
74
- // look inside it and the admin-only child would show to everyone.
75
- const items = [
76
- item({
77
- id: 'main',
78
- children: [item({ id: 'open' }), item({ id: 'audit', roles: ['admin'] })],
79
- }),
80
- ];
81
- const filtered = filterNavItems(items, { userRoles: ['agent'] });
82
- expect(ids(filtered[0].children)).toEqual(['open']);
83
- });
84
- it('filters arbitrarily deep', () => {
85
- const items = [
86
- item({
87
- id: 'l1',
88
- children: [
89
- item({
90
- id: 'l2',
91
- children: [item({ id: 'l3', roles: ['admin'] }), item({ id: 'l3-open' })],
92
- }),
93
- ],
94
- }),
95
- ];
96
- const filtered = filterNavItems(items, { userRoles: ['agent'] });
97
- expect(ids(filtered[0].children[0].children)).toEqual(['l3-open']);
98
- });
99
- it('drops a container whose children are all filtered away', () => {
100
- const items = [
101
- item({ id: 'admin-area', children: [item({ id: 'system', roles: ['admin'] })] }),
102
- ];
103
- // Keeping it would render an expandable with nothing behind it.
104
- expect(ids(filterNavItems(items, { userRoles: ['agent'] }))).toEqual([]);
105
- });
106
- it('keeps an emptied parent that is a destination in its own right', () => {
107
- const items = [
108
- item({
109
- id: 'reports',
110
- href: '/reports',
111
- children: [item({ id: 'revenue', roles: ['admin'] })],
112
- }),
113
- ];
114
- const filtered = filterNavItems(items, { userRoles: ['agent'] });
115
- expect(ids(filtered)).toEqual(['reports']);
116
- expect(filtered[0].children).toEqual([]);
117
- });
118
- it('hides everything restricted from a user with no roles', () => {
119
- const items = [item({ id: 'dashboard' }), item({ id: 'users', roles: ['manager'] })];
120
- expect(ids(filterNavItems(items, {}))).toEqual(['dashboard']);
121
- });
122
- it('honors requireAllRoles', () => {
123
- const items = [item({ id: 'both', roles: ['admin', 'manager'] })];
124
- expect(ids(filterNavItems(items, { userRoles: ['admin'], requireAllRoles: true }))).toEqual([]);
125
- expect(ids(filterNavItems(items, { userRoles: ['admin', 'manager'], requireAllRoles: true }))).toEqual(['both']);
126
- });
127
- it('honors requireAllPermissions', () => {
128
- const items = [item({ id: 'both', permissions: ['a:read', 'b:read'] })];
129
- expect(ids(filterNavItems(items, { userPermissions: ['a:read'], requireAllPermissions: true }))).toEqual([]);
130
- expect(ids(filterNavItems(items, {
131
- userPermissions: ['a:read', 'b:read'],
132
- requireAllPermissions: true,
133
- }))).toEqual(['both']);
134
- });
135
- it('leaves childless items without a children key', () => {
136
- const filtered = filterNavItems([item({ id: 'a' })], {});
137
- expect('children' in filtered[0]).toBe(false);
138
- });
139
- it('does not mutate the input', () => {
140
- const items = [item({ id: 'main', children: [item({ id: 'audit', roles: ['admin'] })] })];
141
- const before = JSON.stringify(items);
142
- filterNavItems(items, { userRoles: ['agent'] });
143
- expect(JSON.stringify(items)).toBe(before);
144
- });
145
- });
@@ -1,36 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { render, screen } from '@testing-library/svelte';
3
- import PageHeader from '../lib/components/PageHeader.svelte';
4
- /**
5
- * The title must carry its own type scale. Tailwind preflight resets heading
6
- * size/weight and outranks the theme's layered base rule in consumer apps, so
7
- * a bare <h1> is body-sized there - PageHeader cannot lean on it.
8
- */
9
- describe('PageHeader title typography', () => {
10
- it('sets the Spectral display scale on the default h1', () => {
11
- render(PageHeader, { props: { title: 'All Available Homes' } });
12
- const h1 = screen.getByRole('heading', { level: 1 });
13
- expect(h1).toHaveClass('text-h1', 'font-serif', 'italic');
14
- });
15
- it('follows the `as` level: h2 is Figtree at the h2 scale', () => {
16
- render(PageHeader, { props: { title: 'Flying Horse', as: 'h2' } });
17
- const h2 = screen.getByRole('heading', { level: 2 });
18
- expect(h2).toHaveClass('text-h2', 'font-sans', 'not-italic');
19
- expect(h2).not.toHaveClass('text-h1', 'italic');
20
- });
21
- it('applies the same scale to the centered variant', () => {
22
- render(PageHeader, { props: { title: 'About', variant: 'centered' } });
23
- expect(screen.getByRole('heading', { level: 1 })).toHaveClass('text-h1', 'font-serif');
24
- });
25
- it('leaves the hero and form display styles alone', () => {
26
- const { unmount } = render(PageHeader, { props: { title: 'Ship', variant: 'hero' } });
27
- const hero = screen.getByRole('heading', { level: 1 });
28
- expect(hero).toHaveClass('text-5xl', 'font-black');
29
- expect(hero).not.toHaveClass('text-h1', 'font-serif');
30
- unmount();
31
- render(PageHeader, { props: { title: 'Sign in', variant: 'form' } });
32
- const form = screen.getByRole('heading', { level: 1 });
33
- expect(form).toHaveClass('font-light');
34
- expect(form).not.toHaveClass('text-h1');
35
- });
36
- });