/** * 26-preview: Preview Vue 组件化测试 */ import { describe, it, expect, beforeEach, afterEach } from 'vitest' import { h, render, nextTick } from 'vue' import PreviewComponent from '../../src/apps/preview/Preview.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: 'pv', appId: 'preview', el, body, timers: [] as any[], data: {} } } describe('26-preview — Preview Vue 组件化', () => { let win: any beforeEach(() => { setupDOM(); win = makeMockWin() }) afterEach(() => { render(null, win.body); win.el.remove() }) function mount() { const v = h(PreviewComponent, { win }); render(v, win.body) } it('挂载后渲染画廊', () => { mount(); expect(win.body.querySelector('.preview-gallery')).toBeTruthy() }) it('工具栏有缩放/旋转按钮', () => { mount() expect(win.body.querySelector('.fb-btn[title="放大"]')).toBeTruthy() expect(win.body.querySelector('.fb-btn[title="缩小"]')).toBeTruthy() }) it('暴露 zoom/zoomReset 给菜单', () => { mount() expect(typeof win.appState.zoom).toBe('function') expect(typeof win.appState.zoomReset).toBe('function') }) it('卸载后 DOM 为空', () => { mount(); render(null, win.body); expect(win.body.children.length).toBe(0) }) })