Files
order-notification-automation/tests/assistant/toolbar-sidebar-ui.test.cjs
T

93 lines
3.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
const { test } = require('node:test'),
assert = require('node:assert/strict'),
fs = require('node:fs/promises'),
path = require('node:path');
const { managementFixture } = require('./management-fixture.cjs');
test(
'toolbar controls align and operation sidebar can collapse from inside on desktop and mobile',
{ timeout: 90000 },
async (t) => {
require('../fixtures/isolated-vault-key.cjs')(t);
const f = await managementFixture(t, { browser: true }),
{ page, open, store, users } = f;
store.saveSettings({
...store.settings(),
runtimePath: process.execPath,
apiKey: 'TEST_UI_LAYOUT_KEY',
});
const row = store.providers.read('deepseek');
store.providers.save({
...row,
models: row.models.map((m) => ({ ...m, name: 'skyworth-deepseek-v4.1-flash' })),
});
const owner = users.users()[0].id,
c = store.create(owner),
turn = store.beginTurn(c.id, owner, '测试查看操作');
store.updateTurn(turn.id, 'success', {
reply: '待确认操作已准备。',
actions: [
{
id: 'layout-fixture',
kind: 'check_storage',
targetId: 'server-fixture',
label: '检查存储连接',
status: 'proposed',
},
],
});
await open();
await page.getByRole('button', { name: '查看操作(1)', exact: true }).waitFor();
for (const width of [1440, 390]) {
await page.setViewportSize({ width, height: 844 });
await page.getByRole('button', { name: '查看操作(1)', exact: true }).click();
const panel = page.getByRole('complementary', { name: '诊断详情', exact: true });
await panel.waitFor();
const openOutput = path.resolve(__dirname, '../../output/verification/dsh-ui-polish');
await fs.mkdir(openOutput, { recursive: true });
await page.screenshot({
path: path.join(openOutput, 'sidebar-open-' + width + '.png'),
fullPage: true,
});
await panel.getByRole('button', { name: '收起右侧栏', exact: true }).click();
await panel.waitFor({ state: 'hidden' });
const toggle = page.getByRole('button', { name: '右侧栏', exact: true });
assert.equal(await toggle.getAttribute('aria-expanded'), 'false');
await toggle.click();
await panel.waitFor();
await panel.getByRole('button', { name: '收起右侧栏', exact: true }).click();
const dimensions = await page.evaluate(() => {
const sizes = (selectors) =>
selectors.map((s) => document.querySelector(s).getBoundingClientRect().height);
return {
bottom: sizes([
'#assistant-attach',
'#assistant-commands',
'#assistant-model-picker',
'#assistant-send',
]),
top: sizes(['[data-aw-left]', '.aw-back', '[data-aw-right]']),
rightLabel: document.querySelector('[data-aw-right]').textContent.trim(),
};
});
assert.ok(
Math.max(...dimensions.bottom) - Math.min(...dimensions.bottom) <= 1,
JSON.stringify(dimensions),
);
assert.ok(
Math.max(...dimensions.top) - Math.min(...dimensions.top) <= 1,
JSON.stringify(dimensions),
);
assert.equal(dimensions.rightLabel, '');
assert.equal(await page.locator('.aw-back svg').count(), 1);
assert.equal(await toggle.locator('svg').count(), 1);
const output = path.resolve(__dirname, '../../output/verification/dsh-ui-polish');
await fs.mkdir(output, { recursive: true });
await page.screenshot({
path: path.join(output, 'workspace-' + width + '.png'),
fullPage: true,
});
}
},
);