fix(frontend): 修复文件树点击切换竞态

This commit is contained in:
2026-08-30 10:29:08 +08:00
parent 99a0595dbc
commit 1564df434d
4 changed files with 104 additions and 3 deletions
@@ -0,0 +1,32 @@
// @vitest-environment happy-dom
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { mount, type VueWrapper } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import WorkspaceView from './WorkspaceView.vue'
import { useWorkspaceStore } from '@/stores/workspace'
let wrapper: VueWrapper | null = null
beforeEach(() => {
localStorage.clear()
setActivePinia(createPinia())
})
afterEach(() => {
wrapper?.unmount()
wrapper = null
})
describe('WorkspaceView initial file', () => {
it('does not overwrite a file selected while the welcome note is loading', async () => {
const workspaceStore = useWorkspaceStore()
wrapper = mount(WorkspaceView, {
global: { stubs: { EditorHeader: true, EditorPane: true } },
})
workspaceStore.openFile('/数据结构/红黑树.md')
await new Promise((resolve) => setTimeout(resolve, 0))
expect(workspaceStore.activeFilePath).toBe('/数据结构/红黑树.md')
})
})