review-mobile-ui.mjs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. #!/usr/bin/env node
  2. /** 当前 Angular UI 的隔离审查;--verify 自动回归,默认打开可交互手机窗口。 */
  3. import { spawn } from 'node:child_process';
  4. import { createServer } from 'node:net';
  5. import { existsSync } from 'node:fs';
  6. import { mkdir, writeFile } from 'node:fs/promises';
  7. import { resolve, dirname } from 'node:path';
  8. import { fileURLToPath } from 'node:url';
  9. import { chromium } from 'playwright';
  10. const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
  11. const verify = process.argv.includes('--verify');
  12. const out = resolve(root, 'test-results/mobile-ui-' + new Date().toISOString().slice(0, 10).replaceAll('-', ''));
  13. const socket = createServer();
  14. await new Promise((ok, no) => { socket.once('error', no); socket.listen(0, '127.0.0.1', ok); });
  15. const port = socket.address().port;
  16. await new Promise((ok) => socket.close(ok));
  17. const base = 'http://127.0.0.1:' + port;
  18. const server = spawn(process.execPath, [resolve(root, 'node_modules/@angular/cli/bin/ng.js'),
  19. 'serve', '--configuration', 'mock', '--host', '127.0.0.1', '--port', String(port)],
  20. { cwd: root, stdio: ['ignore', 'pipe', 'pipe'] });
  21. let serverLog = '';
  22. let serverClosed = false;
  23. server.on('exit', () => { serverClosed = true; });
  24. for (const stream of [server.stdout, server.stderr]) stream.on('data', (x) => { serverLog = (serverLog + x).slice(-16000); });
  25. let browser;
  26. const stop = () => { if (!serverClosed) server.kill(); };
  27. process.once('SIGINT', () => { stop(); process.exit(130); });
  28. process.once('SIGTERM', () => { stop(); process.exit(143); });
  29. try {
  30. console.log('正在编译当前 Angular 移动端,使用隔离演示数据…');
  31. const started = Date.now();
  32. while (true) {
  33. if (serverClosed) throw new Error(serverLog);
  34. try { if ((await fetch(base)).ok) break; } catch { /* 等待开发服务 */ }
  35. if (Date.now() - started > 120000) throw new Error('本地预览启动超时\n' + serverLog);
  36. await new Promise((ok) => setTimeout(ok, 500));
  37. }
  38. const chrome = [
  39. 'C:/Program Files/Google/Chrome/Application/chrome.exe',
  40. 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe',
  41. ].find(existsSync);
  42. browser = await chromium.launch({ headless: verify, ...(chrome ? { executablePath: chrome } : {}) });
  43. const context = await browser.newContext({ viewport: { width: 390, height: 844 },
  44. deviceScaleFactor: 1, isMobile: true, hasTouch: true });
  45. // 整个审查浏览器只允许访问本次新建的本地服务。
  46. await context.route('**/*', (route) => new URL(route.request().url()).origin === base ? route.continue() : route.abort());
  47. await context.addInitScript(() => {
  48. if (sessionStorage.getItem('mobile-ui-review-seeded')) return;
  49. sessionStorage.setItem('mobile-ui-review-seeded', '1');
  50. localStorage.setItem('fmode_session_token', 'demo-fmode');
  51. localStorage.setItem('fmode_me', JSON.stringify({ id: 'demo-user', name: '林悦', companyId: 'demo-company' }));
  52. localStorage.setItem('fmode_ui_mode_override', 'mobile');
  53. localStorage.setItem('fmode_palette', 'platinum');
  54. localStorage.setItem('fmode_workspaces_demo-user', JSON.stringify([
  55. { id: 'ws-shell', name: '外壳 3D', createdAt: Date.now() - 86400000 * 2 },
  56. { id: 'ws-electronics', name: '电子件', createdAt: Date.now() - 86400000 },
  57. ]));
  58. localStorage.setItem('mock/chat-threads', JSON.stringify(Array.from({ length: 10 }, (_, i) => ({
  59. objectId: 'ui-review-' + i, agentId: ['zhixia', 'qiyun', 'jianwei', 'xingzhou'][i % 4],
  60. roomId: '!ui-review-' + i + ':example.invalid', threadRoot: '$ui-review-' + i,
  61. workspaceId: i % 2 === 0 ? 'ws-shell' : 'ws-electronics',
  62. title: ['整理秋季品牌策略提案与渠道执行清单', '预发布环境部署与验证', '第三季度业务数据分析', '客户反馈整理与待确认事项'][i % 4],
  63. titleLocked: true, messageCount: 4, lastMessageAt: Date.now() - i * 2400000,
  64. archived: false, lastPreview: '本地 UI 审查演示内容,方便检查摘要、长标题和状态。',
  65. }))));
  66. });
  67. const page = await context.newPage();
  68. // 演示心跳固定在该日期;只固定 Date,保留真实计时器,避免样例随日历推进全部离线。
  69. await page.clock.setFixedTime(new Date('2026-10-14T10:43:00+08:00'));
  70. const errors = [];
  71. page.on('pageerror', (e) => errors.push(e.message));
  72. const go = async (route) => {
  73. await page.goto(base + '/mobile/' + route, { waitUntil: 'networkidle' });
  74. await page.locator('app-m-app-bar .m-title-main').waitFor({ state: 'visible' });
  75. await page.waitForTimeout(350);
  76. await page.waitForFunction(() => document.querySelector('.m-title-main') && document.querySelector('.m-bar-right') && document.querySelector('.m-body, .m-chat-body'));
  77. };
  78. if (!verify) {
  79. await go('messages');
  80. console.log('审查窗口已打开:' + base + '/mobile/messages');
  81. console.log('这是当前源码的 Mock 页面,可修改本地演示内容;远程业务请求已阻断。');
  82. console.log('聊天审查可在地址栏进入 ' + base + '/mobile/chat/zhixia/$ui-review-0');
  83. console.log('关闭审查浏览器或按 Ctrl+C 结束,普通浏览器的登录和偏好不受影响。');
  84. if (process.argv.includes('--smoke')) {
  85. console.log('可交互审查窗口启动验证通过。');
  86. } else {
  87. await new Promise((ok) => browser.once('disconnected', ok));
  88. }
  89. } else {
  90. await mkdir(out, { recursive: true });
  91. const results = [];
  92. const check = (name, ok, detail = '') => {
  93. results.push({ name, ok: !!ok, detail });
  94. console.log((ok ? 'PASS ' : 'FAIL ') + name + (detail ? ' ' + detail : ''));
  95. };
  96. const routes = ['messages', 'contacts', 'workbench', 'mine', 'chat/zhixia/$ui-review-0'];
  97. for (const width of [320, 360, 390, 430]) {
  98. await page.setViewportSize({ width, height: 844 });
  99. for (const route of routes) {
  100. await go(route);
  101. const metrics = await page.evaluate(() => {
  102. const title = document.querySelector('.m-title-main').getBoundingClientRect();
  103. const right = document.querySelector('.m-bar-right').getBoundingClientRect();
  104. const left = document.querySelector('.m-app-bar > .m-fab')?.getBoundingClientRect();
  105. const body = document.querySelector('.m-body, .m-chat-body');
  106. return { overflow: document.documentElement.scrollWidth > innerWidth || body.scrollWidth > body.clientWidth,
  107. offset: title.x + title.width / 2 - innerWidth / 2,
  108. overlap: title.width > 0 && ((left && title.x < left.right) || title.right > right.left) };
  109. });
  110. check(width + 'px ' + route, !metrics.overflow && !metrics.overlap && Math.abs(metrics.offset) < 1, JSON.stringify(metrics));
  111. if (width === 390) await page.screenshot({ path: resolve(out, route.split('/').slice(0, 2).join('-') + '.png') });
  112. }
  113. }
  114. await page.setViewportSize({ width: 390, height: 844 });
  115. await go('chat/zhixia/$ui-review-0');
  116. const textarea = page.locator('app-m-dock textarea');
  117. await page.getByRole('button', { name: '选择项目并切换对话' }).click();
  118. const projectPicker = page.locator('.m-project-root');
  119. check('聊天页可打开项目选择器', await projectPicker.isVisible());
  120. await page.locator('.m-project-sheet').evaluate(async (el) => { await Promise.all(el.getAnimations().map((animation) => animation.finished)); });
  121. await page.screenshot({ path: resolve(out, 'project-switcher.png') });
  122. await page.locator('.m-project-row').filter({ hasText: '电子件' }).click();
  123. await page.waitForFunction(() => document.querySelectorAll('.m-project-session').length === 5);
  124. check('项目列表展示跨数字生命的对话', (await page.locator('.m-project-list').innerText()).includes('预发布环境部署与验证') &&
  125. (await page.locator('.m-project-session').count()) === 5);
  126. await page.screenshot({ path: resolve(out, 'project-conversations.png') });
  127. await page.getByRole('searchbox', { name: '搜索项目内对话' }).fill('不存在的会话');
  128. check('项目内搜索展示空态', await page.getByText('没有匹配的对话', { exact: true }).isVisible());
  129. await page.getByRole('button', { name: '清除搜索' }).click();
  130. await page.locator('.m-project-session').first().click();
  131. await page.waitForURL((url) => decodeURIComponent(url.pathname) === '/mobile/chat/qiyun/$ui-review-1');
  132. check('可从项目对话列表继续工作', true, page.url());
  133. await page.getByRole('button', { name: '选择项目并切换对话' }).click();
  134. await page.locator('.m-project-row').filter({ hasText: '外壳 3D' }).click();
  135. await page.getByRole('button', { name: '将当前对话移入此项目' }).waitFor({ state: 'visible' });
  136. const projectActionSizes = await page.evaluate(() => ({
  137. move: document.querySelector('.m-project-move').getBoundingClientRect().height,
  138. create: document.querySelector('.m-project-new-chat').getBoundingClientRect().height,
  139. }));
  140. check('项目移动与新建入口点击区域至少44px', projectActionSizes.move >= 44 && projectActionSizes.create >= 44, JSON.stringify(projectActionSizes));
  141. check('可将当前对话直接移入另一个项目', true);
  142. await page.getByRole('button', { name: '将当前对话移入此项目' }).click();
  143. await page.waitForFunction(() => document.querySelector('.m-project-name')?.textContent?.trim() === '外壳 3D');
  144. await page.waitForFunction(() => document.querySelectorAll('.m-project-session').length === 6);
  145. check('移动后当前项目与项目会话列表即时更新', (await page.locator('.m-project-name').innerText()) === '外壳 3D' &&
  146. (await page.locator('.m-project-session').count()) === 6);
  147. await go('chat/zhixia/$ui-review-0');
  148. await page.getByRole('button', { name: '选择项目并切换对话' }).click();
  149. await page.getByRole('button', { name: '创建新项目' }).click();
  150. await page.locator('#m-new-project-name').fill('总装演示');
  151. await page.getByRole('button', { name: '创建项目' }).click();
  152. await page.getByText('这个项目还没有对话').waitFor();
  153. check('创建项目后明确提示空项目并可直接新建', (await page.locator('.m-project-head h2').innerText()) === '总装演示' &&
  154. (await page.locator('.m-project-empty').innerText()).includes('新建后会自动归入此项目') &&
  155. await page.locator('.m-project-new-chat').isVisible());
  156. await page.locator('.m-project-new-chat').click();
  157. const newChatSheet = page.locator('app-m-new-chat .m-sheet-root');
  158. await newChatSheet.waitFor({ state: 'visible' });
  159. check('可在新项目中启动新对话', await newChatSheet.isVisible());
  160. await page.locator('app-m-new-chat .m-row:not([disabled])').first().click();
  161. await page.waitForFunction(() => document.querySelector('.m-project-name')?.textContent?.trim() === '总装演示');
  162. check('选择数字生命后新对话归属新项目', (await page.locator('.m-project-name').innerText()) === '总装演示');
  163. await page.getByRole('button', { name: '选择项目并切换对话' }).click();
  164. await page.getByRole('button', { name: '创建新项目' }).click();
  165. await page.locator('#m-new-project-name').fill('空项目重试');
  166. await page.getByRole('button', { name: '创建项目' }).click();
  167. await page.getByText('这个项目还没有对话', { exact: true }).waitFor();
  168. await page.waitForFunction(() => {
  169. const picker = window.ng.getComponent(document.querySelector('app-m-project-switcher'));
  170. return picker && !picker.loadingSessions();
  171. });
  172. await page.evaluate(() => {
  173. const picker = window.ng.getComponent(document.querySelector('app-m-project-switcher'));
  174. window.__reviewEnsureLoaded = picker.live.ensureLoaded.bind(picker.live);
  175. picker.live.ensureLoaded = async () => { throw new Error('模拟同步失败'); };
  176. void picker.loadSessions();
  177. });
  178. await page.getByText('对话暂时没能加载', { exact: true }).waitFor();
  179. check('会话目录加载失败时不再无限转圈,提供重试且新建仍可用',
  180. await page.getByRole('button', { name: '重试加载' }).isVisible() && await page.locator('.m-project-new-chat').isVisible());
  181. await page.evaluate(() => {
  182. const picker = window.ng.getComponent(document.querySelector('app-m-project-switcher'));
  183. picker.live.ensureLoaded = window.__reviewEnsureLoaded;
  184. });
  185. await page.getByRole('button', { name: '重试加载' }).click();
  186. await page.waitForFunction(() => {
  187. const picker = window.ng.getComponent(document.querySelector('app-m-project-switcher'));
  188. return !picker.loadingSessions() && picker.sessionLoadIssue() === 'none';
  189. });
  190. check('重试成功后切换到真实空项目说明', await page.getByText('这个项目还没有对话', { exact: true }).isVisible() &&
  191. await page.locator('.m-project-new-chat').isVisible());
  192. await page.keyboard.press('Escape');
  193. check('Esc 可关闭项目选择器', await projectPicker.count() === 0);
  194. await page.setViewportSize({ width: 320, height: 480 });
  195. await page.evaluate(() => document.documentElement.style.setProperty('--ui-scale', '1.75'));
  196. await page.getByRole('button', { name: '选择项目并切换对话' }).click();
  197. await page.getByRole('searchbox', { name: '搜索项目', exact: true }).fill('外壳');
  198. await page.locator('.m-project-sheet').evaluate(el => Promise.all(el.getAnimations().map(a => a.finished)));
  199. const compactProject = await page.locator('.m-project-sheet').evaluate((el) => {
  200. const footer = el.querySelector('.m-project-foot').getBoundingClientRect();
  201. const clear = el.querySelector('.m-project-search button').getBoundingClientRect();
  202. const rect = el.getBoundingClientRect();
  203. return { fits: rect.top >= 0 && rect.bottom <= innerHeight + 1 && rect.right <= innerWidth,
  204. footer: footer.bottom <= innerHeight + 1, clear: clear.width >= 44 && clear.height >= 44,
  205. scrollable: getComputedStyle(el.querySelector('.m-project-list')).overflowY === 'auto' };
  206. });
  207. check('小高度大字项目弹层按钮可达且内容独立滚动', Object.values(compactProject).every(Boolean), JSON.stringify(compactProject));
  208. await page.screenshot({ path: resolve(out, 'project-compact-large.png') });
  209. await page.getByRole('button', { name: '完成', exact: true }).click();
  210. await page.setViewportSize({ width: 390, height: 844 });
  211. await page.evaluate(() => document.documentElement.style.setProperty('--ui-scale', '1'));
  212. await go('chat/zhixia/$ui-review-0');
  213. const draft = 'UI审查第一行';
  214. await textarea.fill(draft);
  215. await textarea.press('Enter');
  216. check('Enter 换行且保留草稿', (await textarea.inputValue()) === draft + '\n');
  217. const composing = await textarea.evaluate((el) => {
  218. const event = new KeyboardEvent('keydown', { key: 'Enter', ctrlKey: true, isComposing: true, bubbles: true, cancelable: true });
  219. el.dispatchEvent(event);
  220. return { prevented: event.defaultPrevented, value: el.value };
  221. });
  222. check('组合态快捷键不提交', !composing.prevented && composing.value === draft + '\n');
  223. const message = 'UI审查发送验证-' + Date.now();
  224. await textarea.fill(message + '\n第二行\n第三行');
  225. const expanded = await textarea.evaluate((el) => el.getBoundingClientRect().height);
  226. await page.locator('app-m-dock .m-send').click();
  227. await page.waitForFunction((text) => document.querySelector('.m-chat-body')?.textContent?.includes(text), message);
  228. check('点击发送后草稿清空且高度复位', (await textarea.inputValue()) === '' &&
  229. (await textarea.evaluate((el) => el.getBoundingClientRect().height)) < expanded);
  230. check('演示消息显示在当前会话', (await page.locator('.m-chat-body').innerText()).includes(message));
  231. const tools = await page.locator('app-m-dock button').evaluateAll((els) => els.map((el) => {
  232. const r = el.getBoundingClientRect(); return { width: r.width, height: r.height };
  233. }));
  234. check('输入工具点击区域至少44px', tools.every((r) => r.width >= 44 && r.height >= 44));
  235. await page.getByRole('button', { name: '查看成果与状态' }).click();
  236. const detailSheet = page.locator('[aria-label="会话面板"]');
  237. await detailSheet.waitFor({ state: 'visible', timeout: 5000 });
  238. check('会话详情可打开', await detailSheet.isVisible());
  239. await detailSheet.locator('.m-sheet-x').click();
  240. await detailSheet.waitFor({ state: 'detached', timeout: 5000 });
  241. check('会话详情可关闭', (await detailSheet.count()) === 0);
  242. await go('workbench');
  243. const cardGap = await page.locator('.m-life-card').evaluateAll((els) => els[1].getBoundingClientRect().top - els[0].getBoundingClientRect().bottom);
  244. check('工作台卡片间距12px', Math.abs(cardGap - 12) < 1);
  245. await page.locator('.m-body').evaluate((el) => { el.scrollTop = el.scrollHeight; });
  246. const lastCard = await page.locator('.m-life-card').last().boundingBox();
  247. const tab = await page.locator('.m-tabbar').boundingBox();
  248. check('末张卡片不被底栏遮挡', lastCard.y + lastCard.height <= tab.y + 1);
  249. await page.getByRole('button', { name: '打开导航' }).click();
  250. check('导航抽屉可打开', await page.locator('app-m-drawer').evaluate((el) => !!el.querySelector('.open, .is-open, [aria-modal="true"]')));
  251. await go('mine');
  252. const paletteButtons = page.locator('.m-palette');
  253. for (let i = 0; i < 4; i++) {
  254. await paletteButtons.nth(i).click();
  255. check('配色选中态 ' + i, await paletteButtons.nth(i).getAttribute('aria-pressed') === 'true');
  256. }
  257. await paletteButtons.first().click();
  258. await page.getByRole('switch', { name: '深色模式' }).click();
  259. check('深色模式与状态说明', await page.locator('html').evaluate((el) => el.classList.contains('dark')) &&
  260. (await page.locator('.m-row--plain').innerText()).includes('已开启'));
  261. // 先把界面大小归「标准」,后面单独验证界面档位的效果
  262. await page.getByRole('radio', { name: '标准', exact: true }).click();
  263. const uiScaleBefore = await page.evaluate(() => document.documentElement.style.getPropertyValue('--ui-scale'));
  264. await page.locator('.m-slider').fill('18');
  265. for (const route of routes) {
  266. await page.setViewportSize({ width: 320, height: 700 });
  267. await go(route);
  268. const appearance = await page.evaluate((uiBefore) => {
  269. const root = document.documentElement;
  270. return { dark: root.classList.contains('dark'), font: root.style.getPropertyValue('--chat-read-size'),
  271. // 2026-11-21:正文与界面拆开后,改正文不得推动界面比例
  272. scaleUnchanged: root.style.getPropertyValue('--ui-scale') === uiBefore,
  273. palette: root.dataset.palette,
  274. overflow: root.scrollWidth > innerWidth };
  275. }, uiScaleBefore);
  276. check('320px 深色大字 ' + route, appearance.dark && appearance.font === '18px' &&
  277. appearance.scaleUnchanged && appearance.palette === 'platinum' && !appearance.overflow, JSON.stringify(appearance));
  278. await page.waitForTimeout(300);
  279. await page.screenshot({ path: resolve(out, 'dark-large-' + route.split('/').slice(0, 2).join('-') + '.png') });
  280. }
  281. /*
  282. * 2026-11-21 字号拆分后的回归口径:
  283. * · 正文大小 → 只影响 --chat-read-size
  284. * · 界面大小 → 驱动 --ui-scale / --icon-scale(标题、图标、栏高)
  285. * 原先的「标题/图标必须随正文档位单调递增」断言已被新设计取代。
  286. */
  287. await page.setViewportSize({ width: 390, height: 844 });
  288. await go('mine');
  289. if (await page.getByRole('radio', { name: '标准', exact: true }).isVisible().catch(() => false)) {
  290. await page.getByRole('radio', { name: '标准', exact: true }).click();
  291. }
  292. const fontSamples = [];
  293. for (const size of [14, 16, 20]) {
  294. await go('mine');
  295. await page.locator('.m-slider').fill(String(size));
  296. await page.waitForTimeout(100);
  297. const metrics = await page.evaluate(() => {
  298. const css = el => getComputedStyle(document.querySelector(el));
  299. const rect = el => document.querySelector(el).getBoundingClientRect();
  300. return { title: parseFloat(css('.m-title').fontSize), icon: parseFloat(css('.m-tab-icon').fontSize),
  301. bar: rect('.m-app-bar').height, tabbar: rect('.m-tabbar').height,
  302. touch: rect('.m-tab').height, input: parseFloat(css('.m-slider').fontSize),
  303. read: parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--chat-read-size')),
  304. overflow: document.documentElement.scrollWidth > innerWidth };
  305. });
  306. fontSamples.push(metrics);
  307. check('正文字号 ' + size + 'px 生效且保留点击面积', metrics.read === size && metrics.touch >= 44 && !metrics.overflow, JSON.stringify(metrics));
  308. await page.screenshot({ path: resolve(out, 'font-' + size + '-mine.png') });
  309. for (const route of ['messages', 'chat/zhixia/$ui-review-0']) {
  310. await go(route);
  311. const noOverflow = await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth);
  312. check('正文字号 ' + size + 'px 无横向溢出 ' + route, noOverflow);
  313. await page.screenshot({ path: resolve(out, 'font-' + size + '-' + route.split('/')[0] + '.png') });
  314. }
  315. }
  316. check('正文大小不改变导航标题', fontSamples[0].title === fontSamples[1].title && fontSamples[1].title === fontSamples[2].title,
  317. JSON.stringify(fontSamples.map(x => x.title)));
  318. // 界面大小:三档驱动标题/图标/栏高,但图标有上限(不撑满 44px 按钮)
  319. const uiSamples = [];
  320. for (const label of ['紧凑', '标准', '大']) {
  321. await go('mine');
  322. await page.getByRole('radio', { name: label, exact: true }).click();
  323. await page.waitForTimeout(100);
  324. uiSamples.push(await page.evaluate(() => {
  325. const css = el => getComputedStyle(document.querySelector(el));
  326. const rect = el => document.querySelector(el).getBoundingClientRect();
  327. return { title: parseFloat(css('.m-title').fontSize), icon: parseFloat(css('.m-tab-icon').fontSize),
  328. bar: rect('.m-app-bar').height, tabbar: rect('.m-tabbar').height,
  329. touch: rect('.m-tab').height };
  330. }));
  331. await page.screenshot({ path: resolve(out, 'ui-' + label + '-mine.png') });
  332. }
  333. for (const prop of ['title', 'icon', 'bar', 'tabbar']) {
  334. check('界面大小驱动 ' + prop, uiSamples[0][prop] <= uiSamples[1][prop] && uiSamples[1][prop] <= uiSamples[2][prop],
  335. JSON.stringify(uiSamples.map(x => x[prop])));
  336. }
  337. // 图标上限:最大档也不超过 21px(20 × 1.04),且触控区仍 44px
  338. check('最大界面档图标不撑满按钮', uiSamples[2].icon <= 21 && uiSamples[2].touch >= 44, JSON.stringify(uiSamples[2]));
  339. await go('mine');
  340. await page.getByRole('radio', { name: '标准', exact: true }).click();
  341. // 原生权限交互在隔离浏览器中用状态替身覆盖;真实投递另由装机测试验证。
  342. await go('mine');
  343. await page.evaluate(() => {
  344. const setup = window.ng.getComponent(document.querySelector('app-permission-guide')).setup;
  345. window.__permissionReview = { setup, settingsCalls: [] };
  346. setup.notifications.isGranted = async () => setup.granted();
  347. setup.notifications.request = async () => false;
  348. setup.push.start = async () => true;
  349. setup.settings.refresh = async () => null;
  350. setup.settings.open = async (target) => { window.__permissionReview.settingsCalls.push(target); return true; };
  351. setup.notifications.granted.set(false);
  352. document.documentElement.style.setProperty('--ui-scale', '1.75');
  353. setup.show();
  354. });
  355. const guide = page.locator('.pg-root');
  356. await guide.waitFor({ state: 'visible' });
  357. check('首次通知引导不展示省电步骤', await guide.getByRole('heading', { name: '不错过新消息' }).isVisible() && await guide.locator('.pg-saver').count() === 0);
  358. await page.screenshot({ path: resolve(out, 'permission-first-large.png') });
  359. await guide.getByRole('button', { name: '开启通知', exact: true }).click();
  360. await guide.getByRole('alert').waitFor();
  361. check('拒绝后保留引导且不自动跳设置', await guide.isVisible() && await page.evaluate(() => window.__permissionReview.settingsCalls.length === 0));
  362. await page.screenshot({ path: resolve(out, 'permission-denied-large.png') });
  363. await guide.getByRole('button', { name: '去系统设置', exact: true }).click();
  364. check('用户主动进入通知设置', await page.evaluate(() => window.__permissionReview.settingsCalls.join(',') === 'notifications'));
  365. await page.evaluate(() => window.__permissionReview.setup.notifications.granted.set(true));
  366. await guide.getByRole('heading', { name: '通知权限已开启' }).waitFor();
  367. // 2026-11-21:后台接收步骤从 1 个变成 2 个(省电策略 + 自启动),断言同步更新
  368. const saverCount = await guide.locator('.pg-saver').count();
  369. check('授权返回后展示后台接收步骤', saverCount === 2 &&
  370. (await guide.locator('.pg-saver').first().isVisible()));
  371. check('后台步骤含自启动入口', await guide.getByRole('button', { name: '去设置自启动' }).isVisible());
  372. check('权限已开不冒充推送已就绪', (await guide.locator('.pg-status').innerText()).includes('尚未启用'));
  373. for (const dark of [false, true]) {
  374. await page.evaluate((dark) => { document.documentElement.classList.toggle('dark', dark); document.documentElement.style.setProperty('--ui-scale', '1.75'); }, dark);
  375. const layout = await guide.evaluate((el) => {
  376. const card = el.querySelector('.pg-card').getBoundingClientRect();
  377. const actions = el.querySelector('.pg-actions').getBoundingClientRect();
  378. const body = el.querySelector('.pg-body');
  379. return { fits: card.x >= 0 && card.right <= innerWidth && card.y >= 0 && card.bottom <= innerHeight,
  380. actions: actions.bottom <= innerHeight && actions.height > 44,
  381. scrollable: getComputedStyle(body).overflowY === 'auto', overflow: document.documentElement.scrollWidth > innerWidth };
  382. });
  383. check('320px 140%系统字与20px应用字 ' + (dark ? '深色' : '浅色'), layout.fits && layout.actions && layout.scrollable && !layout.overflow, JSON.stringify(layout));
  384. await page.screenshot({ path: resolve(out, `permission-large-${dark ? 'dark' : 'light'}.png`) });
  385. }
  386. await page.keyboard.press('Escape');
  387. check('通知引导支持Esc关闭', await guide.count() === 0);
  388. check('无浏览器运行异常', errors.length === 0, errors.join(' | '));
  389. await writeFile(resolve(out, 'results.json'), JSON.stringify({ results, errors }, null, 2));
  390. console.log('结果:' + results.filter((r) => r.ok).length + '/' + results.length + ';截图:' + out);
  391. if (results.some((r) => !r.ok)) process.exitCode = 1;
  392. }
  393. } catch (error) {
  394. console.error(error);
  395. process.exitCode = 1;
  396. } finally {
  397. await browser?.close();
  398. stop();
  399. }