/** * features/admin/modules/shipping-audit/ShippingAuditEventDetailDrawer.spec.ts * 用途:锁定审计详情抽屉脱敏提示与 Diff 渲染契约。 * 依赖:Vitest、@vue/test-utils、ShippingAuditEventDetailDrawer。 * 逻辑:敏感脱敏文案可见;Diff 行按 key 渲染;无 Diff 显示空态。 */ import { describe, expect, it } from 'vitest'; import { mount } from '@vue/test-utils'; import { createI18n } from 'vue-i18n'; import ShippingAuditEventDetailDrawer from './ShippingAuditEventDetailDrawer.vue'; import type { ShippingAuditEventDetail } from '@/features/admin/api/shipping-audit.api'; const messages = { 'zh-CN': { admin: { close: '关闭', shippingAudit: { detailTitle: '审计详情', loading: '正在加载...', sensitiveRedacted: '敏感快照已按权限脱敏', diff: '前后差异', before: '变更前', after: '变更后', noDiff: '无可展示的白名单差异', eventHash: '事件哈希', previousEventHash: '前序哈希', columns: { event: '事件', actor: '操作者', run: 'Run', task: 'Task', result: '结果' }, filters: { workflowId: 'Workflow', workflowItemId: 'Workflow Item', documentId: 'PDF/文档', reviewCaseNo: 'Case', }, }, }, }, }; /** * 挂载详情抽屉。 */ function mountDrawer(detail: ShippingAuditEventDetail | null, loading = false) { const i18n = createI18n({ legacy: false, locale: 'zh-CN', messages }); return mount(ShippingAuditEventDetailDrawer, { props: { detail, loading }, global: { plugins: [i18n] }, }); } describe('ShippingAuditEventDetailDrawer', () => { it('shows sensitive redaction banner when snapshots are trimmed', () => { const detail: ShippingAuditEventDetail = { id: 1, event_type: 'order_review_confirmed', aggregate_type: 'shipping_order_review_case', aggregate_id: 'SRC-1', actor_type: 'user', has_snapshots: true, sensitive_redacted: true, diff: [], }; const wrapper = mountDrawer(detail); // 关键断言:无敏感读权限时展示脱敏提示。 expect(wrapper.find('[data-testid="shipping-audit-sensitive-redacted"]').exists()).toBe(true); expect(wrapper.text()).toContain('敏感快照已按权限脱敏'); }); it('renders whitelist diff rows', () => { const detail: ShippingAuditEventDetail = { id: 2, event_type: 'status_changed', aggregate_type: 'order_extraction_run', aggregate_id: 'SNER-1', actor_type: 'system', has_snapshots: true, sensitive_redacted: false, diff: [{ key: 'status', change: 'changed', before: 'queued', after: 'processing' }], }; const wrapper = mountDrawer(detail); // 关键断言:Diff 仅展示白名单键变化。 expect(wrapper.find('[data-testid="shipping-audit-diff-rows"]').text()).toContain('status'); expect(wrapper.text()).toContain('queued'); expect(wrapper.text()).toContain('processing'); }); });