/** * features/chat/components/messages/TransferSourceSelectCard.spec.ts * 用途:来源实例选择卡——平台分组、全选已启用、清空、按所选类型证据流门禁确认、 * 确认提交、按流重试;调拨类型选项=接口下发(含 record_kinds): * 选项渲染/名称多语言回退/空配置空态/确认禁用,「即将上线」占位不再出现; * 括号只画当前类型的 record_kinds,抓取中不渲染重试。 * 依赖:@vue/test-utils、i18n。 * 逻辑:平台 DBS/Crane 仅分组;实例为选择与执行边界(决策 2/3/4); * 确认门禁=所选类型每条流都是 ready 或 no_data;混合选择先披露未就绪流再确认; * 抓取中与未配置不渲染重试,其余状态可重试(ready 亦可强制重抓); * 证据清单默认只显示最新一份,更早点开后才列出;首行「重新解析」走 reparseCurrentFile,不 emit retry; 单文件下载走 downloadEvidenceFile,不再把预签名地址放进 href; * 类型选项=props.transferTypes 接口真相(enabled 过滤与排序在后端契约内, * 前端不过滤),名称 names[locale]→zh-CN→en→code 回退,空列表空态+确认禁用。 */ import { flushPromises, mount } from '@vue/test-utils'; import { describe, expect, it, vi } from 'vitest'; import i18n from '@/i18n'; const transferApiMocks = vi.hoisted(() => ({ listEvidenceFiles: vi.fn(), downloadEvidenceFile: vi.fn(), reparseCurrentFile: vi.fn(), })); vi.mock('../../api/transfer.api', () => transferApiMocks); const messageMocks = vi.hoisted(() => ({ warning: vi.fn(), error: vi.fn(), success: vi.fn(), info: vi.fn(), warn: vi.fn(), })); vi.mock('@/shared/composables/useMessage', () => ({ useMessage: () => messageMocks, })); import TransferSourceSelectCard from './TransferSourceSelectCard.vue'; import { defaultMovementDate, shanghaiBusinessDate } from './transferDate'; import type { TransferTypeOption } from '../../types/transfer.types'; 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' }, ]; /** 接口下发的调拨类型选项(GET /transfer-types;record_kinds 由范围规则推导,不落库)。 */ const defaultTransferTypes: TransferTypeOption[] = [ { code: 'in_transit_to_hub', names: { 'zh-CN': '在途仓至HUB仓', 'en': 'In-transit to HUB' }, sort_order: 10, transform_rules: [{ field: 'lot_no', op: 'prefix_replace', source: 'WTP', target: 'HOW' }], record_kinds: ['inbound'], }, { code: 'hub_to_hub', names: { 'zh-CN': 'HUB仓间调拨' }, sort_order: 30, transform_rules: [], record_kinds: ['inbound', 'outbound'], }, ]; /** 双证据流来源:入站就绪、出站抓取中。括号只画当前类型 record_kinds 里的流。 */ const hubSource = { source_code: 'DSV360_AWSBI_BYAWSCMH01', display_name: 'CMH01', platform: 'crane', enabled: true, has_ready_file: true, file_status: 'ready' as const, streams: [ { record_kind: 'inbound' as const, file_status: 'ready' as const, has_ready_file: true }, { record_kind: 'outbound' as const, file_status: 'fetching' as const, has_ready_file: false }, ], }; function mountCard(props = {}, sources = readySources, transferTypes: TransferTypeOption[] = defaultTransferTypes) { return mount(TransferSourceSelectCard, { props: { sources, transferTypes, ...props }, global: { plugins: [i18n] }, }); } /** 按外壳 data-testid 定位内部 ElDatePicker。 */ function datePicker(wrapper: ReturnType, testId: string) { const shell = wrapper.find(`[data-testid="${testId}"]`); const found = shell.findComponent({ name: 'ElDatePicker' }); if (!found.exists()) throw new Error(`ElDatePicker ${testId} not found`); return found; } /** 切换调拨类型(ElRadioGroup.setValue;裸 click 不一定落到 is-active)。 */ async function selectTransferType(wrapper: ReturnType, code: string) { await wrapper.findComponent({ name: 'ElRadioGroup' }).setValue(code); } describe('TransferSourceSelectCard', () => { // EP DatePicker/Radio 首挂较重,并行套件下偶发超默认 5s。 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'); }, 30_000); 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({}, [ { source_code: 'DSV-FETCH', display_name: 'fetching', platform: 'dbs', enabled: true, has_ready_file: false, file_status: 'fetching' as const }, ]); await wrapper.find('[data-testid="transfer-source-option-DSV-FETCH"] input').setValue(true); const confirm = wrapper.find('[data-testid="transfer-source-confirm"]'); expect((confirm.element as HTMLButtonElement).disabled).toBe(false); await confirm.trigger('click'); expect(wrapper.emitted('confirm')).toBeUndefined(); const warning = String(messageMocks.warning.mock.calls.at(-1)?.[0] ?? ''); expect(warning).toContain('DSV-FETCH'); expect(warning).toContain('入站'); expect(warning).toContain('抓取中'); expect(warning).not.toContain('请先重试入站 RPA'); }); it('“全选可见”勾选全部启用实例,混合选择先披露再确认 ready-only', async () => { // [断言意图] 知情部分确认(2026-10-09):混合选择(2 ready + 1 none)点确认先出现 // 披露条且不提交;披露后确认只携带具备 ready 文件的来源码。 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.find('[data-testid="transfer-source-partial-confirm"]').exists()).toBe(true); expect(wrapper.emitted('confirm')).toBeUndefined(); await wrapper.find('[data-testid="transfer-source-partial-proceed"]').trigger('click'); expect(wrapper.emitted('confirm')?.[0][0]).toEqual(['DBS-AWSBI', 'CRANE-SZ']); }); it('勾选 ready+parse_failed 先披露,披露后确认只提交 ready 来源', async () => { // [断言意图] 解析失败来源(has_ready_file=false)勾选后不阻断确认, // 但须经披露条确认,确认事件只携带具备 ready 文件的来源码。 const sources = [ { source_code: 'DSV-OK', display_name: 'ok', platform: 'dbs', enabled: true, has_ready_file: true, file_status: 'ready' as const }, { source_code: 'DSV-BAD', display_name: 'bad', platform: 'dbs', enabled: true, has_ready_file: false, file_status: 'parse_failed' as const }, ]; const wrapper = mountCard({}, sources); await wrapper.find('[data-testid="transfer-source-option-DSV-OK"] input').setValue(true); await wrapper.find('[data-testid="transfer-source-option-DSV-BAD"] input').setValue(true); await wrapper.find('[data-testid="transfer-source-confirm"]').trigger('click'); expect(wrapper.emitted('confirm')).toBeUndefined(); await wrapper.find('[data-testid="transfer-source-partial-proceed"]').trigger('click'); expect(wrapper.emitted('confirm')?.[0][0]).toEqual(['DSV-OK']); }); it('混合选择披露条展示可匹配/暂不可匹配计数与状态分组', async () => { // [断言意图] 披露必须让「抓取中」与「真失败」可区分:摘要含三段计数, // 分组明细含「抓取中 1」——用户知情后再决定是否仅匹配就绪来源。 const sources = [ { source_code: 'DSV-OK', display_name: 'ok', platform: 'dbs', enabled: true, has_ready_file: true, file_status: 'ready' as const }, { source_code: 'DSV-FETCH', display_name: 'fetching', platform: 'dbs', enabled: true, has_ready_file: false, file_status: 'fetching' as const }, ]; const wrapper = mountCard({}, sources); await wrapper.find('[data-testid="transfer-source-option-DSV-OK"] input').setValue(true); await wrapper.find('[data-testid="transfer-source-option-DSV-FETCH"] input').setValue(true); await wrapper.find('[data-testid="transfer-source-confirm"]').trigger('click'); const summary = wrapper.find('[data-testid="transfer-source-partial-summary"]').text(); expect(summary).toContain('可匹配 1 个'); expect(summary).toContain('暂不可匹配 1 个'); expect(summary).toContain('抓取中 1'); }); 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-option-DBS-AWSSG"] input').setValue(true); await wrapper.find('[data-testid="transfer-source-confirm"]').trigger('click'); expect(wrapper.find('[data-testid="transfer-source-partial-confirm"]').exists()).toBe(true); await wrapper.find('[data-testid="transfer-source-partial-cancel"]').trigger('click'); expect(wrapper.find('[data-testid="transfer-source-partial-confirm"]').exists()).toBe(false); expect(wrapper.find('[data-testid="transfer-source-confirm"]').exists()).toBe(true); expect(wrapper.emitted('confirm')).toBeUndefined(); }); 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-option-DBS-AWSSG"] input').setValue(true); await wrapper.find('[data-testid="transfer-source-confirm"]').trigger('click'); expect(wrapper.find('[data-testid="transfer-source-partial-confirm"]').exists()).toBe(true); await wrapper.find('[data-testid="transfer-source-option-DBS-AWSSG"] input').setValue(false); expect(wrapper.find('[data-testid="transfer-source-partial-confirm"]').exists()).toBe(false); expect(wrapper.emitted('confirm')).toBeUndefined(); }); 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-option-CRANE-SZ"] input').setValue(true); await wrapper.find('[data-testid="transfer-source-confirm"]').trigger('click'); expect(wrapper.find('[data-testid="transfer-source-partial-confirm"]').exists()).toBe(false); expect(wrapper.emitted('confirm')?.[0][0]).toEqual(['DBS-AWSBI', 'CRANE-SZ']); }); it('parse_failed 显示解析失败徽标且可重试', async () => { // [断言意图] 当日入站文件解析失败(file_status=parse_failed)不得误报就绪; // 与 none/failed/expired 一样允许重新触发入站 RPA。 const wrapper = mountCard({}, [ { source_code: 'DSV-BAD', display_name: 'bad', platform: 'dbs', enabled: true, has_ready_file: false, file_status: 'parse_failed' as const }, ]); // [断言意图] 方案 A:状态芯片与重试钮分离;芯片含 ▾,↻ 不在芯片文案里。 expect(wrapper.find('[data-testid="transfer-source-status-DSV-BAD"]').text()).toBe('入站 !解析失败 ▾'); expect(wrapper.find('[data-testid="transfer-source-retry-DSV-BAD"]').exists()).toBe(true); expect((wrapper.find('[data-testid="transfer-source-retry-DSV-BAD"]').element as HTMLButtonElement).disabled).toBe(false); }); 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('日期默认值提示收进 ⓘ 悬浮(title),不再平铺占宽', () => { // [断言意图] 长规则文案通过原生 title 渐进披露,紧凑日期行不换行错位。 const wrapper = mountCard(); const title = wrapper.find('[data-testid="transfer-source-date-hint"]').attributes('title') ?? ''; expect(title).toContain('T−2'); expect(title).toContain('业务日期'); }); it('异动日期默认与上限同为 T−2 可匹配截止日(T−2 管控恢复),movementDateLabel 文案渲染', () => { // [断言意图] 默认值=T−2 产品默认作业点;disabled-date 卡 T−2 之后(T−1/当天/ // 未来均无成熟数据,不可选;越界另由后端 MOVEMENT_DATE_RANGE_INVALID 兜底); // 日期标签 i18n 键 chat.transfer.movementDateLabel(Task 5,值=异动日期)。 const wrapper = mountCard(); const from = datePicker(wrapper, 'transfer-source-date-from'); const to = datePicker(wrapper, 'transfer-source-date-to'); const today = shanghaiBusinessDate(); expect(from.props('modelValue')).toBe(defaultMovementDate()); expect(to.props('modelValue')).toBe(defaultMovementDate()); const [y, m, d] = today.split('-').map(Number); const [maxY, maxM, maxD] = defaultMovementDate().split('-').map(Number); const disabledFrom = from.props('disabledDate') as (date: Date) => boolean; // [边界] T−2 恰好可选;T(当天)与未来日都晚于截止 → 禁用。 expect(disabledFrom(new Date(maxY, maxM - 1, maxD))).toBe(false); expect(disabledFrom(new Date(y, m - 1, d))).toBe(true); expect(disabledFrom(new Date(y, m - 1, d + 1))).toBe(true); // i18n 键更名后标签正常解析(深层嵌套纯文本键,不依赖命名插值)。 expect(wrapper.find('[data-testid="transfer-source-params"]').text()).toContain('异动日期'); }); it('起始晚于截止时行内提示并禁用确认(不等提交报错)', async () => { // [断言意图] 日期维护期即时卡控:非法区间直接禁用确认并显示行内红字。 const wrapper = mountCard(); await wrapper.find('[data-testid="transfer-source-option-DBS-AWSBI"] input').setValue(true); await datePicker(wrapper, 'transfer-source-date-from').setValue('2026-09-20'); await datePicker(wrapper, '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 datePicker(wrapper, 'transfer-source-date-to').setValue('2026-09-22'); expect(wrapper.find('[data-testid="transfer-source-date-invalid"]').exists()).toBe(false); }); it('文件已就绪来源行尾重试图标可用,可强制重抓', async () => { // [断言意图] 2026-09-29 去管控:ready 不再禁用重试(文件内容异常时覆盖重抓), // 点击行尾图标按单来源 emit retry。 const wrapper = mountCard(); expect((wrapper.find('[data-testid="transfer-source-retry-DBS-AWSBI"]').element as HTMLButtonElement).disabled).toBe(false); await wrapper.find('[data-testid="transfer-source-retry-DBS-AWSBI"]').trigger('click'); expect(wrapper.emitted('retry')?.[0][0]).toEqual(['DBS-AWSBI']); expect(wrapper.emitted('retry')?.[0][1]).toMatchObject({ recordKind: 'inbound' }); expect(wrapper.find('[data-testid="transfer-source-status-DBS-AWSBI"]').text()).toBe('入站 √就绪 ▾'); expect(wrapper.find('[data-testid="transfer-source-retry-DBS-AWSBI"]').text()).toBe('↻'); }); it('抓取中来源不渲染重试按钮(在途去重,状态字只表示抓取中)', async () => { // [断言意图] fetching 无独立重试钮;芯片只显示 ⟳抓取中 + ▾。 const wrapper = mountCard({}, [ { source_code: 'DSV-FETCH', display_name: 'fetching', platform: 'dbs', enabled: true, has_ready_file: false, file_status: 'fetching' }, ]); expect(wrapper.find('[data-testid="transfer-source-retry-DSV-FETCH"]').exists()).toBe(false); expect(wrapper.find('[data-testid="transfer-source-status-DSV-FETCH"]').text()).toBe('入站 ⟳抓取中 ▾'); }); it('“只选可重试”不把仅就绪来源算进批量', async () => { // [断言意图] 批量只收非 ready、非 fetching、非 unconfigured 的流。 // ready 来源不勾上;无文件来源勾上后批量按钮可用。 const wrapper = mountCard(); await wrapper.find('[data-testid="transfer-source-select-retryable"]').trigger('click'); expect((wrapper.find('[data-testid="transfer-source-option-DBS-AWSBI"] input').element as HTMLInputElement).checked).toBe(false); expect((wrapper.find('[data-testid="transfer-source-option-DBS-AWSSG"] input').element as HTMLInputElement).checked).toBe(true); expect((wrapper.find('[data-testid="transfer-source-batch-retry"]').element as HTMLButtonElement).disabled).toBe(false); }); 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('单个非就绪来源点批量重试不带 recordKind,只带 transferType', async () => { // [断言意图] 批量按钮即使只选一个来源,emit 也不带 recordKind,避免被当成入站单源重试。 const wrapper = mountCard(); await wrapper.find('[data-testid="transfer-source-option-DBS-AWSSG"] input').setValue(true); await wrapper.find('[data-testid="transfer-source-batch-retry"]').trigger('click'); expect(wrapper.emitted('retry')?.[0][0]).toEqual(['DBS-AWSSG']); expect(wrapper.emitted('retry')?.[0][1]).toEqual({ transferType: 'in_transit_to_hub' }); }); it('空数据来源显示「无入站数据」徽标而非抓取失败', async () => { // [断言意图] 抓取成功但当日无入站记录(file_status=no_data)属业务结果, // 必须如实展示"无入站数据",不得与"抓取失败"混淆(2026-10-08 PRD01 误标事故)。 const wrapper = mountCard({}, [ { source_code: 'CRANE-NODATA', display_name: '空数据在途仓', platform: 'crane', enabled: true, has_ready_file: false, file_status: 'no_data' }, ]); expect(wrapper.find('[data-testid="transfer-source-status-CRANE-NODATA"]').text()).toBe('入站 —无数据 ▾'); expect(wrapper.find('[data-testid="transfer-source-retry-CRANE-NODATA"]').exists()).toBe(true); expect((wrapper.find('[data-testid="transfer-source-retry-CRANE-NODATA"]').element as HTMLButtonElement).disabled).toBe(false); }); 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"]').exists()).toBe(true); 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('确认默认携带首个接口选项的调拨类型 code(缺省选中第一项)', async () => { // [断言意图] 类型选项接口化(Task 7)后缺省选中不再是写死字面量, // 而是接口下发列表的首项(现行配置首项= in_transit_to_hub),确认事件第三参回传。 const wrapper = mountCard(); expect(wrapper.find('[data-testid="transfer-type-option-in_transit_to_hub"]').classes()).toContain('is-active'); 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('调拨类型选项=接口下发数据逐项渲染,名称按 names 多语言显示,「即将上线」占位不再出现', () => { // [断言意图] 选项即接口真相:props 给几个渲染几个(enabled 过滤与排序在后端契约内), // 名称取 names[locale];写死三选项数组与「即将上线」徽标必须彻底消失。 const wrapper = mountCard(); const options = wrapper.findAll('[data-testid^="transfer-type-option-"]'); expect(options).toHaveLength(2); expect(wrapper.find('[data-testid="transfer-type-option-in_transit_to_hub"]').text()).toContain('在途仓至HUB仓'); expect(wrapper.find('[data-testid="transfer-type-option-hub_to_hub"]').text()).toContain('HUB仓间调拨'); expect(wrapper.text()).not.toContain('即将上线'); }); it('类型名称回退:names 缺当前 locale 时依次回退 zh-CN → en → code', () => { // [断言意图] 规格 §12.2 名称回退链:locale → zh-CN → en → code(code 是终极兜底, // 未配置任何名称也不出现空白按钮)。 const types: TransferTypeOption[] = [ { code: 'only_en', names: { en: 'Only EN' }, sort_order: 1, transform_rules: [], record_kinds: ['inbound'] }, { code: 'no_names', names: {}, sort_order: 2, transform_rules: [], record_kinds: ['inbound'] }, ]; const wrapper = mountCard({}, readySources, types); expect(wrapper.find('[data-testid="transfer-type-option-only_en"]').text()).toContain('Only EN'); expect(wrapper.find('[data-testid="transfer-type-option-no_names"]').text()).toContain('no_names'); }); it('点击类型按钮切换选中(选中态高亮),确认携带所选 code', async () => { // [断言意图] 选中类型 code 随 confirm 事件上抛(现有签名不变): // 点击第二项后确认,第三参必须是其 code 而非缺省首项。 const wrapper = mountCard(); await selectTransferType(wrapper, 'hub_to_hub'); expect(wrapper.find('[data-testid="transfer-type-option-hub_to_hub"]').classes()).toContain('is-active'); 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('hub_to_hub'); }); it('类型配置为空:渲染空态文案,确认按钮禁用且 title 说明原因', () => { // [断言意图] 空配置空态(规格 §12.2):空态文案 chat.transfer.transferTypeEmpty + // 确认禁用(disabled + tooltip 说明原因),防止用户在无类型可配时发起匹配。 const wrapper = mountCard({}, readySources, []); const empty = wrapper.find('[data-testid="transfer-type-empty"]'); expect(empty.exists()).toBe(true); expect(empty.text()).toContain('暂无可用调拨类型'); const confirm = wrapper.find('[data-testid="transfer-source-confirm"]'); expect((confirm.element as HTMLButtonElement).disabled).toBe(true); expect(confirm.attributes('title') ?? '').toContain('暂无可用调拨类型'); // 空态下不再渲染任何类型选项,也不出现「即将上线」历史占位。 expect(wrapper.find('[data-testid^="transfer-type-option-"]').exists()).toBe(false); expect(wrapper.text()).not.toContain('即将上线'); }); it('只在清单第一行显示重新解析,点击不发出 retry', async () => { transferApiMocks.listEvidenceFiles.mockResolvedValue([ { file_id: 25, original_filename: 'outbound_TRIG-BATCH-A629464D_DBS-AWSBI_NA_20261021101739.xlsx', created_at: '2026-10-21T10:00:00', sha256: 'abc', file_size: 10, presigned_url: 'https://files.example/current', download_url: 'https://files.example/current?filename=DBS-AWSBI_20261021_1800.xlsx' }, { file_id: 9, original_filename: 'older.xlsx', created_at: '2026-10-20T10:00:00', sha256: 'def', file_size: 10, presigned_url: 'https://files.example/older', download_url: 'https://files.example/older?filename=DBS-AWSBI_20261020_1800.xlsx' }, ]); transferApiMocks.reparseCurrentFile.mockResolvedValue({ source_code: 'DBS-AWSBI', record_kind: 'inbound', ok: true, file_status: 'ready', file_id: 25, inserted: 2, updated: 0, skipped: 0, sealed_skipped: 0, error_code: null, error_message: null, }); const wrapper = mount(TransferSourceSelectCard, { props: { sources: readySources, transferTypes: defaultTransferTypes }, global: { plugins: [i18n] }, }); await wrapper.find('[data-testid="transfer-source-status-DBS-AWSBI"]').trigger('click'); await flushPromises(); // [断言意图] 行内对齐排程包的来源名,不展示 Worker 落盘名;完整原名在 title。 const list = wrapper.get('[data-testid="transfer-evidence-list-DBS-AWSBI-inbound"]'); expect(list.text()).toContain('DBS-AWSBI.xlsx'); expect(list.text()).toContain('10-21 18:00'); expect(list.text()).not.toContain('10-21 10:00'); expect(list.text()).not.toContain('TRIG-BATCH'); expect(list.get('p').attributes('title')).toContain('outbound_TRIG-BATCH-A629464D_DBS-AWSBI_NA_20261021101739.xlsx'); expect(list.get('p').attributes('title')).toContain('2026-10-21 18:00'); expect(wrapper.get('[data-testid="transfer-evidence-download-25"]').attributes('href')).toBeUndefined(); expect(wrapper.text()).not.toContain('older.xlsx'); expect(wrapper.text()).not.toContain('abc'); const buttons = wrapper.findAll('[data-testid="transfer-evidence-reparse-DBS-AWSBI-inbound"]'); expect(buttons).toHaveLength(1); expect(list.findAll('p')).toHaveLength(1); await wrapper.find('[data-testid="transfer-evidence-earlier-DBS-AWSBI-inbound"]').trigger('click'); expect(list.findAll('p')).toHaveLength(2); expect(list.text()).not.toContain('older.xlsx'); expect(wrapper.findAll('[data-testid="transfer-evidence-reparse-DBS-AWSBI-inbound"]')).toHaveLength(1); await buttons[0].trigger('click'); expect(transferApiMocks.reparseCurrentFile).toHaveBeenCalledWith('DBS-AWSBI', 'inbound'); expect(wrapper.emitted('retry')).toBeUndefined(); expect(wrapper.emitted('reparsed')).toBeTruthy(); }); it('点击下载走站点接口,不打开预签名地址', async () => { // [断言意图] 下载按钮不再带 MinIO href;点击后按来源、文件和记录类型请求当前站点。 transferApiMocks.listEvidenceFiles.mockResolvedValue([ { file_id: 25, original_filename: 'CRANE.xlsx', created_at: '2026-10-26T07:00:00', sha256: 'abc', file_size: 10, presigned_url: 'http://192.168.100.192:9000/file', download_url: 'http://192.168.100.192:9000/file?filename=CRANE.xlsx' }, ]); transferApiMocks.downloadEvidenceFile.mockResolvedValue({ blob: new Blob(['xlsx']), filename: 'DBS-AWSBI_20261026_1500.xlsx' }); const wrapper = mount(TransferSourceSelectCard, { props: { sources: readySources, transferTypes: defaultTransferTypes }, global: { plugins: [i18n] }, }); await wrapper.find('[data-testid="transfer-source-status-DBS-AWSBI"]').trigger('click'); await flushPromises(); await wrapper.get('[data-testid="transfer-evidence-download-25"]').trigger('click'); await flushPromises(); expect(transferApiMocks.downloadEvidenceFile).toHaveBeenCalledWith('DBS-AWSBI', 25, 'inbound'); }); it('按所选类型的 record_kinds 绘制证据流芯片,抓取中无重试,下载按钮为证据文件', async () => { // [断言意图] 方案 A:状态芯片与重试钮分离。hub_to_hub 两种流各一枚芯片; // 出站抓取中无 ↻;入站 ↻ 的 aria-label 为「重试入站」。切回只含 inbound 时不出现「出站」。 const wrapper = mountCard({}, [hubSource]); const row = () => wrapper.find('[data-testid="transfer-source-option-DSV360_AWSBI_BYAWSCMH01"]'); expect(row().text()).not.toContain('出站'); await selectTransferType(wrapper, 'hub_to_hub'); expect(row().find('[data-testid="transfer-source-status-DSV360_AWSBI_BYAWSCMH01"]').text()).toBe('入站 √就绪 ▾'); expect(row().find('[data-testid="transfer-source-status-DSV360_AWSBI_BYAWSCMH01-outbound"]').text()).toBe('出站 ⟳抓取中 ▾'); expect(row().find('[aria-label="重试出站"]').exists()).toBe(false); expect(row().find('[aria-label="重试入站"]').exists()).toBe(true); // [断言意图] 重试/状态芯片已迁 el-button(2026-10-20),不再断言手写 border 类。 expect(row().find('[aria-label="重试入站"]').classes()).toContain('el-button'); expect(row().find('[data-testid="transfer-source-status-DSV360_AWSBI_BYAWSCMH01"]').classes()).toContain('el-button'); expect(wrapper.findAll('button').some((button) => button.text().trim() === '文件')).toBe(false); await wrapper.find('[data-testid="transfer-source-option-DSV360_AWSBI_BYAWSCMH01"] input').setValue(true); expect(wrapper.find('[data-testid="transfer-source-download"]').text()).toContain('下载证据文件'); await selectTransferType(wrapper, 'in_transit_to_hub'); expect(row().text()).not.toContain('出站'); }); });