test: 补 Contacts mount 后 store 可读、FaceTime 跨组件集成回归测试(拦截 persist 遗漏 bug)

This commit is contained in:
李岩岩 2026-07-23 14:06:16 +08:00
parent 2298f22b03
commit 3cbe69064f
2 changed files with 31 additions and 0 deletions

View File

@ -272,6 +272,15 @@ describe('32-contacts — Contacts Vue 组件化', () => {
expect(win.body.querySelector('.note-title')?.textContent).toBe('自定义')
})
// ⚠️ 关键回归测试mount 后 store 必须可读取默认数据
// 这是 FaceTime 等跨组件读取联系人的前提
it('mount 后 store.get 可读取默认联系人', () => {
mount()
const data = store.get('contacts', [])
expect(data.length).toBeGreaterThanOrEqual(1)
expect(data[0].name).toBeTruthy()
})
it('新增联系人后 store 更新', async () => {
mount()
const addBtn = win.body.querySelector('.fb-btn') as HTMLElement

View File

@ -73,6 +73,28 @@ describe('34-facetime', () => {
it('暴露 startCall', () => { m(); expect(typeof w.appState.startCall).toBe('function') })
it('startCall 呼叫', async () => { m(); w.appState.startCall(C[0]); await nextTick(); expect(document.querySelector('.ft-status')?.textContent).toContain('正在呼叫') })
// --- integration: store 空时不预设数据,模拟真实首次打开 ---
describe('store 集成', () => {
it('store 有数据时显示联系人', () => { m(); expect(document.querySelector('.ft-cell')).toBeTruthy() })
// ⚠️ 回归:真实流程 Contacts mount→persist→FaceTime mount 可读
it('Contacts mount 后 FaceTime 可读取', async () => {
// 模拟真实流程:先 mount Contacts 写 store再 mount FaceTime 读
const ContactsComponent = (await import('../../src/apps/contacts/Contacts.vue')).default
const cEl = document.createElement('div'); cEl.className = 'window'; document.body.appendChild(cEl)
const cBody = document.createElement('div'); cBody.className = 'win-body'; cEl.appendChild(cBody)
const cWin = { id: 'ct', appId: 'contacts', el: cEl, body: cBody, timers: [], data: {} }
render(h(ContactsComponent, { win: cWin }), cBody)
await nextTick()
// 验证 Contacts 已 persist
const contacts = store.get('contacts', [])
expect(contacts.length).toBeGreaterThanOrEqual(1)
// FaceTime 应能读取
render(null, w.body); m()
expect(document.querySelector('.ft-cell')).toBeTruthy()
render(null, cBody); cEl.remove()
})
})
// --- unmount ---
it('卸载', () => { m(); render(null, w.body); expect(w.body.children.length).toBe(0) })
})