| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- import assert from 'node:assert/strict';
- import { chromium } from 'playwright';
- import { fileURLToPath, pathToFileURL } from 'node:url';
- import path from 'node:path';
- const root = path.dirname(fileURLToPath(import.meta.url));
- const base = pathToFileURL(path.join(root, 'index.html')).href;
- const browser = await chromium.launch({
- channel: process.env.PLAYWRIGHT_CHANNEL || 'chrome',
- headless: true,
- });
- const context = await browser.newContext({
- viewport: { width: 390, height: 844 },
- reducedMotion: 'reduce',
- deviceScaleFactor: 1,
- });
- const page = await context.newPage();
- page.setDefaultTimeout(10000);
- const errors = [];
- const externalRequests = [];
- page.on('pageerror', (error) => errors.push(error.message));
- page.on('request', (request) => {
- if (/^https?:/.test(request.url())) externalRequests.push(request.url());
- });
- let checks = 0;
- async function check(label, operation) {
- await operation();
- checks += 1;
- console.log(`PASS ${checks}: ${label}`);
- }
- async function go(route) {
- await page.goto(`${base}#/${route}`);
- await page.evaluate(() => document.fonts.ready);
- }
- async function click(action, extra = '') {
- const selector = `button[data-action="${action}"]${extra}`;
- const overlayButton = page.locator('#overlay-root').locator(selector);
- await (await overlayButton.count() ? overlayButton : page.locator(selector)).first().click();
- }
- async function screenshot(name) {
- await page.screenshot({ path: path.join(root, name), style: '.toast { visibility: hidden !important; }' });
- }
- try {
- await go('chat/c1');
- await check('会话页隐藏主导航,保留正文与操作入口', async () => {
- assert.equal(await page.locator('#tabbar button').count(), 0);
- assert.equal(await page.locator('.activity-entry').count(), 1);
- assert.equal(await page.locator('.assistant-body').count(), 1);
- assert.equal(await page.locator('.process[open]').count(), 0);
- });
- await screenshot('preview-chat.png');
- await check('回车只换行,中文组合输入不提交', async () => {
- await page.locator('#draft').fill('第一行');
- await page.locator('#draft').press('End');
- await page.locator('#draft').press('Enter');
- await page.locator('#draft').pressSequentially('第二行');
- assert.equal(await page.locator('#draft').inputValue(), '第一行\n第二行');
- assert.equal(await page.locator('.user-message').count(), 1);
- await page
- .locator('#draft')
- .dispatchEvent('keydown', { key: 'Enter', isComposing: true, keyCode: 229 });
- assert.equal(await page.locator('.user-message').count(), 1);
- });
- await check('跨会话切换与同分身多会话草稿隔离', async () => {
- await click('activity');
- assert.equal(await page.locator('.activity-card').count(), 4);
- await screenshot('preview-switcher.png');
- await click('activity-open', '[data-id="c3"]');
- await page.waitForURL('**#/chat/c3');
- assert.equal(await page.locator('#draft').inputValue(), '');
- await page.locator('#draft').fill('这是另一条会话的草稿');
- await click('activity');
- await click('activity-open', '[data-id="c1"]');
- await page.waitForURL('**#/chat/c1');
- assert.equal(await page.locator('#draft').inputValue(), '第一行\n第二行');
- });
- await check('协作筛选与搜索不混淆在线状态', async () => {
- await click('activity');
- await click('activity-filter', '[data-value="attention"]');
- assert.equal(await page.locator('.activity-card').count(), 1);
- assert.match(await page.locator('.activity-card').innerText(), /连接中断/);
- await page.getByRole('searchbox', { name: '搜索正在协作的事' }).fill('不存在的内容');
- assert.equal(await page.locator('.activity-card').count(), 0);
- await page.getByRole('searchbox', { name: '搜索正在协作的事' }).fill('');
- await click('activity-filter', '[data-value="all"]');
- await click('close');
- });
- await check('标题候选不会在取消时写回,手动保存同步到列表', async () => {
- await click('edit-current-title');
- await click('regenerate-title');
- assert.equal(await page.locator('#form-value').inputValue(), '移动端第一印象与体验优化');
- await click('close');
- assert.equal(await page.locator('.header-title strong').innerText(), '把产品的第一印象做好');
- await click('edit-current-title');
- await page.locator('#form-value').fill('我的产品体验优化');
- await screenshot('preview-title.png');
- await page.locator('.sheet-form button[type="submit"]').click();
- assert.equal(await page.locator('.header-title strong').innerText(), '我的产品体验优化');
- });
- await check('当前数字生命内新建,保留原会话和工作区', async () => {
- await click('quick-current');
- await page.waitForFunction(() => location.hash !== '#/chat/c1');
- assert.match(await page.locator('.header-center small').innerText(), /小禾/);
- assert.match(await page.locator('.blank-chat').innerText(), /产品与灵感/);
- assert.equal(await page.locator('#draft').inputValue(), '');
- await page.locator('#draft').fill('新会话独立草稿');
- await click('drawer');
- await click('open-chat', '[data-id="c1"]');
- await page.waitForURL('**#/chat/c1');
- assert.equal(await page.locator('#draft').inputValue(), '第一行\n第二行');
- });
- await check('附件仅本地暂存,发送和回复明确标记演示', async () => {
- await page
- .locator('#file-input')
- .setInputFiles({ name: '体验调研.txt', mimeType: 'text/plain', buffer: Buffer.from('demo') });
- assert.match(await page.locator('.attachment-list').innerText(), /体验调研/);
- await page.locator('#draft').fill('<img src=x onerror="alert(1)">');
- await click('send');
- assert.equal(await page.locator('.send-button').isDisabled(), true);
- await page.waitForFunction(
- () =>
- !document.querySelector('.send-button').disabled ||
- document.querySelector('.send-button').getAttribute('aria-label') === '发送消息',
- );
- assert.equal(await page.locator('.user-bubble img').count(), 0);
- assert.match(await page.locator('.assistant-body').last().innerText(), /本地模拟回复/);
- assert.equal(await page.locator('#draft').inputValue(), '');
- assert.equal(await page.locator('.attachment-chip').count(), 0);
- });
- await check('侧栏按数字生命分组,不引入全局任务入口', async () => {
- await click('drawer');
- await click('drawer-view', '[data-value="agents"]');
- assert.equal(await page.locator('.drawer-agent-group').count(), 3);
- assert.equal(await page.locator('.drawer-nav button').count(), 4);
- await screenshot('preview-drawer.png');
- await page.keyboard.press('Escape');
- assert.equal(await page.locator('[role="dialog"]').count(), 0);
- });
- await check('弹层支持焦点约束、Escape 与下拉关闭', async () => {
- await click('activity');
- const buttons = page.locator('#overlay-root button');
- await buttons.last().focus();
- await page.keyboard.press('Tab');
- assert.equal(await buttons.first().evaluate((element) => element === document.activeElement), true);
- const handle = await page.locator('.sheet-handle').boundingBox();
- await page.mouse.move(handle.x + handle.width / 2, handle.y + 12);
- await page.mouse.down();
- await page.mouse.move(handle.x + handle.width / 2, handle.y + 120, { steps: 6 });
- await page.mouse.up();
- assert.equal(await page.locator('[role="dialog"]').count(), 0);
- assert.equal(await page.locator('#app').evaluate((element) => element.inert), false);
- });
- await check('文件/成果面板与真实格式区分,预览可返回', async () => {
- await click('details');
- await click('detail-tab', '[data-value="file"]');
- await click('preview-file');
- assert.equal(await page.locator('.preview-document').count(), 1);
- assert.match(await page.locator('[data-action="download-demo"]').innerText(), /TXT/);
- await click('details', '[data-tab="file"]');
- await click('close');
- });
- await check('完成提醒可直接返回对应会话', async () => {
- await click('activity');
- await click('complete-demo');
- assert.equal(await page.locator('#completion-banner').count(), 1);
- await screenshot('preview-completion.png');
- await click('completion-open');
- await page.waitForURL('**#/chat/c4');
- assert.match(await page.locator('.header-center small').innerText(), /已完成/);
- });
- await go('messages');
- await check('工作区默认折叠、名称去重、删除不删会话', async () => {
- await click('message-filter', '[data-value="workspace"]');
- assert.equal(await page.locator('.workspace-toggle[aria-expanded="false"]').count(), 2);
- await click('create-workspace');
- await page.locator('#form-value').fill('产品与灵感');
- await page.locator('.sheet-form button[type="submit"]').click();
- assert.match(await page.locator('.form-error').innerText(), /同名/);
- await page.locator('#form-value').fill('临时验证区');
- await page.locator('.sheet-form button[type="submit"]').click();
- assert.equal(await page.locator('.workspace').count(), 3);
- await click('workspace-menu', '[data-id="w1"]');
- await click('delete-workspace');
- await click('confirm-delete-workspace');
- assert.equal(await page.locator('.workspace').count(), 2);
- await click('message-filter', '[data-value="all"]');
- assert.match(await page.locator('#conversation-results').innerText(), /我的产品体验优化/);
- });
- await check('搜索保留输入焦点,主导航为四栏', async () => {
- const search = page.getByRole('searchbox', { name: '搜索会话或数字生命' });
- await search.fill('不存在');
- assert.match(await page.locator('#conversation-results').innerText(), /没有找到/);
- assert.equal(await search.evaluate((element) => element === document.activeElement), true);
- assert.equal(await page.locator('#tabbar button').count(), 4);
- });
- await go('mine');
- await check('深色、配色和字号只持久化原型偏好', async () => {
- await click('theme');
- assert.equal(await page.locator('#device.dark').count(), 1);
- await click('palette', '[data-value="blue"]');
- await click('font');
- await click('choose-font', '[data-value="18"]');
- await click('close');
- assert.match(await page.locator('[data-action="font"]').innerText(), /大号/);
- await page.reload();
- assert.equal(await page.locator('#device.dark').count(), 1);
- const stored = await page.evaluate(() =>
- JSON.parse(localStorage.getItem('fmode_mobile_proposal_v1')),
- );
- assert.equal(stored.palette, 'blue');
- assert.equal(stored.font, 18);
- });
- await check('骨架、空态、错误和重试可以完整体验', async () => {
- await click('preview-states');
- await click('list-state', '[data-value="loading"]');
- assert.equal(await page.locator('.skeleton-row').count(), 5);
- await page.waitForSelector('.conversation-row');
- await page.goto(`${base}#/mine`);
- await click('preview-states');
- await click('list-state', '[data-value="error"]');
- await click('retry-list');
- assert.ok((await page.locator('.conversation-row').count()) > 0);
- });
- await page.evaluate(() => localStorage.removeItem('fmode_mobile_proposal_v1'));
- await page.reload();
- await check('320 到 1440 宽度无横向溢出,输入框始终在视窗内', async () => {
- for (const [width, height] of [
- [320, 568],
- [360, 740],
- [390, 844],
- [430, 932],
- [768, 1024],
- [1440, 1000],
- ]) {
- await page.setViewportSize({ width, height });
- for (const route of ['home', 'chat/c1', 'messages', 'contacts', 'workbench', 'mine']) {
- await go(route);
- const dimensions = await page.evaluate(() => ({
- viewport: innerWidth,
- width: document.documentElement.scrollWidth,
- composer: document.querySelector('#composer-area').getBoundingClientRect().bottom,
- height: innerHeight,
- }));
- assert.ok(
- dimensions.width <= dimensions.viewport + 1,
- `${width}px ${route}: horizontal overflow`,
- );
- assert.ok(
- dimensions.composer <= dimensions.height + 1,
- `${width}px ${route}: composer outside viewport`,
- );
- }
- }
- });
- await page.setViewportSize({ width: 1440, height: 1000 });
- await go('chat/c1');
- await screenshot('preview-desktop.png');
- await page.setViewportSize({ width: 390, height: 844 });
- await go('home');
- await screenshot('preview-home.png');
- await go('workbench');
- await screenshot('preview-workbench.png');
- assert.deepEqual(errors, [], 'Browser runtime errors');
- assert.deepEqual(externalRequests, [], 'Prototype must not make external requests');
- console.log(
- `PASS ${checks} groups; 36 responsive routes; no runtime errors or external requests.`,
- );
- } finally {
- await browser.close();
- }
|