52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
/**
|
|
* Catalogue section 17.1 — ProductListDialog
|
|
* (`tests/components/product-list-dialog.test.tsx`).
|
|
*/
|
|
import React from 'react'
|
|
import { TouchableOpacity } from 'react-native'
|
|
import { fireEvent, render } from '@testing-library/react-native'
|
|
|
|
import { ProductListDialog } from '@/components/ProductListDialog'
|
|
import { resetAllMocks } from '../helpers/reset'
|
|
|
|
const PRODUCTS = [
|
|
{ id: 11, name: 'Chicken Breast - 500g' },
|
|
{ id: 13, name: 'Cucumber - 500g' },
|
|
]
|
|
|
|
describe('ProductListDialog (APLD-01..03)', () => {
|
|
beforeEach(() => resetAllMocks())
|
|
|
|
it('APLD-01: an open dialog lists every product with its count', () => {
|
|
const onClose = jest.fn()
|
|
const view = render(
|
|
<ProductListDialog open onClose={onClose} products={PRODUCTS} />
|
|
)
|
|
|
|
expect(view.getByText('Products (2)')).toBeTruthy()
|
|
expect(view.getByText('Chicken Breast - 500g')).toBeTruthy()
|
|
expect(view.getByText('Cucumber - 500g')).toBeTruthy()
|
|
})
|
|
|
|
it('APLD-02: pressing the backdrop closes the dialog', () => {
|
|
const onClose = jest.fn()
|
|
const view = render(
|
|
<ProductListDialog open onClose={onClose} products={PRODUCTS} />
|
|
)
|
|
|
|
// BottomDialog's dismissible backdrop is the first touchable in the modal.
|
|
fireEvent.press(view.UNSAFE_getAllByType(TouchableOpacity)[0])
|
|
|
|
expect(onClose).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('APLD-03: no products shows the empty count and copy', () => {
|
|
const view = render(
|
|
<ProductListDialog open onClose={jest.fn()} products={[]} />
|
|
)
|
|
|
|
expect(view.getByText('Products (0)')).toBeTruthy()
|
|
expect(view.queryByText('Chicken Breast - 500g')).toBeNull()
|
|
})
|
|
})
|