Polish personal Agent conversation workspace

This commit is contained in:
鲨鱼辣椒 committed 2026-10-12 20:39:58 +08:00
1 parent 1aef423df0
commit a340c0fd94
7 files changed
+599 -53

No files matched your search

+38
View File
@@ -1,4 +1,5 @@
import { closeElectronApp, expect, getStableWindow, test } from './fixtures/electron';
import { writeFile } from 'node:fs/promises';
test('personal cloud Agent identity, configuration and separate published chat in Electron', async ({ launchElectronApp }, testInfo) => {
const app = await launchElectronApp({ skipSetup: true });
@@ -245,10 +246,47 @@ test('personal cloud Agent identity, configuration and separate published chat i
await expect(formalChat).toBeVisible();
expect((await fixtureState()).operations.filter((operation: string) => operation === 'publish')).toHaveLength(1);
expect(await messageOperations()).toEqual([]);
await expect(formalChat.getByRole('heading', { name: 'Hi,今天想聊些什么?', exact: true })).toBeVisible();
await expect(formalChat.locator('.agent-chat-welcome').getByRole('img', { name: '我的写作搭档头像', exact: true })).toHaveAttribute('src', avatar.icon_url);
const conversationSources = page.getByRole('navigation', { name: '对话来源', exact: true });
const sourceBounds = await conversationSources.getByRole('button', { name: '客户端对话', exact: true }).boundingBox();
const adjustBounds = await conversationSources.getByRole('button', { name: '调整智能体', exact: true }).boundingBox();
expect(sourceBounds).not.toBeNull();
expect(adjustBounds).not.toBeNull();
expect(Math.abs(sourceBounds!.y + sourceBounds!.height / 2 - adjustBounds!.y - adjustBounds!.height / 2)).toBeLessThanOrEqual(1);
const example = formalChat.locator('.agent-chat-example').first();
const exampleText = await example.innerText();
await example.click();
await expect(formalChat.getByLabel('消息', { exact: true })).toHaveValue(exampleText);
expect(await messageOperations()).toEqual([]);
await formalChat.getByLabel('消息', { exact: true }).fill('');
await page.screenshot({ path: testInfo.outputPath('cloud-agent-chat-welcome.png') });
await formalChat.getByLabel('消息', { exact: true }).fill('先给我一些创作建议');
await formalChat.getByRole('button', { name: '发送', exact: true }).click();
await expect(formalChat.getByRole('heading', { name: '创作建议' })).toBeAttached();
expect(await messageOperations()).toEqual(['submit']);
await expect(formalChat.locator('.agent-chat-message[data-role="assistant"]').getByRole('img', { name: '我的写作搭档头像', exact: true })).toHaveAttribute('src', avatar.icon_url);
await expect(formalChat.getByLabel('消息', { exact: true })).toBeInViewport();
const transcriptBounds = await formalChat.getByTestId('cloud-chat-messages').boundingBox();
const composerBounds = await formalChat.getByTestId('cloud-chat-composer').boundingBox();
expect(transcriptBounds).not.toBeNull();
expect(composerBounds).not.toBeNull();
expect(transcriptBounds!.y + transcriptBounds!.height).toBeLessThanOrEqual(composerBounds!.y + 1);
await page.screenshot({ path: testInfo.outputPath('cloud-agent-chat-long-reply.png') });
await app.evaluate(({ BrowserWindow }) => { const win = BrowserWindow.getAllWindows()[0]; win.setSize(980, 680); win.webContents.setZoomFactor(1.5); });
await expect(formalChat.getByTestId('cloud-chat-composer')).toBeInViewport({ ratio: 1 });
await expect(formalChat.getByRole('button', { name: '发送', exact: true })).toBeInViewport({ ratio: 1 });
await expect(conversationSources.getByRole('button', { name: '调整智能体', exact: true })).toBeInViewport({ ratio: 1 });
await expect.poll(() => editor.evaluate(el => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
await expect.poll(() => formalChat.getByTestId('cloud-chat-messages').evaluate(el => el.clientHeight)).toBeGreaterThanOrEqual(80);
// Chromium screenshots can crop a zoomed Electron surface. Capture the
// isolated native fixture's complete window for the responsive visual check.
const compactWindowImage = await app.evaluate(async ({ BrowserWindow }) => {
const image = await BrowserWindow.getAllWindows()[0].capturePage();
return image.toPNG().toString('base64');
});
await writeFile(testInfo.outputPath('cloud-agent-chat-compact-window.png'), Buffer.from(compactWindowImage, 'base64'));
await app.evaluate(({ BrowserWindow }) => { const win = BrowserWindow.getAllWindows()[0]; win.webContents.setZoomFactor(1); win.setSize(1366, 768); });
await page.getByRole('button', { name: '调整智能体', exact: true }).click();
await expect(prompt).toHaveValue(initialPrompt);
await page.getByLabel('名称', { exact: true }).fill('我的新版写作搭档');