/** * 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['orders'][number] const order = (overrides: Partial = {}): 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( ) expect(screen.getByText('Orders for "VS_5"')).toBeVisible() expect(screen.getByText('2 orders • Total: ₹150.50')).toBeVisible() }) it('pluralises a single order', () => { renderWithProviders( ) expect(screen.getByText('1 order • Total: ₹100.00')).toBeVisible() }) it('renders an order card with products and the matched flag', () => { renderWithProviders( ) 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( ) 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( ) fireEvent.press(screen.getByText('✕')) expect(onClose).toHaveBeenCalled() }) })