- 新增行字段补充合并与订单模板匹配能力 - 优化运行时解析策略、签名校验及资料验证 - 完善库存 RPA 归档、收尾与 Worker 启动流程 - 补充前后端测试、多语言文案及功能文档
172 lines
7.1 KiB
TypeScript
172 lines
7.1 KiB
TypeScript
/**
|
||
* features/chat/components/shipping-review/ReviewProfileMatchPanel.spec.ts
|
||
* 用途:锁定模板匹配侧栏的候选披露规则,避免候选数量增长撑长工作台。
|
||
* 依赖:vitest、@vue/test-utils、vue-i18n、ReviewProfileMatchPanel。
|
||
* 逻辑:所有状态默认收起;用户可手动展开/收起候选列表。
|
||
*/
|
||
import { describe, expect, it } from 'vitest';
|
||
import { mount } from '@vue/test-utils';
|
||
import { createI18n } from 'vue-i18n';
|
||
import ReviewProfileMatchPanel from './ReviewProfileMatchPanel.vue';
|
||
|
||
const i18n = createI18n({
|
||
legacy: false,
|
||
locale: 'zh-CN',
|
||
messages: {
|
||
'zh-CN': {
|
||
chat: { shippingOrderReview: { profileMatch: {
|
||
title: '文档模板匹配', subtitle: '摘要', selected: '命中模板', noSelected: '未选定模板',
|
||
expandCandidates: '查看候选模板({count})', collapseCandidates: '收起候选模板',
|
||
routeType: '路由类型', executionMode: '执行模式',
|
||
extractionBlocked: '模板已命中,但字段提取仍被安全门禁阻断',
|
||
extractionBlockedNoMatch: '模板未唯一命中,字段提取被阻断',
|
||
extractionBlockedReason: '阻断原因:{reasons}',
|
||
coordinateModel: {
|
||
anchorFrame: '锚点坐标框架', status: '变换状态', translateX: '横向平移',
|
||
translateY: '纵向平移', reasonCodes: '原因码',
|
||
},
|
||
status: { matched: '已匹配', ambiguous: '多个候选' },
|
||
} } },
|
||
},
|
||
},
|
||
});
|
||
|
||
function mountPanel(needsReview = false) {
|
||
return mount(ReviewProfileMatchPanel, {
|
||
props: {
|
||
profileMatch: {
|
||
available: true,
|
||
visibility: 'admin',
|
||
status: needsReview ? 'ambiguous' : 'matched',
|
||
needs_review: needsReview,
|
||
selected_profile: { profile_code: 'ODP-A', display_name: '客户订单模板', version: 1 },
|
||
candidates: [
|
||
{ profile_code: 'ODP-A', display_name: '客户订单模板', score: 0.99 },
|
||
{ profile_code: 'ODP-B', display_name: '客户订单模板(旧版)', score: 0.98 },
|
||
],
|
||
fallback_reason_codes: [],
|
||
},
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
}
|
||
|
||
function mountAnchorFramePanel(visibility: 'admin' | 'admin_only' = 'admin') {
|
||
return mount(ReviewProfileMatchPanel, {
|
||
props: {
|
||
profileMatch: {
|
||
available: true,
|
||
visibility,
|
||
status: 'unique_match',
|
||
needs_review: false,
|
||
selected_profile: { profile_code: 'ODP-A', display_name: '客户订单模板', version: 1 },
|
||
candidates: [{
|
||
profile_code: 'ODP-A',
|
||
version: 1,
|
||
display_name: '客户订单模板',
|
||
score: 0.99,
|
||
coordinate_transform: {
|
||
status: 'applied',
|
||
translate_x: 0.001,
|
||
translate_y: 0.03,
|
||
reason_codes: [],
|
||
},
|
||
}],
|
||
fallback_reason_codes: [],
|
||
},
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
}
|
||
|
||
describe('ReviewProfileMatchPanel', () => {
|
||
it('默认收起无需关注的候选列表', () => {
|
||
const wrapper = mountPanel(false);
|
||
expect(wrapper.find('[data-testid="review-profile-match-candidates"]').exists()).toBe(false);
|
||
expect(wrapper.get('[data-testid="review-profile-match-candidates-toggle"]').text()).toContain('查看候选模板(2)');
|
||
});
|
||
|
||
it('多个候选且需要人工处理时也默认收起,并允许展开后收起', async () => {
|
||
const wrapper = mountPanel(true);
|
||
expect(wrapper.find('[data-testid="review-profile-match-candidates"]').exists()).toBe(false);
|
||
await wrapper.get('[data-testid="review-profile-match-candidates-toggle"]').trigger('click');
|
||
expect(wrapper.find('[data-testid="review-profile-match-candidates"]').exists()).toBe(true);
|
||
await wrapper.get('[data-testid="review-profile-match-candidates-toggle"]').trigger('click');
|
||
expect(wrapper.find('[data-testid="review-profile-match-candidates"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('候选模板优先展示模板名称,不把内部编号作为主文案', async () => {
|
||
const wrapper = mountPanel(true);
|
||
|
||
await wrapper.get('[data-testid="review-profile-match-candidates-toggle"]').trigger('click');
|
||
|
||
// 关键断言:业务用户辨认模板依赖 display_name,ODP 编号不应出现在候选列表主展示中。
|
||
expect(wrapper.get('[data-testid="review-profile-match-candidates"]').text()).toContain('客户订单模板');
|
||
expect(wrapper.get('[data-testid="review-profile-match-candidates"]').text()).not.toContain('ODP-A');
|
||
});
|
||
|
||
it('唯一命中时仍展示下游字段提取门禁的阻断原因', () => {
|
||
const wrapper = mount(ReviewProfileMatchPanel, {
|
||
props: {
|
||
profileMatch: {
|
||
available: true,
|
||
visibility: 'admin',
|
||
status: 'unique_match',
|
||
needs_review: true,
|
||
selected_profile: { profile_code: 'ODP-A', display_name: '客户订单模板', version: 1 },
|
||
candidates: [{ profile_code: 'ODP-A', display_name: '客户订单模板', score: 0.99 }],
|
||
fallback_reason_codes: ['PARSE_STRATEGY_ROW_MODE_AMBIGUOUS'],
|
||
},
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
|
||
// 关键断言:唯一模板命中不等于字段已提取,必须明确暴露下游阻断原因。
|
||
expect(wrapper.get('[data-testid="review-profile-match-extraction-blocked"]').text())
|
||
.toContain('PARSE_STRATEGY_ROW_MODE_AMBIGUOUS');
|
||
expect(wrapper.get('[data-testid="review-profile-match-extraction-blocked"]').text())
|
||
.toContain('模板已命中');
|
||
});
|
||
|
||
it('未选定模板时阻断文案不得再写模板已命中', () => {
|
||
const wrapper = mount(ReviewProfileMatchPanel, {
|
||
props: {
|
||
profileMatch: {
|
||
available: true,
|
||
visibility: 'admin',
|
||
status: 'evidence_insufficient',
|
||
needs_review: true,
|
||
selected_profile: null,
|
||
candidates: [],
|
||
fallback_reason_codes: ['coordinate_evidence_unavailable'],
|
||
},
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
|
||
const blocked = wrapper.get('[data-testid="review-profile-match-extraction-blocked"]').text();
|
||
expect(blocked).toContain('模板未唯一命中');
|
||
expect(blocked).not.toContain('模板已命中');
|
||
expect(blocked).toContain('coordinate_evidence_unavailable');
|
||
});
|
||
|
||
it('管理员技术详情展示锚点框架平移和稳定原因码,不展示原始正文或完整坐标', async () => {
|
||
const wrapper = mountAnchorFramePanel();
|
||
|
||
await wrapper.get('[data-testid="review-profile-match-candidates-toggle"]').trigger('click');
|
||
|
||
const details = wrapper.get('[data-testid="review-profile-match-details"]');
|
||
expect(details.text()).toContain('锚点坐标框架');
|
||
expect(details.text()).toContain('纵向平移');
|
||
expect(details.text()).toContain('0.03');
|
||
expect(details.text()).not.toContain('ORDER NO.');
|
||
expect(details.text()).not.toContain('x0');
|
||
});
|
||
|
||
it('非管理员不可见锚点框架技术详情', async () => {
|
||
const wrapper = mountAnchorFramePanel('admin_only');
|
||
expect(wrapper.find('[data-testid="review-profile-match-panel"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="review-profile-match-coordinate-transform"]').exists()).toBe(false);
|
||
});
|
||
});
|