| 1234567891011121314151617181920212223242526272829 |
- /** 本地 UI 取证隔离与几何检查,供审查脚本和故障夹具共用。 */
- export function isUiAssetRequest(request, origin) {
- const url = new URL(request.url());
- return url.origin === origin && !/^\/(?:api(?:-platform)?|parse)(?:\/|$)/i.test(url.pathname);
- }
- export async function assertExpectedUiPage(page, { origin, pathname, selector, timeout = 10000 }) {
- const actual = new URL(page.url());
- if (actual.origin !== origin || decodeURIComponent(actual.pathname) !== pathname) {
- throw new Error('原型路由发生重定向:' + actual.pathname + ',预期 ' + pathname);
- }
- await page.locator(selector).first().waitFor({ state: 'attached', timeout });
- const angular = await page.locator(selector).first().evaluate(el =>
- !!document.querySelector('app-root') && !!globalThis.ng?.getComponent(el));
- if (!angular) throw new Error('不是当前 Angular Mock 页面,停止操作');
- }
- export async function uiLayoutMetrics(page) {
- const expectedWidth = page.viewportSize().width;
- return page.evaluate(expected => {
- const root = document.documentElement;
- const width = root.clientWidth;
- return {
- viewport: expected, width, scrollWidth: root.scrollWidth,
- overflow: root.scrollWidth > width + 1 || innerWidth > width + 1 || Math.abs(width - expected) > 1,
- content: document.body.innerText.trim().length, path: location.pathname,
- };
- }, expectedWidth);
- }
|