92 lines
4 KiB
TypeScript
92 lines
4 KiB
TypeScript
/**
|
|
* Catalogue section 15 — Order success (`tests/pages/order-success.test.tsx`,
|
|
* SUCCESS-01..SUCCESS-10).
|
|
*
|
|
* Both the regular (`home/order-success.tsx`) and flash
|
|
* (`flash-delivery/order-success.tsx`) routes run for real. Params come from the
|
|
* expo-router mock; navigation is asserted on the router spy.
|
|
*/
|
|
import * as React from 'react'
|
|
import { fireEvent } from '@testing-library/react-native'
|
|
|
|
import OrderSuccess from '@/app/(drawer)/(tabs)/home/order-success'
|
|
import FlashOrderSuccess from '@/app/(drawer)/(tabs)/flash-delivery/order-success'
|
|
|
|
import { renderWithProviders } from '../helpers/test-utils'
|
|
import { resetAllMocks } from '../helpers/reset'
|
|
import { __setParams, router } from '../mocks/expo-router-mock'
|
|
|
|
function renderSuccess(flash = false, params: Record<string, any> = {}) {
|
|
__setParams(params)
|
|
return renderWithProviders(flash ? <FlashOrderSuccess /> : <OrderSuccess />, {
|
|
auth: false,
|
|
})
|
|
}
|
|
|
|
describe('Order success — SUCCESS-01..10', () => {
|
|
beforeEach(() => resetAllMocks())
|
|
|
|
it('SUCCESS-01: no params shows the regular copy and hides the detail block', () => {
|
|
const { getByText, queryByTestId } = renderSuccess()
|
|
expect(getByText('Order Placed Successfully!')).toBeTruthy()
|
|
expect(getByText('Thank you for your order')).toBeTruthy()
|
|
expect(getByText('Your order will be delivered as per your selected slot')).toBeTruthy()
|
|
expect(queryByTestId('order-success-details')).toBeNull()
|
|
})
|
|
|
|
it('SUCCESS-02: orderId + total show "Order #…" and "Total: ₹…"', () => {
|
|
const { getByTestId } = renderSuccess(false, { orderId: '1001', totalAmount: '445' })
|
|
expect(getByTestId('order-success-order-id')).toHaveTextContent('Order #1001')
|
|
expect(getByTestId('order-success-total')).toHaveTextContent('Total: ₹445')
|
|
})
|
|
|
|
it('SUCCESS-03: orderId only hides the total line', () => {
|
|
const { getByTestId, queryByTestId } = renderSuccess(false, { orderId: '1001' })
|
|
expect(getByTestId('order-success-order-id')).toHaveTextContent('Order #1001')
|
|
expect(queryByTestId('order-success-total')).toBeNull()
|
|
})
|
|
|
|
it('SUCCESS-04: total only hides the whole detail block', () => {
|
|
const { queryByTestId } = renderSuccess(false, { totalAmount: '445' })
|
|
expect(queryByTestId('order-success-details')).toBeNull()
|
|
expect(queryByTestId('order-success-total')).toBeNull()
|
|
})
|
|
|
|
it('SUCCESS-05: a total of "0" is truthy and renders ₹0', () => {
|
|
const { getByTestId } = renderSuccess(false, { orderId: '1001', totalAmount: '0' })
|
|
expect(getByTestId('order-success-total')).toHaveTextContent('Total: ₹0')
|
|
})
|
|
|
|
it('SUCCESS-06: Continue Shopping dismisses to home', () => {
|
|
const { getByTestId } = renderSuccess()
|
|
fireEvent.press(getByTestId('order-success-continue'))
|
|
expect(router.dismissTo).toHaveBeenCalledWith('/(drawer)/(tabs)/home')
|
|
})
|
|
|
|
it('SUCCESS-07: View My Orders dismisses all then pushes my-orders', () => {
|
|
const { getByTestId } = renderSuccess()
|
|
fireEvent.press(getByTestId('order-success-view-orders'))
|
|
expect(router.dismissAll).toHaveBeenCalled()
|
|
expect(router.push).toHaveBeenCalledWith('/(drawer)/(tabs)/me/my-orders')
|
|
})
|
|
|
|
it('SUCCESS-08: the flash route shows the 1 Hr copy', () => {
|
|
const { getByText } = renderSuccess(true)
|
|
expect(getByText('1 Hr Order Placed!')).toBeTruthy()
|
|
expect(getByText('Lightning-fast delivery on the way!')).toBeTruthy()
|
|
expect(getByText('Your order will be delivered in just within 1 hour')).toBeTruthy()
|
|
})
|
|
|
|
it('SUCCESS-09: flash Continue Shopping dismisses to flash-delivery', () => {
|
|
const { getByTestId } = renderSuccess(true)
|
|
fireEvent.press(getByTestId('order-success-continue'))
|
|
expect(router.dismissTo).toHaveBeenCalledWith('/(drawer)/(tabs)/flash-delivery')
|
|
})
|
|
|
|
it('SUCCESS-10: flash View My Orders uses the same my-orders route', () => {
|
|
const { getByTestId } = renderSuccess(true)
|
|
fireEvent.press(getByTestId('order-success-view-orders'))
|
|
expect(router.dismissAll).toHaveBeenCalled()
|
|
expect(router.push).toHaveBeenCalledWith('/(drawer)/(tabs)/me/my-orders')
|
|
})
|
|
})
|