333 lines
20 KiB
TypeScript
333 lines
20 KiB
TypeScript
/**
|
||
* features/chat/components/messages/transferCards.spec.ts
|
||
* 用途:验证在途调拨核心卡片(文件进度/匹配/融合结果卡)+ 关闭弹窗的交互与禁用语义。
|
||
* 依赖:@vue/test-utils、i18n、transfer.types、Element Plus(匹配卡 EP 壳)。
|
||
* 逻辑:断言按钮禁用、勾选禁用、融合卡单行常驻展开(历史回放旧 result 投影兼容)、
|
||
* 异常展示、下载按钮与结果页不出现“查看执行审计”入口(决策 19);
|
||
* 计数卡新字段(待查库存/已失效,历史缺省按 0)与 pending 徽标
|
||
* (evidence-sync,2026-09-25;EP 化后 el-tag warning);匹配卡批号列
|
||
* deriveBatchNo 旧路径兼容(Task 7 规则化后未传规则仍 WTP→HOW);
|
||
* 匹配卡行定位经 el-table row-class-name(transfer-item-<invoice>)。
|
||
*/
|
||
import { mount, flushPromises } from '@vue/test-utils';
|
||
import { describe, expect, it, vi } 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';
|
||
|
||
// EP el-table 在 jsdom 挂载较重(与 TransferMessageView.spec 同口径),本文件放宽到 30s。
|
||
vi.setConfig({ testTimeout: 30000 });
|
||
|
||
const mountOptions = { global: { plugins: [i18n] } };
|
||
|
||
/**
|
||
* 挂载匹配卡并 flush:el-table 行槽位在 jsdom 下需等下一拍才渲染出 checkbox/行类。
|
||
*/
|
||
async function mountMatchCard(props: Record<string, unknown>) {
|
||
const wrapper = mount(TransferMatchCard, { props, ...mountOptions });
|
||
await flushPromises();
|
||
return wrapper;
|
||
}
|
||
|
||
const summary = {
|
||
matching_id: 'MTG-1',
|
||
status: 'ready_to_execute',
|
||
business_date: '2026-08-06',
|
||
expires_at: '',
|
||
counts: { file_invoice_count: 3, matched_count: 3, executable_count: 2, blocked_count: 1 },
|
||
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: 'result_unknown' },
|
||
];
|
||
|
||
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:可执行项可选,终态行(result_unknown)checkbox 禁用', async () => {
|
||
const wrapper = await mountMatchCard({ summary, items, selected: new Set<number>([101]) });
|
||
// [断言意图] EP el-checkbox:testid 挂根,读写走内层 input。
|
||
const executableCheck = wrapper.find('[data-testid="transfer-check-INV-001"] input');
|
||
const terminalCheck = wrapper.find('[data-testid="transfer-check-INV-041"] input');
|
||
expect((executableCheck.element as HTMLInputElement).disabled).toBe(false);
|
||
expect((executableCheck.element as HTMLInputElement).checked).toBe(true);
|
||
// [断言意图] blocked 行可勾(供重查),终态行(result_unknown,不可执行不可重查)禁用。
|
||
expect((terminalCheck.element as HTMLInputElement).disabled).toBe(true);
|
||
});
|
||
|
||
it('历史回放行(无 item_id)checkbox 禁用,防误选', async () => {
|
||
// [断言意图] 行式执行重构(2026-09-23):chat 消息流回放的旧 payload 行没有
|
||
// item_id,不能作为执行勾选键;这类行必须禁选(防误选后 400)。
|
||
const legacyItems = [{ ...items[0], item_id: undefined }];
|
||
const wrapper = await mountMatchCard({ summary, items: legacyItems, selected: new Set<number>() });
|
||
expect((wrapper.find('[data-testid="transfer-check-INV-001"] input').element as HTMLInputElement).disabled).toBe(true);
|
||
// [断言意图] EP el-button 禁用态挂在 button 元素上,testid 仍可定位。
|
||
expect((wrapper.find('[data-testid="transfer-generate-button"]').element as HTMLButtonElement).disabled).toBe(true);
|
||
});
|
||
|
||
it('未选择任何项时生成按钮禁用', async () => {
|
||
const wrapper = await mountMatchCard({ summary, items, selected: new Set<number>() });
|
||
expect((wrapper.find('[data-testid="transfer-generate-button"]').element as HTMLButtonElement).disabled).toBe(true);
|
||
});
|
||
|
||
it('busy 时生成按钮禁用', async () => {
|
||
const wrapper = await mountMatchCard({ summary, items, selected: new Set<number>([101]), busy: true });
|
||
expect((wrapper.find('[data-testid="transfer-generate-button"]').element as HTMLButtonElement).disabled).toBe(true);
|
||
});
|
||
|
||
it('点击生成按钮提交可执行勾选行的 item_id 数组', async () => {
|
||
const wrapper = await mountMatchCard({ summary, items, selected: new Set<number>([101]) });
|
||
await wrapper.find('[data-testid="transfer-generate-button"]').trigger('click');
|
||
expect(wrapper.emitted('execute')?.[0][0]).toEqual([101]);
|
||
});
|
||
|
||
it('批号列展示派生批号:未传规则走 transferBatch 旧路径(WTP→HOW 兼容行为)', async () => {
|
||
// [断言意图] Task 7 deriveBatchNo 规则化后的调用方回归锁:匹配卡批号列
|
||
// 不传规则(过渡期兼容窗),WTP 批号必须仍派生为 HOW 真实批号。
|
||
// 行定位:el-table 经 row-class-name 注入 transfer-item-<invoice_no>。
|
||
const itemsWithLot = [{ ...items[0], lot_no: 'WTP26082728' }];
|
||
const wrapper = await mountMatchCard({ summary, items: itemsWithLot, selected: new Set<number>() });
|
||
expect(wrapper.find('.transfer-item-INV-001').text()).toContain('HOW26082728');
|
||
});
|
||
|
||
it('库存数量与完整查询时刻同一行(数量 · YYYY-MM-DD HH:mm)', async () => {
|
||
// [断言意图] 数量与时刻同行,避免第二行撑高整表;完整日期才能判断新旧。
|
||
const wrapper = await mountMatchCard({ summary, items, selected: new Set<number>() });
|
||
const cell = wrapper.find('[data-testid="transfer-checked-at-INV-001"]');
|
||
expect(cell.exists()).toBe(true);
|
||
expect(cell.text()).toBe('1200 · 2026-09-23 09:05');
|
||
// [断言意图] 无查询时刻时仍单行只显示数量,不拆第二行。
|
||
expect(wrapper.find('[data-testid="transfer-checked-at-INV-041"]').text()).not.toContain('·');
|
||
});
|
||
|
||
it('stale 行置灰 + 短徽标;file_current=false 行展示文件更新短徽标;顶栏汇总过期', async () => {
|
||
const flaggedItems = [
|
||
{ ...items[0], stale: true, file_current: false },
|
||
];
|
||
const wrapper = await mountMatchCard({ summary, items: flaggedItems, selected: new Set<number>() });
|
||
// [断言意图] el-table 行类经 row-class-name 注入 opacity-60。
|
||
const row = wrapper.find('.transfer-item-INV-001');
|
||
expect(row.classes()).toContain('opacity-60');
|
||
// [断言意图] 长句只放悬停;行内只留短徽标;顶栏 el-alert 汇总可批量重查。
|
||
expect(wrapper.find('[data-testid="transfer-item-stale"]').text()).toContain('已过期');
|
||
expect(wrapper.find('[data-testid="transfer-item-stale"]').attributes('title')).toContain('重查');
|
||
expect(wrapper.find('[data-testid="transfer-item-file-changed"]').text()).toContain('文件更新');
|
||
expect(wrapper.find('[data-testid="transfer-item-file-changed"]').attributes('title')).toContain('自动对齐');
|
||
expect(wrapper.find('[data-testid="transfer-match-stale-banner"]').text()).toContain('1');
|
||
});
|
||
|
||
it('计数卡透出待查库存/已失效计数;历史 payload 缺省按 0 展示', async () => {
|
||
// [断言意图] 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 = await mountMatchCard({ summary: summaryWithNewCounts, items, selected: new Set<number>() });
|
||
const counts = wrapper.find('[data-testid="transfer-match-counts"]');
|
||
expect(counts.text()).toContain('待查库存');
|
||
expect(counts.text()).toContain('已失效 2 行');
|
||
const legacyWrapper = await mountMatchCard({ summary, items, selected: new Set<number>() });
|
||
expect(legacyWrapper.find('[data-testid="transfer-match-counts"]').text()).toContain('已失效 0 行');
|
||
});
|
||
|
||
it('pending_stock_check 行徽标展示「待查库存」(warning 提示色)', async () => {
|
||
// [断言意图] evidence-sync(2026-09-25):文件已落地未查 ERP 的行为
|
||
// pending_stock_check,徽标须用独立文案且为 warning 族(非阻断 danger)。
|
||
// EP 化后走 el-tag type=warning(替代旧 bg-amber-50 手写类)。
|
||
const pendingItems = [{ ...items[0], result: 'pending_stock_check' }];
|
||
const wrapper = await mountMatchCard({ summary, items: pendingItems, selected: new Set<number>() });
|
||
// [断言意图] EP el-tag type=warning;testid 可能落在组件包装层,type 经 props 断言。
|
||
const badge = wrapper.find('[data-testid="transfer-item-result"]');
|
||
expect(badge.text()).toContain('待查库存');
|
||
const tag = wrapper.findComponent({ name: 'ElTag' });
|
||
expect(tag.exists()).toBe(true);
|
||
expect(tag.props('type')).toBe('warning');
|
||
});
|
||
|
||
it('blocked_file_removed 行退出主视图:表格不渲染,仅折叠提示计数并引导去待处理池', async () => {
|
||
// [断言意图] 回归防线(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 = await mountMatchCard({ summary, items: mixedItems, selected: new Set<number>() });
|
||
// 失效行不出现在表格(含其重查按钮/勾选框),可行动行照常渲染。
|
||
expect(wrapper.find('.transfer-item-INV-077').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="transfer-check-INV-077"]').exists()).toBe(false);
|
||
expect(wrapper.find('.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('全部行均文件移除时表格为空,仅剩折叠提示', async () => {
|
||
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 = await mountMatchCard({ summary, items: removedOnly, selected: new Set<number>() });
|
||
// [断言意图] 无行动行时不挂 el-table,避免空壳表;仅折叠提示。
|
||
expect(wrapper.find('[data-testid="transfer-match-table"]').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', movement_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', movement_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', movement_date: '2026-09-04', from_warehouse: 'HTP-D43', from_quantity: null, to_warehouse: 'HTP-D49', to_quantity: '36', result: 'blocked_quantity_mismatch' },
|
||
];
|
||
const wrapper = await mountMatchCard({ summary, items: dupItems, selected: new Set<number>() });
|
||
expect(wrapper.findAll('.el-table__body tbody tr').length).toBe(3);
|
||
// el-input:testid 落在 .el-input 根上;经组件 setValue 触发 v-model(勿直接找嵌套 input,
|
||
// VTU 对 EP 内部 input 偶发空包装)。
|
||
const filter = wrapper.findComponent({ name: 'ElInput' });
|
||
expect(filter.exists()).toBe(true);
|
||
await filter.setValue('HOX');
|
||
await flushPromises();
|
||
const rows = wrapper.findAll('.el-table__body tbody tr');
|
||
expect(rows.length).toBe(1);
|
||
expect(rows[0].text()).toContain('HOX-1');
|
||
});
|
||
|
||
it('可调拨清单客户端分页 50/页:>50 行只渲染当前页切片,筛选变更回第 1 页', async () => {
|
||
// [断言意图] 积压日 items 可达数百行(557 行实测全量直染卡顿):表体只挂
|
||
// 50 行切片 + 分页器出现;翻页渲染下一批;关键字筛选变更回第 1 页;
|
||
// 全选/计数语义仍按 filtered 全量(不在本用例展开,由交互用例覆盖小数据量)。
|
||
const bulk = Array.from({ length: 120 }, (_, index) => ({
|
||
item_id: 1000 + index,
|
||
source_code: 'DBS-AWSBI',
|
||
material_no: `MAT-${index}`,
|
||
material_name: '物料',
|
||
specification: '',
|
||
invoice_no: `INV-${String(index).padStart(4, '0')}`,
|
||
from_warehouse: 'DBS-TRANSIT',
|
||
from_quantity: '1',
|
||
to_warehouse: 'HUB-CN01',
|
||
to_quantity: '1',
|
||
result: 'blocked_quantity_mismatch',
|
||
}));
|
||
const wrapper = await mountMatchCard({ summary, items: bulk, selected: new Set<number>() });
|
||
const bodyRows = () => wrapper.findAll('.el-table__body tbody tr');
|
||
expect(bodyRows().length).toBe(50); // [断言意图] 第 1 页只渲染切片
|
||
const pagination = wrapper.find('[data-testid="transfer-match-pagination"]');
|
||
expect(pagination.exists()).toBe(true); // [断言意图] 分页器出现
|
||
// 翻到第 2 页:渲染第 51-100 行(首行 INV-0050)。
|
||
const pager = wrapper.findComponent({ name: 'ElPagination' });
|
||
expect(pager.exists()).toBe(true);
|
||
await pager.vm.$emit('update:current-page', 2);
|
||
await flushPromises();
|
||
expect(bodyRows().length).toBe(50);
|
||
expect(bodyRows()[0].text()).toContain('INV-0050');
|
||
// 关键字筛选变更回第 1 页:只剩命中的 1 行。
|
||
const filter = wrapper.findComponent({ name: 'ElInput' });
|
||
await filter.setValue('INV-0119');
|
||
await flushPromises();
|
||
expect(wrapper.findAll('.el-table__body tbody tr').length).toBe(1);
|
||
expect(wrapper.text()).toContain('INV-0119');
|
||
});
|
||
});
|
||
|
||
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();
|
||
// [断言意图] 行明细已迁 el-table,jsdom 下需 flush 后槽位才渲染物料文本。
|
||
await flushPromises();
|
||
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-inbound"]').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('downloadInbound')).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,
|
||
});
|
||
// [断言意图] EP el-dialog 挂载后下一 tick 才渲染弹层内容,先 flush 再断言。
|
||
await flushPromises();
|
||
const confirm = wrapper.find('[data-testid="transfer-close-confirm"]');
|
||
expect((confirm.element as HTMLButtonElement).disabled).toBe(true);
|
||
// el-input textarea:经组件 setValue 触发 v-model(勿对包装节点直接 setValue)。
|
||
const reason = wrapper.findComponent({ name: 'ElInput' });
|
||
expect(reason.exists()).toBe(true);
|
||
await reason.setValue('线下已处理');
|
||
await flushPromises();
|
||
expect((confirm.element as HTMLButtonElement).disabled).toBe(false);
|
||
await confirm.trigger('click');
|
||
expect(wrapper.emitted('confirm')?.[0][0]).toBe('线下已处理');
|
||
});
|
||
});
|