闭合拆分预览令牌单次消费、样本 checksum 绑定与确认审计;正式提取改为 bindings-only。 同步统一标注工作台交互,并补齐进度投影/任务中心与迁移文档。 Co-authored-by: Cursor <cursoragent@cursor.com>
98 lines
2.9 KiB
TypeScript
98 lines
2.9 KiB
TypeScript
/**
|
||
* features/chat/components/shipping-review/ReviewDocumentNavigation.spec.ts
|
||
* 用途:验收 OT 导航数量阈值与模式切换。
|
||
*/
|
||
|
||
import { describe, expect, it } from 'vitest';
|
||
import { mount } from '@vue/test-utils';
|
||
import { createI18n } from 'vue-i18n';
|
||
import ReviewDocumentNavigation, {
|
||
type ReviewDocumentNavItem,
|
||
} from './ReviewDocumentNavigation.vue';
|
||
|
||
const i18n = createI18n({
|
||
legacy: false,
|
||
locale: 'zh-CN',
|
||
messages: {
|
||
'zh-CN': {
|
||
chat: {
|
||
shippingOrderReview: {
|
||
unnamedDocument: '未命名 PDF',
|
||
documentNavigation: '导航',
|
||
caseStatuses: { draft: '草稿', unknown: '未知' },
|
||
otNav: {
|
||
listTitle: '订单列表 · {count}',
|
||
searchPlaceholder: '搜索',
|
||
filterAll: '全部',
|
||
filterNeedsAction: '待人工',
|
||
filterProcessing: '处理中',
|
||
filterDone: '完成',
|
||
filterFailed: '失败',
|
||
narrowTrigger: '订单 {current}/{total}',
|
||
},
|
||
},
|
||
},
|
||
},
|
||
},
|
||
});
|
||
|
||
/**
|
||
* 生成 n 个导航项。
|
||
*/
|
||
function items(count: number): ReviewDocumentNavItem[] {
|
||
return Array.from({ length: count }, (_, i) => ({
|
||
case_no: `C-${i + 1}`,
|
||
file_name: `f${i + 1}.pdf`,
|
||
status: 'draft',
|
||
issue_count: i === 0 ? 1 : 0,
|
||
}));
|
||
}
|
||
|
||
type NavForceMode = 'hidden' | 'tabs' | 'sidebar' | 'sidebar_search' | 'narrow';
|
||
|
||
/**
|
||
* 挂载导航。
|
||
*/
|
||
function mountNav(count: number, forceMode?: NavForceMode) {
|
||
return mount(ReviewDocumentNavigation, {
|
||
props: {
|
||
items: items(count),
|
||
activeCaseNo: 'C-1',
|
||
navAriaLabel: 'nav',
|
||
forceMode: forceMode ?? null,
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
}
|
||
|
||
describe('ReviewDocumentNavigation', () => {
|
||
it('hides navigation for a single OT', () => {
|
||
const wrapper = mountNav(1, 'hidden');
|
||
expect(wrapper.find('[data-testid="review-document-navigation"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('uses top tabs for 2–4 OTs', () => {
|
||
const wrapper = mountNav(3, 'tabs');
|
||
expect(wrapper.find('[data-testid="review-doc-nav-tabs"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="review-doc-nav-list"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('uses sidebar list for 5–20 OTs', () => {
|
||
const wrapper = mountNav(8, 'sidebar');
|
||
expect(wrapper.find('[data-testid="review-doc-nav-list"]').exists()).toBe(true);
|
||
expect(wrapper.attributes('data-nav-mode')).toBe('sidebar');
|
||
});
|
||
|
||
it('shows search for 20+ OTs', () => {
|
||
const wrapper = mountNav(25, 'sidebar_search');
|
||
expect(wrapper.find('[data-testid="review-doc-nav-search"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="review-doc-nav-filter"]').exists()).toBe(true);
|
||
});
|
||
|
||
it('emits select when a tab is clicked', async () => {
|
||
const wrapper = mountNav(2, 'tabs');
|
||
await wrapper.get('[data-testid="review-doc-nav-C-2"]').trigger('click');
|
||
expect(wrapper.emitted('select')?.[0]).toEqual(['C-2']);
|
||
});
|
||
});
|