import { beforeEach, describe, expect, it, vi } from 'vitest'; import type { TenantContext } from '../src/services/tenantScope'; vi.mock('../src/services/inspectionReviewOps', () => ({ listInspectionReviews: vi.fn(async () => ({ rows: [{ id: 'r1', order_code: 'ORD1', item_name: '土豆', source_type: 'purchase' }], total: 1, })), listLoadingPhotoReviews: vi.fn(async () => ({ rows: [], total: 0 })), listDeliverySignPhotoReviews: vi.fn(async () => ({ rows: [], total: 0 })), listPickingOutboundPhotoReviews: vi.fn(async () => ({ rows: [], total: 0 })), })); import { listInspectionReviews } from '../src/services/inspectionReviewOps'; import { executeCapability } from '../src/capabilities/registry'; import { registerBuiltinCapabilities } from '../src/capabilities/registerBuiltins'; import { routeModules } from '../src/capabilities/routeModules'; registerBuiltinCapabilities(); const superAdmin: TenantContext = { userId: 'u1', roles: ['super_admin'], permissions: [], branchCode: 'BR001', supplierCode: null, purchaserCode: null, isSuperAdmin: true, isBranchAdmin: false, isInternalStaff: true, isSupplierAccount: false, }; describe('list_inspection_reviews', () => { beforeEach(() => { vi.mocked(listInspectionReviews).mockClear(); }); it('asks for date_from instead of defaulting to today', async () => { const result = await executeCapability('list_inspection_reviews', { userId: 'u1', ctx: superAdmin, args: {}, surface: 'web', }); expect(result.ok).toBe(false); if (!result.ok) { expect(result.code).toBe('need_input'); expect(result.missing).toContain('date_from'); } expect(listInspectionReviews).not.toHaveBeenCalled(); }); it('defaults date_field to delivery_date and navigates menu path', async () => { const result = await executeCapability('list_inspection_reviews', { userId: 'u1', ctx: superAdmin, args: { date_from: '2026-09-06', search: '土豆', sync_page: true }, surface: 'web', visiblePages: [{ path: '/inspection/review', label: '验收照片复核' }], }); expect(result.ok).toBe(true); if (result.ok) { const data = result.data as { count: number; date_field: string; items: Array<{ item_name: string }>; ui: Array<{ type: string; path?: string; patches?: Array<{ name: string; value: unknown }> }>; }; expect(data.count).toBe(1); expect(data.date_field).toBe('delivery_date'); expect(data.items[0].item_name).toBe('土豆'); const nav = data.ui.find((row) => row.type === 'navigate'); expect(nav?.path).toBe('/inspection/review'); const fields = data.ui.find((row) => row.type === 'set_fields'); expect(fields?.patches?.some((p) => p.name === 'status_tab' && p.value === 'inspections')).toBe(true); } expect(listInspectionReviews).toHaveBeenCalledWith( expect.objectContaining({ query: '土豆', dateField: 'delivery_date', dateFrom: '2026-09-06', dateTo: '2026-09-06', }) ); }); it('routes 照片复核 to inspection-review, 待验收 to inbound-list', () => { const review = routeModules({ text: '验收照片复核入库照片多少张', visibleModuleIds: ['navigate', 'order-entry', 'inbound-list', 'inspection-review'], }); expect(review.modules).toContain('inspection-review'); expect(review.modules).not.toContain('order-entry'); const inbound = routeModules({ text: '入库列表待验收多少条', visibleModuleIds: ['navigate', 'order-entry', 'inbound-list', 'inspection-review'], }); expect(inbound.modules).toContain('inbound-list'); expect(inbound.modules).not.toContain('inspection-review'); }); });