feat: 回忆对比记录并展示复习耗时

This commit is contained in:
2026-10-09 11:16:30 +08:00
parent 99a1b16196
commit 21af81f48c
11 changed files with 424 additions and 6 deletions
@@ -1,4 +1,4 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { flushPromises, mount } from '@vue/test-utils'
import ElementPlus, { ElMessage } from 'element-plus'
import { createMemoryHistory, createRouter } from 'vue-router'
@@ -46,9 +46,13 @@ const MindMapViewerStub = {
*/
describe('ReviewRecall 交互流程(集成)', () => {
beforeEach(() => {
// 只伪造 Date,保留真实定时器,避免 flushPromises 卡住
vi.useFakeTimers({ toFake: ['Date'] })
vi.clearAllMocks()
localStorage.clear()
localStorage.setItem('isLoggedIn', 'true')
// clearAllMocks 不会重置 mockReturnValue,需显式恢复默认大纲
toOutline.mockReturnValue('根主题\n- 子节点')
vi.mocked(getStandardMindMap).mockResolvedValue(ok(standardMap))
vi.mocked(listRecallRecords).mockResolvedValue(
@@ -76,6 +80,10 @@ describe('ReviewRecall 交互流程(集成)', () => {
vi.mocked(recallCompare).mockResolvedValue(ok(standardMap))
})
afterEach(() => {
vi.useRealTimers()
})
const mountPage = async () => {
const router = createRouter({
history: createMemoryHistory(),
@@ -104,8 +112,14 @@ describe('ReviewRecall 交互流程(集成)', () => {
await flushPromises()
await flushPromises()
expect(recallCompare).toHaveBeenCalledWith('T001', '根主题\n- 子节点', undefined)
expect(recallCompare).toHaveBeenCalledWith('T001', '根主题\n- 子节点', undefined, {
startedAt: expect.stringMatching(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/),
lastInteractionAt: expect.stringMatching(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/),
durationSeconds: expect.any(Number),
})
expect(ElMessage.success).toHaveBeenCalledWith('回忆对比完成')
// 提交后统计卡片展示“本次耗时”
expect(wrapper.text()).toContain('本次耗时')
// 对比完成后出现“清空重写”入口(v-if=hasCompared)
expect(wrapper.findAll('button').some((b) => b.text().trim() === '清空重写')).toBe(true)
wrapper.unmount()
@@ -124,4 +138,28 @@ describe('ReviewRecall 交互流程(集成)', () => {
expect(recallCompare).not.toHaveBeenCalled()
wrapper.unmount()
})
it('提交按钮点击不计入交互,耗时以编辑区最后一次交互为准', async () => {
vi.setSystemTime(new Date(2026, 0, 15, 9, 0, 0))
const { wrapper } = await mountPage()
// 在回忆编辑区交互一次
vi.setSystemTime(new Date(2026, 0, 15, 9, 0, 10))
await wrapper.find('.recall-edit-area').trigger('pointerdown')
// 之后 20 秒无交互,直接点提交按钮
vi.setSystemTime(new Date(2026, 0, 15, 9, 0, 30))
const submit = wrapper.findAll('button').find((b) => b.text().trim() === '提交对比')!
await submit.trigger('click')
await flushPromises()
await flushPromises()
expect(recallCompare).toHaveBeenCalledWith('T001', '根主题\n- 子节点', undefined, {
startedAt: '2026-01-15T09:00:00',
lastInteractionAt: '2026-01-15T09:00:10',
durationSeconds: 30,
})
expect(wrapper.text()).toContain('30秒')
wrapper.unmount()
})
})