feat: restore Orven iris purple appearance with remembered defaults
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { chromium, expect } from 'playwright/test';
|
||||
import { fixture, launchWorkbench } from '../tests/helpers.mjs';
|
||||
@@ -12,13 +13,24 @@ const output = path.resolve('output/playwright/orven-appearance'); fs.mkdirSync(
|
||||
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); });
|
||||
let persistent;
|
||||
function observeContext(context) {
|
||||
const observePage = page => page.on('pageerror', error => errors.push(error.message));
|
||||
context.pages().forEach(observePage); context.on('page', observePage);
|
||||
context.on('request', request => { if (request.url().includes('/api/') && request.method() !== 'GET') mutations.push(request.method() + ' ' + new URL(request.url()).pathname); });
|
||||
}
|
||||
observeContext(context);
|
||||
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 panelFits(page) {
|
||||
const fits = await page.getByRole('dialog', { name: '外观', exact: true }).evaluate(dialog => {
|
||||
const rect = dialog.getBoundingClientRect();
|
||||
return rect.left >= 0 && rect.right <= innerWidth && rect.top >= 0 && rect.bottom <= innerHeight && dialog.scrollWidth <= dialog.clientWidth + 1 && dialog.scrollHeight <= dialog.clientHeight + 1;
|
||||
});
|
||||
assert.ok(fits, 'all three choices and saved state should fit within the viewport');
|
||||
}
|
||||
async function sample(locator, label) {
|
||||
const colors = await locator.evaluate(element => {
|
||||
let node = element, background = 'rgb(255, 255, 255)';
|
||||
@@ -37,9 +49,10 @@ try {
|
||||
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 expect(appearance().getByRole('radio')).toHaveCount(3);
|
||||
await appearance().getByRole('radio', { name: '雾蓝', exact: true }).check();
|
||||
await chosen(page, 'blue');
|
||||
await expect(page.locator('.appearance-note')).toContainText('已自动保存');
|
||||
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)');
|
||||
@@ -68,10 +81,30 @@ try {
|
||||
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');
|
||||
await page.getByRole('button', { name: '外观', exact: true }).click();
|
||||
await appearance().getByRole('radio', { name: '鸢尾紫', exact: true }).check();
|
||||
await chosen(page, 'purple'); await chosen(other, 'purple');
|
||||
await expect(page.locator('meta[name="theme-color"]')).toHaveAttribute('content', '#6253b5');
|
||||
await expect(page.locator('link[rel="icon"]')).toHaveAttribute('href', '/brand/orven-icon-purple.svg');
|
||||
assert.equal(await page.locator('.task-pane').evaluate(element => getComputedStyle(element).backgroundColor), 'rgb(255, 255, 255)');
|
||||
assert.equal(await page.locator('.project-sidebar').evaluate(element => getComputedStyle(element).backgroundColor), 'rgb(245, 245, 248)');
|
||||
await sample(page.locator('.appearance-choice.selected .appearance-choice-description'), 'purple appearance description');
|
||||
await sample(page.locator('.appearance-note'), 'purple saved state');
|
||||
await panelFits(page); await shot('appearance-purple');
|
||||
await page.keyboard.press('Escape');
|
||||
await sample(page.locator('.orven-welcome > p'), 'purple welcome text');
|
||||
await sample(page.locator('.sidebar-view-tabs button[aria-selected="true"]'), 'purple selected navigation');
|
||||
await shot('purple-desktop');
|
||||
await page.getByRole('button', { name: '选择与管理模型', exact: true }).click();
|
||||
await sample(page.getByRole('button', { name: '从上游添加模型', exact: true }), 'purple primary action');
|
||||
await sample(page.locator('.mc-tabs button[aria-current="page"]'), 'purple model category');
|
||||
await page.keyboard.press('Escape');
|
||||
await page.reload(); await chosen(page, 'purple'); await other.close();
|
||||
mark('original purple palette restores white workspace and gray navigation, updates metadata and persists across reload and tabs');
|
||||
|
||||
await page.goto(host.url + '/?palette=purple&keep=1#review'); await chosen(page, 'purple');
|
||||
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();
|
||||
@@ -80,42 +113,75 @@ try {
|
||||
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 page.goto(host.url + '/?palette=purple'); await page.locator('.connection.connected').waitFor();
|
||||
for (const viewport of [{ width: 600, height: 900 }, { width: 320, height: 740 }, { width: 390, height: 844 }]) {
|
||||
await page.setViewportSize(viewport);
|
||||
await page.getByRole('button', { name: '外观', exact: true }).click();
|
||||
await expect(appearance().getByRole('radio')).toHaveCount(3);
|
||||
await expect(appearance().getByRole('radio', { name: '鸢尾紫', exact: true })).toBeChecked();
|
||||
await panelFits(page); await shot('appearance-' + viewport.width); await page.keyboard.press('Escape');
|
||||
}
|
||||
await page.goto(host.url + '/mobile.html'); await chosen(page, 'purple');
|
||||
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 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');
|
||||
await appearance().getByRole('radio', { name: '鸢尾紫', exact: true }).check();
|
||||
await panelFits(page); 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');
|
||||
mark('600px, 390px and 320px panels fit all three choices; actual companion shell retains local preference and gateway icon');
|
||||
|
||||
const restricted = await browser.newContext({ viewport: { width: 390, height: 844 } });
|
||||
observeContext(restricted);
|
||||
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));
|
||||
const limited = await restricted.newPage();
|
||||
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 limited.getByRole('radio', { name: '鸢尾紫', exact: true }).check(); await chosen(limited, 'purple');
|
||||
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');
|
||||
|
||||
// Use an isolated on-disk profile: no injected storage state or user's browser profile.
|
||||
const profile = fs.mkdtempSync(path.join(os.tmpdir(), 'orven-appearance-'));
|
||||
assert.equal(path.dirname(path.resolve(profile)), path.resolve(os.tmpdir()));
|
||||
disposers.push(() => fs.rmSync(profile, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }));
|
||||
async function reopen() {
|
||||
persistent = await chromium.launchPersistentContext(profile, { channel: 'msedge', headless: true, viewport: { width: 1440, height: 960 } });
|
||||
observeContext(persistent);
|
||||
const reopened = persistent.pages()[0] ?? await persistent.newPage();
|
||||
await reopened.goto(host.url); await reopened.locator('.connection.connected').waitFor({ state: 'attached' });
|
||||
return reopened;
|
||||
}
|
||||
let reopened = await reopen();
|
||||
for (const [palette, name] of [['blue', '雾蓝'], ['green', '深青绿'], ['purple', '鸢尾紫']]) {
|
||||
await reopened.keyboard.press('Escape');
|
||||
await reopened.getByRole('button', { name: '外观', exact: true }).click();
|
||||
await reopened.getByRole('radio', { name, exact: true }).check();
|
||||
await chosen(reopened, palette);
|
||||
await expect(reopened.locator('.appearance-note')).toContainText('下次打开会继续使用');
|
||||
await persistent.close(); persistent = undefined;
|
||||
reopened = await reopen(); await chosen(reopened, palette);
|
||||
assert.equal(await reopened.evaluate(() => localStorage.getItem('orven-palette')), palette);
|
||||
await reopened.getByRole('button', { name: '外观', exact: true }).click();
|
||||
await expect(reopened.getByRole('radio', { name, exact: true })).toBeChecked();
|
||||
}
|
||||
await reopened.screenshot({ path: path.join(output, 'reopened-purple.png'), fullPage: true });
|
||||
await persistent.close(); persistent = undefined;
|
||||
mark('each palette survives a full browser close and relaunch using the same isolated persistent profile');
|
||||
|
||||
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 persistent?.close();
|
||||
await browser.close(); for (const dispose of disposers.reverse()) await dispose();
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import { fixture, compatibleFixture, completion, call, launchWorkbench } from '.
|
||||
|
||||
// Real browser + real isolated host + local protocol fixture. No real model or user project.
|
||||
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'));
|
||||
assert.ok(['green', 'blue', 'purple'].includes(palette));
|
||||
const output = path.resolve('output/playwright/' + (palette === 'green' ? 'orven' : 'orven-' + palette));
|
||||
fs.mkdirSync(output, { recursive: true });
|
||||
const disposers = [], t = { after: dispose => disposers.push(dispose) };
|
||||
const f = fixture(t, { modernDefaults: true });
|
||||
|
||||
Reference in New Issue
Block a user