Skip to content

Commit 42a201d

Browse files
committed
Add video test and enable 'all stories test'
1 parent ba21068 commit 42a201d

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

tests/html.test.tsx

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,36 @@ const allStoryNames = Object.keys(stories).filter(key => key !== 'default');
88

99
const wait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
1010

11+
const waitForVideoToLoad = (video: HTMLVideoElement): Promise<void> => {
12+
return new Promise<void>((resolve, reject) => {
13+
const timeout = setTimeout(() => reject(new Error('Video load timeout after 30s')), 30000);
14+
15+
const cleanup = () => clearTimeout(timeout);
16+
17+
if (video.readyState >= 2) {
18+
cleanup();
19+
resolve();
20+
return;
21+
}
22+
23+
const onSuccess = () => {
24+
cleanup();
25+
resolve();
26+
};
27+
28+
const onError = (e: Event) => {
29+
cleanup();
30+
reject(new Error(`Video failed to load: ${(e.target as HTMLVideoElement)?.error?.message || 'unknown error'}`));
31+
};
32+
33+
video.addEventListener('loadeddata', onSuccess, { once: true });
34+
video.addEventListener('canplay', onSuccess, { once: true });
35+
video.addEventListener('error', onError, { once: true });
36+
37+
video.load();
38+
});
39+
};
40+
1141
const storyTests: Record<string, (result: RenderResult) => void | Promise<void>> = {
1242
'RenderThingsInDifferentPlaces': ({ container }) => {
1343
expect(container.innerHTML).toContain(
@@ -184,10 +214,32 @@ const storyTests: Record<string, (result: RenderResult) => void | Promise<void>>
184214
expect(valueCounts['3'] + valueCounts['nothing']).toBeGreaterThanOrEqual(2);
185215
expect(seenValues.size).toBeGreaterThanOrEqual(2);
186216
},
217+
'PersistDOMWhilstMoving': async ({ container, getAllByText }) => {
218+
const video = container.querySelector('video') as HTMLVideoElement;
219+
expect(video).not.toBeNull();
220+
expect(video.src).toContain('giphy.mp4');
221+
222+
await waitForVideoToLoad(video);
223+
await video.play();
224+
await wait(200);
225+
226+
expect(video.paused).toBe(false);
227+
const playbackPosition = video.currentTime;
228+
expect(playbackPosition).toBeGreaterThan(0);
229+
230+
const moveButtons = getAllByText('Click to move the OutPortal');
231+
moveButtons[0].click();
232+
await wait(50);
233+
234+
const videoAfterMove = container.querySelector('video') as HTMLVideoElement;
235+
expect(videoAfterMove).toBe(video);
236+
expect(videoAfterMove.paused).toBe(false);
237+
expect(videoAfterMove.currentTime).toBeGreaterThanOrEqual(playbackPosition);
238+
expect(videoAfterMove.currentTime).toBeGreaterThan(playbackPosition);
239+
},
187240
};
188241

189-
// Skipped for now, until we have full test coverage of the stories:
190-
test.skip('all stories have tests', () => {
242+
test('all stories have tests', () => {
191243
const testedStories = Object.keys(storyTests);
192244
const untestedStories = allStoryNames.filter(name => !testedStories.includes(name));
193245

vite.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ export default defineConfig({
1818
instances: [{
1919
browser: 'chromium',
2020
launch: {
21-
args: ['--autoplay-policy=no-user-gesture-required']
21+
channel: 'chrome',
22+
args: [
23+
'--autoplay-policy=no-user-gesture-required',
24+
'--disable-web-security',
25+
'--disable-features=IsolateOrigins,site-per-process'
26+
]
2227
}
2328
}]
2429
},

0 commit comments

Comments
 (0)