From f8e1a970aa3082613ffd1d33ac9929246aaf1be7 Mon Sep 17 00:00:00 2001 From: cat-shark <1716967236@qq.com> Date: Thu, 22 Oct 2026 22:01:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8C=89=E6=A0=87=E7=AD=BE=E5=A4=8D?= =?UTF-8?q?=E4=B9=A0=E9=A1=B5=E4=BB=A5=E5=B7=B2=E6=9C=89=E5=AF=BC=E5=9B=BE?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E4=B8=BA=E4=B8=BB=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/components/TagReview.spec.ts | 92 +++++++++- src/components/TagReview.vue | 197 +++++++++++++++++---- 2 files changed, 255 insertions(+), 34 deletions(-) diff --git a/src/__tests__/components/TagReview.spec.ts b/src/__tests__/components/TagReview.spec.ts index 74b74aa..2df334d 100644 --- a/src/__tests__/components/TagReview.spec.ts +++ b/src/__tests__/components/TagReview.spec.ts @@ -1,15 +1,18 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import { flushPromises, mount } from '@vue/test-utils' import ElementPlus from 'element-plus' +import { createMemoryHistory, createRouter } from 'vue-router' import TagReview from '@/components/TagReview.vue' -import { queryTagMindMap, listTagRecallRecords } from '@/api/tagMindMap' +import { queryTagMindMap, listTagRecallRecords, listTagMindMaps } from '@/api/tagMindMap' import { listTagCandidates } from '@/api/markers' +import { pageOf } from '../support/page' import { submitAiTask } from '@/api/aiTasks' vi.mock('@/api/tagMindMap', () => ({ queryTagMindMap: vi.fn(), updateTagMindMap: vi.fn(), listTagRecallRecords: vi.fn(), + listTagMindMaps: vi.fn(), })) vi.mock('@/api/markers', () => ({ @@ -42,9 +45,27 @@ const tagMap = { sourceFragmentCount: 3, } -const mountTagReview = async () => { +const listSummary = { + id: 1, + scopeKey: 'SCOPE_1', + tags: ['英语'], + mode: 'UNION', + title: '英语', + generator: 'AI', + sourceFragmentCount: 3, + needsUpdate: false, + generatedTime: '2026-10-10T10:00:00', +} + +const mountTagReview = async (query: Record = {}) => { + const router = createRouter({ + history: createMemoryHistory(), + routes: [{ path: '/review/by-tag', component: TagReview }], + }) + await router.push({ path: '/review/by-tag', query }) + await router.isReady() const wrapper = mount(TagReview, { - global: { plugins: [ElementPlus], stubs: { MindMapViewer: mindMapStub } }, + global: { plugins: [ElementPlus, router], stubs: { MindMapViewer: mindMapStub } }, }) await flushPromises() return wrapper @@ -60,6 +81,7 @@ beforeEach(() => { vi.clearAllMocks() recallOutline = '- 根主题' vi.mocked(listTagCandidates).mockResolvedValue({ code: 200, data: ['英语', '数学'] } as never) + vi.mocked(listTagMindMaps).mockResolvedValue({ code: 200, data: pageOf([]) } as never) vi.mocked(listTagRecallRecords).mockResolvedValue({ code: 200, data: [] } as never) vi.mocked(submitAiTask).mockResolvedValue({ code: 201, data: { taskNum: 'AI1', status: 'PENDING' } } as never) }) @@ -86,6 +108,51 @@ describe('TagReview 按标签复习(闭环-04)', () => { wrapper.unmount() }) + it('置顶展示已生成过导图的标签集合,点卡片直接进入复习', async () => { + vi.mocked(listTagMindMaps).mockResolvedValue({ + code: 200, + data: pageOf([{ ...listSummary, needsUpdate: true }]), + } as never) + vi.mocked(queryTagMindMap).mockResolvedValue({ + code: 200, + data: { scopeKey: 'SCOPE_1', tags: ['英语'], mode: 'UNION', map: tagMap, latestRecallRecord: null }, + } as never) + + const wrapper = await mountTagReview() + + expect(wrapper.text()).toContain('已生成的标签导图') + expect(wrapper.text()).toContain('有新碎片待整理') + const card = wrapper.find('.map-row') + expect(card.exists()).toBe(true) + + await card.trigger('click') + await flushPromises() + + expect(queryTagMindMap).toHaveBeenCalledWith(['英语'], 'UNION') + expect(wrapper.text()).toContain('回忆对比') + wrapper.unmount() + }) + + it('行内「补充新碎片」按该导图的标签与模式提交增量任务', async () => { + vi.mocked(listTagMindMaps).mockResolvedValue({ + code: 200, + data: pageOf([{ ...listSummary, needsUpdate: true }]), + } as never) + const wrapper = await mountTagReview() + vi.mocked(submitAiTask).mockClear() + + const supplement = wrapper.findAll('button').find((b) => b.text().includes('补充新碎片')) + await supplement!.trigger('click') + await flushPromises() + + expect(submitAiTask).toHaveBeenCalledWith({ + type: 'TAG_MIND_MAP', + targetNum: 'SCOPE_1', + params: { tags: ['英语'], combineMode: 'UNION', mode: 'incremental' }, + }) + wrapper.unmount() + }) + it('生成导图走 TAG_MIND_MAP 异步任务,targetNum 用范围键', async () => { vi.mocked(queryTagMindMap).mockResolvedValue({ code: 200, @@ -188,6 +255,25 @@ describe('TagReview 按标签复习(闭环-04)', () => { wrapper.unmount() }) + it('从复习总览深链进来:URL 里的标签集合与取数模式直接开始复习', async () => { + vi.mocked(queryTagMindMap).mockResolvedValue({ + code: 200, + data: { scopeKey: 'SCOPE_1', tags: ['英语'], mode: 'UNION', map: tagMap, latestRecallRecord: null }, + } as never) + + const wrapper = await mountTagReview({ tag: '英语', mode: 'UNION' }) + + expect(queryTagMindMap).toHaveBeenCalledWith(['英语'], 'UNION') + expect(wrapper.text()).toContain('回忆对比') + wrapper.unmount() + }) + + it('没有 URL 范围时不自动查询', async () => { + const wrapper = await mountTagReview() + expect(queryTagMindMap).not.toHaveBeenCalled() + wrapper.unmount() + }) + it('回忆内容只有一个节点时拒绝提交,补全后才提交对比任务', async () => { vi.mocked(queryTagMindMap).mockResolvedValue({ code: 200, diff --git a/src/components/TagReview.vue b/src/components/TagReview.vue index ed63250..6703873 100644 --- a/src/components/TagReview.vue +++ b/src/components/TagReview.vue @@ -1,28 +1,37 @@