优化
This commit is contained in:
@@ -2,13 +2,14 @@ import { describe, expect, it } from 'vitest'
|
||||
import { buckets, expired, inventoryExpired, parseDashboardDrilldown, previousDate } from './dashboardNavigation'
|
||||
import type { QueryContext } from './types'
|
||||
|
||||
const context: QueryContext = { salesRunId: '11', inventoryRunId: '12', salesScopeHash: 'sales', inventoryScopeHash: 'stock', queryAsOf: '2026-10-13T00:00:00Z', queryExpiresAt: '2026-10-13T00:30:00Z', businessTimezone: 'Asia/Shanghai', anchorDate: '2026-10-13', inventoryDrilldownExpiresAt: '2026-10-13T00:10:00Z' }
|
||||
const context: QueryContext = { salesRunId: '11', inventoryRunId: '12', salesScopeHash: 'sales', inventoryScopeHash: 'stock', queryAsOf: '2026-10-13T00:00:00Z', queryExpiresAt: '2026-10-13T00:30:00Z', businessTimezone: 'Asia/Shanghai', anchorDate: '2026-10-13', rangeStartDate: '2026-09-29', rangeEndDateExclusive: '2026-10-14', inventoryDrilldownExpiresAt: '2026-10-13T00:10:00Z' }
|
||||
const base = { from: 'overview', warehouseCode: 'WH-A', context: JSON.stringify(context), overviewReturn: JSON.stringify({ rangePreset: 'LAST_15_DAYS', scroll: 650 }) }
|
||||
describe('dashboard exact drilldown contract', () => {
|
||||
it.each(buckets)('maps $code to exact server bucket rather than an attention approximation', ({ code }) => {
|
||||
const parsed = parseDashboardDrilldown({ ...base, coverageBucket: code, bucketRuleVersion: 'COVERAGE_DISTRIBUTION_V1' }, 'inventory')!
|
||||
expect(parsed.inventory).toMatchObject({ coverageBucket: code, bucketRuleVersion: 'COVERAGE_DISTRIBUTION_V1', drilldownFrom: 'DASHBOARD', attention: 'ALL' })
|
||||
expect(parsed.context).toEqual(context)
|
||||
expect(parsed).toMatchObject({ rangePreset: 'CUSTOM', startDate: '2026-09-29', endDate: '2026-10-13' })
|
||||
expect(parsed.returnTo).toEqual({ rangePreset: 'LAST_15_DAYS', scroll: 650 })
|
||||
})
|
||||
it('preserves exact owner/SKU, maps hot enum and the independent finite candidate selector', () => {
|
||||
@@ -20,10 +21,10 @@ describe('dashboard exact drilldown contract', () => {
|
||||
{ coverageBucket: 'BAD', bucketRuleVersion: 'COVERAGE_DISTRIBUTION_V1' },
|
||||
{ coverageBucket: 'DAYS_GT_90', bucketRuleVersion: 'BAD' },
|
||||
{ bucketRuleVersion: 'COVERAGE_DISTRIBUTION_V1' },
|
||||
{ coverageBucket: 'DAYS_GT_90', bucketRuleVersion: 'COVERAGE_DISTRIBUTION_V1', attention: 'NO_OUTBOUND_30D' },
|
||||
{ coverageSelection: 'FINITE_POSITIVE', attention: 'NO_OUTBOUND_30D' },
|
||||
{ coverageBucket: 'DAYS_GT_90', bucketRuleVersion: 'COVERAGE_DISTRIBUTION_V1', attention: 'NO_OUTBOUND_IN_WINDOW' },
|
||||
{ coverageSelection: 'FINITE_POSITIVE', attention: 'NO_OUTBOUND_IN_WINDOW' },
|
||||
{ coverageSelection: 'FINITE_POSITIVE', coverageBucket: 'UNKNOWN', bucketRuleVersion: 'COVERAGE_DISTRIBUTION_V1' },
|
||||
{ context: '{}' }, { warehouseCode: '' }, { drilldownFrom: 'OTHER' },
|
||||
{ context: '{}' }, { context: JSON.stringify({ ...context, rangeStartDate: undefined }) }, { context: JSON.stringify({ ...context, rangeEndDateExclusive: '2026-09-01' }) }, { warehouseCode: '' }, { drilldownFrom: 'OTHER' },
|
||||
])('rejects malformed/conflicting parameters without widening to the whole warehouse: %j', invalid => {
|
||||
expect(() => parseDashboardDrilldown(Object.fromEntries(Object.entries({ ...base, ...invalid }).filter(([, value]) => value !== undefined)) as Record<string, string>, 'inventory')).toThrow()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user