61 lines
6.1 KiB
JavaScript
61 lines
6.1 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import assert from 'node:assert/strict';
|
|
import { chromium, expect } from 'playwright/test';
|
|
import { hash } from './desktop-f-state.mjs';
|
|
const root = path.resolve('.qa/release-efficiency-formal-view');
|
|
assert.equal(fs.existsSync(root), false); fs.mkdirSync(root);
|
|
const url = 'http://127.0.0.1:4318', screenshots = [], results = [], errors = [];
|
|
const read = file => JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
const finalRelease = read('releases/latest.json'); assert.ok(finalRelease.portableRoot.endsWith('20261102025721172'));
|
|
const finalManifestSha256 = hash(fs.readFileSync(path.join(finalRelease.portableRoot, 'MANIFEST.json')));
|
|
const boot = await (await fetch(url + '/api/bootstrap')).json(); assert.equal(boot.version, '1.23.0');
|
|
const headers = { 'X-Workbench-Token': boot.token, Connection: 'close' };
|
|
const original = read('.qa/local-files-native-original.json'), fileName = path.basename(original.path);
|
|
const project = boot.projects.find(value => path.resolve(value.root).toLowerCase() === path.dirname(path.resolve(original.path)).toLowerCase()); assert.ok(project);
|
|
const fileRoute = url + '/api/projects/' + project.id + '/file?path=' + encodeURIComponent(fileName);
|
|
const before = await (await fetch(fileRoute, { headers })).json(); assert.equal(before.sha256, original.sha256);
|
|
let browser, page;
|
|
async function capture(name) { const file = path.join(root, name + '.png'); await page.screenshot({ path: file }); screenshots.push({ file, sha256: hash(fs.readFileSync(file)) }); }
|
|
const record = name => results.push({ name, passed: true });
|
|
try {
|
|
browser = await chromium.launch({ channel: 'msedge', headless: true }); page = await browser.newPage({ viewport: { width: 1440, height: 960 } });
|
|
page.on('pageerror', error => errors.push(error.message));
|
|
await page.goto(url + '/?release=1.23.0'); await page.locator('.connection.connected').waitFor();
|
|
await page.getByRole('combobox', { name: '当前项目', exact: true }).selectOption(project.id);
|
|
await page.getByRole('button', { name: fileName, exact: true }).click();
|
|
const frame = page.frameLocator('iframe'); await expect(frame.locator('svg')).toBeVisible();
|
|
const button = frame.locator('button').first(), initial = await button.innerText(); await button.click(); await expect(button).not.toHaveText(initial);
|
|
const changed = await button.innerText(); await button.click(); await expect(button).toHaveText(initial); await capture('formal-original-html');
|
|
record('Original saved user HTML renders directly; actual pause/play behavior observed without editing its bytes');
|
|
await page.getByRole('button', { name: '源码', exact: true }).click();
|
|
await page.getByRole('button', { name: '预览', exact: true }).click(); await expect(page.frameLocator('iframe').locator('svg')).toBeVisible();
|
|
await page.getByRole('button', { name: '刷新预览', exact: true }).click(); await expect(page.frameLocator('iframe').locator('svg')).toBeVisible();
|
|
record('Source/preview switching and explicit refresh retain visible saved HTML');
|
|
await page.getByRole('button', { name: '打开项目', exact: true }).click(); await page.getByRole('button', { name: '选择文件夹', exact: true }).click();
|
|
await page.getByLabel('浏览文件夹路径').fill(project.root); await page.getByRole('button', { name: '前往', exact: true }).click();
|
|
await expect(page.getByRole('button', { name: '使用此文件夹', exact: true })).toBeEnabled(); await capture('formal-folder-picker');
|
|
await page.getByRole('button', { name: '取消选择', exact: true }).click(); await page.getByRole('dialog').getByRole('button', { name: '关闭窗口', exact: true }).click();
|
|
record('Formal browser can select a real local project folder; cancelled without registering a project');
|
|
await page.getByRole('button', { name: '版本与更新', exact: true }).click();
|
|
await expect(page.getByRole('region', { name: '版本与更新状态' })).toContainText('正在运行 v1.23.0');
|
|
await expect(page.getByRole('region', { name: '版本与更新状态' })).toContainText('已登记 v1.23.0');
|
|
await expect(page.getByText('版本激活完成', { exact: true })).toBeVisible(); await capture('formal-update-completed-wide');
|
|
const response = await fetch(url + '/api/installation/status', { headers }); assert.equal(response.status, 200);
|
|
const installed = await response.json(); assert.equal(installed.operations[0].state, 'completed'); assert.equal(installed.activeVersion, '1.23.0');
|
|
assert.equal(installed.operations[0].candidate.manifestSha256, finalManifestSha256);
|
|
record('Formal update UI and authenticated API show the actual completed installer operation and fixed candidate manifest');
|
|
await page.getByRole('dialog').getByRole('button', { name: '关闭窗口', exact: true }).click();
|
|
await page.setViewportSize({ width: 390, height: 844 }); await page.getByRole('button', { name: '展开项目栏', exact: true }).click();
|
|
await page.getByRole('button', { name: '版本与更新', exact: true }).click(); await expect(page.getByText('版本激活完成', { exact: true })).toBeVisible();
|
|
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false); await capture('formal-update-completed-390');
|
|
record('390px formal update state retains readable Chinese paths and no page overflow');
|
|
const after = await (await fetch(fileRoute, { headers })).json(); assert.equal(after.sha256, before.sha256);
|
|
assert.equal(hash(fs.readFileSync(original.path)), original.sha256); assert.deepEqual(errors, []);
|
|
const result = { success: true, version: boot.version, projectId: project.id, file: original.path, originalSha256: original.sha256,
|
|
finalSha256: after.sha256, controls: { initial, changed }, results, screenshots, errors, projectRegistrationRequests: 0,
|
|
realModelRequests: 0, userFileWrites: 0 };
|
|
fs.writeFileSync(path.join(root, 'result.json'), JSON.stringify(result, null, 2)); console.log(JSON.stringify({ success: true, root, groups: results.length }));
|
|
} catch (error) { fs.writeFileSync(path.join(root, 'failure.json'), JSON.stringify({ success: false, error: error.stack, results, screenshots, errors }, null, 2)); throw error; }
|
|
finally { await browser?.close(); }
|