63 lines
4.4 KiB
JavaScript
63 lines
4.4 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import fs from "node:fs/promises";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { chromium } from "playwright";
|
|
|
|
const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
const browser = await chromium.launch({ headless: true, executablePath: "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe" });
|
|
const context = await browser.newContext({ viewport: { width: 360, height: 900 }, reducedMotion: "reduce" });
|
|
await context.addInitScript({ path: path.join(root, "tests/ui-fixture.js") });
|
|
await context.addInitScript(() => { window.__helperVersion = "1.3.0"; });
|
|
await context.route("https://ui.ytdl.test/**", async route => {
|
|
const name = new URL(route.request().url()).pathname.slice(1);
|
|
if (!["downloader.html", "downloader.js", "onboarding.js", "ui-connection.js", "theme-init.js", "styles.css", "shared.js", "session.js"].includes(name)) return route.abort();
|
|
return route.fulfill({ body: await fs.readFile(path.join(root, "extension", name)), contentType: name.endsWith(".html") ? "text/html" : name.endsWith(".css") ? "text/css" : "application/javascript" });
|
|
});
|
|
try {
|
|
const page = await context.newPage();
|
|
const errors = [];
|
|
page.on("pageerror", error => errors.push(error.message));
|
|
await page.goto("https://ui.ytdl.test/downloader.html?theme=dark&url=https://www.youtube.com/watch?v=aircAruvnKk");
|
|
await page.locator('#helper-panel[data-state="incompatible"]').waitFor();
|
|
assert.match(await page.locator('#helper-message').textContent(), /1\.3\.0.*1\.4\.5/);
|
|
assert.match(await page.locator('#helper-versions').textContent(), /Расширение 1\.4\.5.*Помощник 1\.3\.0/);
|
|
assert.equal(await page.locator('#helper-install').textContent(), 'Обновить помощник');
|
|
assert.equal(await page.locator('#download').isDisabled(), true);
|
|
assert.equal(await page.locator('#download-form').isVisible(), false);
|
|
await page.locator('#open-setup').click();
|
|
await page.locator('#setup-next').click();
|
|
await page.locator('#setup-helper[data-state="incompatible"]').waitFor();
|
|
assert.equal(await page.locator('#setup-next').isDisabled(), true);
|
|
assert.equal(await page.locator('#setup-install').textContent(), 'Обновить помощник');
|
|
assert.match(await page.locator('#setup-versions').textContent(), /1\.4\.5.*1\.3\.0/);
|
|
await page.evaluate(() => { window.__helperVersion = '1.3.2'; });
|
|
await page.locator('#setup-check').click();
|
|
await page.locator('#setup-helper[data-state="running"]').waitFor();
|
|
assert.match(await page.locator('#setup-versions').textContent(), /Версии совместимы/);
|
|
await page.locator('#setup-next:not([disabled])').waitFor();
|
|
await page.evaluate(() => { window.__helperVersion = '1.3.3'; });
|
|
await page.locator('#setup-check').click();
|
|
await page.locator('#setup-helper[data-state="incompatible"]').waitFor();
|
|
assert.equal(await page.locator('#setup-next').isDisabled(), true);
|
|
assert.equal(await page.locator('#setup-install').textContent(), 'Обновить расширение');
|
|
assert.equal(await page.locator('#setup-install-steps').isVisible(), false);
|
|
await page.locator('#setup-close').click();
|
|
assert.equal(await page.locator('#helper-install').textContent(), 'Обновить расширение');
|
|
assert.match(await page.locator('#helper-message').textContent(), /Помощник 1\.3\.3.*расширением 1\.4\.5/);
|
|
assert.equal(await page.locator('#download').isDisabled(), true);
|
|
await page.evaluate(() => { window.__helperVersion = '1.3.2'; });
|
|
await page.locator('#helper-start').click();
|
|
await page.locator('#helper-panel[data-state="running"]').waitFor();
|
|
await page.locator('#download:not([disabled])').waitFor();
|
|
assert.match(await page.locator('#helper-versions').textContent(), /Версии совместимы/);
|
|
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true);
|
|
await fs.mkdir(path.join(root, 'test-artifacts'), { recursive: true });
|
|
await page.screenshot({ path: path.join(root, 'test-artifacts/version-compatibility-360.png'), animations: 'disabled' });
|
|
assert.deepEqual(errors, []);
|
|
console.log('Version UI passed in Edge: both update directions, versions shown in settings and first-run wizard, downloads blocked until compatible, recovery without reload, 360px layout.');
|
|
} finally {
|
|
await context.close();
|
|
await browser.close();
|
|
}
|