| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402 |
- #!/usr/bin/env node
- /** 当前 Angular UI 的隔离审查;--verify 自动回归,默认打开可交互手机窗口。 */
- import { spawn } from 'node:child_process';
- import { createServer } from 'node:net';
- import { existsSync } from 'node:fs';
- import { mkdir, writeFile } from 'node:fs/promises';
- import { resolve, dirname } from 'node:path';
- import { fileURLToPath } from 'node:url';
- import { chromium } from 'playwright';
- const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
- const verify = process.argv.includes('--verify');
- const out = resolve(root, 'test-results/mobile-ui-' + new Date().toISOString().slice(0, 10).replaceAll('-', ''));
- const socket = createServer();
- await new Promise((ok, no) => { socket.once('error', no); socket.listen(0, '127.0.0.1', ok); });
- const port = socket.address().port;
- await new Promise((ok) => socket.close(ok));
- const base = 'http://127.0.0.1:' + port;
- const server = spawn(process.execPath, [resolve(root, 'node_modules/@angular/cli/bin/ng.js'),
- 'serve', '--configuration', 'mock', '--host', '127.0.0.1', '--port', String(port)],
- { cwd: root, stdio: ['ignore', 'pipe', 'pipe'] });
- let serverLog = '';
- let serverClosed = false;
- server.on('exit', () => { serverClosed = true; });
- for (const stream of [server.stdout, server.stderr]) stream.on('data', (x) => { serverLog = (serverLog + x).slice(-16000); });
- let browser;
- const stop = () => { if (!serverClosed) server.kill(); };
- process.once('SIGINT', () => { stop(); process.exit(130); });
- process.once('SIGTERM', () => { stop(); process.exit(143); });
- try {
- console.log('正在编译当前 Angular 移动端,使用隔离演示数据…');
- const started = Date.now();
- while (true) {
- if (serverClosed) throw new Error(serverLog);
- try { if ((await fetch(base)).ok) break; } catch { /* 等待开发服务 */ }
- if (Date.now() - started > 120000) throw new Error('本地预览启动超时\n' + serverLog);
- await new Promise((ok) => setTimeout(ok, 500));
- }
- const chrome = [
- 'C:/Program Files/Google/Chrome/Application/chrome.exe',
- 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe',
- ].find(existsSync);
- browser = await chromium.launch({ headless: verify, ...(chrome ? { executablePath: chrome } : {}) });
- const context = await browser.newContext({ viewport: { width: 390, height: 844 },
- deviceScaleFactor: 1, isMobile: true, hasTouch: true });
- // 整个审查浏览器只允许访问本次新建的本地服务。
- await context.route('**/*', (route) => new URL(route.request().url()).origin === base ? route.continue() : route.abort());
- await context.addInitScript(() => {
- if (sessionStorage.getItem('mobile-ui-review-seeded')) return;
- sessionStorage.setItem('mobile-ui-review-seeded', '1');
- localStorage.setItem('fmode_session_token', 'demo-fmode');
- localStorage.setItem('fmode_me', JSON.stringify({ id: 'demo-user', name: '林悦', companyId: 'demo-company' }));
- localStorage.setItem('fmode_ui_mode_override', 'mobile');
- localStorage.setItem('fmode_palette', 'platinum');
- localStorage.setItem('fmode_workspaces_demo-user', JSON.stringify([
- { id: 'ws-shell', name: '外壳 3D', createdAt: Date.now() - 86400000 * 2 },
- { id: 'ws-electronics', name: '电子件', createdAt: Date.now() - 86400000 },
- ]));
- localStorage.setItem('mock/chat-threads', JSON.stringify(Array.from({ length: 10 }, (_, i) => ({
- objectId: 'ui-review-' + i, agentId: ['zhixia', 'qiyun', 'jianwei', 'xingzhou'][i % 4],
- roomId: '!ui-review-' + i + ':example.invalid', threadRoot: '$ui-review-' + i,
- workspaceId: i % 2 === 0 ? 'ws-shell' : 'ws-electronics',
- title: ['整理秋季品牌策略提案与渠道执行清单', '预发布环境部署与验证', '第三季度业务数据分析', '客户反馈整理与待确认事项'][i % 4],
- titleLocked: true, messageCount: 4, lastMessageAt: Date.now() - i * 2400000,
- archived: false, lastPreview: '本地 UI 审查演示内容,方便检查摘要、长标题和状态。',
- }))));
- });
- const page = await context.newPage();
- // 演示心跳固定在该日期;只固定 Date,保留真实计时器,避免样例随日历推进全部离线。
- await page.clock.setFixedTime(new Date('2026-10-14T10:43:00+08:00'));
- const errors = [];
- page.on('pageerror', (e) => errors.push(e.message));
- const go = async (route) => {
- await page.goto(base + '/mobile/' + route, { waitUntil: 'networkidle' });
- await page.locator('app-m-app-bar .m-title-main').waitFor({ state: 'visible' });
- await page.waitForTimeout(350);
- await page.waitForFunction(() => document.querySelector('.m-title-main') && document.querySelector('.m-bar-right') && document.querySelector('.m-body, .m-chat-body'));
- };
- if (!verify) {
- await go('messages');
- console.log('审查窗口已打开:' + base + '/mobile/messages');
- console.log('这是当前源码的 Mock 页面,可修改本地演示内容;远程业务请求已阻断。');
- console.log('聊天审查可在地址栏进入 ' + base + '/mobile/chat/zhixia/$ui-review-0');
- console.log('关闭审查浏览器或按 Ctrl+C 结束,普通浏览器的登录和偏好不受影响。');
- if (process.argv.includes('--smoke')) {
- console.log('可交互审查窗口启动验证通过。');
- } else {
- await new Promise((ok) => browser.once('disconnected', ok));
- }
- } else {
- await mkdir(out, { recursive: true });
- const results = [];
- const check = (name, ok, detail = '') => {
- results.push({ name, ok: !!ok, detail });
- console.log((ok ? 'PASS ' : 'FAIL ') + name + (detail ? ' ' + detail : ''));
- };
- const routes = ['messages', 'contacts', 'workbench', 'mine', 'chat/zhixia/$ui-review-0'];
- for (const width of [320, 360, 390, 430]) {
- await page.setViewportSize({ width, height: 844 });
- for (const route of routes) {
- await go(route);
- const metrics = await page.evaluate(() => {
- const title = document.querySelector('.m-title-main').getBoundingClientRect();
- const right = document.querySelector('.m-bar-right').getBoundingClientRect();
- const left = document.querySelector('.m-app-bar > .m-fab')?.getBoundingClientRect();
- const body = document.querySelector('.m-body, .m-chat-body');
- return { overflow: document.documentElement.scrollWidth > innerWidth || body.scrollWidth > body.clientWidth,
- offset: title.x + title.width / 2 - innerWidth / 2,
- overlap: title.width > 0 && ((left && title.x < left.right) || title.right > right.left) };
- });
- check(width + 'px ' + route, !metrics.overflow && !metrics.overlap && Math.abs(metrics.offset) < 1, JSON.stringify(metrics));
- if (width === 390) await page.screenshot({ path: resolve(out, route.split('/').slice(0, 2).join('-') + '.png') });
- }
- }
- await page.setViewportSize({ width: 390, height: 844 });
- await go('chat/zhixia/$ui-review-0');
- const textarea = page.locator('app-m-dock textarea');
- await page.getByRole('button', { name: '选择项目并切换对话' }).click();
- const projectPicker = page.locator('.m-project-root');
- check('聊天页可打开项目选择器', await projectPicker.isVisible());
- await page.locator('.m-project-sheet').evaluate(async (el) => { await Promise.all(el.getAnimations().map((animation) => animation.finished)); });
- await page.screenshot({ path: resolve(out, 'project-switcher.png') });
- await page.locator('.m-project-row').filter({ hasText: '电子件' }).click();
- await page.waitForFunction(() => document.querySelectorAll('.m-project-session').length === 5);
- check('项目列表展示跨数字生命的对话', (await page.locator('.m-project-list').innerText()).includes('预发布环境部署与验证') &&
- (await page.locator('.m-project-session').count()) === 5);
- await page.screenshot({ path: resolve(out, 'project-conversations.png') });
- await page.getByRole('searchbox', { name: '搜索项目内对话' }).fill('不存在的会话');
- check('项目内搜索展示空态', await page.getByText('没有匹配的对话', { exact: true }).isVisible());
- await page.getByRole('button', { name: '清除搜索' }).click();
- await page.locator('.m-project-session').first().click();
- await page.waitForURL((url) => decodeURIComponent(url.pathname) === '/mobile/chat/qiyun/$ui-review-1');
- check('可从项目对话列表继续工作', true, page.url());
- await page.getByRole('button', { name: '选择项目并切换对话' }).click();
- await page.locator('.m-project-row').filter({ hasText: '外壳 3D' }).click();
- await page.getByRole('button', { name: '将当前对话移入此项目' }).waitFor({ state: 'visible' });
- const projectActionSizes = await page.evaluate(() => ({
- move: document.querySelector('.m-project-move').getBoundingClientRect().height,
- create: document.querySelector('.m-project-new-chat').getBoundingClientRect().height,
- }));
- check('项目移动与新建入口点击区域至少44px', projectActionSizes.move >= 44 && projectActionSizes.create >= 44, JSON.stringify(projectActionSizes));
- check('可将当前对话直接移入另一个项目', true);
- await page.getByRole('button', { name: '将当前对话移入此项目' }).click();
- await page.waitForFunction(() => document.querySelector('.m-project-name')?.textContent?.trim() === '外壳 3D');
- await page.waitForFunction(() => document.querySelectorAll('.m-project-session').length === 6);
- check('移动后当前项目与项目会话列表即时更新', (await page.locator('.m-project-name').innerText()) === '外壳 3D' &&
- (await page.locator('.m-project-session').count()) === 6);
- await go('chat/zhixia/$ui-review-0');
- await page.getByRole('button', { name: '选择项目并切换对话' }).click();
- await page.getByRole('button', { name: '创建新项目' }).click();
- await page.locator('#m-new-project-name').fill('总装演示');
- await page.getByRole('button', { name: '创建项目' }).click();
- await page.getByText('这个项目还没有对话').waitFor();
- check('创建项目后明确提示空项目并可直接新建', (await page.locator('.m-project-head h2').innerText()) === '总装演示' &&
- (await page.locator('.m-project-empty').innerText()).includes('新建后会自动归入此项目') &&
- await page.locator('.m-project-new-chat').isVisible());
- await page.locator('.m-project-new-chat').click();
- const newChatSheet = page.locator('app-m-new-chat .m-sheet-root');
- await newChatSheet.waitFor({ state: 'visible' });
- check('可在新项目中启动新对话', await newChatSheet.isVisible());
- await page.locator('app-m-new-chat .m-row:not([disabled])').first().click();
- await page.waitForFunction(() => document.querySelector('.m-project-name')?.textContent?.trim() === '总装演示');
- check('选择数字生命后新对话归属新项目', (await page.locator('.m-project-name').innerText()) === '总装演示');
- await page.getByRole('button', { name: '选择项目并切换对话' }).click();
- await page.getByRole('button', { name: '创建新项目' }).click();
- await page.locator('#m-new-project-name').fill('空项目重试');
- await page.getByRole('button', { name: '创建项目' }).click();
- await page.getByText('这个项目还没有对话', { exact: true }).waitFor();
- await page.waitForFunction(() => {
- const picker = window.ng.getComponent(document.querySelector('app-m-project-switcher'));
- return picker && !picker.loadingSessions();
- });
- await page.evaluate(() => {
- const picker = window.ng.getComponent(document.querySelector('app-m-project-switcher'));
- window.__reviewEnsureLoaded = picker.live.ensureLoaded.bind(picker.live);
- picker.live.ensureLoaded = async () => { throw new Error('模拟同步失败'); };
- void picker.loadSessions();
- });
- await page.getByText('对话暂时没能加载', { exact: true }).waitFor();
- check('会话目录加载失败时不再无限转圈,提供重试且新建仍可用',
- await page.getByRole('button', { name: '重试加载' }).isVisible() && await page.locator('.m-project-new-chat').isVisible());
- await page.evaluate(() => {
- const picker = window.ng.getComponent(document.querySelector('app-m-project-switcher'));
- picker.live.ensureLoaded = window.__reviewEnsureLoaded;
- });
- await page.getByRole('button', { name: '重试加载' }).click();
- await page.waitForFunction(() => {
- const picker = window.ng.getComponent(document.querySelector('app-m-project-switcher'));
- return !picker.loadingSessions() && picker.sessionLoadIssue() === 'none';
- });
- check('重试成功后切换到真实空项目说明', await page.getByText('这个项目还没有对话', { exact: true }).isVisible() &&
- await page.locator('.m-project-new-chat').isVisible());
- await page.keyboard.press('Escape');
- check('Esc 可关闭项目选择器', await projectPicker.count() === 0);
- await page.setViewportSize({ width: 320, height: 480 });
- await page.evaluate(() => document.documentElement.style.setProperty('--ui-scale', '1.75'));
- await page.getByRole('button', { name: '选择项目并切换对话' }).click();
- await page.getByRole('searchbox', { name: '搜索项目', exact: true }).fill('外壳');
- await page.locator('.m-project-sheet').evaluate(el => Promise.all(el.getAnimations().map(a => a.finished)));
- const compactProject = await page.locator('.m-project-sheet').evaluate((el) => {
- const footer = el.querySelector('.m-project-foot').getBoundingClientRect();
- const clear = el.querySelector('.m-project-search button').getBoundingClientRect();
- const rect = el.getBoundingClientRect();
- return { fits: rect.top >= 0 && rect.bottom <= innerHeight + 1 && rect.right <= innerWidth,
- footer: footer.bottom <= innerHeight + 1, clear: clear.width >= 44 && clear.height >= 44,
- scrollable: getComputedStyle(el.querySelector('.m-project-list')).overflowY === 'auto' };
- });
- check('小高度大字项目弹层按钮可达且内容独立滚动', Object.values(compactProject).every(Boolean), JSON.stringify(compactProject));
- await page.screenshot({ path: resolve(out, 'project-compact-large.png') });
- await page.getByRole('button', { name: '完成', exact: true }).click();
- await page.setViewportSize({ width: 390, height: 844 });
- await page.evaluate(() => document.documentElement.style.setProperty('--ui-scale', '1'));
- await go('chat/zhixia/$ui-review-0');
- const draft = 'UI审查第一行';
- await textarea.fill(draft);
- await textarea.press('Enter');
- check('Enter 换行且保留草稿', (await textarea.inputValue()) === draft + '\n');
- const composing = await textarea.evaluate((el) => {
- const event = new KeyboardEvent('keydown', { key: 'Enter', ctrlKey: true, isComposing: true, bubbles: true, cancelable: true });
- el.dispatchEvent(event);
- return { prevented: event.defaultPrevented, value: el.value };
- });
- check('组合态快捷键不提交', !composing.prevented && composing.value === draft + '\n');
- const message = 'UI审查发送验证-' + Date.now();
- await textarea.fill(message + '\n第二行\n第三行');
- const expanded = await textarea.evaluate((el) => el.getBoundingClientRect().height);
- await page.locator('app-m-dock .m-send').click();
- await page.waitForFunction((text) => document.querySelector('.m-chat-body')?.textContent?.includes(text), message);
- check('点击发送后草稿清空且高度复位', (await textarea.inputValue()) === '' &&
- (await textarea.evaluate((el) => el.getBoundingClientRect().height)) < expanded);
- check('演示消息显示在当前会话', (await page.locator('.m-chat-body').innerText()).includes(message));
- const tools = await page.locator('app-m-dock button').evaluateAll((els) => els.map((el) => {
- const r = el.getBoundingClientRect(); return { width: r.width, height: r.height };
- }));
- check('输入工具点击区域至少44px', tools.every((r) => r.width >= 44 && r.height >= 44));
- await page.getByRole('button', { name: '查看成果与状态' }).click();
- const detailSheet = page.locator('[aria-label="会话面板"]');
- await detailSheet.waitFor({ state: 'visible', timeout: 5000 });
- check('会话详情可打开', await detailSheet.isVisible());
- await detailSheet.locator('.m-sheet-x').click();
- await detailSheet.waitFor({ state: 'detached', timeout: 5000 });
- check('会话详情可关闭', (await detailSheet.count()) === 0);
- await go('workbench');
- const cardGap = await page.locator('.m-life-card').evaluateAll((els) => els[1].getBoundingClientRect().top - els[0].getBoundingClientRect().bottom);
- check('工作台卡片间距12px', Math.abs(cardGap - 12) < 1);
- await page.locator('.m-body').evaluate((el) => { el.scrollTop = el.scrollHeight; });
- const lastCard = await page.locator('.m-life-card').last().boundingBox();
- const tab = await page.locator('.m-tabbar').boundingBox();
- check('末张卡片不被底栏遮挡', lastCard.y + lastCard.height <= tab.y + 1);
- await page.getByRole('button', { name: '打开导航' }).click();
- check('导航抽屉可打开', await page.locator('app-m-drawer').evaluate((el) => !!el.querySelector('.open, .is-open, [aria-modal="true"]')));
- await go('mine');
- const paletteButtons = page.locator('.m-palette');
- for (let i = 0; i < 4; i++) {
- await paletteButtons.nth(i).click();
- check('配色选中态 ' + i, await paletteButtons.nth(i).getAttribute('aria-pressed') === 'true');
- }
- await paletteButtons.first().click();
- await page.getByRole('switch', { name: '深色模式' }).click();
- check('深色模式与状态说明', await page.locator('html').evaluate((el) => el.classList.contains('dark')) &&
- (await page.locator('.m-row--plain').innerText()).includes('已开启'));
- // 先把界面大小归「标准」,后面单独验证界面档位的效果
- await page.getByRole('radio', { name: '标准', exact: true }).click();
- const uiScaleBefore = await page.evaluate(() => document.documentElement.style.getPropertyValue('--ui-scale'));
- await page.locator('.m-slider').fill('18');
- for (const route of routes) {
- await page.setViewportSize({ width: 320, height: 700 });
- await go(route);
- const appearance = await page.evaluate((uiBefore) => {
- const root = document.documentElement;
- return { dark: root.classList.contains('dark'), font: root.style.getPropertyValue('--chat-read-size'),
- // 2026-11-21:正文与界面拆开后,改正文不得推动界面比例
- scaleUnchanged: root.style.getPropertyValue('--ui-scale') === uiBefore,
- palette: root.dataset.palette,
- overflow: root.scrollWidth > innerWidth };
- }, uiScaleBefore);
- check('320px 深色大字 ' + route, appearance.dark && appearance.font === '18px' &&
- appearance.scaleUnchanged && appearance.palette === 'platinum' && !appearance.overflow, JSON.stringify(appearance));
- await page.waitForTimeout(300);
- await page.screenshot({ path: resolve(out, 'dark-large-' + route.split('/').slice(0, 2).join('-') + '.png') });
- }
- /*
- * 2026-11-21 字号拆分后的回归口径:
- * · 正文大小 → 只影响 --chat-read-size
- * · 界面大小 → 驱动 --ui-scale / --icon-scale(标题、图标、栏高)
- * 原先的「标题/图标必须随正文档位单调递增」断言已被新设计取代。
- */
- await page.setViewportSize({ width: 390, height: 844 });
- await go('mine');
- if (await page.getByRole('radio', { name: '标准', exact: true }).isVisible().catch(() => false)) {
- await page.getByRole('radio', { name: '标准', exact: true }).click();
- }
- const fontSamples = [];
- for (const size of [14, 16, 20]) {
- await go('mine');
- await page.locator('.m-slider').fill(String(size));
- await page.waitForTimeout(100);
- const metrics = await page.evaluate(() => {
- const css = el => getComputedStyle(document.querySelector(el));
- const rect = el => document.querySelector(el).getBoundingClientRect();
- return { title: parseFloat(css('.m-title').fontSize), icon: parseFloat(css('.m-tab-icon').fontSize),
- bar: rect('.m-app-bar').height, tabbar: rect('.m-tabbar').height,
- touch: rect('.m-tab').height, input: parseFloat(css('.m-slider').fontSize),
- read: parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--chat-read-size')),
- overflow: document.documentElement.scrollWidth > innerWidth };
- });
- fontSamples.push(metrics);
- check('正文字号 ' + size + 'px 生效且保留点击面积', metrics.read === size && metrics.touch >= 44 && !metrics.overflow, JSON.stringify(metrics));
- await page.screenshot({ path: resolve(out, 'font-' + size + '-mine.png') });
- for (const route of ['messages', 'chat/zhixia/$ui-review-0']) {
- await go(route);
- const noOverflow = await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth);
- check('正文字号 ' + size + 'px 无横向溢出 ' + route, noOverflow);
- await page.screenshot({ path: resolve(out, 'font-' + size + '-' + route.split('/')[0] + '.png') });
- }
- }
- check('正文大小不改变导航标题', fontSamples[0].title === fontSamples[1].title && fontSamples[1].title === fontSamples[2].title,
- JSON.stringify(fontSamples.map(x => x.title)));
- // 界面大小:三档驱动标题/图标/栏高,但图标有上限(不撑满 44px 按钮)
- const uiSamples = [];
- for (const label of ['紧凑', '标准', '大']) {
- await go('mine');
- await page.getByRole('radio', { name: label, exact: true }).click();
- await page.waitForTimeout(100);
- uiSamples.push(await page.evaluate(() => {
- const css = el => getComputedStyle(document.querySelector(el));
- const rect = el => document.querySelector(el).getBoundingClientRect();
- return { title: parseFloat(css('.m-title').fontSize), icon: parseFloat(css('.m-tab-icon').fontSize),
- bar: rect('.m-app-bar').height, tabbar: rect('.m-tabbar').height,
- touch: rect('.m-tab').height };
- }));
- await page.screenshot({ path: resolve(out, 'ui-' + label + '-mine.png') });
- }
- for (const prop of ['title', 'icon', 'bar', 'tabbar']) {
- check('界面大小驱动 ' + prop, uiSamples[0][prop] <= uiSamples[1][prop] && uiSamples[1][prop] <= uiSamples[2][prop],
- JSON.stringify(uiSamples.map(x => x[prop])));
- }
- // 图标上限:最大档也不超过 21px(20 × 1.04),且触控区仍 44px
- check('最大界面档图标不撑满按钮', uiSamples[2].icon <= 21 && uiSamples[2].touch >= 44, JSON.stringify(uiSamples[2]));
- await go('mine');
- await page.getByRole('radio', { name: '标准', exact: true }).click();
- // 原生权限交互在隔离浏览器中用状态替身覆盖;真实投递另由装机测试验证。
- await go('mine');
- await page.evaluate(() => {
- const setup = window.ng.getComponent(document.querySelector('app-permission-guide')).setup;
- window.__permissionReview = { setup, settingsCalls: [] };
- setup.notifications.isGranted = async () => setup.granted();
- setup.notifications.request = async () => false;
- setup.push.start = async () => true;
- setup.settings.refresh = async () => null;
- setup.settings.open = async (target) => { window.__permissionReview.settingsCalls.push(target); return true; };
- setup.notifications.granted.set(false);
- document.documentElement.style.setProperty('--ui-scale', '1.75');
- setup.show();
- });
- const guide = page.locator('.pg-root');
- await guide.waitFor({ state: 'visible' });
- check('首次通知引导不展示省电步骤', await guide.getByRole('heading', { name: '不错过新消息' }).isVisible() && await guide.locator('.pg-saver').count() === 0);
- await page.screenshot({ path: resolve(out, 'permission-first-large.png') });
- await guide.getByRole('button', { name: '开启通知', exact: true }).click();
- await guide.getByRole('alert').waitFor();
- check('拒绝后保留引导且不自动跳设置', await guide.isVisible() && await page.evaluate(() => window.__permissionReview.settingsCalls.length === 0));
- await page.screenshot({ path: resolve(out, 'permission-denied-large.png') });
- await guide.getByRole('button', { name: '去系统设置', exact: true }).click();
- check('用户主动进入通知设置', await page.evaluate(() => window.__permissionReview.settingsCalls.join(',') === 'notifications'));
- await page.evaluate(() => window.__permissionReview.setup.notifications.granted.set(true));
- await guide.getByRole('heading', { name: '通知权限已开启' }).waitFor();
- // 2026-11-21:后台接收步骤从 1 个变成 2 个(省电策略 + 自启动),断言同步更新
- const saverCount = await guide.locator('.pg-saver').count();
- check('授权返回后展示后台接收步骤', saverCount === 2 &&
- (await guide.locator('.pg-saver').first().isVisible()));
- check('后台步骤含自启动入口', await guide.getByRole('button', { name: '去设置自启动' }).isVisible());
- check('权限已开不冒充推送已就绪', (await guide.locator('.pg-status').innerText()).includes('尚未启用'));
- for (const dark of [false, true]) {
- await page.evaluate((dark) => { document.documentElement.classList.toggle('dark', dark); document.documentElement.style.setProperty('--ui-scale', '1.75'); }, dark);
- const layout = await guide.evaluate((el) => {
- const card = el.querySelector('.pg-card').getBoundingClientRect();
- const actions = el.querySelector('.pg-actions').getBoundingClientRect();
- const body = el.querySelector('.pg-body');
- return { fits: card.x >= 0 && card.right <= innerWidth && card.y >= 0 && card.bottom <= innerHeight,
- actions: actions.bottom <= innerHeight && actions.height > 44,
- scrollable: getComputedStyle(body).overflowY === 'auto', overflow: document.documentElement.scrollWidth > innerWidth };
- });
- check('320px 140%系统字与20px应用字 ' + (dark ? '深色' : '浅色'), layout.fits && layout.actions && layout.scrollable && !layout.overflow, JSON.stringify(layout));
- await page.screenshot({ path: resolve(out, `permission-large-${dark ? 'dark' : 'light'}.png`) });
- }
- await page.keyboard.press('Escape');
- check('通知引导支持Esc关闭', await guide.count() === 0);
- check('无浏览器运行异常', errors.length === 0, errors.join(' | '));
- await writeFile(resolve(out, 'results.json'), JSON.stringify({ results, errors }, null, 2));
- console.log('结果:' + results.filter((r) => r.ok).length + '/' + results.length + ';截图:' + out);
- if (results.some((r) => !r.ok)) process.exitCode = 1;
- }
- } catch (error) {
- console.error(error);
- process.exitCode = 1;
- } finally {
- await browser?.close();
- stop();
- }
|