freshyo/apps/user-ui/tests/components/cart-address-gate.test.tsx
2026-10-13 19:10:27 +05:30

62 lines
2.1 KiB
TypeScript

/**
* CartAddressGate (components/CartAddressGate.tsx).
*
* The cart's first-address gate: shown before the cart when a signed-in user
* has no delivery address. Offers "Address of current Location" (needs a device
* fix) or "Choose another location" (opens the address form).
*/
jest.mock('expo-router', () => require('../mocks/router').expoRouterMock())
import React from 'react'
import { fireEvent, screen, waitFor } from '@testing-library/react-native'
import CartAddressGate from '@/components/CartAddressGate'
import { useLocationStore } from '@/src/store/locationStore'
import { resetStorage, setupApiMocks } from '../mocks/api'
import { renderWithProviders } from '../helpers/render'
const LOCATION = { latitude: 16.7488, longitude: 77.9851 }
describe('CartAddressGate', () => {
beforeEach(async () => {
await resetStorage()
useLocationStore.getState().stop()
})
it('offers the current-location and map options', () => {
useLocationStore.setState({ coords: LOCATION, status: 'granted', error: null })
setupApiMocks()
renderWithProviders(<CartAddressGate onDone={jest.fn()} onBack={jest.fn()} />, {
centralStores: false,
})
expect(screen.getByText('Where should we deliver?')).toBeVisible()
expect(screen.getByTestId('cart-address-current')).toBeEnabled()
expect(screen.getByTestId('cart-address-other')).toBeVisible()
})
it('disables the current-location option without a device fix', () => {
setupApiMocks()
renderWithProviders(<CartAddressGate onDone={jest.fn()} onBack={jest.fn()} />, {
centralStores: false,
})
expect(screen.getByTestId('cart-address-current')).toBeDisabled()
expect(screen.getByText('Turn on location to use this option')).toBeVisible()
})
it('opens the address form from the map option', async () => {
setupApiMocks()
renderWithProviders(<CartAddressGate onDone={jest.fn()} onBack={jest.fn()} />, {
centralStores: false,
})
fireEvent.press(screen.getByTestId('cart-address-other'))
await waitFor(() => expect(screen.getByTestId('address-name')).toBeVisible())
})
})