Files
syops/frontend/src/features/chat/components/shipping-review/ReviewDocumentNavigation.spec.ts
T
hugo 1b6483a4ea feat(shipping-notice,receipt-report): 新增收料报表功能并优化发货通知流程
清理废弃的shipping xfa ocr automark相关代码和job配置
新增收料报表管理的前端页面、路由和侧边栏入口
新增后端收料报表配置接口、数据库模型和RPA脚本
优化发货通知流程的重试策略,将shipping相关job默认不自动重试
移除废弃的库存源确认相关逻辑,更新流程门禁规则
重构订单模板的值适配器模块,新增坐标OCR值适配器
清理前端shipping菜单和action的废弃选项
更新相关文档和测试用例,调整.gitignore忽略规则
2026-08-20 20:23:10 +08:00

176 lines
6.3 KiB
TypeScript
Raw 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.
/**
* 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: '未知' },
lifecycle: {
stages: {
order_review: '订单复核',
fulfillment_prep: '通知准备',
upload_complete: '通知完成',
},
},
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 compact top tabs for 2–4 OTs', () => {
const wrapper = mountNav(3);
expect(wrapper.find('[data-testid="review-doc-nav-tabs"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="review-doc-nav-list"]').exists()).toBe(false);
expect(wrapper.attributes('data-nav-mode')).toBe('tabs');
});
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');
expect(wrapper.classes()).toContain('sticky');
});
it('keeps the sidebar collapse rail and the explicitly forced sidebar mode', async () => {
const wrapper = mount(ReviewDocumentNavigation, {
props: {
items: items(8),
activeCaseNo: 'C-1',
navAriaLabel: 'nav',
forceMode: 'sidebar',
initiallyCollapsed: true,
},
global: { plugins: [i18n] },
});
// 关键断言:收起后仍保留文件身份摘要,不能退化成无法识别的纯编号轨。
expect(wrapper.attributes('data-nav-mode')).toBe('sidebar');
expect(wrapper.get('[data-testid="review-doc-nav-C-2"]').text()).toContain('f2');
await wrapper.get('[data-testid="review-doc-nav-collapse"]').trigger('click');
expect(wrapper.get('[data-testid="review-doc-nav-C-2"]').text()).toContain('f2.pdf');
expect(wrapper.get('[data-testid="review-doc-nav-list"]').attributes('data-collapsed')).toBe('false');
});
it('keeps the file name as the queue row title while projecting PO, lifecycle stage and status', () => {
const rows = items(5);
rows[1] = {
...rows[1],
file_name: 'purchase-order-2.pdf',
po_number: 'PO-002',
lifecycle_stage: 'fulfillment_prep',
status: 'processing',
};
const wrapper = mount(ReviewDocumentNavigation, {
props: {
items: rows,
activeCaseNo: 'C-1',
navAriaLabel: 'nav',
forceMode: 'sidebar',
},
global: { plugins: [i18n] },
});
// 文件导航先展示可识别的文件名;PO/阶段/状态仍都来自后端队列 DTO。
const queueRow = wrapper.get('[data-testid="review-doc-nav-C-2"]');
expect(queueRow.find('.font-medium').text()).toBe('purchase-order-2.pdf');
expect(queueRow.text()).toContain('PO-002');
expect(queueRow.text()).toContain('通知准备');
// 关键断言:队列行内容必须是实际 DOM 子节点,不能被原生 template 隐藏成空白框。
expect(queueRow.find('template').exists()).toBe(false);
});
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']);
});
it('keeps backend lifecycle stage visible in tabs and narrow queue', async () => {
const rows = items(2);
rows[1] = { ...rows[1], lifecycle_stage: 'fulfillment_prep', status: 'processing' };
const tabs = mount(ReviewDocumentNavigation, {
props: { items: rows, activeCaseNo: 'C-1', navAriaLabel: 'nav', forceMode: 'tabs' },
global: { plugins: [i18n] },
});
const narrow = mount(ReviewDocumentNavigation, {
props: { items: rows, activeCaseNo: 'C-1', navAriaLabel: 'nav', forceMode: 'narrow' },
global: { plugins: [i18n] },
attachTo: document.body,
});
// 关键断言:文件队列在任何响应式形态都只投影后端已裁决阶段。
expect(tabs.get('[data-testid="review-doc-nav-C-2"]').text()).toContain('通知准备');
await narrow.get('[data-testid="review-doc-nav-narrow-trigger"]').trigger('click');
// 窄屏抽屉通过 Teleport 挂到 body,断言真实可见容器而非组件根节点。
expect(document.body.querySelector('[data-testid="review-doc-nav-C-2"]')?.textContent).toContain('通知准备');
narrow.unmount();
});
});