/** * Home page top-level states: loading, error and the two empty states. * * These render branches (see app/(drawer)/(tabs)/home/index.tsx) are not hit by * the happy-path file, so they are covered here with success/failure variants of * the mocked network layer. */ jest.mock('expo-router', () => require('../mocks/router').expoRouterMock()) import { fireEvent, screen, waitFor } from '@testing-library/react-native' import { EMPTY_PRODUCTS, EMPTY_TAG, resetStorage, setupApiMocks } from '../mocks/api' import { useNavigationStore } from '@/src/store/navigationStore' import { renderHome, renderLoadedHome } from './render' describe('Home page states', () => { beforeEach(async () => { await resetStorage() useNavigationStore.setState({ isNavigatedFromHome: false, selectedStoreId: null, }) }) it('shows the loading screen while the products request is pending', async () => { setupApiMocks({ pendingProducts: true }) renderHome() await waitFor(() => { expect(screen.getByText('Loading products...')).toBeVisible() }) }) it('shows the products error state when the products request fails', async () => { setupApiMocks({ failProducts: true }) renderHome() await waitFor(() => { expect(screen.getByText('Failed to load products')).toBeVisible() }) expect(screen.getByText('Oops!')).toBeVisible() }) it('shows the app-settings error state when essentialConsts fails', async () => { setupApiMocks({ failConsts: true }) renderHome() await waitFor(() => { expect(screen.getByText('Failed to load app settings')).toBeVisible() }) expect(screen.getByText('Oops!')).toBeVisible() }) it('shows the empty state when there are no products', async () => { setupApiMocks({ products: EMPTY_PRODUCTS }) renderHome() await waitFor(() => { expect(screen.getByText('No products available')).toBeVisible() }) }) it('shows the empty-category message for a tag with no products', async () => { setupApiMocks({ extraTags: [EMPTY_TAG] }) await renderLoadedHome() fireEvent.press(screen.getByTestId(`tag-tab-${EMPTY_TAG.id}`)) expect(screen.getByText('No products in this category yet')).toBeVisible() }) })