562 lines
21 KiB
TypeScript
562 lines
21 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||
/**
|
||
* Section 22 — Order detail (`tests/pages/order-detail.test.tsx`, OD-01..35).
|
||
*
|
||
* `getOrderById({ orderId })` returns the order object directly. The header,
|
||
* tracker, notes editor, item list and totals all read from that object;
|
||
* notes/cancel go through `updateUserNotes` / `cancelOrder`.
|
||
*
|
||
* Rows marked "(current)" pin documented behaviour instead of the ideal one.
|
||
* A few rows assert the observable half of a refetch: the trpc mock's
|
||
* `refetch` is a no-op `jest.fn`, so it cannot be counted directly.
|
||
*/
|
||
import * as React from 'react'
|
||
import { Alert, StyleSheet } from 'react-native'
|
||
import { fireEvent } from '@testing-library/react-native'
|
||
import dayjs from 'dayjs'
|
||
|
||
import OrderDetails from '@/app/(drawer)/(tabs)/me/my-orders/[id]'
|
||
|
||
import { flush, renderWithProviders } from '../helpers/test-utils'
|
||
import { resetAllMocks } from '../helpers/reset'
|
||
import { __setParams, router } from '../mocks/expo-router-mock'
|
||
import {
|
||
lastProcedureInput,
|
||
procedureInvalidations,
|
||
procedureMutationCalls,
|
||
procedureQueryCalls,
|
||
setProcedure,
|
||
} from '../mocks/trpc-client'
|
||
import { O1 } from '../fixtures'
|
||
|
||
/* -------------------------------------------------------------------------- */
|
||
/* Builders */
|
||
/* -------------------------------------------------------------------------- */
|
||
|
||
const ORDER_DATE = '2026-03-14T10:30:00.000Z'
|
||
const DELIVERY_DATE = '2026-03-14T12:30:00.000Z'
|
||
|
||
function item(overrides: any = {}) {
|
||
return {
|
||
id: 1,
|
||
skuId: 2,
|
||
productName: 'Chicken Breast',
|
||
name: 'Chicken Breast',
|
||
quantity: 2,
|
||
unit: '500g',
|
||
unitNotation: '500g',
|
||
price: 215,
|
||
amount: 430,
|
||
image: 'chicken.jpg',
|
||
isPackaged: false,
|
||
isVerified: false,
|
||
...overrides,
|
||
}
|
||
}
|
||
|
||
function makeOrder(overrides: any = {}) {
|
||
return {
|
||
...O1,
|
||
orderId: 'ORD-1001',
|
||
id: 1001,
|
||
orderDate: ORDER_DATE,
|
||
createdAt: ORDER_DATE,
|
||
deliveryDate: DELIVERY_DATE,
|
||
deliveryStatus: 'pending',
|
||
orderStatus: 'pending',
|
||
orderAmount: 445,
|
||
totalAmount: 445,
|
||
discountAmount: 0,
|
||
deliveryCharge: 0,
|
||
couponCode: null,
|
||
userNotes: null,
|
||
cancelReason: null,
|
||
isFlashDelivery: false,
|
||
items: [item()],
|
||
...overrides,
|
||
}
|
||
}
|
||
|
||
function renderOrder(order: any = makeOrder()) {
|
||
setProcedure('user.order.getOrderById', { data: order })
|
||
__setParams({ id: order.orderId })
|
||
return renderWithProviders(<OrderDetails />, { auth: 'out' })
|
||
}
|
||
|
||
async function load() {
|
||
await flush(3)
|
||
}
|
||
|
||
function dotColor(view: ReturnType<typeof renderOrder>, stage: string) {
|
||
return StyleSheet.flatten(view.getByTestId(`order-status-dot-${stage}`).props.style)
|
||
?.backgroundColor
|
||
}
|
||
|
||
function spyAlert() {
|
||
return jest.spyOn(Alert, 'alert').mockImplementation(() => {})
|
||
}
|
||
|
||
/* -------------------------------------------------------------------------- */
|
||
/* Tests */
|
||
/* -------------------------------------------------------------------------- */
|
||
|
||
describe('Order detail (OD)', () => {
|
||
beforeEach(() => {
|
||
resetAllMocks()
|
||
})
|
||
|
||
it('OD-01: while the order is pending the page shows "Loading details..."', async () => {
|
||
setProcedure('user.order.getOrderById', { mode: 'pending' })
|
||
__setParams({ id: 'ORD-1001' })
|
||
const view = renderWithProviders(<OrderDetails />, { auth: 'out' })
|
||
await flush(2)
|
||
|
||
expect(view.getByTestId('order-detail-loading')).toBeTruthy()
|
||
expect(view.getByText('Loading details...')).toBeTruthy()
|
||
})
|
||
|
||
it('OD-02: a failed fetch shows "Failed to load" and Go Back calls router.back', async () => {
|
||
setProcedure('user.order.getOrderById', { mode: 'error', error: new Error('offline') })
|
||
__setParams({ id: 'ORD-1001' })
|
||
const view = renderWithProviders(<OrderDetails />, { auth: 'out' })
|
||
await load()
|
||
|
||
expect(view.getByTestId('order-detail-error')).toBeTruthy()
|
||
expect(view.getByText('Failed to load')).toBeTruthy()
|
||
|
||
fireEvent.press(view.getByTestId('order-detail-go-back'))
|
||
|
||
expect(router.back).toHaveBeenCalled()
|
||
})
|
||
|
||
it('OD-03: without an id the query is disabled and the error screen renders', async () => {
|
||
__setParams({})
|
||
const view = renderWithProviders(<OrderDetails />, { auth: 'out' })
|
||
await load()
|
||
|
||
expect(view.getByText('Failed to load')).toBeTruthy()
|
||
// The disabled query never runs.
|
||
expect(procedureQueryCalls('user.order.getOrderById')).toHaveLength(0)
|
||
})
|
||
|
||
it('OD-04: the header shows id, date, region, flash marker and status', async () => {
|
||
const view = renderOrder(
|
||
makeOrder({ regionName: 'Hyderabad', isFlashDelivery: true, deliveryStatus: 'packaged' })
|
||
)
|
||
await load()
|
||
|
||
expect(view.getByText('Order #ORD-1001')).toBeTruthy()
|
||
expect(view.getByText(dayjs(ORDER_DATE).format('DD MMM, h:mm A'))).toBeTruthy()
|
||
expect(view.getByText('Hyderabad')).toBeTruthy()
|
||
expect(view.getByText('⚡ 1 Hr Delivery')).toBeTruthy()
|
||
expect(view.getByTestId('order-detail-status')).toHaveTextContent('packaged')
|
||
expect(lastProcedureInput('user.order.getOrderById')).toEqual({ orderId: 'ORD-1001' })
|
||
})
|
||
|
||
it('OD-05: a flash order shows the 1 Hr Delivery banner and lightning marker', async () => {
|
||
const view = renderOrder(makeOrder({ isFlashDelivery: true }))
|
||
await load()
|
||
|
||
expect(view.getByTestId('order-flash-banner')).toBeTruthy()
|
||
expect(view.getByText('1 Hr Delivery Order')).toBeTruthy()
|
||
expect(view.getByText('Your order will be delivered within 1 hr of placement')).toBeTruthy()
|
||
expect(view.getByText('⚡')).toBeTruthy()
|
||
})
|
||
|
||
it('OD-06: a delivered flash order shows "Flash Delivered on ..."', async () => {
|
||
const view = renderOrder(makeOrder({ isFlashDelivery: true, deliveryStatus: 'delivered' }))
|
||
await load()
|
||
|
||
const expected = `Flash Delivered on ${dayjs(ORDER_DATE).add(30, 'minutes').format('DD MMM YYYY, h:mm A')}`
|
||
expect(view.getByTestId('order-delivered-row')).toBeTruthy()
|
||
expect(view.getByText(expected)).toBeTruthy()
|
||
})
|
||
|
||
it('OD-07: an undelivered flash order shows the estimated date instead', async () => {
|
||
const view = renderOrder(makeOrder({ isFlashDelivery: true, deliveryStatus: 'packaged' }))
|
||
await load()
|
||
|
||
const expected = `1 Hr Delivery: ${dayjs(ORDER_DATE).add(30, 'minutes').format('DD MMM YYYY, h:mm A')}`
|
||
expect(view.getByText(expected)).toBeTruthy()
|
||
expect(view.queryByText(/^Flash Delivered on/)).toBeNull()
|
||
})
|
||
|
||
it('OD-08: a delivered scheduled order shows "Delivered on ..."', async () => {
|
||
const view = renderOrder(makeOrder({ deliveryStatus: 'success' }))
|
||
await load()
|
||
|
||
const expected = `Delivered on ${dayjs(DELIVERY_DATE).format('DD MMM YYYY, h:mm A')}`
|
||
expect(view.getByTestId('order-delivered-row')).toBeTruthy()
|
||
expect(view.getByText(expected)).toBeTruthy()
|
||
})
|
||
|
||
it('OD-09: an undelivered scheduled order has no delivered row', async () => {
|
||
const view = renderOrder(makeOrder({ deliveryStatus: 'packaged' }))
|
||
await load()
|
||
|
||
expect(view.queryByTestId('order-delivered-row')).toBeNull()
|
||
expect(view.queryByText(/^Delivered on/)).toBeNull()
|
||
})
|
||
|
||
it('OD-10: the status tracker maps pending / packaged / success / cancelled', async () => {
|
||
const ACTIVE = '#10B981'
|
||
const INACTIVE = '#E2E8F0'
|
||
|
||
const pending = renderOrder(makeOrder({ deliveryStatus: 'pending' }))
|
||
await load()
|
||
expect(dotColor(pending, 'placed')).toBe(ACTIVE)
|
||
expect(dotColor(pending, 'packed')).toBe(INACTIVE)
|
||
expect(dotColor(pending, 'delivered')).toBe(INACTIVE)
|
||
pending.unmount()
|
||
|
||
const packaged = renderOrder(makeOrder({ deliveryStatus: 'packaged' }))
|
||
await load()
|
||
expect(dotColor(packaged, 'placed')).toBe(ACTIVE)
|
||
expect(dotColor(packaged, 'packed')).toBe(ACTIVE)
|
||
expect(dotColor(packaged, 'delivered')).toBe(INACTIVE)
|
||
packaged.unmount()
|
||
|
||
const success = renderOrder(makeOrder({ deliveryStatus: 'success' }))
|
||
await load()
|
||
expect(dotColor(success, 'placed')).toBe(ACTIVE)
|
||
expect(dotColor(success, 'packed')).toBe(ACTIVE)
|
||
expect(dotColor(success, 'delivered')).toBe(ACTIVE)
|
||
success.unmount()
|
||
|
||
const cancelled = renderOrder(makeOrder({ deliveryStatus: 'cancelled' }))
|
||
await load()
|
||
expect(dotColor(cancelled, 'placed')).toBe(INACTIVE)
|
||
expect(dotColor(cancelled, 'packed')).toBe(INACTIVE)
|
||
expect(dotColor(cancelled, 'delivered')).toBe(INACTIVE)
|
||
})
|
||
|
||
it('OD-11: without notes the section shows "No instructions added" and an Add action', async () => {
|
||
const view = renderOrder(makeOrder({ userNotes: null }))
|
||
await load()
|
||
|
||
expect(view.getByTestId('order-notes-text')).toHaveTextContent('No instructions added')
|
||
expect(view.getByText('Add')).toBeTruthy()
|
||
})
|
||
|
||
it('OD-12: with notes the section shows the text and an Edit action', async () => {
|
||
const view = renderOrder(makeOrder({ userNotes: 'Leave at the door' }))
|
||
await load()
|
||
|
||
expect(view.getByTestId('order-notes-text')).toHaveTextContent('Leave at the door')
|
||
expect(view.getByText('Edit')).toBeTruthy()
|
||
})
|
||
|
||
it('OD-13: Add/Edit opens the input, Cancel restores and Save calls updateUserNotes', async () => {
|
||
const alertSpy = spyAlert()
|
||
// The save triggers a real `refetch()`; keep the fixture stateful so the
|
||
// refetched order carries the saved notes (a static fixture would restore
|
||
// the old text).
|
||
let savedNotes: string | null = 'Leave at the door'
|
||
setProcedure('user.order.getOrderById', { impl: () => makeOrder({ userNotes: savedNotes }) })
|
||
setProcedure('user.order.updateUserNotes', {
|
||
impl: (input: any) => {
|
||
savedNotes = input.userNotes
|
||
return { success: true }
|
||
},
|
||
})
|
||
const view = renderOrder(makeOrder({ userNotes: 'Leave at the door' }))
|
||
await load()
|
||
|
||
fireEvent.press(view.getByTestId('order-notes-edit'))
|
||
const input = view.getByTestId('order-notes-input')
|
||
expect(input.props.value).toBe('Leave at the door')
|
||
|
||
fireEvent.changeText(input, 'Ring the bell')
|
||
fireEvent.press(view.getByTestId('order-notes-cancel'))
|
||
|
||
expect(view.getByTestId('order-notes-text')).toHaveTextContent('Leave at the door')
|
||
expect(procedureMutationCalls('user.order.updateUserNotes')).toHaveLength(0)
|
||
|
||
fireEvent.press(view.getByTestId('order-notes-edit'))
|
||
fireEvent.changeText(view.getByTestId('order-notes-input'), 'Ring the bell')
|
||
fireEvent.press(view.getByTestId('order-notes-save'))
|
||
await flush(3)
|
||
|
||
expect(lastProcedureInput('user.order.updateUserNotes')).toEqual({
|
||
id: 1001,
|
||
userNotes: 'Ring the bell',
|
||
})
|
||
expect(alertSpy).toHaveBeenCalledWith('Success', 'Notes updated successfully')
|
||
expect(view.queryByTestId('order-notes-input')).toBeNull()
|
||
expect(view.getByTestId('order-notes-text')).toHaveTextContent('Ring the bell')
|
||
})
|
||
|
||
it('OD-14: a pending notes save shows "Saving..." and disables the button', async () => {
|
||
setProcedure('user.order.updateUserNotes', { mode: 'pending' })
|
||
const view = renderOrder(makeOrder({ userNotes: 'Leave at the door' }))
|
||
await load()
|
||
|
||
fireEvent.press(view.getByTestId('order-notes-edit'))
|
||
fireEvent.changeText(view.getByTestId('order-notes-input'), 'Ring the bell')
|
||
fireEvent.press(view.getByTestId('order-notes-save'))
|
||
await flush(2)
|
||
|
||
expect(view.getByTestId('order-notes-save')).toHaveTextContent('Saving...')
|
||
expect(view.getByTestId('order-notes-save')).toBeDisabled()
|
||
})
|
||
|
||
it('OD-15: a successful notes save closes the editor and alerts', async () => {
|
||
const alertSpy = spyAlert()
|
||
const view = renderOrder(makeOrder({ userNotes: null }))
|
||
await load()
|
||
|
||
fireEvent.press(view.getByTestId('order-notes-edit'))
|
||
fireEvent.changeText(view.getByTestId('order-notes-input'), 'Call on arrival')
|
||
fireEvent.press(view.getByTestId('order-notes-save'))
|
||
await flush(3)
|
||
|
||
// The mutation's onSuccess runs `refetch()`; the mock exposes it as a no-op
|
||
// jest.fn, so the observable result is the closed editor + alert.
|
||
expect(view.queryByTestId('order-notes-input')).toBeNull()
|
||
expect(view.getByTestId('order-notes-text')).toHaveTextContent('Call on arrival')
|
||
expect(alertSpy).toHaveBeenCalledWith('Success', 'Notes updated successfully')
|
||
})
|
||
|
||
it('OD-16: a failing notes save alerts and keeps the editor open', async () => {
|
||
const alertSpy = spyAlert()
|
||
setProcedure('user.order.updateUserNotes', {
|
||
mode: 'error',
|
||
error: new Error('notes exploded'),
|
||
})
|
||
const view = renderOrder(makeOrder({ userNotes: 'Leave at the door' }))
|
||
await load()
|
||
|
||
fireEvent.press(view.getByTestId('order-notes-edit'))
|
||
fireEvent.changeText(view.getByTestId('order-notes-input'), 'Ring the bell')
|
||
fireEvent.press(view.getByTestId('order-notes-save'))
|
||
await flush(3)
|
||
|
||
expect(alertSpy).toHaveBeenCalledWith('Error', 'notes exploded')
|
||
expect(view.getByTestId('order-notes-input')).toBeTruthy()
|
||
expect(view.getByTestId('order-notes-save')).toHaveTextContent('Save')
|
||
})
|
||
|
||
it('OD-17: a cancel reason renders a cancellation block', async () => {
|
||
const view = renderOrder(
|
||
makeOrder({ deliveryStatus: 'cancelled', cancelReason: 'Out of stock' })
|
||
)
|
||
await load()
|
||
|
||
expect(view.getByText('Cancellation Reason')).toBeTruthy()
|
||
expect(view.getByText('Out of stock')).toBeTruthy()
|
||
})
|
||
|
||
it('OD-18: order items show name, qty × unit, unit price and amount', async () => {
|
||
const view = renderOrder(
|
||
makeOrder({
|
||
items: [item({ quantity: 2, unitNotation: '500g', price: 215, amount: 430 })],
|
||
})
|
||
)
|
||
await load()
|
||
|
||
expect(view.getByText('Chicken Breast')).toBeTruthy()
|
||
expect(view.getByText('2 × 500g · ₹215')).toBeTruthy()
|
||
// The single item's amount doubles as the subtotal.
|
||
expect(view.getAllByText('₹430')).toHaveLength(2)
|
||
})
|
||
|
||
it('OD-19: an item without an image does not crash', async () => {
|
||
const view = renderOrder(
|
||
makeOrder({ items: [item({ image: null, productName: 'Mystery Cut' })] })
|
||
)
|
||
await load()
|
||
|
||
expect(view.getByText('Order Items')).toBeTruthy()
|
||
expect(view.getByText('Mystery Cut')).toBeTruthy()
|
||
})
|
||
|
||
it('OD-20: a coupon renders its block and the negated discount', async () => {
|
||
const view = renderOrder(makeOrder({ couponCode: 'SAVE10', discountAmount: 43 }))
|
||
await load()
|
||
|
||
expect(view.getByText('SAVE10')).toBeTruthy()
|
||
expect(view.getByText('Coupon Applied')).toBeTruthy()
|
||
// Coupon block + summary discount row.
|
||
expect(view.getAllByText('-₹43')).toHaveLength(2)
|
||
})
|
||
|
||
it('OD-21: a positive discount adds the summary discount row', async () => {
|
||
const view = renderOrder(makeOrder({ discountAmount: 43 }))
|
||
await load()
|
||
|
||
expect(view.getByText('Discount')).toBeTruthy()
|
||
expect(view.getByTestId('order-summary-discount')).toHaveTextContent('-₹43')
|
||
})
|
||
|
||
it('OD-22: the summary shows the delivery charge, or "Free" when zero', async () => {
|
||
const charged = renderOrder(makeOrder({ deliveryCharge: 15 }))
|
||
await load()
|
||
expect(charged.getByTestId('order-summary-delivery')).toHaveTextContent('₹15')
|
||
expect(charged.queryByText('Free')).toBeNull()
|
||
charged.unmount()
|
||
|
||
const free = renderOrder(makeOrder({ deliveryCharge: 0 }))
|
||
await load()
|
||
expect(free.getByTestId('order-summary-delivery')).toHaveTextContent('Free')
|
||
})
|
||
|
||
it('OD-23: the total uses order.orderAmount', async () => {
|
||
const view = renderOrder(makeOrder({ orderAmount: 777 }))
|
||
await load()
|
||
|
||
expect(view.getByTestId('order-summary-total')).toHaveTextContent('₹777')
|
||
})
|
||
|
||
it('OD-24: the subtotal is the sum of the item amounts', async () => {
|
||
const view = renderOrder(
|
||
makeOrder({
|
||
orderAmount: 999,
|
||
items: [item({ amount: 430 }), item({ id: 2, amount: 150 })],
|
||
})
|
||
)
|
||
await load()
|
||
|
||
expect(view.getByTestId('order-summary-subtotal')).toHaveTextContent('₹580')
|
||
})
|
||
|
||
it('OD-25: Raise Complaint opens the complaint dialog', async () => {
|
||
const view = renderOrder()
|
||
await load()
|
||
|
||
fireEvent.press(view.getByTestId('order-raise-complaint'))
|
||
|
||
expect(view.getByTestId('complaint-body')).toBeTruthy()
|
||
expect(view.getByText('Describe the issue')).toBeTruthy()
|
||
})
|
||
|
||
it('OD-26: closing the complaint dialog refetches the order and closes it', async () => {
|
||
const view = renderOrder()
|
||
await load()
|
||
|
||
fireEvent.press(view.getByTestId('order-raise-complaint'))
|
||
expect(view.getByTestId('complaint-body')).toBeTruthy()
|
||
|
||
fireEvent.press(view.getByTestId('complaint-close'))
|
||
await flush(2)
|
||
|
||
expect(view.queryByTestId('complaint-body')).toBeNull()
|
||
// The close handler is `setComplaintDialogOpen(false); refetch()`; refetch is
|
||
// a no-op jest.fn in the harness, so only the close is observable.
|
||
expect(view.getByText('Order #ORD-1001')).toBeTruthy()
|
||
})
|
||
|
||
it('OD-27: the footer Back button replaces the route with the me tab', async () => {
|
||
const view = renderOrder()
|
||
await load()
|
||
|
||
fireEvent.press(view.getByTestId('order-detail-back'))
|
||
|
||
expect(router.replace).toHaveBeenCalledWith('/(drawer)/(tabs)/me')
|
||
})
|
||
|
||
it('OD-28: Cancel Order is hidden only for exact lower-case success/cancelled', async () => {
|
||
const success = renderOrder(makeOrder({ deliveryStatus: 'success' }))
|
||
await load()
|
||
expect(success.queryByTestId('order-cancel-order')).toBeNull()
|
||
success.unmount()
|
||
|
||
const upper = renderOrder(makeOrder({ deliveryStatus: 'SUCCESS' }))
|
||
await load()
|
||
expect(upper.getByTestId('order-cancel-order')).toBeTruthy()
|
||
})
|
||
|
||
it('OD-29: a "delivered" order still shows Cancel Order (current)', async () => {
|
||
const view = renderOrder(makeOrder({ deliveryStatus: 'delivered' }))
|
||
await load()
|
||
|
||
// The visibility check only excludes the exact strings `success` and
|
||
// `cancelled`, so `delivered` keeps the button.
|
||
expect(view.getByTestId('order-cancel-order')).toBeTruthy()
|
||
})
|
||
|
||
it('OD-30: opening the cancel dialog shows the reason field and confirm button', async () => {
|
||
const view = renderOrder()
|
||
await load()
|
||
|
||
fireEvent.press(view.getByTestId('order-cancel-order'))
|
||
|
||
expect(view.getByText('Reason for cancellation')).toBeTruthy()
|
||
expect(view.getByTestId('cancel-reason')).toBeTruthy()
|
||
expect(view.getByTestId('order-cancel-confirm')).toHaveTextContent('Confirm Cancellation')
|
||
})
|
||
|
||
it('OD-31: a blank or whitespace reason alerts and never mutates', async () => {
|
||
const alertSpy = spyAlert()
|
||
const view = renderOrder()
|
||
await load()
|
||
|
||
fireEvent.press(view.getByTestId('order-cancel-order'))
|
||
fireEvent.changeText(view.getByTestId('cancel-reason'), ' ')
|
||
fireEvent.press(view.getByTestId('order-cancel-confirm'))
|
||
await flush(2)
|
||
|
||
expect(alertSpy).toHaveBeenCalledWith('Error', 'Please enter a reason for cancellation')
|
||
expect(procedureMutationCalls('user.order.cancelOrder')).toHaveLength(0)
|
||
})
|
||
|
||
it('OD-32: confirming cancels the order, closes, invalidates orders and alerts', async () => {
|
||
const alertSpy = spyAlert()
|
||
const view = renderOrder()
|
||
await load()
|
||
|
||
fireEvent.press(view.getByTestId('order-cancel-order'))
|
||
fireEvent.changeText(view.getByTestId('cancel-reason'), 'Ordered by mistake')
|
||
fireEvent.press(view.getByTestId('order-cancel-confirm'))
|
||
await flush(3)
|
||
|
||
expect(lastProcedureInput('user.order.cancelOrder')).toEqual({
|
||
id: 1001,
|
||
reason: 'Ordered by mistake',
|
||
})
|
||
expect(view.queryByTestId('cancel-reason')).toBeNull()
|
||
expect(procedureInvalidations('user.order.getOrders').length).toBeGreaterThan(0)
|
||
expect(alertSpy).toHaveBeenCalledWith('Success', 'Order cancelled successfully')
|
||
})
|
||
|
||
it('OD-33: a failed cancel alerts and keeps the dialog open', async () => {
|
||
const alertSpy = spyAlert()
|
||
setProcedure('user.order.cancelOrder', {
|
||
mode: 'error',
|
||
error: new Error('cancel exploded'),
|
||
})
|
||
const view = renderOrder()
|
||
await load()
|
||
|
||
fireEvent.press(view.getByTestId('order-cancel-order'))
|
||
fireEvent.changeText(view.getByTestId('cancel-reason'), 'Changed plans')
|
||
fireEvent.press(view.getByTestId('order-cancel-confirm'))
|
||
await flush(3)
|
||
|
||
expect(alertSpy).toHaveBeenCalledWith('Error', 'cancel exploded')
|
||
expect(view.getByTestId('cancel-reason')).toBeTruthy()
|
||
expect(view.getByTestId('order-cancel-confirm')).toBeTruthy()
|
||
})
|
||
|
||
it('OD-34: a pending cancel shows a spinner and disables the confirm button', async () => {
|
||
setProcedure('user.order.cancelOrder', { mode: 'pending' })
|
||
const view = renderOrder()
|
||
await load()
|
||
|
||
fireEvent.press(view.getByTestId('order-cancel-order'))
|
||
fireEvent.changeText(view.getByTestId('cancel-reason'), 'Changed plans')
|
||
fireEvent.press(view.getByTestId('order-cancel-confirm'))
|
||
await flush(2)
|
||
|
||
expect(view.getByTestId('order-cancel-confirm')).toBeDisabled()
|
||
expect(view.queryByText('Confirm Cancellation')).toBeNull()
|
||
})
|
||
|
||
it('OD-35: the header back button calls router.back', async () => {
|
||
const view = renderOrder()
|
||
await load()
|
||
|
||
fireEvent.press(view.getByTestId('order-detail-header-back'))
|
||
|
||
expect(router.back).toHaveBeenCalled()
|
||
})
|
||
})
|