58 lines
5.5 KiB
TypeScript
58 lines
5.5 KiB
TypeScript
import { expect, it } from 'vitest'
|
|
import { actionAllowed, actionRoute, referenceRoute, commandName, workDate, workStatus, workReason } from './workPresentation'
|
|
import { followAction, workItem } from './work.test-support'
|
|
import type { WorkAction } from './workApi'
|
|
it.each([
|
|
['SOURCE_TIMEZONE', '原业务作业地点时区待核实'],
|
|
['SOURCE_CONFIGURATION', '原货源或仓库配置待核实'],
|
|
['LASTLEG_SOURCE', '尾程货源待建立'],
|
|
['READY_WINDOW_UNVERIFIED', '货物备妥窗口待核实'],
|
|
['CARGO_QUANTITY_REVIEW', '货量或重复关联需要核对。'],
|
|
])('shows readable text for work item reason %s', (code, expected) => {
|
|
expect(workReason(code)).toBe(expected)
|
|
})
|
|
it('preserves the server explanation for an overdue or blocked work item', () => {
|
|
expect(workReason('作业日期已过,尚未完成')).toBe('作业日期已过,尚未完成')
|
|
expect(workReason('实际提柜后才能记录直送卸货')).toBe('实际提柜后才能记录直送卸货')
|
|
})
|
|
it('links original dispatch and delivery references by business number without inventing unknown routes', () => {
|
|
expect(referenceRoute({ kind: 'DISPATCH', key: 'DISPATCH:9007199254740999', businessNo: 'DS/001', label: '客户仓排车' })).toBe('/overseas-warehouse/dispatches?dispatchNo=DS%2F001')
|
|
expect(referenceRoute({ kind: 'DELIVERY', key: 'internal', businessNo: 'DL/001', label: '原派送' })).toBe('/overseas-warehouse/delivery-orders/DL%2F001')
|
|
expect(referenceRoute({ kind: 'DELIVERY', key: 'internal', businessNo: null, label: '原派送' })).toBeNull()
|
|
expect(referenceRoute({ kind: 'EXTERNAL_URL', key: 'https://example.com', businessNo: 'example', label: '未知' })).toBeNull()
|
|
})
|
|
it('shows both complete local dates for a confirmed cross-day slot', () => {
|
|
expect(workDate(workItem({ calendarDate: '2026-10-15', dateBasis: 'CONFIRMED', confirmed: { date: '2026-10-15', startTime: '23:00', endDate: '2026-10-16', endTime: '01:00', timezone: 'America/Los_Angeles' } }))).toBe('确认 2026-10-15 23:00 → 2026-10-16 01:00')
|
|
})
|
|
it('keeps executed pickup on its actual location date after the plan moves', () => {
|
|
const item = workItem({ type: 'PICKUP', dateBasis: 'ACTUAL', calendarDate: '2026-10-14', actual: { occurredAt: '2026-10-15T03:00:00Z', localOccurredAt: null, timezone: 'America/Los_Angeles' }, target: { date: '2026-10-20', startTime: null, endDate: null, endTime: null, timezone: 'America/Los_Angeles' } })
|
|
expect(workDate(item)).toContain('2026/10/14'); expect(workDate(item)).not.toContain('2026-10-20')
|
|
expect(item.target?.date).toBe('2026-10-20')
|
|
})
|
|
it('preserves original local actual and planned dates without imposing a browser or default timezone', () => {
|
|
expect(workDate(workItem({ dateBasis: 'ACTUAL', calendarDate: '2026-10-15', timezone: null, actual: { occurredAt: null, localOccurredAt: '2026-10-15T23:30:00', timezone: null } }))).toBe('实际 2026-10-15 23:30:00')
|
|
expect(workDate(workItem({ dateBasis: 'TARGET', calendarDate: '2026-10-15', timezone: null, target: { date: '2026-10-15', startTime: '23:30', endDate: '2026-10-16', endTime: '01:30', timezone: null } }))).toBe('目标 2026-10-15 23:30 → 2026-10-16 01:30')
|
|
})
|
|
it('does not turn a follow-up date into a work slot or no-booking into a confirmation', () => {
|
|
expect(workDate(workItem())).toBe('作业日期未定')
|
|
expect(workStatus(workItem({ planStatus: 'NOT_REQUIRED' }))).toBe('无需预约')
|
|
})
|
|
it('rejects unknown commands and never treats internal trip identifiers as business numbers', () => {
|
|
const unknown = { ...followAction, target: { kind: 'WORK_COMMAND', command: 'MARK_COMPLETE' } } as unknown as WorkAction
|
|
expect(commandName(unknown)).toBeNull(); expect(actionAllowed(workItem(), unknown)).toBe(false)
|
|
const trip: WorkAction = { code: 'RECORD_EXECUTION', label: '登记发车', targetWorkItemKey: null, target: { kind: 'FLEET_TRIP', tripId: 'internal-1', batchKeys: [] } }
|
|
expect(actionRoute(trip, [])).toBeNull()
|
|
expect(actionRoute(trip, [{ kind: 'FLEET_TRIP', key: 'internal-1', businessNo: 'TR/2026-1', label: '车次' }])).toBe('/overseas-master-data/trips/TR%2F2026-1')
|
|
})
|
|
it('opens the original container operation with a real source selection for direct unloading', () => {
|
|
const action: WorkAction = { code: 'RECORD_EXECUTION', label: '登记执行', targetWorkItemKey: null, target: { kind: 'FIRSTLEG_CONTAINER', containerBookingId: '9007199254740993' } }
|
|
expect(actionRoute(action, [], workItem({ type: 'PICKUP' }))).toBe('/container-loading/overseas/9007199254740993?action=pickup')
|
|
expect(actionRoute(action, [], workItem({ type: 'EMPTY_RETURN' }))).toBe('/container-loading/overseas/9007199254740993?action=empty-return')
|
|
expect(actionRoute(action, [], workItem({ type: 'DELIVERY', flow: 'DIRECT', requirementKey: 'INBOUND:9007199254740999' }))).toBe('/container-loading/overseas/9007199254740993?action=direct-unload&requirementKey=INBOUND%3A9007199254740999')
|
|
})
|
|
it('routes receiving by plan business number plus customer scope, never the internal plan ID', () => {
|
|
const action: WorkAction = { code: 'RECORD_EXECUTION', label: '查看接仓', targetWorkItemKey: null, target: { kind: 'WAREHOUSE_RECEIPT', inboundPlanId: 'internal-plan', inboundPlanNo: 'IP/TEST', customerId: '9007199254740999', containerBookingId: 'container-1' } }
|
|
expect(actionRoute(action, [])).toBe('/overseas-warehouse/inbound-orders/IP%2FTEST?customerId=9007199254740999')
|
|
expect(actionRoute({ ...action, target: { kind: 'WAREHOUSE_RECEIPT', inboundPlanId: null, inboundPlanNo: null, customerId: null, containerBookingId: 'container-1' } }, [])).toBeNull()
|
|
})
|