52 lines
2.6 KiB
JavaScript
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');
|
|
});
|