79 lines
2.4 KiB
TypeScript
79 lines
2.4 KiB
TypeScript
/**
|
|
* Offers / order-again (app/(drawer)/(tabs)/order-again/index.tsx).
|
|
*
|
|
* Two sections over the products cache: Offers (isOffer) and Combos
|
|
* (productType === 'combo'). The fixture has no offers and six combos.
|
|
*/
|
|
|
|
jest.mock('expo-router', () => require('../mocks/router').expoRouterMock())
|
|
|
|
import React from 'react'
|
|
import { fireEvent, screen, waitFor } from '@testing-library/react-native'
|
|
|
|
import Offers from '@/app/(drawer)/(tabs)/order-again/index'
|
|
import { resetStorage, setupApiMocks } from '../mocks/api'
|
|
import { routerMock } from '../mocks/router'
|
|
import { renderWithProviders } from '../helpers/render'
|
|
|
|
const CARD = 'product-card'
|
|
|
|
describe('Offers (order-again) screen', () => {
|
|
beforeEach(async () => {
|
|
await resetStorage()
|
|
})
|
|
|
|
it('renders both section headers', async () => {
|
|
setupApiMocks()
|
|
renderWithProviders(<Offers />)
|
|
|
|
await waitFor(() => expect(screen.getByText('Offers')).toBeVisible())
|
|
expect(screen.getByText('Combos')).toBeVisible()
|
|
})
|
|
|
|
it('shows the empty message for a section with no products', async () => {
|
|
setupApiMocks()
|
|
renderWithProviders(<Offers />)
|
|
|
|
await waitFor(() =>
|
|
expect(screen.getByText('No offers available right now')).toBeVisible()
|
|
)
|
|
})
|
|
|
|
it('renders a card for every combo', async () => {
|
|
setupApiMocks()
|
|
renderWithProviders(<Offers />)
|
|
|
|
await waitFor(() =>
|
|
expect(screen.getAllByTestId(CARD).length).toBeGreaterThan(0)
|
|
)
|
|
})
|
|
|
|
it('opens the product detail page when a card is pressed', async () => {
|
|
setupApiMocks()
|
|
renderWithProviders(<Offers />)
|
|
|
|
await waitFor(() =>
|
|
expect(screen.getAllByTestId(CARD).length).toBeGreaterThan(0)
|
|
)
|
|
fireEvent.press(screen.getAllByTestId(CARD)[0])
|
|
|
|
expect(routerMock.push).toHaveBeenCalledWith(
|
|
expect.stringContaining('/order-again/product-detail/')
|
|
)
|
|
})
|
|
|
|
it('shows the loading state while products are pending', async () => {
|
|
setupApiMocks({ pendingProducts: true })
|
|
renderWithProviders(<Offers />)
|
|
|
|
await waitFor(() => expect(screen.getByText('Loading offers...')).toBeVisible())
|
|
})
|
|
|
|
it('shows the error state when products fail to load', async () => {
|
|
setupApiMocks({ failProducts: true })
|
|
renderWithProviders(<Offers />)
|
|
|
|
await waitFor(() => expect(screen.getByText('Failed to load offers')).toBeVisible())
|
|
expect(screen.getByText('Oops!')).toBeVisible()
|
|
})
|
|
})
|