macos-web/tests/cases/42-vscode.test.ts

29 lines
1.6 KiB
TypeScript

/**
* 42-vscode: VS Code Web Vue 组件化测试
* 覆盖: 文件树容器/资源管理器标题、编辑器/状态栏、appState、卸载
* ⚠️ FS mock 在 jsdom 中 vi.mock 不稳定,验证 DOM 结构
*/
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { h, render } from 'vue'
import VSCodeComponent from '../../src/apps/vscode/VSCode.vue'
import { setupDOM } from '../helpers'
describe('42-vscode', () => {
let body: HTMLElement, win: any
beforeEach(() => {
setupDOM(); const el = document.createElement('div'); el.className = 'window'; document.body.appendChild(el)
body = document.createElement('div'); body.className = 'win-body'; el.appendChild(body)
win = { el, body, timers: [], data: {} };
(window as any).FS = { HOME: '/Users/guest', TRASH: '/Users/guest/.Trash', walk: () => {}, read: () => '', write: () => {}, baseName: (p: string) => p.split('/').pop() || '' }
})
afterEach(() => { render(null, body); win.el.remove() })
function m() { render(h(VSCodeComponent, { win }), body) }
it('资源管理器标题', () => { m(); expect(body.querySelector('.fb-side-title')?.textContent).toBe('资源管理器') })
it('vs-tree 容器存在', () => { m(); expect(body.querySelector('.vs-tree')).toBeTruthy() })
it('编辑器 textarea 存在', () => { m(); expect(body.querySelector('.vs-editor')).toBeTruthy() })
it('状态栏存在', () => { m(); expect(body.querySelector('.vs-status')).toBeTruthy() })
it('appState.save 存在', () => { m(); expect(typeof win.appState.save).toBe('function') })
it('卸载', () => { m(); render(null, body); expect(body.children.length).toBe(0) })
})