/** * Order amount display — order-success and order-detail. * * Both screens show money the app derived rather than money the backend * charged. The known display bugs are pinned and listed in tests/KNOWN-GAPS.md. */ jest.mock('expo-router', () => require('../mocks/router').expoRouterMock()) import React from 'react' import { screen, waitFor } from '@testing-library/react-native' import OrderSuccess from '@/app/(drawer)/(tabs)/home/order-success' import OrderDetails from '@/app/(drawer)/(tabs)/me/my-orders/[id]' import { resetStorage, setupApiMocks } from '../mocks/api' import { resetAuthMock } from '../mocks/auth' import { searchParamsMock } from '../mocks/router' import { renderWithProviders } from '../helpers/render' const order = (over: Record = {}) => ({ id: 42, orderId: 'ORD-42', orderDate: '2026-09-20T10:00:00.000Z', createdAt: '2026-09-20T10:00:00.000Z', orderStatus: 'confirmed', deliveryStatus: 'pending', deliveryDate: '2026-09-26T10:00:00.000Z', cancelReason: null, paymentMode: 'COD', paymentStatus: 'pending', orderAmount: 500, discountAmount: 0, deliveryCharge: 15, couponCode: null, isFlashDelivery: false, userNotes: null, items: [ { productName: 'Chicken Breast 500 g', quantity: 1, unitNotation: '500g', price: 215, amount: 215, image: null, }, ], ...over, }) describe('Order success amounts', () => { beforeEach(async () => { resetAuthMock() await resetStorage() searchParamsMock.current = {} setupApiMocks() }) it('shows the order id and the amount from the route params', async () => { searchParamsMock.current = { orderId: '99', totalAmount: '230' } renderWithProviders(, { centralStores: false }) await waitFor(() => expect(screen.getByText('Order Placed Successfully!')).toBeVisible()) expect(screen.getByText('Order #99')).toBeVisible() expect(screen.getByText('Total: ₹230')).toBeVisible() }) /** * KNOWN GAP: `totalAmount` is the frontend's `finalTotalWithDelivery` written * into the query string by PaymentAndOrderComponent, not the amount the * backend stored on the order. The multi-slot discount is scaled by * `orderGroupProportion` server-side but not in the UI, so this number can * differ from what was charged. Pinned as-is. */ it('renders whatever amount the caller put in the query string', async () => { searchParamsMock.current = { orderId: '99', totalAmount: '1234.56' } renderWithProviders(, { centralStores: false }) await waitFor(() => expect(screen.getByText('Total: ₹1234.56')).toBeVisible()) }) it('omits the amount block when the param is missing', async () => { searchParamsMock.current = { orderId: '99' } renderWithProviders(, { centralStores: false }) await waitFor(() => expect(screen.getByText('Order #99')).toBeVisible()) expect(screen.queryByText(/Total: ₹/)).toBeNull() }) }) describe('Order detail amounts', () => { beforeEach(async () => { resetAuthMock() await resetStorage() searchParamsMock.current = { id: '42' } setupApiMocks({ procedures: { 'user.order.getOrderById': order(), 'user.order.updateUserNotes': { success: true }, 'user.order.cancelOrder': { success: true }, }, }) }) it('hides the coupon block when nothing was discounted', async () => { renderWithProviders(, { centralStores: false }) await waitFor(() => expect(screen.getByText('Order #ORD-42')).toBeVisible()) expect(screen.queryByText('Coupon Applied')).toBeNull() expect(screen.queryByText(/^Coupon/)).toBeNull() // The summary shows a Discount row only above zero. expect(screen.queryByText('Discount')).toBeNull() expect(screen.getByText('₹500')).toBeVisible() }) it('shows the coupon badge and the discount rows for a discounted order', async () => { setupApiMocks({ procedures: { 'user.order.getOrderById': order({ couponCode: 'SAVE20', discountAmount: 20, orderAmount: 480, }), 'user.order.updateUserNotes': { success: true }, 'user.order.cancelOrder': { success: true }, }, }) renderWithProviders(, { centralStores: false }) await waitFor(() => expect(screen.getByText('SAVE20')).toBeVisible()) expect(screen.getByText('Coupon Applied')).toBeVisible() // Badge row and summary row both show the discount. expect(screen.getAllByText('-₹20').length).toBeGreaterThanOrEqual(1) expect(screen.getByText('Discount')).toBeVisible() expect(screen.getByText('₹480')).toBeVisible() }) it('renders a fractional discount verbatim in both the badge and the summary', async () => { setupApiMocks({ procedures: { 'user.order.getOrderById': order({ couponCode: 'SAVE20', discountAmount: 20.5, }), 'user.order.updateUserNotes': { success: true }, 'user.order.cancelOrder': { success: true }, }, }) renderWithProviders(, { centralStores: false }) await waitFor(() => expect(screen.getByText('SAVE20')).toBeVisible()) // The coupon badge and the summary row both print the stored amount as-is. expect(screen.getAllByText('-₹20.5')).toHaveLength(2) }) })