freshyo/apps/user-ui/tests/components/neo-address-flow.test.tsx
2026-11-08 15:43:46 +05:30

66 lines
2.3 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* NeoAddressFlow (`tests/components/neo-address-flow.test.tsx`).
*
* Covers the notice area above the address choices: an out-of-area device fix,
* the permission notices, and the "nothing to say" case. The chooser itself is
* the real component; the add form and the inline login screen are stubbed
* because they have their own suites and would pull in the map / auth stack.
*/
import * as React from 'react'
import { resetAllMocks } from '../helpers/reset'
import { renderWithProviders } from '../helpers/test-utils'
import { useLocationStore } from '@/src/store/locationStore'
import { useNeoRegionStore } from '@/src/store/neoRegionStore'
jest.mock('@/src/components/location/neo/NeoAddressForm', () => ({
__esModule: true,
default: () => null,
}))
jest.mock('@/app/(auth)/login', () => ({
__esModule: true,
default: () => null,
}))
import NeoAddressFlow from '@/src/components/location/neo/NeoAddressFlow'
describe('NeoAddressFlow — location notices', () => {
beforeEach(() => resetAllMocks())
it('NEOFLOW-01: an out-of-area fix is explained above the address choices', () => {
useNeoRegionStore.setState({ deviceOutOfService: true })
const { getByTestId, getByText } = renderWithProviders(<NeoAddressFlow />, { auth: false })
expect(getByTestId('neo-location-notice')).toBeTruthy()
expect(getByText('Outside delivery area')).toBeTruthy()
expect(getByText(/outside our delivery area/)).toBeTruthy()
})
it('NEOFLOW-02: no out-of-area notice when the fix is serviceable', () => {
useNeoRegionStore.setState({ deviceOutOfService: false })
const { queryByText } = renderWithProviders(<NeoAddressFlow />, { auth: false })
expect(queryByText(/outside our delivery area/)).toBeNull()
})
it('NEOFLOW-03: the permission notice still shows when there is no region', () => {
useNeoRegionStore.setState({
regionId: null,
boundId: null,
regionName: null,
coords: null,
deviceOutOfService: false,
})
useLocationStore.setState({ status: 'denied' })
const { getByText } = renderWithProviders(<NeoAddressFlow />, { auth: false })
expect(getByText('Location access is off')).toBeTruthy()
expect(getByText(/Location access is not granted/)).toBeTruthy()
})
})