46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
/**
|
|
* ProductListDialog (components/ProductListDialog.tsx) — a read-only bottom
|
|
* dialog listing the products passed in as props.
|
|
*/
|
|
|
|
import React from 'react'
|
|
import { screen } from '@testing-library/react-native'
|
|
|
|
import { ProductListDialog } from '@/components/ProductListDialog'
|
|
import { renderWithProviders } from '../helpers/render'
|
|
|
|
const products = [
|
|
{ id: 1, name: 'Chicken' },
|
|
{ id: 2, name: 'Mutton' },
|
|
{ id: 3, name: 'Fish' },
|
|
]
|
|
|
|
describe('ProductListDialog', () => {
|
|
it('renders the product count and each product when open', () => {
|
|
renderWithProviders(
|
|
<ProductListDialog open onClose={jest.fn()} products={products} />
|
|
)
|
|
|
|
expect(screen.getByText('Products (3)')).toBeVisible()
|
|
expect(screen.getByText('Chicken')).toBeVisible()
|
|
expect(screen.getByText('Mutton')).toBeVisible()
|
|
expect(screen.getByText('Fish')).toBeVisible()
|
|
})
|
|
|
|
it('shows a count of zero for an empty list', () => {
|
|
renderWithProviders(
|
|
<ProductListDialog open onClose={jest.fn()} products={[]} />
|
|
)
|
|
|
|
expect(screen.getByText('Products (0)')).toBeVisible()
|
|
})
|
|
|
|
it('hides its content while closed', () => {
|
|
renderWithProviders(
|
|
<ProductListDialog open={false} onClose={jest.fn()} products={products} />
|
|
)
|
|
|
|
// A closed Modal does not mount its children in the tree.
|
|
expect(screen.queryByText('Products (3)')).toBeNull()
|
|
})
|
|
})
|