Files
PlantAI-rag-new/tests/frontend/unit/b3/benchpanel.test.js
jerryandClaude Fable 5 5888e1d5c1 test(docgen): 测试治理资产——131 条验收用例 + 三轮留痕 + E2E/回归套件
- tests/docgen/:DC-UNIT/API/CONF/E2E/UI/REGRESSION/PERF 分组用例与可复跑脚本,报告逐条留痕(R1-R3 全记录)
- 意图 30 条前后端同表双跑(pytest + node)
- Playwright headless:docgen-ui/docgen-regression spec + b3 benchpanel 第 5 TAB 断言更新

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-03 21:13:47 +08:00

88 lines
3.7 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// benchpanel.test.js —— B3 单测:BenchPanel 五 tab 切换与 ExtractionPane 轮询联动
// P3 修订(2026-09-03):dev3 新增第 5 个「文档」TAB(DOCGEN_TAB={key:'doc',label:'文档'},追加在 BENCH_TABS 之后),
// 原「四 tab 长度 4」断言更新为 5 并追加文档 TAB 用例(行为变化属开发交付,非缺陷)。
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { mount } from '@vue/test-utils';
import { createPinia, setActivePinia } from 'pinia';
import { useBenchStore } from '../../../../ui/src/stores/bench.js';
import BenchPanel from '../../../../ui/src/components/bench/BenchPanel.vue';
vi.mock('../../../../ui/src/api/extraction.js', () => ({
listJobs: vi.fn().mockResolvedValue({ jobs: [], count: 0 }),
getJob: vi.fn(),
uploadPaper: vi.fn(),
getRunLog: vi.fn().mockResolvedValue({ text: '' }),
getProcessingStatus: vi.fn(),
getSummary: vi.fn(),
}));
vi.mock('../../../../ui/src/api/kg.js', () => ({
kgStatus: vi.fn().mockResolvedValue({ ok: true }),
kgOverview: vi.fn(),
searchEntities: vi.fn(),
getEntity: vi.fn(),
getNeighborhood: vi.fn(),
}));
describe('BenchPanel(FR-RETRIEVAL/SOURCE/EXTRACT/KG + P3 文档入口)', () => {
let store;
let pinia;
beforeEach(() => {
pinia = createPinia();
setActivePinia(pinia);
store = useBenchStore();
});
it('五 tab = labels.BENCH_TABS + 文档 TAB,默认激活检索过程', () => {
const wrapper = mount(BenchPanel, { global: { plugins: [pinia] } });
const tabs = wrapper.findAll('.bench-tab');
expect(tabs).toHaveLength(5);
expect(tabs.map((t) => t.text())).toEqual(['检索过程', '文献来源', '提取任务', '知识图谱', '文档']);
expect(wrapper.find('.bench-tab.on').text()).toBe('检索过程');
});
it('文档 TAB 存在:key=doc、label=文档,点击后激活 DocPane(P3)', async () => {
const wrapper = mount(BenchPanel, { global: { plugins: [pinia] } });
const tabs = wrapper.findAll('.bench-tab');
const docTab = tabs[4];
expect(docTab.text()).toBe('文档');
await docTab.trigger('click');
expect(store.activeTab).toBe('doc');
expect(wrapper.find('.bench-tab.on').text()).toBe('文档');
expect(wrapper.findComponent({ name: 'DocPane' }).exists()).toBe(true);
});
it('点击 tab 切换 pane,激活 tab 有渐变下划线(on 类)', async () => {
const wrapper = mount(BenchPanel, { global: { plugins: [pinia] } });
const tabs = wrapper.findAll('.bench-tab');
await tabs[2].trigger('click');
expect(wrapper.find('.bench-tab.on').text()).toBe('提取任务');
expect(wrapper.findComponent({ name: 'ExtractionPane' }).exists()).toBe(true);
await tabs[3].trigger('click');
expect(wrapper.findComponent({ name: 'KgPane' }).exists()).toBe(true);
});
it('Tab 切走 extract 时暂停轮询(FR-EXTRACT-005)', async () => {
const wrapper = mount(BenchPanel, { global: { plugins: [pinia] } });
const tabs = wrapper.findAll('.bench-tab');
await tabs[2].trigger('click'); // extract
store.pollPaused = false;
await tabs[0].trigger('click'); // retrieval
expect(store.pollPaused).toBe(true);
expect(store.isPolling()).toBe(false);
});
it('折叠状态经 props/emit 同步(FR-SHELL-005 手柄由 B1 对接)', async () => {
const wrapper = mount(BenchPanel, {
props: { collapsed: false },
global: { plugins: [pinia] },
});
const handle = wrapper.find('.bench-handle-btn');
expect(handle.exists()).toBe(true);
await handle.trigger('click');
expect(wrapper.emitted('collapse')).toBeTruthy();
expect(wrapper.emitted('collapse')[0]).toEqual([true]);
expect(wrapper.classes()).toContain('collapsed-local');
});
});