tts-voice-creator-clone-and.../tests/vocal-isolation.spec.js
mARTin-B78 e8c0df027e test: fail any spec that would write to the live API
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-04 21:00:25 +02:00

52 lines
2.6 KiB
JavaScript

// @ts-check
// "Remove background music" in the URL import card (all /api routes mocked).
const { test, expect } = require('./_guard');
async function open(page, available) {
await page.route('**/api/**', route => route.request().method() === 'GET' ? route.fulfill({ json: {} }) : route.fulfill({ json: { ok: true } }));
await page.route('**/api/voices*', route => route.fulfill({ json: [] }));
await page.route('**/api/version', route => route.fulfill({ json: { version: 'x', features: { vocal_isolation: available } } }));
await page.route('**/api/audio/*', route => route.fulfill({ status: 404, body: '' }));
await page.route('**/static/dist/main.min.js*', r => r.abort());
await page.goto('/', { waitUntil: 'domcontentloaded' });
await page.waitForFunction(() => typeof window.navTo === 'function', null, { timeout: 15_000 });
await page.waitForSelector('#app-skeleton', { state: 'detached', timeout: 15_000 });
}
test('button hidden when the server cannot isolate', async ({ page }) => {
await open(page, false);
await expect(page.locator('#lib-iso-btn')).toHaveAttribute('hidden', '');
await expect(page.locator('#yt-iso-btn')).toHaveAttribute('hidden', '');
});
test('isolate, compare with original, and show errors', async ({ page }) => {
await open(page, true);
/** @type {any[]} */ const calls = [];
let fail = false;
await page.route('**/api/isolate-vocals', route => {
calls.push(route.request().postDataJSON());
return fail ? route.fulfill({ status: 503, json: { detail: 'Vocal isolation is turned off' } })
: route.fulfill({ json: { id: 'clean1', duration: 4 } });
});
await page.evaluate(() => window.navTo('s-voices'));
const btn = page.locator('#lib-iso-btn');
await expect(btn).not.toHaveAttribute('hidden', '');
const msg = page.locator('#lib-iso-msg');
await expect(msg).toHaveAttribute('aria-live', 'polite');
await btn.evaluate(el => el.click());
await expect(msg).toContainText('Load audio first');
await page.evaluate(() => { libAddState.id = 'orig1'; libAddState.duration = 6; });
await btn.evaluate(el => el.click());
await expect(msg).toContainText('Background music removed');
expect(calls).toEqual([{ id: 'orig1' }]);
expect(await page.evaluate(() => libAddState.id)).toBe('clean1');
const toggle = page.locator('#lib-iso-toggle');
await expect(toggle).toHaveText('Play original');
await toggle.evaluate(el => el.click());
expect(await page.evaluate(() => libAddState.id)).toBe('orig1');
await expect(toggle).toHaveText('Play without music');
fail = true;
await btn.evaluate(el => el.click());
await expect(msg).toContainText('turned off');
});