freshyo/apps/admin-ui/tests/pages/slot-details.test.tsx
2026-11-05 22:31:05 +05:30

62 lines
2.2 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Catalogue section 7.2 — Slot details (`tests/pages/slot-details.test.tsx`).
*/
import React from 'react'
import { fireEvent } from '@testing-library/react-native'
import SlotDetails from '@/app/(drawer)/dashboard/slots/slot-details'
import { renderWithProviders, renderAndFlush } from '../helpers/test-utils'
import { resetAllMocks } from '../helpers/reset'
import { setProcedure } from '../mocks/trpc-client'
import { __setParams, router } from '../mocks/expo-router-mock'
import { SLOT_DETAIL } from '../fixtures'
function renderDetails() {
return renderAndFlush(<SlotDetails />, { auth: 'in' })
}
describe('Slot details (ASLOTDET-01, 02, 05, 06)', () => {
beforeEach(() => {
resetAllMocks()
__setParams({ slotId: '1849' })
})
it('ASLOTDET-01: shows the loading copy', () => {
setProcedure('admin.slots.getSlotById', { mode: 'pending' })
const view = renderWithProviders(<SlotDetails />, { auth: 'in' })
// Loading assertions stay synchronous: the query never settles.
expect(view.getByText('Loading slot details...')).toBeTruthy()
})
it('ASLOTDET-02: a query error shows the error copy', async () => {
setProcedure('admin.slots.getSlotById', { mode: 'error', error: new Error('boom') })
const view = await renderDetails()
expect(await view.findByText('Error loading slot details')).toBeTruthy()
})
it('ASLOTDET-05: renders product names/count and the empty copy', async () => {
const view = await renderDetails()
expect(view.getByText('2 items')).toBeTruthy()
expect(view.getByText('Chicken Breast')).toBeTruthy()
expect(view.getByText('Cucumber')).toBeTruthy()
view.unmount()
setProcedure('admin.slots.getSlotById', {
data: { slot: { ...SLOT_DETAIL, products: [] } },
})
const empty = await renderDetails()
expect(empty.getByText('0 items')).toBeTruthy()
expect(empty.getByText('No products in this slot')).toBeTruthy()
})
it('ASLOTDET-06: the edit FAB opens the edit route', async () => {
const view = await renderDetails()
fireEvent.press(view.getByTestId('edit-slot-fab'))
expect(router.push).toHaveBeenCalledWith('/(drawer)/dashboard/slots/edit/1849')
})
})