import test, { before, after } from 'node:test'; import assert from 'node:assert/strict'; import { chromium } from 'playwright'; import { existsSync } from 'node:fs'; import { isUiAssetRequest, assertExpectedUiPage, uiLayoutMetrics } from './lib/ui-review-isolation.mjs'; let browser; before(async () => { const executablePath = ['C:/Program Files/Google/Chrome/Application/chrome.exe','C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'].find(existsSync); browser = await chromium.launch({ headless: true, ...(executablePath ? { executablePath } : {}) }); }); after(async () => { await browser?.close(); }); test('local business proxy endpoints and remote origins are blocked', () => { const origin = 'http://127.0.0.1:4400'; for (const url of [origin + '/api/functions', origin + '/api-platform/functions', origin + '/parse/classes/Agent', 'https://server.fmode.cn/a.js']) { assert.equal(isUiAssetRequest({ url: () => url }, origin), false); } assert.equal(isUiAssetRequest({ url: () => origin + '/chunk-ABC.js' }, origin), true); }); test('mobile layout overflow is detected even when innerWidth expands', async () => { const context = await browser.newContext({ viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true }); try { const page = await context.newPage(); await page.setContent('
wide fixture
'); const measured = await uiLayoutMetrics(page); assert.equal(measured.width, 390); assert.equal(measured.overflow, true); } finally { await context.close(); } }); test('a non-Angular local HTML page is rejected before interaction', async () => { const context = await browser.newContext(); try { await context.route('**/*', route => route.fulfill({ contentType: 'text/html', body: 'fixture' })); const page = await context.newPage(); await page.goto('http://127.0.0.1:4400/mobile/messages'); await assert.rejects(assertExpectedUiPage(page, { origin: 'http://127.0.0.1:4400', pathname: '/mobile/messages', selector: 'app-mb-messages-page' }), /不是当前 Angular Mock/); } finally { await context.close(); } }); test('a redirected route cannot be captured as the requested page', async () => { const context = await browser.newContext(); try { const page = await context.newPage(); await assert.rejects(assertExpectedUiPage(page, { origin: 'http://127.0.0.1:4400', pathname: '/mobile/messages', selector: 'app-mb-messages-page' }), /路由发生重定向/); } finally { await context.close(); } });