verify.mjs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. import assert from 'node:assert/strict';
  2. import { chromium } from 'playwright';
  3. import { fileURLToPath, pathToFileURL } from 'node:url';
  4. import path from 'node:path';
  5. const directory = path.dirname(fileURLToPath(import.meta.url));
  6. const base = pathToFileURL(path.join(directory, 'index.html')).href;
  7. const browser = await chromium.launch({ channel: 'chrome', headless: true });
  8. const context = await browser.newContext({
  9. viewport: { width: 390, height: 844 },
  10. deviceScaleFactor: 1,
  11. reducedMotion: 'reduce',
  12. });
  13. const page = await context.newPage();
  14. page.setDefaultTimeout(8000);
  15. const errors = [];
  16. const requests = [];
  17. page.on('pageerror', (error) => errors.push(error.message));
  18. page.on('request', (request) => {
  19. if (/^https?:/.test(request.url())) requests.push(request.url());
  20. });
  21. const phone = page.locator('#polished');
  22. const click = async (action, selector = '') => {
  23. const query = `[data-action="${action}"]${selector}`;
  24. const overlay = phone.locator('.overlay').locator(query);
  25. await ((await overlay.count()) ? overlay : phone.locator(query)).first().click();
  26. };
  27. const go = async (route) => {
  28. await page.goto(`${base}#/${route}`);
  29. await page.evaluate(() => document.fonts.ready);
  30. };
  31. let checks = 0;
  32. async function check(name, operation) {
  33. await operation();
  34. checks++;
  35. console.log(`PASS ${checks}: ${name}`);
  36. }
  37. const shot = async (name) => {
  38. await page.mouse.move(0, 0);
  39. return page.screenshot({
  40. path: path.join(directory, name),
  41. fullPage: true,
  42. style: '.toast{visibility:hidden!important}',
  43. });
  44. };
  45. try {
  46. await go('messages');
  47. await check('当前会话结构、四栏导航和前后对照', async () => {
  48. assert.equal(await phone.locator('.tabbar button').count(), 4);
  49. assert.deepEqual(await phone.locator('.segmented button').allTextContents(), [
  50. '全部',
  51. '工作区',
  52. ]);
  53. assert.equal(await phone.locator('.conversation').count(), 6);
  54. assert.equal(await page.locator('#baseline .conversation').count(), 6);
  55. assert.equal(await page.locator('#baseline').isVisible(), false);
  56. await page.locator('.mobile-review [data-view="baseline"]').click();
  57. assert.equal(await page.locator('#baseline').isVisible(), true);
  58. await page.locator('.mobile-review [data-view="polished"]').click();
  59. });
  60. await check('即时搜索与空状态', async () => {
  61. await phone.locator('[data-field="search"]').fill('Nova');
  62. assert.equal(await phone.locator('.conversation').count(), 2);
  63. await phone.locator('[data-field="search"]').fill('不存在的关键词');
  64. assert.equal(await phone.locator('.empty h3').textContent(), '没有找到相关会话');
  65. await phone.locator('[data-field="search"]').fill('');
  66. });
  67. await shot('preview-messages.png');
  68. await check('工作区折叠、新建、重命名、删除保留会话', async () => {
  69. await click('filter', '[data-value="workspace"]');
  70. assert.equal(await phone.locator('.group-toggle[aria-expanded="false"]').count(), 2);
  71. await click('group', '[data-id="w1"]');
  72. assert.equal(
  73. await phone.locator('.group-toggle[data-id="w1"]').getAttribute('aria-expanded'),
  74. 'true',
  75. );
  76. await click('workspace-new');
  77. await phone.locator('[data-field="workspace"]').fill('设计评审');
  78. await phone.locator('[data-form="workspace"] button[type="submit"]').click();
  79. assert.equal(await phone.locator('.group-toggle').count(), 3);
  80. const group = phone
  81. .locator('.list')
  82. .filter({ has: page.locator('.group-toggle', { hasText: '设计评审' }) });
  83. await group.locator('[data-action="workspace-rename"]').click();
  84. await phone.locator('[data-field="workspace"]').fill('设计迭代');
  85. await phone.locator('[data-form="workspace"] button[type="submit"]').click();
  86. await phone
  87. .locator('.list')
  88. .filter({ has: page.locator('.group-toggle', { hasText: '设计迭代' }) })
  89. .locator('[data-action="workspace-delete"]')
  90. .click();
  91. await click('confirm-workspace-delete');
  92. assert.equal(await phone.locator('.group-toggle').count(), 2);
  93. await phone
  94. .locator('.list')
  95. .filter({ has: page.locator('.group-toggle[data-id="w1"]') })
  96. .locator('[data-action="workspace-delete"]')
  97. .click();
  98. await click('confirm-workspace-delete');
  99. await click('filter', '[data-value="all"]');
  100. assert.equal(await phone.locator('.conversation').count(), 6);
  101. });
  102. await go('chat/c1');
  103. await check('保留回复卡片、过程折叠和两份文件', async () => {
  104. assert.equal(await phone.locator('.tabbar').count(), 0);
  105. assert.equal(await phone.locator('.assistant-card').count(), 1);
  106. assert.equal(await phone.locator('.file-card').count(), 2);
  107. assert.equal(await phone.locator('details[open]').count(), 0);
  108. await phone.locator('.process summary').click();
  109. assert.equal(await phone.locator('details[open]').count(), 1);
  110. await phone.locator('.process summary').click();
  111. await click('files');
  112. await click('preview', '[data-id="ppt"]');
  113. assert.equal(await phone.locator('.preview-document').count(), 1);
  114. await page.keyboard.press('Escape');
  115. assert.equal(await phone.locator('.overlay').count(), 0);
  116. });
  117. await shot('preview-chat.png');
  118. await check('标题校验、预设建议与安全文本渲染', async () => {
  119. await click('title');
  120. await phone.locator('[data-field="title"]').fill(' ');
  121. await phone.locator('[data-form="title"] button[type="submit"]').click();
  122. assert.equal(await phone.locator('.form-error').textContent(), '名称不能为空');
  123. await click('suggest-title');
  124. assert.equal(await phone.locator('.candidate').count(), 2);
  125. await click('use-title');
  126. await phone.locator('[data-field="title"]').fill('<img src=x onerror=alert(1)>');
  127. await phone.locator('[data-form="title"] button[type="submit"]').click();
  128. assert.equal(await phone.locator('.appbar h2').textContent(), '<img src=x onerror=alert(1)>');
  129. assert.equal(await phone.locator('img').count(), 0);
  130. await click('title');
  131. await phone.locator('[data-field="title"]').fill('季度经营复盘报告');
  132. await phone.locator('[data-form="title"] button[type="submit"]').click();
  133. });
  134. await check('Enter 换行、IME 安全和同一数字生命不同会话草稿隔离', async () => {
  135. const draft = phone.locator('[data-field="draft"]');
  136. await draft.fill('第一行');
  137. await draft.press('Enter');
  138. await draft.pressSequentially('第二行');
  139. assert.equal(await draft.inputValue(), '第一行\n第二行');
  140. await draft.dispatchEvent('keydown', { key: 'Enter', isComposing: true });
  141. assert.equal(await phone.locator('.user-message').count(), 1);
  142. await click('activity');
  143. await click('chat', '[data-id="c6"]');
  144. assert.equal(await phone.locator('[data-field="draft"]').inputValue(), '');
  145. await phone.locator('[data-field="draft"]').fill('另一条 Nova 草稿');
  146. await click('activity');
  147. await click('chat', '[data-id="c1"]');
  148. assert.equal(await phone.locator('[data-field="draft"]').inputValue(), '第一行\n第二行');
  149. await click('activity');
  150. await shot('preview-switcher.png');
  151. await click('close');
  152. });
  153. await check('附件、本地发送、后台完成提醒与返回结果', async () => {
  154. await phone
  155. .locator('[data-field="attachment"]')
  156. .setInputFiles({ name: '季度资料.txt', mimeType: 'text/plain', buffer: Buffer.from('demo') });
  157. assert.equal(await phone.locator('.attachment-chip').count(), 1);
  158. await click('send');
  159. assert.equal(await phone.locator('[data-field="draft"]').inputValue(), '');
  160. assert.equal(await phone.locator('[data-action="send"]').isDisabled(), true);
  161. await click('activity');
  162. await click('chat', '[data-id="c6"]');
  163. await page.waitForTimeout(1400);
  164. assert.match(await phone.locator('.toast').textContent(), /已完成/);
  165. await phone.locator('.toast [data-action="chat"]').click();
  166. assert.equal(await phone.locator('.assistant-card').count(), 2);
  167. assert.match(await phone.locator('.assistant-card').last().textContent(), /未请求 AI/);
  168. });
  169. await check('当前容器快速新建、归档与恢复', async () => {
  170. await click('chat-menu');
  171. await click('quick-new');
  172. assert.equal(await phone.locator('.appbar h2').textContent(), '新对话');
  173. assert.match(await phone.locator('.appbar p').textContent(), /Nova/);
  174. await click('chat-menu');
  175. await click('archive');
  176. await click('drawer');
  177. await click('archived');
  178. assert.match(await phone.locator('.sheet').textContent(), /新对话/);
  179. await click('restore');
  180. assert.match(await phone.locator('.sheet').textContent(), /没有已归档会话/);
  181. await click('close');
  182. });
  183. await go('contacts');
  184. await check('通讯录原有三段筛选、同事展开和容器重命名', async () => {
  185. assert.deepEqual(await phone.locator('.segmented button').allTextContents(), [
  186. '全部',
  187. '数字生命',
  188. '同事',
  189. ]);
  190. await click('contact-filter', '[data-value="people"]');
  191. await click('person', '[data-id="p1"]');
  192. assert.equal(await phone.locator('.person-children .conversation').count(), 2);
  193. await click('agent', '[data-id="nova"]');
  194. assert.equal(await phone.locator('.appbar h2').textContent(), '容器设置');
  195. assert.equal(await phone.locator('.tabbar').count(), 0);
  196. await click('rename-agent');
  197. await phone.locator('[data-field="agent-name"]').fill('Nova 分析助手');
  198. await phone.locator('[data-form="agent"] button[type="submit"]').click();
  199. assert.match(await phone.locator('.settings-card').textContent(), /Nova 分析助手/);
  200. });
  201. await go('workbench');
  202. await check('工作台原有状态筛选、指标缺失与通道充值入口', async () => {
  203. assert.deepEqual(await phone.locator('.segmented button').allTextContents(), [
  204. '全部',
  205. '在线',
  206. '离线',
  207. ]);
  208. assert.equal(await phone.locator('.life-card').count(), 5);
  209. await click('work-filter', '[data-value="offline"]');
  210. assert.equal(await phone.locator('.life-card').count(), 1);
  211. assert.match(await phone.locator('.life-card').textContent(), /指标未上报/);
  212. await click('enter-agent');
  213. assert.match(await phone.locator('.toast').textContent(), /当前离线/);
  214. await click('channel');
  215. assert.match(await phone.locator('.sheet').textContent(), /不修改通道配置/);
  216. await click('close');
  217. await click('recharge');
  218. assert.match(await phone.locator('.sheet').textContent(), /不会产生支付/);
  219. await click('close');
  220. await click('work-filter', '[data-value="all"]');
  221. });
  222. await shot('preview-workbench.png');
  223. await go('mine');
  224. await check('保留四套配色、深色、字号和脱敏 Token', async () => {
  225. assert.equal(await phone.locator('.palette-grid button').count(), 4);
  226. assert.equal(await phone.locator('[data-action="copy-token"]').isDisabled(), true);
  227. await click('token');
  228. assert.match(await phone.locator('.settings-card').first().textContent(), /NOT-A-REAL/);
  229. await click('palette', '[data-id="ice"]');
  230. assert.equal(await phone.getAttribute('data-palette'), 'ice');
  231. await click('dark');
  232. assert.match(await phone.getAttribute('class'), /dark/);
  233. await phone.locator('[data-field="font"]').fill('17');
  234. assert.equal(
  235. await phone.evaluate((element) => element.style.getPropertyValue('--chat-size')),
  236. '17px',
  237. );
  238. await page.reload();
  239. assert.match(await phone.getAttribute('class'), /dark/);
  240. await click('dark');
  241. await click('palette', '[data-id="platinum"]');
  242. await phone.locator('[data-field="font"]').fill('14');
  243. });
  244. await go('messages');
  245. await check('侧栏焦点约束、Escape 关闭与原型提醒', async () => {
  246. await click('drawer');
  247. assert.equal(await phone.locator('.app-shell').getAttribute('inert'), '');
  248. await shot('preview-drawer.png');
  249. const focusable = phone.locator('.drawer button');
  250. await focusable.last().focus();
  251. await page.keyboard.press('Tab');
  252. assert.equal(
  253. await focusable.first().evaluate((element) => element === document.activeElement),
  254. true,
  255. );
  256. await page.keyboard.press('Escape');
  257. assert.equal(await phone.locator('.overlay').count(), 0);
  258. await click('chat', '[data-id="c1"]');
  259. await click('activity');
  260. await click('demo-complete');
  261. assert.match(await phone.locator('.toast').textContent(), /演示/);
  262. });
  263. await check('新建入口保留品牌与起始输入', async () => {
  264. await go('home');
  265. assert.equal(await phone.locator('.home-logo').textContent(), 'fmode');
  266. await phone.locator('[data-field="draft"]').fill('帮我做一份报告');
  267. await click('send');
  268. await click('create-chat', '[data-id="nova"]');
  269. assert.equal(await phone.locator('[data-field="draft"]').inputValue(), '帮我做一份报告');
  270. });
  271. await check('响应式布局、横向溢出与固定输入区', async () => {
  272. let screens = 0;
  273. for (const [width, height] of [
  274. [320, 640],
  275. [375, 667],
  276. [390, 844],
  277. [430, 932],
  278. [768, 1024],
  279. [1440, 1130],
  280. ]) {
  281. await page.setViewportSize({ width, height });
  282. for (const route of [
  283. 'messages',
  284. 'chat/c1',
  285. 'contacts',
  286. 'workbench',
  287. 'mine',
  288. 'home',
  289. 'agent/nova',
  290. ]) {
  291. await go(route);
  292. assert.equal(
  293. await page.evaluate(() => document.documentElement.scrollWidth > innerWidth),
  294. false,
  295. `document ${width} ${route}`,
  296. );
  297. const overflow = await phone.evaluate(
  298. (element) => element.scrollWidth > element.clientWidth,
  299. );
  300. assert.equal(overflow, false, `phone ${width} ${route}`);
  301. if (route === 'chat/c1') {
  302. const geometry = await phone.evaluate((element) => ({
  303. phone: element.getBoundingClientRect().bottom,
  304. send: element.querySelector('.send-button').getBoundingClientRect().bottom,
  305. scroll: element.querySelector('.page-content').clientHeight,
  306. }));
  307. assert.ok(geometry.send <= geometry.phone, `send ${width}`);
  308. assert.ok(geometry.scroll > 150, `chat height ${width}`);
  309. }
  310. screens++;
  311. }
  312. }
  313. console.log(` ${screens} viewport/route combinations checked`);
  314. });
  315. await page.evaluate(() => localStorage.clear());
  316. await page.reload();
  317. await go('messages');
  318. await shot('preview-comparison.png');
  319. await go('chat/c1');
  320. await shot('preview-chat-comparison.png');
  321. await page.setViewportSize({ width: 390, height: 844 });
  322. await go('messages');
  323. await shot('preview-messages.png');
  324. await go('chat/c1');
  325. await shot('preview-chat.png');
  326. await go('workbench');
  327. await shot('preview-workbench.png');
  328. await go('contacts');
  329. await shot('preview-contacts.png');
  330. await go('mine');
  331. await shot('preview-mine.png');
  332. await go('home');
  333. await shot('preview-home.png');
  334. await go('chat/c1');
  335. await click('activity');
  336. await shot('preview-switcher.png');
  337. await click('close');
  338. await click('back');
  339. await click('drawer');
  340. await shot('preview-drawer.png');
  341. await click('close');
  342. await check('无脚本错误、无外部网络请求', async () => {
  343. assert.deepEqual(errors, []);
  344. assert.deepEqual(requests, []);
  345. });
  346. console.log(`PASS: ${checks} interaction groups; standalone offline prototype verified.`);
  347. } finally {
  348. await browser.close();
  349. }