40 lines
2.4 KiB
JavaScript
40 lines
2.4 KiB
JavaScript
// @ts-check
|
|
// Seed Finder "Auto-pick best": all /api routes mocked, nothing is ever saved or generated for real.
|
|
const { test, expect } = require('./_guard');
|
|
|
|
const WAV = 'UklGRiQAAABXQVZFZm10IBAAAAABAAEAQB8AAIA+AAACABAAZGF0YQAAAAA='; // empty 16-bit wav
|
|
|
|
test('auto-pick highlights the winner; saving needs an explicit click', async ({ page }) => {
|
|
const saves = [];
|
|
const cand = (seed, score) => ({ seed, score, accuracy: 90, loudness_score: 80, problems_score: 100, problems: [], audio_b64: WAV, media_type: 'audio/wav' });
|
|
await page.route('**/api/**', route => route.request().method() === 'GET'
|
|
? route.fulfill({ json: [] }) : route.fulfill({ json: { ok: true } }));
|
|
await page.route('**/api/seed-autopick', route => route.fulfill({ json: {
|
|
winner: 2, degraded: true, cancelled: false, stt: { available: false, note: 'down' },
|
|
candidates: [cand(1, 60), cand(2, 88), { seed: 3, error: 'boom' }] } }));
|
|
await page.route('**/api/tts-voice-seed', route => { saves.push(route.request().postData()); route.fulfill({ json: { ok: true } }); });
|
|
await page.route('**/static/dist/main.min.js*', r => r.abort());
|
|
await page.goto('/', { waitUntil: 'domcontentloaded' });
|
|
await page.waitForFunction(() => typeof window.attachSeedFinder === 'function', null, { timeout: 15_000 });
|
|
await page.evaluate(() => {
|
|
const host = document.createElement('div'); host.id = 'sf-host'; document.body.prepend(host);
|
|
window.attachSeedFinder('DE_test', host);
|
|
host.querySelector('.seed-finder-group').classList.add('open');
|
|
});
|
|
const btn = page.getByRole('button', { name: /Auto-pick best/ });
|
|
await btn.focus();
|
|
await page.keyboard.press('Enter');
|
|
const status = page.locator('.seed-finder-autopick-status');
|
|
await expect(status).toHaveAttribute('aria-live', 'polite');
|
|
await expect(status).toContainText('Best seed: 2');
|
|
await expect(status).toContainText('level and audio problems only');
|
|
await expect(page.locator('.sfr-winner')).toContainText('Best');
|
|
await expect(page.locator('.sfr-winner')).toContainText('score 88/100');
|
|
await expect(page.locator('.seed-finder-result-error')).toContainText('boom');
|
|
expect(saves).toHaveLength(0);
|
|
await page.locator('.sfr-winner .sfr-use-btn').click();
|
|
await expect(page.locator('.sfr-winner .sfr-saved')).toContainText('Saved');
|
|
expect(saves).toHaveLength(1);
|
|
expect(JSON.parse(saves[0])).toEqual({ voice: 'DE_test', seed: 2 });
|
|
});
|