Files
syops/frontend/src/features/chat/components/messages/TransferSourceSelectCard.spec.ts
T
hugo 0cf3c24119 refactor(in-transit-transfer): 行归属解耦、按行执行三层门禁并重构术语为匹配
- 行不迁移:匹配记录降级为评估留痕(scope/counts/hash 留痕不拦执行),
  匹配/重查原地刷新行并续行级新鲜度(updated_at)
- 执行改按行:POST /items/execute 三层门禁(行级新鲜度 TTL/文件版本对账/写前复查),
  Run 留痕不绑匹配记录;消失行 blocked_file_removed fail-closed 入异常池
- 恢复处理收敛为行级重查(batch-resume 删除);待处理池补齐匹配窗口字段,
  排序改业务稳定键(收料日期→Invoice→created_at,操作不再引起跳位)
- 首页待办看板四队列:可调拨明细/待恢复异常/已人工关闭/结果未知;「最近预检」移除;
  收料日期默认 T-1 并加输入期限制;「重新查询 ERP」更名「重查」
- 术语重构 precheck→match:表 transfer_matchings、列 matching_id/matching_no/matching_hash、
  API /matchings、单号前缀 MTG、状态值 prechecking→matching(迁移 rn1a2b3c4d5e6,模块未上线无兼容层)
- 修复 integration_connector mapping 扇出嵌套丢行缺陷;对账结论:0 vs 30/40/36
  系收料仓库映射曾指向错误账套 TGHX(已改 TGHX1),探针留档 backend/tmp
- 测试:后端 in_transit_transfer+api+connector 393 passed;前端 chat 713 passed;build ✓
2026-09-24 00:24:03 +08:00

168 lines
9.6 KiB
TypeScript

/**
* features/chat/components/messages/TransferSourceSelectCard.spec.ts
* 用途:来源实例选择卡——平台分组、全选已启用、清空、按收料文件状态门禁确认、
* 确认提交、重试收料 RPA。
* 依赖:@vue/test-utils、i18n。
* 逻辑:平台 DBS/Crane 仅分组;实例为选择与执行边界(决策 2/3/4);
* 所选来源需至少一个 has_ready_file 才能确认匹配(决策:无 ready 文件禁止确认)。
*/
import { mount } from '@vue/test-utils';
import { describe, expect, it } from 'vitest';
import i18n from '@/i18n';
import TransferSourceSelectCard from './TransferSourceSelectCard.vue';
import { eligibleReceiptDateTo } from './transferDate';
const readySources = [
{ source_code: 'DBS-AWSBI', display_name: 'AWSBI 在途仓', platform: 'dbs', enabled: true, has_ready_file: true, file_status: 'ready' },
{ source_code: 'DBS-AWSSG', display_name: 'AWSSG 在途仓', platform: 'dbs', enabled: true, file_status: 'none' },
{ source_code: 'CRANE-SZ', display_name: '深圳在途仓', platform: 'crane', enabled: true, has_ready_file: true, file_status: 'ready' },
];
function mountCard(props = {}, sources = readySources) {
return mount(TransferSourceSelectCard, {
props: { sources, ...props },
global: { plugins: [i18n] },
});
}
describe('TransferSourceSelectCard', () => {
it('按平台分组展示来源实例', () => {
const wrapper = mountCard();
expect(wrapper.find('[data-testid="transfer-source-option-DBS-AWSBI"]').text()).toContain('DBS-AWSBI');
expect(wrapper.find('[data-testid="transfer-source-option-CRANE-SZ"]').text()).toContain('CRANE-SZ');
});
it('未选任何来源时确认按钮禁用(需至少一个 ready 文件来源)', () => {
const wrapper = mountCard();
expect((wrapper.find('[data-testid="transfer-source-confirm"]').element as HTMLButtonElement).disabled).toBe(true);
});
it('勾选含 ready 文件来源后确认提交所选来源', async () => {
const wrapper = mountCard();
await wrapper.find('[data-testid="transfer-source-option-DBS-AWSBI"] input').setValue(true);
await wrapper.find('[data-testid="transfer-source-option-CRANE-SZ"] input').setValue(true);
await wrapper.find('[data-testid="transfer-source-confirm"]').trigger('click');
expect(wrapper.emitted('confirm')?.[0][0]).toEqual(['DBS-AWSBI', 'CRANE-SZ']);
});
it('仅勾选无 ready 文件来源时不提交(门禁)', async () => {
const wrapper = mountCard();
await wrapper.find('[data-testid="transfer-source-option-DBS-AWSSG"] input').setValue(true);
await wrapper.find('[data-testid="transfer-source-confirm"]').trigger('click');
expect(wrapper.emitted('confirm')).toBeUndefined();
});
it('“全选可见”勾选全部启用实例', async () => {
const wrapper = mountCard();
await wrapper.find('[data-testid="transfer-source-select-visible"]').trigger('click');
await wrapper.find('[data-testid="transfer-source-confirm"]').trigger('click');
expect(wrapper.emitted('confirm')?.[0][0]).toEqual(['DBS-AWSBI', 'DBS-AWSSG', 'CRANE-SZ']);
});
it('“清空选择”清空已选实例', async () => {
const wrapper = mountCard();
await wrapper.find('[data-testid="transfer-source-select-visible"]').trigger('click');
await wrapper.find('[data-testid="transfer-source-clear"]').trigger('click');
await wrapper.find('[data-testid="transfer-source-confirm"]').trigger('click');
expect(wrapper.emitted('confirm')).toBeUndefined();
});
it('选中后上下文操作条原位替换选择辅助区,清空选择后还原', async () => {
// [断言意图] 未选中零死按钮(仅辅助区);有选中时批量操作条同槽位出现并带计数;
// 清空选择后还原辅助区——Gmail/Linear 式批量操作栏切换行为。
const wrapper = mountCard();
expect(wrapper.find('[data-testid="transfer-source-aids"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="transfer-source-action-bar"]').exists()).toBe(false);
await wrapper.find('[data-testid="transfer-source-option-DBS-AWSBI"] input').setValue(true);
expect(wrapper.find('[data-testid="transfer-source-aids"]').exists()).toBe(false);
expect(wrapper.find('[data-testid="transfer-source-action-bar"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="transfer-source-action-bar"]').text()).toContain('已选 1');
await wrapper.find('[data-testid="transfer-source-clear"]').trigger('click');
expect(wrapper.find('[data-testid="transfer-source-aids"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="transfer-source-action-bar"]').exists()).toBe(false);
expect(wrapper.emitted('confirm')).toBeUndefined();
});
it('D+1 规则提示收进 ⓘ 悬浮(title),不再平铺占宽', () => {
// [断言意图] 长规则文案通过原生 title 渐进披露,紧凑日期行不换行错位。
const wrapper = mountCard();
const title = wrapper.find('[data-testid="transfer-source-date-hint"]').attributes('title') ?? '';
expect(title).toContain('D+1 规则');
expect(title).toContain('业务日期前一天');
});
it('收料日期默认为 D+1 规则日期(T-1)且上限锁定(输入期限制)', () => {
// [断言意图] 默认值与 max 均为上海口径 T-1,未来日期在选择器层面不可选。
const wrapper = mountCard();
const from = wrapper.find('[data-testid="transfer-source-date-from"]').element as HTMLInputElement;
const to = wrapper.find('[data-testid="transfer-source-date-to"]').element as HTMLInputElement;
const cutoff = eligibleReceiptDateTo();
expect(from.value).toBe(cutoff);
expect(to.value).toBe(cutoff);
expect(from.max).toBe(cutoff);
expect(to.max).toBe(cutoff);
});
it('起始晚于截止时行内提示并禁用确认(不等提交报错)', async () => {
// [断言意图] 日期维护期即时卡控:非法区间直接禁用确认并显示行内红字。
const wrapper = mountCard();
await wrapper.find('[data-testid="transfer-source-option-DBS-AWSBI"] input').setValue(true);
await wrapper.find('[data-testid="transfer-source-date-from"]').setValue('2026-09-20');
await wrapper.find('[data-testid="transfer-source-date-to"]').setValue('2026-09-10');
expect(wrapper.find('[data-testid="transfer-source-date-invalid"]').exists()).toBe(true);
expect((wrapper.find('[data-testid="transfer-source-confirm"]').element as HTMLButtonElement).disabled).toBe(true);
await wrapper.find('[data-testid="transfer-source-date-to"]').setValue('2026-09-22');
expect(wrapper.find('[data-testid="transfer-source-date-invalid"]').exists()).toBe(false);
});
it('“只选可重试”勾选无文件/失败来源', async () => {
const wrapper = mountCard();
await wrapper.find('[data-testid="transfer-source-select-retryable"]').trigger('click');
const selected = (wrapper.find('[data-testid="transfer-source-confirm"]').element as HTMLButtonElement).disabled;
// 可重试来源为 DBS-AWSSG(none);选中它但无 ready 文件 → 确认仍禁用(门禁)。
expect(selected).toBe(true);
});
it('点击行尾重试图标 emit retry([sourceCode])', async () => {
const wrapper = mountCard();
await wrapper.find('[data-testid="transfer-source-retry-DBS-AWSSG"]').trigger('click');
expect(wrapper.emitted('retry')?.[0][0]).toEqual(['DBS-AWSSG']);
});
it('批量重试仅传可重试来源', async () => {
const wrapper = mountCard();
await wrapper.find('[data-testid="transfer-source-select-retryable"]').trigger('click');
await wrapper.find('[data-testid="transfer-source-batch-retry"]').trigger('click');
expect(wrapper.emitted('retry')?.[0][0]).toEqual(['DBS-AWSSG']);
});
it('已过期来源显示「文件已过期」徽标且可重试', async () => {
// [断言意图] 保留期已到的来源不得误报就绪(has_ready_file=false);
// expired 状态与 none/failed 一样允许重新触发收料 RPA。
const wrapper = mountCard({}, [
{ source_code: 'CRANE-EXP', display_name: '过期在途仓', platform: 'crane', enabled: true, has_ready_file: false, file_status: 'expired' },
]);
expect(wrapper.find('[data-testid="transfer-source-status-CRANE-EXP"]').text()).toBe('文件已过期');
expect((wrapper.find('[data-testid="transfer-source-retry-CRANE-EXP"]').element as HTMLButtonElement).disabled).toBe(false);
await wrapper.find('[data-testid="transfer-source-option-CRANE-EXP"] input').setValue(true);
await wrapper.find('[data-testid="transfer-source-batch-retry"]').trigger('click');
expect(wrapper.emitted('retry')?.[0][0]).toEqual(['CRANE-EXP']);
});
it('确认默认携带调拨类型 in_transit_to_hub', async () => {
// [断言意图] 类型 1 为缺省选中值,确认事件第三参回传类型。
const wrapper = mountCard();
await wrapper.find('[data-testid="transfer-source-option-DBS-AWSBI"] input').setValue(true);
await wrapper.find('[data-testid="transfer-source-confirm"]').trigger('click');
expect(wrapper.emitted('confirm')?.[0][2]).toBe('in_transit_to_hub');
});
it('调拨类型 2/3 占位禁用且不可选中', async () => {
// [断言意图] 一期仅开放类型 1;占位类型按钮 disabled,防止发起未支持链路。
const wrapper = mountCard();
expect((wrapper.find('[data-testid="transfer-type-option-hub_repair_out"]').element as HTMLButtonElement).disabled).toBe(true);
expect((wrapper.find('[data-testid="transfer-type-option-hub_to_hub"]').element as HTMLButtonElement).disabled).toBe(true);
expect((wrapper.find('[data-testid="transfer-type-option-in_transit_to_hub"]').element as HTMLButtonElement).disabled).toBe(false);
});
});