clipwright/dashboard/e2e/fixtures/app.js
pedro-bento 97f813553d test: add full E2E coverage (API, pipeline, browser)
Three-level end-to-end suite, all deterministic (no retries, no sleeps, no
unmocked network):

- tests/e2e/api (209 tests): every route in clipwright/api/app.py +
  free_tools — health/config, uploads, process submit matrix + worker/webhook/
  auto-retry/resume, status/source/download-all, edit/effects, transcript/EDL/
  rerender, scenes/reframe, subtitle, hook, Postiz, thumbnails, free tools,
  and the security/path guards.
- tests/e2e/pipeline (136 tests): every stage with real ffmpeg and stubbed
  Gemini/yt-dlp/ASR/ML — download, transcribe, scene detect, selection,
  layout, reframe/render, subtitles, hooks, watermark, thumbnails, plus the
  real CLI full pipeline via stub_env.
- dashboard/e2e (19 Playwright specs): route-interception state machine
  covering every dashboard flow; one real-backend spec left test.fixme.
- Foundation: tests/e2e/conftest.py (state isolation, no-network guard, ffmpeg
  media factory, disk-seeded jobs), FakePopen worker harness, child-process
  stub_env, architecture-consistent fixtures.
- CI: unit + backend-e2e + dashboard-e2e jobs in the python+node container;
  ffmpeg + Playwright installed in-job; no setup-node/cache (act runner).

Verified: unit 790 passed; API E2E 209 passed; pipeline E2E 136 passed;
Playwright 19 passed / 1 skipped.
2026-10-04 22:12:21 +01:00

63 lines
2.7 KiB
JavaScript

// App-level helpers shared by the specs: localStorage seeding (Gemini key,
// Postiz config, a restored session), the in-browser render seam, and a single
// `openApp` that installs mocks, seeds storage and navigates.
import { installApiMocks, JOB_ID, defaultClips, defaultResults } from './api-mocks.js';
// Mirrors SECRET_KEY in src/App.jsx (no VITE_ENCRYPTION_KEY is set by the build).
const SECRET_KEY = 'Clipwright-Static-Salt-Change-Me';
export function encryptSecret(text) {
let xor = '';
for (let i = 0; i < text.length; i += 1) {
xor += String.fromCharCode(text.charCodeAt(i) ^ SECRET_KEY.charCodeAt(i % SECRET_KEY.length));
}
return `ENC:${btoa(xor)}`;
}
export async function seedApp(page, { geminiKey = 'e2e-gemini-key', postizUrl, postizKey, session } = {}) {
await page.addInitScript((payload) => {
try {
// A stored consent decision keeps the cookie banner out of the way
// (the banner is otherwise shown to EEA timezones, which the CI
// runner's TZ would make nondeterministic).
window.localStorage.setItem('clipwright_consent', JSON.stringify({
v: 1, ts: new Date().toISOString(), necessary: true, analytics: true, marketing: false,
}));
if (payload.geminiKey) window.localStorage.setItem('gemini_key', payload.geminiKey);
if (payload.postizUrl) window.localStorage.setItem('postiz_url', payload.postizUrl);
if (payload.encryptedPostizKey) window.localStorage.setItem('postiz_key_v1', payload.encryptedPostizKey);
if (payload.session) window.localStorage.setItem('clipwright_session', JSON.stringify(payload.session));
} catch (_) { /* storage unavailable */ }
}, {
geminiKey,
postizUrl,
encryptedPostizKey: postizKey ? encryptSecret(postizKey) : null,
session,
});
// Replace the WebCodecs/Remotion render with a deterministic blob URL so the
// specs never depend on hardware encoders. See src/lib/renderInBrowser.js.
await page.addInitScript(() => {
window.__CW_E2E_RENDER__ = () => 'blob:http://127.0.0.1:4173/e2e-render';
});
}
export function completedSession({ jobId = JOB_ID, clips = defaultClips() } = {}) {
return {
jobId,
status: 'complete',
results: { clips, cost_analysis: defaultResults().cost_analysis },
processingMedia: null,
activeTab: 'dashboard',
timestamp: Date.now(),
};
}
export async function openApp(page, { hash = '#app', seed, mocks } = {}) {
const state = await installApiMocks(page, mocks);
await seedApp(page, seed);
await page.goto(`/${hash}`);
return state;
}
export { installApiMocks, JOB_ID, defaultClips, defaultResults };