Merge branch 'dev' into runny827

feat(training): 新增精益培训视频与周任务管理

# Conflicts:
#	backend/app/models/__init__.py
This commit is contained in:
runny committed 2026-09-08 18:30:09 +08:00
1 parent 85d27e9ffa
commit 91b7233872
812 files changed
+73763 -18908

No files matched your search

@@ -0,0 +1,173 @@
/**
* features/chat/components/messages/TransferMessageView.spec.ts
* 用途:验证卡片自驱动接线——预检卡渲染、点“直接生成调拨单”真实调 API 并切换结果卡、
* 下载按钮调 requestBlob 封装、结果页无审计入口。
* 依赖:vi.mock(transfer.api)、@vue/test-utils、i18n。
* 逻辑:Mock API 断言调用参数与状态切换(对应后端 197 项测试的契约面)。
*/
import { mount, flushPromises } from '@vue/test-utils';
import { describe, expect, it, vi, beforeEach } from 'vitest';
import i18n from '@/i18n';
const api = vi.hoisted(() => ({
createTransferPrecheck: vi.fn(),
getTransferPrecheck: vi.fn(),
executeTransferPrecheck: vi.fn(),
getTransferRun: vi.fn(),
retryTransferItem: vi.fn(),
manualCloseTransferItem: vi.fn(),
downloadTransferReceiptFiles: vi.fn(),
downloadTransferErpInventory: vi.fn(),
downloadTransferExceptions: vi.fn(),
listTransferBacklog: vi.fn(),
getTransferBacklogSummary: vi.fn(),
listTransferSources: vi.fn(),
}));
vi.mock('@/features/chat/api/transfer.api', () => api);
import TransferMessageView from './TransferMessageView.vue';
const payload = {
kind: 'precheck',
summary: {
precheck_id: 'TPC-1',
status: 'ready_to_execute',
business_date: '2026-08-06',
eligible_receipt_date_to: '2026-08-05',
expires_at: '',
counts: { file_invoice_count: 1, not_matured_count: 0, prechecked_count: 1, executable_count: 1, blocked_count: 0 },
estimated_transfer_quantity: '1200',
estimated_erp_write_count: 1,
precheck_hash: 'sha256:x',
},
items: [{
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',
}],
sources: [{ source_code: 'DBS-AWSBI', stage: 'file_ready', file_no: 'REC-1' }],
};
const runPayload = {
kind: 'result',
run_no: 'RUN-1',
status: 'success',
run: {
run_no: 'RUN-1',
status: 'success',
result: {
erp_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: [],
},
},
};
describe('TransferMessageView self-driving wiring', () => {
beforeEach(() => {
vi.clearAllMocks();
api.executeTransferPrecheck.mockResolvedValue({ run_no: 'RUN-1', status: 'success' });
api.getTransferRun.mockResolvedValue(runPayload.run);
api.downloadTransferReceiptFiles.mockResolvedValue({ blob: new Blob(['z']), filename: 'r.zip' });
api.downloadTransferErpInventory.mockResolvedValue({ blob: new Blob(['c']), filename: 'e.csv' });
});
it('预检 payload 渲染预检卡,且默认勾选可执行项', () => {
const wrapper = mount(TransferMessageView, {
props: { payload },
global: { plugins: [i18n] },
});
expect(wrapper.find('[data-testid="transfer-precheck-card"]').exists()).toBe(true);
expect((wrapper.find('[data-testid="transfer-check-INV-001"]').element as HTMLInputElement).checked).toBe(true);
});
it('点击“直接生成调拨单”调用 execute API 并切换为结果卡', async () => {
const wrapper = mount(TransferMessageView, {
props: { payload },
global: { plugins: [i18n] },
});
await wrapper.find('[data-testid="transfer-generate-button"]').trigger('click');
await flushPromises();
expect(api.executeTransferPrecheck).toHaveBeenCalledWith('TPC-1', ['INV-001']);
expect(wrapper.find('[data-testid="transfer-result-card"]').exists()).toBe(true);
});
it('结果卡下载按钮调用下载 API(收料来源文件 + ERP 库存表)', async () => {
const wrapper = mount(TransferMessageView, {
props: { payload: runPayload },
global: { plugins: [i18n] },
});
await wrapper.find('[data-testid="transfer-download-receipt"]').trigger('click');
await wrapper.find('[data-testid="transfer-download-erp"]').trigger('click');
await flushPromises();
expect(api.downloadTransferReceiptFiles).toHaveBeenCalledWith('RUN-1');
expect(api.downloadTransferErpInventory).toHaveBeenCalledWith('RUN-1');
});
it('结果卡不出现执行审计入口(决策 19)', () => {
const wrapper = mount(TransferMessageView, {
props: { payload: runPayload },
global: { plugins: [i18n] },
});
expect(wrapper.text()).not.toContain('审计');
});
it('backlog 视图拉取待处理列表,重试/关闭调用对应 API', async () => {
api.listTransferBacklog.mockResolvedValue([{
item_id: 7, source_code: 'DBS-AWSBI', invoice_no: 'INV-001', material_no: 'MAT-1',
status: 'blocked_recoverable', reason: '收料 1200 / ERP 1000', age_days: 1, aging_level: 'normal',
}]);
api.getTransferBacklogSummary.mockResolvedValue({
recoverable: 1, closed: 0, unknown: 0, aging: { warn_3d: 0, escalate_5d: 0, critical_7d: 0 },
});
api.retryTransferItem.mockResolvedValue({ item_id: 7, status: 'ready_to_execute', attempt_no: 2 });
api.manualCloseTransferItem.mockResolvedValue({ item_id: 7, status: 'manually_closed' });
const wrapper = mount(TransferMessageView, {
props: { payload: { kind: 'backlog' } },
global: { plugins: [i18n] },
});
await flushPromises();
expect(wrapper.find('[data-testid="transfer-backlog-card"]').exists()).toBe(true);
expect(wrapper.text()).toContain('INV-001');
await wrapper.find('[data-testid="transfer-backlog-retry"]').trigger('click');
await flushPromises();
expect(api.retryTransferItem).toHaveBeenCalledWith(7);
await wrapper.find('[data-testid="transfer-backlog-close"]').trigger('click');
await wrapper.find('[data-testid="transfer-close-reason"]').setValue('线下已处理');
await wrapper.find('[data-testid="transfer-close-confirm"]').trigger('click');
await flushPromises();
expect(api.manualCloseTransferItem).toHaveBeenCalledWith(7, '线下已处理');
});
it('来源实例选择:加载列表 → 确认范围 → 创建预检并切换预检卡', async () => {
api.listTransferSources.mockResolvedValue([
{ source_code: 'DBS-AWSBI', display_name: 'AWSBI', platform: 'dbs', enabled: true, has_ready_file: true, file_status: 'ready' },
]);
api.createTransferPrecheck.mockResolvedValue(payload.summary);
api.getTransferPrecheck.mockResolvedValue({
summary: payload.summary,
items: payload.items,
sources: payload.sources,
});
const wrapper = mount(TransferMessageView, {
props: { payload: { kind: 'source-select' } },
global: { plugins: [i18n] },
});
await flushPromises();
expect(wrapper.find('[data-testid="transfer-source-select-card"]').exists()).toBe(true);
await wrapper.find('[data-testid="transfer-source-option-DBS-AWSBI"] input').setValue(true);
await wrapper.find('[data-testid="transfer-source-confirm"]').trigger('click');
await flushPromises();
expect(api.createTransferPrecheck).toHaveBeenCalledWith({ source_codes: ['DBS-AWSBI'] });
expect(wrapper.find('[data-testid="transfer-precheck-card"]').exists()).toBe(true);
});
});