Files
Portfolio/tests/browser/media-failure.spec.ts

51 lines
2.6 KiB
TypeScript

import { expect, test } from '../helpers/serve-dist';
import {
assertSemanticFaultOracle,
authorizedFaultUrl,
collectBrowserErrors,
readFaultSnapshot,
readUnhandledRejections,
} from '../helpers/test-build-auth';
import { installSceneInstrumentation, readSceneInstrumentation } from '../helpers/scene-instrumentation';
test.beforeEach(async ({ page }, testInfo) => {
test.skip(testInfo.project.name !== 'desktop-chromium', 'Media fault matrix runs once on current desktop Chromium.');
await installSceneInstrumentation(page);
});
test('F7 replaces a failed poster with exactly one CSS fallback and keeps its description', async ({ page, distUrl }) => {
const errors = await collectBrowserErrors(page);
await page.addInitScript(() => localStorage.setItem('portfolio.motion.maximum-quality', 'static'));
await page.goto(authorizedFaultUrl(distUrl, 'F7-poster-failure'), { waitUntil: 'domcontentloaded' });
await expect(page.locator('.journey-world')).toHaveAttribute('data-static-fallback', 'true');
await expect(page.locator('.journey-world')).toHaveAttribute('data-poster-failed', 'true');
await expect(page.locator('.journey-poster')).toHaveCount(0);
await expect(page.locator('.journey-canvas')).toHaveCount(0);
await expect(page.locator('#journey-scene-description')).toContainText('night drive');
const background = await page.locator('.journey-world').evaluate((element) => getComputedStyle(element).backgroundColor);
expect(background).not.toBe('rgba(0, 0, 0, 0)');
expect((await readFaultSnapshot(page)).staticFallbackCount).toBe(1);
await assertSemanticFaultOracle(page);
expect(errors.pageErrors).toEqual([]);
expect(await readUnhandledRejections(page)).toEqual([]);
});
test('F8 remains authenticated and request-free while the public manifest has no approved video', async ({ page, distUrl }) => {
const mediaRequests: string[] = [];
page.on('request', (request) => {
if (/\.(?:mp4|webm)(?:$|[?#])/iu.test(request.url())) mediaRequests.push(request.url());
});
const errors = await collectBrowserErrors(page);
await page.goto(authorizedFaultUrl(distUrl, 'F8-video-failure'), { waitUntil: 'networkidle' });
expect((await readFaultSnapshot(page)).fault).toBe('F8-video-failure');
await expect(page.locator('[data-project-media]')).toHaveCount(0);
await expect(page.locator('video, video source')).toHaveCount(0);
expect(mediaRequests).toEqual([]);
await assertSemanticFaultOracle(page);
expect(errors.pageErrors).toEqual([]);
expect(await readUnhandledRejections(page)).toEqual([]);
expect((await readSceneInstrumentation(page)).unhandledRejections).toEqual([]);
});