feat: add a selectable mist blue appearance for Orven
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { chromium, expect } from 'playwright/test';
|
||||
import { fixture, launchWorkbench } from '../tests/helpers.mjs';
|
||||
|
||||
const disposers = [], t = { after: dispose => disposers.push(dispose) };
|
||||
const f = fixture(t, { modernDefaults: true }); f.store.close();
|
||||
const host = await launchWorkbench(t, f.data);
|
||||
assert.notEqual(new URL(host.url).port, '4318');
|
||||
const output = path.resolve('output/playwright/orven-appearance'); fs.mkdirSync(output, { recursive: true });
|
||||
const browser = await chromium.launch({ channel: 'msedge', headless: true });
|
||||
const context = await browser.newContext({ viewport: { width: 1440, height: 960 } });
|
||||
const page = await context.newPage(), checks = [], errors = [], mutations = [], contrast = [];
|
||||
context.on('page', page => page.on('pageerror', error => errors.push(error.message)));
|
||||
page.on('pageerror', error => errors.push(error.message));
|
||||
context.on('request', request => { if (request.url().includes('/api/') && request.method() !== 'GET') mutations.push(request.method() + ' ' + new URL(request.url()).pathname); });
|
||||
const mark = value => { checks.push(value); console.log('PASS ' + value); };
|
||||
const chosen = (page, palette) => expect(page.locator('html')).toHaveAttribute('data-palette', palette);
|
||||
const appearance = () => page.getByRole('dialog', { name: '外观', exact: true });
|
||||
const shot = name => page.screenshot({ path: path.join(output, name + '.png'), fullPage: true });
|
||||
async function sample(locator, label) {
|
||||
const colors = await locator.evaluate(element => {
|
||||
let node = element, background = 'rgb(255, 255, 255)';
|
||||
while (node) { const color = getComputedStyle(node).backgroundColor; if (color !== 'transparent' && color !== 'rgba(0, 0, 0, 0)') { background = color; break; } node = node.parentElement; }
|
||||
return { foreground: getComputedStyle(element).color, background };
|
||||
});
|
||||
const luminance = color => color.match(/[\d.]+/g).slice(0, 3).map(Number).map(value => { const n = value / 255; return n <= .04045 ? n / 12.92 : ((n + .055) / 1.055) ** 2.4; }).reduce((sum, value, index) => sum + value * [.2126, .7152, .0722][index], 0);
|
||||
const a = luminance(colors.foreground), b = luminance(colors.background), ratio = Math.round((Math.max(a, b) + .05) / (Math.min(a, b) + .05) * 100) / 100;
|
||||
contrast.push({ label, ...colors, ratio }); assert.ok(ratio >= 4.5, label + ': ' + ratio);
|
||||
}
|
||||
try {
|
||||
await page.goto(host.url);
|
||||
await page.locator('.connection.connected').waitFor(); await chosen(page, 'green');
|
||||
await page.getByLabel('任务内容').fill('这段草稿在切换配色后应当保留。');
|
||||
await page.keyboard.press('Control+k');
|
||||
await page.getByLabel('搜索工作台工具').fill('外观');
|
||||
await page.getByRole('dialog', { name: '工具箱', exact: true }).getByRole('button', { name: '外观', exact: true }).click();
|
||||
await expect(appearance().getByRole('radio', { name: '深青绿', exact: true })).toBeChecked();
|
||||
await appearance().getByRole('radio', { name: '雾蓝', exact: true }).check();
|
||||
await chosen(page, 'blue');
|
||||
await expect(page.locator('.appearance-note')).toContainText('已自动保存');
|
||||
await expect(page.locator('meta[name="theme-color"]')).toHaveAttribute('content', '#4f6ef7');
|
||||
await expect(page.locator('link[rel="icon"]')).toHaveAttribute('href', '/brand/orven-icon-blue.svg');
|
||||
assert.equal(await page.locator('.task-pane').evaluate(element => getComputedStyle(element).backgroundColor), 'rgb(246, 248, 252)');
|
||||
await sample(page.locator('.appearance-choice.selected .appearance-choice-description'), 'blue appearance description');
|
||||
await sample(page.locator('.appearance-note'), 'blue saved state');
|
||||
await shot('appearance-blue');
|
||||
await page.keyboard.press('Escape');
|
||||
await expect(page.getByLabel('任务内容')).toHaveValue('这段草稿在切换配色后应当保留。');
|
||||
await page.reload(); await page.locator('.connection.connected').waitFor(); await chosen(page, 'blue');
|
||||
await sample(page.locator('.orven-welcome > p'), 'blue welcome text');
|
||||
await sample(page.locator('.sidebar-view-tabs button[aria-selected="true"]'), 'blue selected navigation');
|
||||
await shot('blue-desktop');
|
||||
await page.getByRole('button', { name: '选择与管理模型', exact: true }).click();
|
||||
await sample(page.getByRole('button', { name: '从上游添加模型', exact: true }), 'blue primary action');
|
||||
await sample(page.locator('.mc-tabs button[aria-current="page"]'), 'blue model category');
|
||||
await page.keyboard.press('Escape');
|
||||
mark('visible appearance choice updates all surfaces, favicon and metadata; draft survives switching and selection survives reload');
|
||||
|
||||
const other = await context.newPage(); await other.goto(host.url); await chosen(other, 'blue');
|
||||
await page.getByRole('button', { name: '外观', exact: true }).click();
|
||||
const blueRadio = appearance().getByRole('radio', { name: '雾蓝', exact: true });
|
||||
await blueRadio.focus(); await blueRadio.press('ArrowLeft');
|
||||
await expect(appearance().getByRole('radio', { name: '深青绿', exact: true })).toBeChecked();
|
||||
await chosen(page, 'green'); await chosen(other, 'green');
|
||||
await sample(page.locator('.appearance-choice.selected .appearance-choice-description'), 'green appearance description');
|
||||
await page.keyboard.press('Escape');
|
||||
await expect(page.getByRole('button', { name: '外观', exact: true })).toBeFocused();
|
||||
await shot('green-desktop');
|
||||
await other.close();
|
||||
mark('native keyboard selection, focus return and cross-tab preference sync work without backend mutations');
|
||||
|
||||
await page.goto(host.url + '/?palette=blue&keep=1#review'); await chosen(page, 'blue');
|
||||
assert.equal(new URL(page.url()).search, '?keep=1'); assert.equal(new URL(page.url()).hash, '#review');
|
||||
await page.getByRole('button', { name: '外观', exact: true }).click();
|
||||
await appearance().getByRole('radio', { name: '深青绿', exact: true }).check();
|
||||
await page.reload(); await chosen(page, 'green');
|
||||
await page.evaluate(() => localStorage.setItem('orven-palette', 'invalid-palette'));
|
||||
await page.reload(); await chosen(page, 'green');
|
||||
mark('preview links select once and preserve other URL data; latest selection wins on reload and invalid stored choices recover');
|
||||
|
||||
await page.goto(host.url + '/?palette=blue'); await page.locator('.connection.connected').waitFor();
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
await page.getByRole('button', { name: '外观', exact: true }).click();
|
||||
await expect(appearance().getByRole('radio', { name: '雾蓝', exact: true })).toBeChecked();
|
||||
await shot('appearance-mobile'); await page.keyboard.press('Escape');
|
||||
await page.goto(host.url + '/mobile.html'); await chosen(page, 'blue');
|
||||
await expect(page.locator('link[rel="icon"]')).toHaveAttribute('href', '/mobile-icon.svg');
|
||||
await page.getByRole('button', { name: '外观', exact: true }).click();
|
||||
await expect(appearance().getByRole('radio', { name: '雾蓝', exact: true })).toBeChecked();
|
||||
await appearance().getByRole('radio', { name: '深青绿', exact: true }).check();
|
||||
await page.keyboard.press('Escape'); await page.reload(); await chosen(page, 'green');
|
||||
await page.getByRole('button', { name: '外观', exact: true }).click();
|
||||
await appearance().getByRole('radio', { name: '雾蓝', exact: true }).check();
|
||||
await shot('companion-appearance');
|
||||
const overflow = await page.evaluate(() => document.documentElement.scrollWidth > innerWidth + 1);
|
||||
assert.equal(overflow, false);
|
||||
mark('390px workbench and actual companion shell expose the same two choices and retain local preference');
|
||||
|
||||
const restricted = await browser.newContext({ viewport: { width: 390, height: 844 } });
|
||||
await restricted.addInitScript(() => {
|
||||
const original = Storage.prototype.setItem;
|
||||
Storage.prototype.setItem = function (key, value) { if (key === 'orven-palette') throw new DOMException('Storage unavailable', 'QuotaExceededError'); return original.call(this, key, value); };
|
||||
});
|
||||
const limited = await restricted.newPage(); limited.on('pageerror', error => errors.push(error.message));
|
||||
await limited.goto(host.url); await limited.locator('.connection.connected').waitFor({ state: 'attached' });
|
||||
await limited.getByRole('button', { name: '外观', exact: true }).click();
|
||||
await limited.getByRole('radio', { name: '雾蓝', exact: true }).check(); await chosen(limited, 'blue');
|
||||
await expect(limited.locator('.appearance-note')).toContainText('暂时无法保存');
|
||||
await limited.reload(); await chosen(limited, 'green'); await restricted.close();
|
||||
mark('unavailable preference storage keeps switching usable and reports that the choice was not saved');
|
||||
|
||||
assert.deepEqual(errors, []); assert.deepEqual(mutations, []);
|
||||
fs.writeFileSync(path.join(output, 'result.json'), JSON.stringify({ checks, contrast, errors, backendMutations: mutations, realModelCalls: 0, userDataAccessed: false }, null, 2));
|
||||
} catch (error) {
|
||||
await shot('failure').catch(() => {});
|
||||
fs.writeFileSync(path.join(output, 'failure.json'), JSON.stringify({ checks, errors, message: error.message }, null, 2)); throw error;
|
||||
} finally {
|
||||
await browser.close(); for (const dispose of disposers.reverse()) await dispose();
|
||||
}
|
||||
@@ -5,7 +5,9 @@ import { chromium, expect } from 'playwright/test';
|
||||
import { fixture, compatibleFixture, completion, call, launchWorkbench } from '../tests/helpers.mjs';
|
||||
|
||||
// Real browser + real isolated host + local protocol fixture. No real model or user project.
|
||||
const output = path.resolve('output/playwright/orven');
|
||||
const palette = process.env.ORVEN_QA_PALETTE ?? 'green';
|
||||
assert.ok(['green', 'blue'].includes(palette));
|
||||
const output = path.resolve('output/playwright/' + (palette === 'blue' ? 'orven-blue' : 'orven'));
|
||||
fs.mkdirSync(output, { recursive: true });
|
||||
const disposers = [], t = { after: dispose => disposers.push(dispose) };
|
||||
const f = fixture(t, { modernDefaults: true });
|
||||
@@ -24,6 +26,7 @@ const host = await launchWorkbench(t, f.data);
|
||||
assert.notEqual(new URL(host.url).port, '4318');
|
||||
const browser = await chromium.launch({ channel: 'msedge', headless: true });
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 960 }, deviceScaleFactor: 1 });
|
||||
await page.addInitScript(palette => localStorage.setItem('orven-palette', palette), palette);
|
||||
page.setDefaultTimeout(12000);
|
||||
const errors = [], checks = [];
|
||||
page.on('pageerror', error => errors.push(error.message));
|
||||
@@ -47,6 +50,7 @@ const bounds = async () => {
|
||||
try {
|
||||
await page.goto(host.url);
|
||||
await page.locator('.connection.connected').waitFor();
|
||||
await expect(page.locator('html')).toHaveAttribute('data-palette', palette);
|
||||
await expect(page).toHaveTitle('Orven · AI 开发工作台');
|
||||
await expect(page.getByRole('heading', { name: '今天,想实现什么?' })).toBeVisible();
|
||||
await expect(page.locator('.inspector')).not.toBeVisible();
|
||||
@@ -185,7 +189,7 @@ try {
|
||||
for (const asset of ['/brand/orven-symbol.svg', '/brand/orven-wordmark.svg', '/workbench-icon.png', '/workbench-icon.ico']) assert.equal((await fetch(host.url + asset)).status, 200);
|
||||
assert.deepEqual(errors, []);
|
||||
mark('brand page, interactive mark backgrounds and downloadable SVG/PNG/ICO assets render without browser errors');
|
||||
fs.writeFileSync(path.join(output, 'result.json'), JSON.stringify({ checks, errors, modelCalls, realModelCalls: 0, fixtureOnly: true, userDataAccessed: false }, null, 2));
|
||||
fs.writeFileSync(path.join(output, 'result.json'), JSON.stringify({ palette, checks, errors, modelCalls, realModelCalls: 0, fixtureOnly: true, userDataAccessed: false }, null, 2));
|
||||
} catch (error) {
|
||||
await shot('failure').catch(() => {});
|
||||
fs.writeFileSync(path.join(output, 'failure.json'), JSON.stringify({ checks, errors, modelCalls, message: error.message }, null, 2));
|
||||
|
||||
Reference in New Issue
Block a user