61 lines
2.2 KiB
TypeScript
61 lines
2.2 KiB
TypeScript
/**
|
|
* Product-detail route wrappers — the `isFlashDelivery` flag wiring.
|
|
*
|
|
* tests/screens/product-detail-routes.test.tsx checks the id param but only
|
|
* matches `/^7:/` for three of the four routes, so a broken flash flag would
|
|
* pass there. This file asserts the flag itself on every wrapper.
|
|
*/
|
|
|
|
jest.mock('expo-router', () => require('../mocks/router').expoRouterMock())
|
|
|
|
jest.mock('@/components/ProductDetail', () => {
|
|
const React = require('react')
|
|
const { Text } = require('react-native')
|
|
return {
|
|
__esModule: true,
|
|
default: ({ productId, isFlashDelivery }: { productId: string; isFlashDelivery?: boolean }) =>
|
|
React.createElement(
|
|
Text,
|
|
{ testID: 'product-detail-mock' },
|
|
`${productId}:${isFlashDelivery ? 'flash' : 'regular'}`
|
|
),
|
|
}
|
|
})
|
|
|
|
import React from 'react'
|
|
import { screen, waitFor } from '@testing-library/react-native'
|
|
|
|
import HomeProductDetail from '@/app/(drawer)/(tabs)/home/product-detail/[id]'
|
|
import StoreProductDetail from '@/app/(drawer)/(tabs)/stores/store-detail/product-detail/[id]'
|
|
import OffersProductDetail from '@/app/(drawer)/(tabs)/order-again/product-detail/[id]/index'
|
|
import FlashProductDetail from '@/app/(drawer)/(tabs)/flash-delivery/product-detail/[id]'
|
|
import { resetStorage, setupApiMocks } from '../mocks/api'
|
|
import { searchParamsMock } from '../mocks/router'
|
|
import { renderWithProviders } from '../helpers/render'
|
|
|
|
const DETAIL = 'product-detail-mock'
|
|
|
|
describe('Product detail flash flag', () => {
|
|
beforeEach(async () => {
|
|
await resetStorage()
|
|
setupApiMocks()
|
|
searchParamsMock.current = { id: '7' }
|
|
})
|
|
|
|
const expectFlag = async (ui: React.ReactElement, expected: string) => {
|
|
renderWithProviders(ui, { centralStores: false })
|
|
await waitFor(() => expect(screen.getByTestId(DETAIL)).toHaveTextContent(expected))
|
|
}
|
|
|
|
it('home route renders a regular product', () =>
|
|
expectFlag(<HomeProductDetail />, '7:regular'))
|
|
|
|
it('stores route renders a regular product', () =>
|
|
expectFlag(<StoreProductDetail />, '7:regular'))
|
|
|
|
it('order-again route renders a regular product', () =>
|
|
expectFlag(<OffersProductDetail />, '7:regular'))
|
|
|
|
it('flash route renders a flash product', () =>
|
|
expectFlag(<FlashProductDetail />, '7:flash'))
|
|
})
|