| 12345678910111213141516171819202122232425262728 |
- /** 验证:运行中改变窗口宽度会自动切换端 */
- import { chromium } from 'playwright';
- import { loadDevLogin } from './dev-login.mjs';
- const login = loadDevLogin();
- const b = await chromium.launch({ headless: true, channel: 'chromium' });
- const ctx = await b.newContext({ viewport: { width: 1440, height: 900 } });
- const p = await ctx.newPage();
- await p.addInitScript((d) => {
- localStorage.setItem('fmode_session_token', d.token);
- localStorage.setItem('fmode_me', JSON.stringify(d.me));
- }, login.payload);
- await p.goto('http://localhost:4200/', { waitUntil: 'domcontentloaded' });
- await p.waitForTimeout(5000);
- console.log('初始(1440):', p.url().replace('http://localhost:4200',''), p.url().includes('/desktop/') ? '✅' : '❌');
- // 缩窄 → 应自动跳移动端
- await p.setViewportSize({ width: 600, height: 900 });
- await p.waitForTimeout(3000);
- const u1 = p.url();
- console.log('缩窄到 600:', u1.replace('http://localhost:4200',''), u1.includes('/mobile/') ? '✅ 自动切换' : '❌ 未切换');
- // 再变宽 → 应自动跳回桌面
- await p.setViewportSize({ width: 1400, height: 900 });
- await p.waitForTimeout(3000);
- const u2 = p.url();
- console.log('放宽到 1400:', u2.replace('http://localhost:4200',''), u2.includes('/desktop/') ? '✅ 自动切回' : '❌ 未切回');
- await b.close();
|