- 新增 TransferDocument 按票执行模型与单据号序列生成(document_id 独立模块,迁移 tt0d/tt8b) - 发票行新增单位字段、matching_id 放宽可空,支持行与票两级执行口径(迁移 tt9c/tt1a) - capability_client 新增 create_transfer 写契约与六态结果裁决,执行链补写前复查门禁 - 抽取/匹配/执行 Job 按 run/item/match 拆分并入 jobs store 队列,transfer 队列单实例 worker 配套本地启动脚本 - 首页新增「已执行调拨单」四统计卡入口与明细列表子视图,重查/重试/关闭/重新触发与筛选分页齐全 - 行评估新鲜度 TTL 从 10 分钟放宽为当日有效(86400s),跨日由文件版本对账门禁兜底 - 同步 chat/errors 文案四语言、测试全家与两份实施计划文档
285 lines
15 KiB
TypeScript
285 lines
15 KiB
TypeScript
/**
|
||
* features/chat/components/messages/transferCards.spec.ts
|
||
* 用途:验证在途调拨核心卡片(文件进度/匹配/融合结果卡)+ 关闭弹窗的交互与禁用语义。
|
||
* 依赖:@vue/test-utils、i18n、transfer.types。
|
||
* 逻辑:断言按钮禁用、勾选禁用、融合卡单行常驻展开(历史回放旧 result 投影兼容)、
|
||
* 异常展示、下载按钮与结果页不出现“查看执行审计”入口(决策 19);
|
||
* 计数卡新字段(待查库存/已失效,历史缺省按 0)与 pending 徽标
|
||
* (evidence-sync,2026-09-25)。
|
||
*/
|
||
import { mount } from '@vue/test-utils';
|
||
import { describe, expect, it } from 'vitest';
|
||
import i18n from '@/i18n';
|
||
import TransferFileProgressCard from './TransferFileProgressCard.vue';
|
||
import TransferMatchCard from './TransferMatchCard.vue';
|
||
import TransferResultCard from './TransferResultCard.vue';
|
||
import TransferManualCloseDialog from './TransferManualCloseDialog.vue';
|
||
|
||
const mountOptions = { global: { plugins: [i18n] } };
|
||
|
||
const summary = {
|
||
matching_id: 'MTG-1',
|
||
status: 'ready_to_execute',
|
||
business_date: '2026-08-06',
|
||
eligible_receipt_date_to: '2026-08-05',
|
||
expires_at: '',
|
||
counts: { file_invoice_count: 3, not_matured_count: 1, matched_count: 2, executable_count: 2, blocked_count: 0 },
|
||
estimated_transfer_quantity: '2400',
|
||
estimated_external_write_count: 2,
|
||
matching_hash: 'sha256:x',
|
||
};
|
||
|
||
const items = [
|
||
{ item_id: 101, source_code: 'DBS-AWSBI', material_no: 'MAT-1', material_name: '连接器', specification: 'A', invoice_no: 'INV-001', from_warehouse: 'DBS-TRANSIT', from_quantity: '1200', to_warehouse: 'HUB-CN01', to_quantity: '1200', result: 'executable', checked_at: '2026-09-23T09:05:00+08:00' },
|
||
{ item_id: 102, source_code: 'DBS-AWSBI', material_no: 'MAT-2', material_name: '控制器', specification: 'B', invoice_no: 'INV-041', from_warehouse: '', from_quantity: null, to_warehouse: '', to_quantity: '400', result: 'not_matured' },
|
||
];
|
||
|
||
describe('TransferFileProgressCard', () => {
|
||
it('按来源显示阶段,不伪造总百分比', () => {
|
||
const wrapper = mount(TransferFileProgressCard, {
|
||
props: { sources: [
|
||
{ source_code: 'DBS-AWSBI', stage: 'file_ready', file_no: 'REC-1', file_version: 'v3' },
|
||
{ source_code: 'CRANE-SZ', stage: 'waiting_rpa_callback' },
|
||
] },
|
||
...mountOptions,
|
||
});
|
||
expect(wrapper.find('[data-testid="transfer-source-DBS-AWSBI"]').text()).toContain('REC-1');
|
||
expect(wrapper.find('[data-testid="transfer-source-CRANE-SZ"]').text()).toContain('RPA');
|
||
});
|
||
});
|
||
|
||
describe('TransferMatchCard', () => {
|
||
it('勾选键为明细行 item_id:阻断/未成熟项 checkbox 禁用,可执行项可选', () => {
|
||
const wrapper = mount(TransferMatchCard, {
|
||
props: { summary, items, selected: new Set<number>([101]) },
|
||
...mountOptions,
|
||
});
|
||
const executableCheck = wrapper.find('[data-testid="transfer-check-INV-001"]');
|
||
const maturedCheck = wrapper.find('[data-testid="transfer-check-INV-041"]');
|
||
expect((executableCheck.element as HTMLInputElement).disabled).toBe(false);
|
||
expect((executableCheck.element as HTMLInputElement).checked).toBe(true);
|
||
expect((maturedCheck.element as HTMLInputElement).disabled).toBe(true);
|
||
});
|
||
|
||
it('历史回放行(无 item_id)checkbox 禁用,防误选', () => {
|
||
// [断言意图] 行式执行重构(2026-09-23):chat 消息流回放的旧 payload 行没有
|
||
// item_id,不能作为执行勾选键;这类行必须禁选(防误选后 400)。
|
||
const legacyItems = [{ ...items[0], item_id: undefined }];
|
||
const wrapper = mount(TransferMatchCard, {
|
||
props: { summary, items: legacyItems, selected: new Set<number>() },
|
||
...mountOptions,
|
||
});
|
||
expect((wrapper.find('[data-testid="transfer-check-INV-001"]').element as HTMLInputElement).disabled).toBe(true);
|
||
expect((wrapper.find('[data-testid="transfer-generate-button"]').element as HTMLButtonElement).disabled).toBe(true);
|
||
});
|
||
|
||
it('未选择任何项时生成按钮禁用', () => {
|
||
const wrapper = mount(TransferMatchCard, {
|
||
props: { summary, items, selected: new Set<number>() },
|
||
...mountOptions,
|
||
});
|
||
expect((wrapper.find('[data-testid="transfer-generate-button"]').element as HTMLButtonElement).disabled).toBe(true);
|
||
});
|
||
|
||
it('busy 时生成按钮禁用', () => {
|
||
const wrapper = mount(TransferMatchCard, {
|
||
props: { summary, items, selected: new Set<number>([101]), busy: true },
|
||
...mountOptions,
|
||
});
|
||
expect((wrapper.find('[data-testid="transfer-generate-button"]').element as HTMLButtonElement).disabled).toBe(true);
|
||
});
|
||
|
||
it('点击生成按钮提交可执行勾选行的 item_id 数组', async () => {
|
||
const wrapper = mount(TransferMatchCard, {
|
||
props: { summary, items, selected: new Set<number>([101]) },
|
||
...mountOptions,
|
||
});
|
||
await wrapper.find('[data-testid="transfer-generate-button"]').trigger('click');
|
||
expect(wrapper.emitted('execute')?.[0][0]).toEqual([101]);
|
||
});
|
||
|
||
it('库存数量下方小字展示查询时刻(HH:mm)', () => {
|
||
const wrapper = mount(TransferMatchCard, {
|
||
props: { summary, items, selected: new Set<number>() },
|
||
...mountOptions,
|
||
});
|
||
const cell = wrapper.find('[data-testid="transfer-checked-at-INV-001"]');
|
||
expect(cell.exists()).toBe(true);
|
||
expect(cell.text()).toMatch(/^\d{2}:\d{2}$/);
|
||
expect(wrapper.find('[data-testid="transfer-checked-at-INV-041"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('stale 行置灰 + 重查小标;file_current=false 行展示文件更新小标', () => {
|
||
const flaggedItems = [
|
||
{ ...items[0], stale: true, file_current: false },
|
||
];
|
||
const wrapper = mount(TransferMatchCard, {
|
||
props: { summary, items: flaggedItems, selected: new Set<number>() },
|
||
...mountOptions,
|
||
});
|
||
const row = wrapper.find('[data-testid="transfer-item-INV-001"]');
|
||
expect(row.classes()).toContain('opacity-60');
|
||
expect(wrapper.find('[data-testid="transfer-item-stale"]').text()).toContain('重查');
|
||
expect(wrapper.find('[data-testid="transfer-item-file-changed"]').text()).toContain('自动对齐');
|
||
});
|
||
|
||
it('计数卡透出待查库存/已失效计数;历史 payload 缺省按 0 展示', () => {
|
||
// [断言意图] evidence-sync(2026-09-25):后端 counts 新增 pending_stock_check_count /
|
||
// invalid_count(历史数据可缺省);卡片须原样透出数值,缺省回退 0,
|
||
// 已失效标签经 {count} 插值渲染(「已失效 N 行」)。
|
||
const summaryWithNewCounts = {
|
||
...summary,
|
||
counts: { ...summary.counts, pending_stock_check_count: 5, invalid_count: 2 },
|
||
};
|
||
const wrapper = mount(TransferMatchCard, {
|
||
props: { summary: summaryWithNewCounts, items, selected: new Set<number>() },
|
||
...mountOptions,
|
||
});
|
||
const counts = wrapper.find('[data-testid="transfer-match-counts"]');
|
||
expect(counts.text()).toContain('待查库存');
|
||
expect(counts.text()).toContain('已失效 2 行');
|
||
const legacyWrapper = mount(TransferMatchCard, {
|
||
props: { summary, items, selected: new Set<number>() },
|
||
...mountOptions,
|
||
});
|
||
expect(legacyWrapper.find('[data-testid="transfer-match-counts"]').text()).toContain('已失效 0 行');
|
||
});
|
||
|
||
it('pending_stock_check 行徽标展示「待查库存」(amber 同未成熟色系)', () => {
|
||
// [断言意图] evidence-sync(2026-09-25):文件已落地未查 ERP 的行为
|
||
// pending_stock_check,徽标须用独立文案且为 amber 族(非阻断红)。
|
||
const pendingItems = [{ ...items[0], result: 'pending_stock_check' }];
|
||
const wrapper = mount(TransferMatchCard, {
|
||
props: { summary, items: pendingItems, selected: new Set<number>() },
|
||
...mountOptions,
|
||
});
|
||
const badge = wrapper.find('[data-testid="transfer-item-result"]');
|
||
expect(badge.text()).toContain('待查库存');
|
||
expect(badge.classes()).toContain('bg-amber-50');
|
||
});
|
||
|
||
it('blocked_file_removed 行退出主视图:表格不渲染,仅折叠提示计数并引导去待处理池', () => {
|
||
// [断言意图] 回归防线(2026-09-24):文件移除的行证据已失效,重查/重新匹配
|
||
// 都救不了——留驻主清单只会提示做不到的动作(死锁观感)。主视图只渲染
|
||
// 可行动行;失效行以折叠提示计数承载,处理入口在待处理异常池。
|
||
const mixedItems = [
|
||
{ ...items[0] },
|
||
{ item_id: 103, source_code: 'DBS-AWSBI', material_no: 'MAT-3', material_name: '线缆', specification: 'C', invoice_no: 'INV-077', from_warehouse: 'DBS-TRANSIT', from_quantity: '50', to_warehouse: 'HUB-CN01', to_quantity: '50', result: 'blocked_file_removed' },
|
||
];
|
||
const wrapper = mount(TransferMatchCard, {
|
||
props: { summary, items: mixedItems, selected: new Set<number>() },
|
||
...mountOptions,
|
||
});
|
||
// 失效行不出现在表格(含其重查按钮/勾选框),可行动行照常渲染。
|
||
expect(wrapper.find('[data-testid="transfer-item-INV-077"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="transfer-executable-check-INV-077"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="transfer-item-INV-001"]').exists()).toBe(true);
|
||
// 折叠提示透出失效行数与去处理池的引导。
|
||
const hint = wrapper.find('[data-testid="transfer-file-removed-hint"]');
|
||
expect(hint.exists()).toBe(true);
|
||
expect(hint.text()).toContain('1');
|
||
expect(hint.text()).toContain('待处理异常');
|
||
});
|
||
|
||
it('全部行均文件移除时表格为空,仅剩折叠提示', () => {
|
||
const removedOnly = [
|
||
{ item_id: 103, source_code: 'DBS-AWSBI', material_no: 'MAT-3', material_name: '线缆', specification: 'C', invoice_no: 'INV-077', from_warehouse: 'DBS-TRANSIT', from_quantity: '50', to_warehouse: 'HUB-CN01', to_quantity: '50', result: 'blocked_file_removed' },
|
||
];
|
||
const wrapper = mount(TransferMatchCard, {
|
||
props: { summary, items: removedOnly, selected: new Set<number>() },
|
||
...mountOptions,
|
||
});
|
||
expect(wrapper.find('tbody tr').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="transfer-file-removed-hint"]').exists()).toBe(true);
|
||
});
|
||
|
||
it('同 Invoice 跨收料日期拆单(重复 invoice_no)时,筛选后仅渲染匹配行', async () => {
|
||
// [断言意图] 回归防线(2026-09-21):拆单设计下 invoice_no 不再唯一,
|
||
// 行 key 若仍用 invoice_no 会出现重复 key,Vue 列表 diff 错乱导致
|
||
// 筛选后不匹配行残留/克隆(用户输入 HOX 仍见 SLC2PHX 行)。
|
||
// 行身份 = (来源, Invoice, 料号, 收料日期),key 必须用同一粒度。
|
||
const dupItems = [
|
||
{ item_id: 201, source_code: 'CRANE', material_no: 'M-1', material_name: '机框', specification: '', invoice_no: 'HOX-1', receipt_date: '2026-09-11', from_warehouse: 'HTP-D43', from_quantity: null, to_warehouse: 'HTP-D49', to_quantity: '36', result: 'blocked_quantity_mismatch' },
|
||
{ item_id: 202, source_code: 'CRANE', material_no: 'M-2', material_name: '护罩', specification: '', invoice_no: 'DUP-1', receipt_date: '2026-09-03', from_warehouse: 'HTP-D43', from_quantity: null, to_warehouse: 'HTP-D49', to_quantity: '36', result: 'blocked_quantity_mismatch' },
|
||
{ item_id: 203, source_code: 'CRANE', material_no: 'M-2', material_name: '护罩', specification: '', invoice_no: 'DUP-1', receipt_date: '2026-09-04', from_warehouse: 'HTP-D43', from_quantity: null, to_warehouse: 'HTP-D49', to_quantity: '36', result: 'blocked_quantity_mismatch' },
|
||
];
|
||
const wrapper = mount(TransferMatchCard, {
|
||
props: { summary, items: dupItems, selected: new Set<number>() },
|
||
...mountOptions,
|
||
});
|
||
expect(wrapper.findAll('tbody tr').length).toBe(3);
|
||
await wrapper.find('[data-testid="transfer-match-filter"]').setValue('HOX');
|
||
const rows = wrapper.findAll('tbody tr');
|
||
expect(rows.length).toBe(1);
|
||
expect(rows[0].text()).toContain('HOX-1');
|
||
});
|
||
});
|
||
|
||
describe('TransferResultCard(Task 13 融合卡)', () => {
|
||
// 历史回放旧 payload(无 orders,仅 result.external_documents)——融合卡投影为成功单展示
|
||
const run = {
|
||
run_no: 'RUN-1',
|
||
status: 'partial_failed',
|
||
result: {
|
||
external_documents: [{
|
||
document_no: 'TRF-10001',
|
||
from_warehouse: 'DBS-TRANSIT',
|
||
to_warehouse: 'HUB-CN01',
|
||
material_count: 1,
|
||
total_quantity: '1200',
|
||
posting_status: 'posted',
|
||
lines: [{ material_no: 'MAT-1', material_name: '连接器', specification: 'A', invoice_no: 'INV-001', quantity: '1200' }],
|
||
}],
|
||
exceptions: [{ source_code: 'DBS-AWSBI', invoice_no: 'INV-999', material_no: 'MAT-9', reason: 'business_failed', facts: '收料 300 / ERP 280' }],
|
||
},
|
||
};
|
||
const mountCard = () => mount(TransferResultCard, { props: { runNo: 'RUN-1', initialRun: run }, ...mountOptions });
|
||
|
||
it('历史回放(旧 result 投影):按单号展示单行,行明细常驻展开无需点击', async () => {
|
||
const wrapper = mountCard();
|
||
const order = wrapper.find('[data-testid="transfer-order-TRF-10001"]');
|
||
expect(order.exists()).toBe(true);
|
||
expect(order.text()).toContain('TRF-10001');
|
||
// 常驻展开:物料行直接可见(旧 <details> 交互移除,D9 调拨单清单=进度=结果)
|
||
expect(wrapper.find('[data-testid="transfer-order-lines-TRF-10001"]').text()).toContain('MAT-1');
|
||
expect(wrapper.find('[data-testid="transfer-order-lines-TRF-10001"]').text()).toContain('连接器');
|
||
// 终态出下载区
|
||
expect(wrapper.find('[data-testid="transfer-result-downloads"]').exists()).toBe(true);
|
||
});
|
||
|
||
it('未入单异常单独展示(口径不变)', () => {
|
||
const wrapper = mountCard();
|
||
expect(wrapper.find('[data-testid="transfer-exceptions-area"]').text()).toContain('INV-999');
|
||
});
|
||
|
||
it('提供下载按钮(收料来源文件 + ERP 库存表 + 异常清单)', async () => {
|
||
const wrapper = mountCard();
|
||
await wrapper.find('[data-testid="transfer-download-receipt"]').trigger('click');
|
||
await wrapper.find('[data-testid="transfer-download-erp"]').trigger('click');
|
||
await wrapper.find('[data-testid="transfer-download-exceptions"]').trigger('click');
|
||
expect(wrapper.emitted('downloadReceipt')).toBeTruthy();
|
||
expect(wrapper.emitted('downloadErp')).toBeTruthy();
|
||
expect(wrapper.emitted('downloadExceptions')).toBeTruthy();
|
||
});
|
||
|
||
it('结果页不出现“查看执行审计”入口(决策 19)', () => {
|
||
const wrapper = mountCard();
|
||
expect(wrapper.text()).not.toContain('审计');
|
||
});
|
||
});
|
||
|
||
describe('TransferManualCloseDialog', () => {
|
||
it('原因为空时确认按钮禁用;填写后可提交', async () => {
|
||
const wrapper = mount(TransferManualCloseDialog, {
|
||
props: { open: true, invoiceNo: 'INV-001' },
|
||
...mountOptions,
|
||
});
|
||
const confirm = wrapper.find('[data-testid="transfer-close-confirm"]');
|
||
expect((confirm.element as HTMLButtonElement).disabled).toBe(true);
|
||
await wrapper.find('[data-testid="transfer-close-reason"]').setValue('线下已处理');
|
||
expect((confirm.element as HTMLButtonElement).disabled).toBe(false);
|
||
await confirm.trigger('click');
|
||
expect(wrapper.emitted('confirm')?.[0][0]).toBe('线下已处理');
|
||
});
|
||
});
|