clipwright/dashboard/e2e/specs/subtitle-modal.spec.js
pedro-bento 0040aa49da
All checks were successful
CI / dashboard-e2e (push) Successful in 1m44s
CI / unit (push) Successful in 29s
CI / backend-e2e (push) Successful in 1m17s
test/e2e-coverage (#5)
Reviewed-on: #5
Co-authored-by: pedro-bento <mail@pbento.pt>
Co-committed-by: pedro-bento <mail@pbento.pt>
2026-10-04 22:28:46 +01:00

46 lines
2 KiB
JavaScript

import { test, expect } from '@playwright/test';
import { openApp, completedSession, JOB_ID } from '../fixtures/app.js';
test.describe('subtitle modal', () => {
test('applies a caption style to one clip and posts the style to /api/subtitle', async ({ page }) => {
await openApp(page, { seed: { session: completedSession() } });
await expect(page.getByRole('heading', { name: 'First viral clip' })).toBeVisible();
await page.getByRole('button', { name: 'subtitles' }).first().click();
const dialog = page.getByRole('dialog');
await expect(dialog.getByText('EDITOR · SUBTITLES')).toBeVisible();
const requestPromise = page.waitForRequest(
(r) => r.method() === 'POST' && r.url().includes('/api/subtitle'),
);
await dialog.getByRole('button', { name: /apply to this clip/i }).click();
const request = await requestPromise;
expect(request.postDataJSON()).toMatchObject({
job_id: JOB_ID,
clip_index: 0,
style: 'karaoke',
input_filename: 'clip_1.mp4',
});
// Success closes the editor.
await expect(page.getByText('EDITOR · SUBTITLES')).toHaveCount(0);
});
test('applies one style to every clip', async ({ page }) => {
await openApp(page, { seed: { session: completedSession() }, mocks: { statusSequence: ['completed'] } });
await expect(page.getByRole('heading', { name: 'First viral clip' })).toBeVisible();
const bodies = [];
page.on('request', (r) => {
if (r.method() === 'POST' && r.url().includes('/api/subtitle')) bodies.push(r.postDataJSON());
});
await page.getByRole('button', { name: 'subtitles' }).first().click();
const dialog = page.getByRole('dialog');
await dialog.getByRole('button', { name: /apply this style to all 2 clips/i }).click();
await expect.poll(() => bodies.length).toBe(2);
expect(bodies.map((b) => b.clip_index).sort()).toEqual([0, 1]);
});
});