123 lines
5.1 KiB
TypeScript
123 lines
5.1 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
/**
|
|
* Catalogue section 24 — `OrderStatusTracker` (OST-01..07).
|
|
*
|
|
* `deliveryStageIndex` maps the backend deliveryStatus onto the furthest stage
|
|
* (Placed -> Packed -> Delivered); `cancelled` supersedes it and marks every
|
|
* stage inactive. Colours are asserted through the flattened style, and the dots
|
|
* carry per-stage testIDs.
|
|
*/
|
|
import * as React from 'react'
|
|
import { StyleSheet } from 'react-native'
|
|
import OrderStatusTracker from '@/components/OrderStatusTracker'
|
|
import { renderWithProviders } from '../helpers/test-utils'
|
|
import { resetAllMocks } from '../helpers/reset'
|
|
|
|
const ACTIVE = '#10B981'
|
|
const INACTIVE = '#E2E8F0'
|
|
const LABEL_GRAY = '#94A3B8'
|
|
|
|
const STAGES = ['placed', 'packed', 'delivered'] as const
|
|
|
|
function renderTracker(props: {
|
|
deliveryStatus?: string | null
|
|
activeColor?: string
|
|
inactiveColor?: string
|
|
}) {
|
|
return renderWithProviders(<OrderStatusTracker {...props} />, { auth: false })
|
|
}
|
|
|
|
function backgroundColor(node: any): string | undefined {
|
|
return StyleSheet.flatten(node.props.style)?.backgroundColor
|
|
}
|
|
|
|
function textColor(node: any): string | undefined {
|
|
return StyleSheet.flatten(node.props.style)?.color
|
|
}
|
|
|
|
describe('OrderStatusTracker', () => {
|
|
beforeEach(() => resetAllMocks())
|
|
|
|
it('OST-01: pending / processing keeps only Placed active', () => {
|
|
const pending = renderTracker({ deliveryStatus: 'pending' })
|
|
expect(backgroundColor(pending.getByTestId('order-status-dot-placed'))).toBe(ACTIVE)
|
|
expect(backgroundColor(pending.getByTestId('order-status-dot-packed'))).toBe(INACTIVE)
|
|
expect(backgroundColor(pending.getByTestId('order-status-dot-delivered'))).toBe(INACTIVE)
|
|
pending.unmount()
|
|
|
|
const processing = renderTracker({ deliveryStatus: 'processing' })
|
|
expect(backgroundColor(processing.getByTestId('order-status-dot-placed'))).toBe(ACTIVE)
|
|
expect(backgroundColor(processing.getByTestId('order-status-dot-packed'))).toBe(INACTIVE)
|
|
})
|
|
|
|
it('OST-02: packaged marks Placed and Packed active', () => {
|
|
const { getByTestId } = renderTracker({ deliveryStatus: 'packaged' })
|
|
|
|
expect(backgroundColor(getByTestId('order-status-dot-placed'))).toBe(ACTIVE)
|
|
expect(backgroundColor(getByTestId('order-status-dot-packed'))).toBe(ACTIVE)
|
|
expect(backgroundColor(getByTestId('order-status-dot-delivered'))).toBe(INACTIVE)
|
|
})
|
|
|
|
it('OST-03: success / delivered marks every stage active', () => {
|
|
const success = renderTracker({ deliveryStatus: 'success' })
|
|
STAGES.forEach((stage) =>
|
|
expect(backgroundColor(success.getByTestId(`order-status-dot-${stage}`))).toBe(ACTIVE)
|
|
)
|
|
success.unmount()
|
|
|
|
const delivered = renderTracker({ deliveryStatus: 'delivered' })
|
|
STAGES.forEach((stage) =>
|
|
expect(backgroundColor(delivered.getByTestId(`order-status-dot-${stage}`))).toBe(ACTIVE)
|
|
)
|
|
})
|
|
|
|
it('OST-04: cancelled leaves no stage active and grays the labels', () => {
|
|
const { getByTestId, getByText } = renderTracker({ deliveryStatus: 'cancelled' })
|
|
|
|
STAGES.forEach((stage) =>
|
|
expect(backgroundColor(getByTestId(`order-status-dot-${stage}`))).toBe(INACTIVE)
|
|
)
|
|
expect(textColor(getByText('Placed'))).toBe(LABEL_GRAY)
|
|
expect(textColor(getByText('Packed'))).toBe(LABEL_GRAY)
|
|
expect(textColor(getByText('Delivered'))).toBe(LABEL_GRAY)
|
|
})
|
|
|
|
it('OST-05: null / empty status falls back to Placed only', () => {
|
|
const empty = renderTracker({ deliveryStatus: null })
|
|
expect(backgroundColor(empty.getByTestId('order-status-dot-placed'))).toBe(ACTIVE)
|
|
expect(backgroundColor(empty.getByTestId('order-status-dot-packed'))).toBe(INACTIVE)
|
|
empty.unmount()
|
|
|
|
const blank = renderTracker({ deliveryStatus: '' })
|
|
expect(backgroundColor(blank.getByTestId('order-status-dot-placed'))).toBe(ACTIVE)
|
|
expect(backgroundColor(blank.getByTestId('order-status-dot-packed'))).toBe(INACTIVE)
|
|
})
|
|
|
|
it('OST-06: custom colors drive both dot and connector colors', () => {
|
|
const active = '#FF0000'
|
|
const inactive = '#0000FF'
|
|
const { getByTestId } = renderTracker({
|
|
deliveryStatus: 'packaged',
|
|
activeColor: active,
|
|
inactiveColor: inactive,
|
|
})
|
|
|
|
expect(backgroundColor(getByTestId('order-status-dot-placed'))).toBe(active)
|
|
expect(backgroundColor(getByTestId('order-status-dot-packed'))).toBe(active)
|
|
expect(backgroundColor(getByTestId('order-status-dot-delivered'))).toBe(inactive)
|
|
|
|
// Placed->Packed connector is reached, Packed->Delivered is not.
|
|
expect(backgroundColor(getByTestId('order-status-line-right-placed'))).toBe(active)
|
|
expect(backgroundColor(getByTestId('order-status-line-left-packed'))).toBe(active)
|
|
expect(backgroundColor(getByTestId('order-status-line-right-packed'))).toBe(inactive)
|
|
expect(backgroundColor(getByTestId('order-status-line-left-delivered'))).toBe(inactive)
|
|
})
|
|
|
|
it('OST-07: exposes one dot per stage plus the tracker container', () => {
|
|
const { getByTestId, getAllByTestId } = renderTracker({ deliveryStatus: 'pending' })
|
|
|
|
expect(getByTestId('order-status-tracker')).toBeTruthy()
|
|
expect(getAllByTestId(/^order-status-dot-/)).toHaveLength(3)
|
|
STAGES.forEach((stage) => expect(getByTestId(`order-status-dot-${stage}`)).toBeTruthy())
|
|
})
|
|
})
|