feat: 学习会话页改用碎片标签匹配相关导图

This commit is contained in:
2026-11-20 18:06:55 +08:00
parent 469e8eb5e1
commit f409b91b1b
6 changed files with 505 additions and 216 deletions
+162 -53
View File
@@ -16,7 +16,9 @@ import {
startOrContinueStudySession,
} from '@/api/studySessions'
import { getFragmentsBySession } from '@/api/reportFragments'
import { getStandardMindMap, updateStandardMindMap } from '@/api/standardMindMap'
import { getTaskReview } from '@/api/review'
import { getMarkersBatch } from '@/api/markers'
import { getRecall, listRecalls } from '@/api/recalls'
vi.mock('@/api/studySessions', () => ({
abortSession: vi.fn(),
@@ -48,9 +50,17 @@ vi.mock('@/api/reportFragments', () => ({
updateFragments: vi.fn(),
}))
vi.mock('@/api/standardMindMap', () => ({
getStandardMindMap: vi.fn(),
updateStandardMindMap: vi.fn(),
vi.mock('@/api/review', () => ({
getTaskReview: vi.fn(),
}))
vi.mock('@/api/markers', () => ({
getMarkersBatch: vi.fn(),
}))
vi.mock('@/api/recalls', () => ({
getRecall: vi.fn(),
listRecalls: vi.fn(),
}))
const defaultSessionData = {
@@ -102,7 +112,12 @@ describe('StartTask.vue', () => {
vi.mocked(startOrContinueStudySession).mockResolvedValue({ code: 200, data: defaultSessionData } as any)
vi.mocked(getExpectation).mockResolvedValue({ code: 200, data: { description: '本次学习预期' } } as any)
vi.mocked(getFragmentsBySession).mockResolvedValue({ code: 200, data: [] } as any)
vi.mocked(getStandardMindMap).mockResolvedValue({ code: 200, data: null } as any)
vi.mocked(getTaskReview).mockResolvedValue({ code: 200, data: [] } as any)
vi.mocked(getMarkersBatch).mockResolvedValue({ code: 200, data: {} } as any)
vi.mocked(listRecalls).mockResolvedValue({
code: 200,
data: { current: 1, size: 100, total: 0, records: [] },
} as any)
vi.mocked(ElMessageBox.confirm).mockResolvedValue('confirm')
await router.push('/login')
await router.isReady()
@@ -296,78 +311,172 @@ describe('StartTask.vue', () => {
wrapper.unmount()
})
it('闭环-05:展示任务基础导图,并把编辑结果整体 PUT 保存', async () => {
vi.mocked(getStandardMindMap).mockResolvedValue({
it('相关导图默认收起,展开前不读取', async () => {
const wrapper = await mountTask()
expect(wrapper.find('.mindmap-toggle').exists()).toBe(true)
expect(wrapper.find('.mindmap-body').exists()).toBe(false)
expect(getTaskReview).not.toHaveBeenCalled()
expect(getMarkersBatch).not.toHaveBeenCalled()
expect(listRecalls).not.toHaveBeenCalled()
wrapper.unmount()
})
it('展开后只列出与任务碎片标签有交集的回忆,并标出命中标签', async () => {
vi.mocked(getTaskReview).mockResolvedValue({
code: 200,
data: [
{ id: 11, sourceType: 'FRAGMENT', taskNum: 'T001', taskName: '测试任务' },
{ id: 12, sourceType: 'FRAGMENT', taskNum: 'T001', taskName: '测试任务' },
{ id: 99, sourceType: 'REPORT', taskNum: 'T001', taskName: '测试任务' },
],
} as any)
vi.mocked(getMarkersBatch).mockResolvedValue({
code: 200,
data: {
id: 1,
taskNum: 'T001',
title: '根主题',
content: JSON.stringify({ title: '根主题', children: [{ title: '子节点', children: [] }] }),
outline: '- 根主题\n - 子节点',
summary: '',
generator: 'AI',
sourceReportCount: 1,
'11': [
{ kind: 'USER', markerName: '线性代数' },
{ kind: 'SYSTEM', markerName: '来源' },
],
'12': [{ kind: 'USER', markerName: '测试任务' }],
},
} as any)
vi.mocked(updateStandardMindMap).mockResolvedValue({
vi.mocked(listRecalls).mockResolvedValue({
code: 200,
data: {
id: 1,
taskNum: 'T001',
title: '根主题',
content: JSON.stringify({ title: '根主题', children: [{ title: '改过的子节点', children: [] }] }),
outline: '- 根主题\n - 改过的子节点',
summary: '用户编辑,共 2 个节点',
generator: 'USER',
sourceReportCount: 1,
current: 1,
size: 100,
total: 2,
records: [
{
recallNum: 'R1',
status: 'ENDED',
scope: {
type: 'TAG',
tags: ['线性代数', '概率论'],
displayName: '线性代数 / 概率论',
},
updatedAt: '2026-11-20T10:00:00',
},
{
recallNum: 'R2',
status: 'ENDED',
scope: { type: 'TAG', tags: ['英语'], displayName: '英语' },
updatedAt: '2026-11-19T10:00:00',
},
],
},
} as any)
const wrapper = await mountTask()
await wrapper.find('.mindmap-toggle').trigger('click')
await flushPromises()
expect(getMarkersBatch).toHaveBeenCalledWith('FRAGMENT', ['11', '12'])
expect(listRecalls).toHaveBeenCalledWith(
{ scopeType: 'TAG', pageNum: 1, pageSize: 100 },
{ silent: true },
)
const rows = wrapper.findAll('.related-map-row')
expect(rows).toHaveLength(1)
expect(rows[0].text()).toContain('线性代数 / 概率论')
expect(rows[0].text()).toContain('命中标签:线性代数')
expect(rows[0].text()).not.toContain('英语')
wrapper.unmount()
})
it('任务没有带用户标签的碎片时,展开只给一行空态', async () => {
vi.mocked(getTaskReview).mockResolvedValue({
code: 200,
data: [{ id: 11, sourceType: 'FRAGMENT', taskNum: 'T001' }],
} as any)
vi.mocked(getMarkersBatch).mockResolvedValue({ code: 200, data: { '11': [] } } as any)
const wrapper = await mountTask()
await wrapper.find('.mindmap-toggle').trigger('click')
await flushPromises()
expect(listRecalls).not.toHaveBeenCalled()
expect(wrapper.text()).toContain('这个任务的知识碎片标签还没有对应的回忆导图')
wrapper.unmount()
})
it('点击一条回忆后只读渲染完整导图', async () => {
vi.mocked(getTaskReview).mockResolvedValue({
code: 200,
data: [{ id: 11, sourceType: 'FRAGMENT', taskNum: 'T001' }],
} as any)
vi.mocked(getMarkersBatch).mockResolvedValue({
code: 200,
data: { '11': [{ kind: 'USER', markerName: '线性代数' }] },
} as any)
vi.mocked(listRecalls).mockResolvedValue({
code: 200,
data: {
current: 1,
size: 100,
total: 1,
records: [
{
recallNum: 'R1',
status: 'ENDED',
scope: { type: 'TAG', tags: ['线性代数'], displayName: '线性代数' },
updatedAt: '2026-11-20T10:00:00',
},
],
},
} as any)
vi.mocked(getRecall).mockResolvedValue({
code: 200,
data: {
recallNum: 'R1',
expression: {
schemaVersion: 1,
root: { id: 'root', title: '根主题', notes: '', provenance: [], children: [] },
},
},
} as any)
const wrapper = await mountTask({
MindMapViewer: {
name: 'MindMapViewer',
props: { tree: Object, recallContent: Boolean, height: String },
template: '<div class="mindmap-stub" />',
methods: { toOutline: () => '- 根主题\n - 改过的子节点' },
},
})
// 拉取到导图后能渲染成树
expect(getStandardMindMap).toHaveBeenCalledWith('T001')
expect((wrapper.vm.standardTree as any)?.title).toBe('根主题')
wrapper.vm.startEditStandard()
await wrapper.find('.mindmap-toggle').trigger('click')
await flushPromises()
await wrapper.find('.related-map-row').trigger('click')
await flushPromises()
expect(wrapper.vm.editingStandard).toBe(true)
await wrapper.vm.saveStandardEdit()
expect(updateStandardMindMap).toHaveBeenCalledWith('T001', '- 根主题\n - 改过的子节点')
expect(wrapper.vm.editingStandard).toBe(false)
expect((wrapper.vm.standard as any)?.outline).toBe('- 根主题\n - 改过的子节点')
wrapper.unmount()
})
it('闭环-05:倒计时在基础导图之上', async () => {
const wrapper = await mountTask()
const html = wrapper.html()
expect(html).toContain('timer-card')
expect(html).toContain('mindmap-card')
expect(html.indexOf('timer-card')).toBeLessThan(html.indexOf('mindmap-card'))
expect(getRecall).toHaveBeenCalledWith('R1')
const viewer = wrapper.findComponent({ name: 'MindMapViewer' })
expect(viewer.exists()).toBe(true)
expect(viewer.props('recallContent')).toBe(true)
expect((viewer.props('tree') as any)?.title).toBe('根主题')
expect(viewer.props('editable')).toBeUndefined()
wrapper.unmount()
})
it('闭环-05:没有导图时可用任务名作为根节点新建', async () => {
vi.mocked(getStandardMindMap).mockResolvedValue({ code: 200, data: null } as any)
const wrapper = await mountTask()
it('读取失败给出原因并能重试', async () => {
vi.mocked(getTaskReview).mockRejectedValueOnce(new Error('network'))
expect(wrapper.vm.standardTree).toBeNull()
wrapper.vm.startEditStandard()
const wrapper = await mountTask()
await wrapper.find('.mindmap-toggle').trigger('click')
await flushPromises()
expect((wrapper.vm.editableStandardTree as any)?.title).toBe('测试任务')
expect(wrapper.text()).toContain('相关导图读取失败')
vi.mocked(getTaskReview).mockResolvedValue({ code: 200, data: [] } as any)
await wrapper.find('.mindmap-retry').trigger('click')
await flushPromises()
expect(wrapper.text()).toContain('这个任务的知识碎片标签还没有对应的回忆导图')
wrapper.unmount()
})
})