/* eslint-disable @typescript-eslint/no-explicit-any */ /** * LocationWrapperNeo's four render branches: loading, address flow, * confirmation, children. The wrapper reads the store directly; only the * bootstrap hook and the two flow screens are mocked. */ import * as React from 'react' import { Text } from 'react-native' import LocationWrapperNeo from '@/components/LocationWrapperNeo' import { useNeoRegionStore } from '@/src/store/neoRegionStore' import { renderWithProviders } from '../helpers/test-utils' jest.mock('@/src/hooks/useRegionNeo', () => ({ useNeoRegionBootstrap: () => undefined, useRegionNeo: () => (globalThis as any).__neoHook, })) jest.mock('@/src/components/location/neo/NeoAddressFlow', () => { const ReactLib = require('react') const { View } = require('react-native') return { __esModule: true, default: () => ReactLib.createElement(View, { testID: 'mock-neo-flow' }), } }) jest.mock('@/src/components/location/neo/NeoConfirmLocation', () => { const ReactLib = require('react') const { View } = require('react-native') return { __esModule: true, default: () => ReactLib.createElement(View, { testID: 'mock-neo-confirm' }), } }) function readyStore(overrides: Record = {}) { useNeoRegionStore.setState({ regionId: 1, boundId: 7, regionName: 'Region A', coords: { latitude: 16.7, longitude: 77.9 }, origin: 'manual', regions: [], addresses: [], selectedAddressId: null, needsAddressFormFlow: false, needsAddressConfirmation: false, ...overrides, }) } function tree() { return ( children ) } describe('LocationWrapperNeo', () => { beforeEach(() => { readyStore() }) it('shows the loading screen until the store has a complete region', () => { readyStore({ regionId: null, boundId: null, regionName: null, coords: null }) const { getByTestId } = renderWithProviders(tree()) expect(getByTestId('neo-location-loading')).toBeTruthy() }) it('renders the address flow when needsAddressFormFlow is set', () => { readyStore({ needsAddressFormFlow: true }) const { getByTestId } = renderWithProviders(tree()) expect(getByTestId('mock-neo-flow')).toBeTruthy() }) it('renders the confirmation when needsAddressConfirmation is set', () => { readyStore({ needsAddressConfirmation: true }) const { getByTestId } = renderWithProviders(tree()) expect(getByTestId('mock-neo-confirm')).toBeTruthy() }) it('renders children once the store holds a region', () => { const { getByText, queryByTestId } = renderWithProviders(tree()) expect(getByText('children')).toBeTruthy() expect(queryByTestId('neo-location-loading')).toBeNull() }) it('the address flow wins if both flags are somehow set', () => { readyStore({ needsAddressFormFlow: true, needsAddressConfirmation: true }) const { getByTestId, queryByTestId } = renderWithProviders(tree()) expect(getByTestId('mock-neo-flow')).toBeTruthy() expect(queryByTestId('mock-neo-confirm')).toBeNull() }) })