109 lines
3.6 KiB
TypeScript
109 lines
3.6 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||
/**
|
||
* Catalogue section 15 — SnippetOrdersView
|
||
* (`tests/components/snippet-orders-view.test.tsx`).
|
||
*/
|
||
import React from 'react'
|
||
import { fireEvent } from '@testing-library/react-native'
|
||
|
||
import SnippetOrdersView from '@/components/SnippetOrdersView'
|
||
import { renderWithProviders } from '../helpers/test-utils'
|
||
import { resetAllMocks } from '../helpers/reset'
|
||
import { SNIPPET_ORDERS } from '../fixtures'
|
||
|
||
type Order = any
|
||
|
||
const ORDER: Order = {
|
||
...SNIPPET_ORDERS.data[0],
|
||
totalAmount: '445',
|
||
slotInfo: {
|
||
time: new Date('2026-10-19T12:00:00.000Z').toISOString(),
|
||
sequence: [],
|
||
},
|
||
products: [
|
||
{
|
||
orderItemId: 1,
|
||
productId: 2,
|
||
productName: 'Chicken Breast',
|
||
quantity: 2,
|
||
productSize: 500,
|
||
price: 215,
|
||
unit: '500g',
|
||
subtotal: 430,
|
||
},
|
||
{
|
||
orderItemId: 2,
|
||
productId: 5,
|
||
productName: 'Cucumber',
|
||
quantity: 1,
|
||
productSize: 500,
|
||
price: 15,
|
||
unit: '500g',
|
||
subtotal: 15,
|
||
},
|
||
],
|
||
}
|
||
|
||
function renderView(props: { orders: Order[]; snippetCode: string; onClose: () => void }) {
|
||
return renderWithProviders(<SnippetOrdersView {...props} />, { auth: false })
|
||
}
|
||
|
||
describe('SnippetOrdersView (ASOV-01..05)', () => {
|
||
beforeEach(() => resetAllMocks())
|
||
|
||
it('ASOV-01: an order card shows id, customer, total, date and slot', () => {
|
||
const view = renderView({ orders: [ORDER], snippetCode: 'ABC123', onClose: jest.fn() })
|
||
|
||
expect(view.getByText('Orders for "ABC123"')).toBeTruthy()
|
||
expect(view.getByText('ORD-1011')).toBeTruthy()
|
||
expect(view.getByText('Test User')).toBeTruthy()
|
||
expect(view.getByText('₹445')).toBeTruthy()
|
||
expect(view.getByText(new Date(ORDER.orderDate).toLocaleDateString())).toBeTruthy()
|
||
expect(
|
||
view.getByText(`Delivery: ${new Date(ORDER.slotInfo.time).toLocaleString()}`)
|
||
).toBeTruthy()
|
||
expect(view.getByText('1 order • Total: ₹445.00')).toBeTruthy()
|
||
})
|
||
|
||
it('ASOV-02: matched products are highlighted and non-matched ones are not', () => {
|
||
const view = renderView({
|
||
orders: [{ ...ORDER, matchedProducts: [2] }],
|
||
snippetCode: 'ABC123',
|
||
onClose: jest.fn(),
|
||
})
|
||
|
||
// Matched rows get the star suffix; the non-matched row keeps its plain name.
|
||
expect(view.getByText('Chicken Breast ⭐')).toBeTruthy()
|
||
expect(view.getByText('Cucumber')).toBeTruthy()
|
||
expect(view.getByText('Matched 1 product(s) from snippet "ABC123"')).toBeTruthy()
|
||
})
|
||
|
||
it('ASOV-03: line subtotals and the order total are formatted to two decimals', () => {
|
||
const view = renderView({ orders: [ORDER], snippetCode: 'ABC123', onClose: jest.fn() })
|
||
|
||
expect(view.getByText('₹430.00')).toBeTruthy()
|
||
expect(view.getByText('₹15.00')).toBeTruthy()
|
||
expect(view.getByText('2 500g × ₹215')).toBeTruthy()
|
||
expect(view.getByText('1 500g × ₹15')).toBeTruthy()
|
||
expect(view.getByText('1 order • Total: ₹445.00')).toBeTruthy()
|
||
})
|
||
|
||
it('ASOV-04: an empty order list shows the empty state', () => {
|
||
const view = renderView({ orders: [], snippetCode: 'ABC123', onClose: jest.fn() })
|
||
|
||
expect(view.getByText('No matching orders')).toBeTruthy()
|
||
expect(
|
||
view.getByText("No orders found that match this snippet's criteria")
|
||
).toBeTruthy()
|
||
expect(view.getByText('0 orders • Total: ₹0.00')).toBeTruthy()
|
||
})
|
||
|
||
it('ASOV-05: the close button calls onClose', () => {
|
||
const onClose = jest.fn()
|
||
const view = renderView({ orders: [ORDER], snippetCode: 'ABC123', onClose })
|
||
|
||
fireEvent.press(view.getByText('✕'))
|
||
|
||
expect(onClose).toHaveBeenCalledTimes(1)
|
||
})
|
||
})
|