77 lines
3.1 KiB
TypeScript
77 lines
3.1 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
/**
|
|
* Section 11 — Product detail route variants (PD-48..PD-51).
|
|
*
|
|
* One smoke case per route file: each mounts the real route component, reads the
|
|
* `id` search param and renders the shared `ProductDetail`. The id is asserted
|
|
* through the product query input; the cart type through the floating cart bar
|
|
* variant that ProductDetail renders.
|
|
*/
|
|
import * as React from 'react'
|
|
import { QueryClient } from '@tanstack/react-query'
|
|
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 { renderWithProviders, seedBoot, flush } from '../helpers/test-utils'
|
|
import { resetAllMocks } from '../helpers/reset'
|
|
import { lastProcedureInput } from '../mocks/trpc-client'
|
|
import { __setParams } from '../mocks/expo-router-mock'
|
|
|
|
function createClient(): QueryClient {
|
|
return new QueryClient({
|
|
defaultOptions: {
|
|
queries: {
|
|
retry: false,
|
|
gcTime: Infinity,
|
|
staleTime: Infinity,
|
|
refetchOnWindowFocus: false,
|
|
},
|
|
mutations: { retry: false, gcTime: 0 },
|
|
},
|
|
})
|
|
}
|
|
|
|
async function renderRoute(route: React.ReactElement) {
|
|
seedBoot()
|
|
__setParams({ id: '2' })
|
|
const utils = renderWithProviders(route, { auth: false, queryClient: createClient() })
|
|
await flush(2)
|
|
return utils
|
|
}
|
|
|
|
describe('ProductDetail route variants', () => {
|
|
beforeEach(() => resetAllMocks())
|
|
|
|
it('PD-48: the home variant passes the id param and uses the regular cart', async () => {
|
|
const { getByText } = await renderRoute(<HomeProductDetail />)
|
|
|
|
expect(lastProcedureInput('user.product.getProductDetails')).toEqual({ id: '2', regionId: 1 })
|
|
expect(getByText('Chicken Breast')).toBeTruthy()
|
|
expect(getByText('No Items In Cart')).toBeTruthy()
|
|
})
|
|
|
|
it('PD-49: the store variant passes the id param and uses the regular cart', async () => {
|
|
const { getByText } = await renderRoute(<StoreProductDetail />)
|
|
|
|
expect(lastProcedureInput('user.product.getProductDetails')).toEqual({ id: '2', regionId: 1 })
|
|
expect(getByText('Chicken Breast')).toBeTruthy()
|
|
expect(getByText('No Items In Cart')).toBeTruthy()
|
|
})
|
|
|
|
it('PD-50: the offers variant passes the id param and uses the regular cart', async () => {
|
|
const { getByText } = await renderRoute(<OffersProductDetail />)
|
|
|
|
expect(lastProcedureInput('user.product.getProductDetails')).toEqual({ id: '2', regionId: 1 })
|
|
expect(getByText('Chicken Breast')).toBeTruthy()
|
|
expect(getByText('No Items In Cart')).toBeTruthy()
|
|
})
|
|
|
|
it('PD-51: the flash variant passes the id param and is flash delivery', async () => {
|
|
const { getByText } = await renderRoute(<FlashProductDetail />)
|
|
|
|
expect(lastProcedureInput('user.product.getProductDetails')).toEqual({ id: '2', regionId: 1 })
|
|
expect(getByText('Chicken Breast')).toBeTruthy()
|
|
expect(getByText('No Flash Items')).toBeTruthy()
|
|
})
|
|
})
|