/** * 27-safari: Safari Vue 组件化测试 */ import { describe, it, expect, beforeEach, afterEach } from 'vitest' import { h, render, nextTick } from 'vue' import SafariComponent from '../../src/apps/safari/Safari.vue' import { setupDOM } from '../helpers' function makeMockWin() { const el = document.createElement('div'); el.className = 'window' document.getElementById('window-layer')?.appendChild(el) const body = document.createElement('div'); body.className = 'win-body' el.appendChild(body) return { id: 'sf', appId: 'safari', el, body, timers: [] as any[], data: {} } } describe('27-safari — Safari Vue 组件化', () => { let win: any beforeEach(() => { setupDOM(); win = makeMockWin() }) afterEach(() => { render(null, win.body); win.el.remove() }) function mount() { const v = h(SafariComponent, { win }); render(v, win.body) } it('挂载后渲染起始页', async () => { mount(); await nextTick(); await nextTick() // setTimeout 380ms 后导航到 start await new Promise(r => setTimeout(r, 500)) expect(win.body.querySelector('.sf-start')).toBeTruthy() }) it('地址栏存在', () => { mount(); expect(win.body.querySelector('.sf-addr')).toBeTruthy() }) it('有后退/前进/刷新按钮', () => { mount() expect(win.body.querySelector('.fb-btn[title="后退"]')).toBeTruthy() expect(win.body.querySelector('.fb-btn[title="前进"]')).toBeTruthy() }) it('导航到内置页后显示内容', async () => { win.data = { url: 'macos://weather' } mount() await new Promise(r => setTimeout(r, 500)) expect(win.body.querySelector('.sf-builtin')).toBeTruthy() }) it('暴露 back/fwd/reload 给菜单', () => { mount() expect(typeof win.appState.back).toBe('function') expect(typeof win.appState.fwd).toBe('function') expect(typeof win.appState.reload).toBe('function') }) it('卸载后 DOM 为空', () => { mount(); render(null, win.body); expect(win.body.children.length).toBe(0) }) })