freshyo/apps/admin-ui/tests/components/snippet-orders-view.test.tsx
2026-10-01 00:33:03 +05:30

94 lines
2.9 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* SnippetOrdersView (components/SnippetOrdersView.tsx) — read-only list of the
* orders matched by a vendor snippet, with per-order totals and an empty state.
*/
import React from 'react'
import { fireEvent, screen } from '@testing-library/react-native'
import SnippetOrdersView from '@/components/SnippetOrdersView'
import { renderWithProviders } from '../helpers/render'
type Order = React.ComponentProps<typeof SnippetOrdersView>['orders'][number]
const order = (overrides: Partial<Order> = {}): Order => ({
orderId: 'ORD1',
orderDate: '2026-01-02T09:00:00.000Z',
customerName: 'Alice',
totalAmount: '100.00',
slotInfo: { time: '2026-01-03T10:00:00.000Z', sequence: [] },
snippetCode: 'VS_5',
matchedProducts: [10],
products: [
{
productId: 10,
productName: 'Chicken',
quantity: 2,
price: 50,
unit: 'kg',
subtotal: 100,
},
],
...overrides,
})
describe('SnippetOrdersView', () => {
it('renders the header with snippet code, count and revenue', () => {
renderWithProviders(
<SnippetOrdersView
orders={[order(), order({ orderId: 'ORD2', totalAmount: '50.50', customerName: 'Bob' })]}
snippetCode="VS_5"
onClose={jest.fn()}
/>
)
expect(screen.getByText('Orders for "VS_5"')).toBeVisible()
expect(screen.getByText('2 orders • Total: ₹150.50')).toBeVisible()
})
it('pluralises a single order', () => {
renderWithProviders(
<SnippetOrdersView orders={[order()]} snippetCode="VS_5" onClose={jest.fn()} />
)
expect(screen.getByText('1 order • Total: ₹100.00')).toBeVisible()
})
it('renders an order card with products and the matched flag', () => {
renderWithProviders(
<SnippetOrdersView orders={[order()]} snippetCode="VS_5" onClose={jest.fn()} />
)
expect(screen.getByText('ORD1')).toBeVisible()
expect(screen.getByText('Alice')).toBeVisible()
// Order total + product subtotal both render ₹100.00.
expect(screen.getAllByText('₹100.00')).toHaveLength(2)
expect(screen.getByText('Chicken ⭐')).toBeVisible()
expect(screen.getByText('2 kg × ₹50')).toBeVisible()
expect(
screen.getByText('Matched 1 product(s) from snippet "VS_5"')
).toBeVisible()
})
it('shows the empty state when there are no matching orders', () => {
renderWithProviders(
<SnippetOrdersView orders={[]} snippetCode="VS_5" onClose={jest.fn()} />
)
expect(screen.getByText('0 orders • Total: ₹0.00')).toBeVisible()
expect(screen.getByText('No matching orders')).toBeVisible()
expect(
screen.getByText("No orders found that match this snippet's criteria")
).toBeVisible()
})
it('closes via the header button', () => {
const onClose = jest.fn()
renderWithProviders(
<SnippetOrdersView orders={[order()]} snippetCode="VS_5" onClose={onClose} />
)
fireEvent.press(screen.getByText('✕'))
expect(onClose).toHaveBeenCalled()
})
})