macos-web/tests/cases/01-boot.test.ts
2026-07-20 14:30:44 +08:00

27 lines
1.1 KiB
TypeScript

/**
* 01-boot: 核心初始化——FS、Bus、Store
*/
import { describe, it, expect, beforeEach } from 'vitest'
import { bus } from '../../src/composables/useBus'
import { store } from '../../src/composables/useStore'
import { fs } from '../../src/composables/useFS'
describe('01-boot — 核心初始化', () => {
beforeEach(() => {
localStorage.clear()
// 重置 fs 内部状态
;(fs as any).root = null
fs.init()
})
it('FS 根节点类型为目录', () => { expect(fs.root!.t).toBe('d') })
it('home 目录存在', () => { expect(fs.exists(fs.HOME)).toBe(true) })
it('Desktop 目录存在', () => { expect(fs.exists(fs.HOME + '/Desktop')).toBe(true) })
it('welcome.txt 存在且包含欢迎语', () => {
expect(fs.exists(fs.HOME + '/Desktop/welcome.txt')).toBe(true)
expect(fs.read(fs.HOME + '/Desktop/welcome.txt')).toContain('欢迎使用 macOS 网页版')
})
it('Bus 发布订阅', () => { let x: any = null; const u = bus.on('e', d => x = d); bus.emit('e', 1); expect(x).toBe(1); u() })
it('Store set/get', () => { store.set('k', { v: 1 }); expect(store.get('k', null)).toEqual({ v: 1 }) })
})