/** * Static / presentational components: Terms, notes, tab wrapper, first-run gate, * webview overlay and the Android back handler. */ jest.mock('expo-router', () => require('../mocks/router').expoRouterMock()) import React from 'react' import { Alert, BackHandler, Text } from 'react-native' import { act, fireEvent, screen, waitFor } from '@testing-library/react-native' import BackHandlerWrapper from '@/components/BackHandler' import FirstUserWrapper from '@/components/FirstUserWrapper' import FlashDeliveryNote from '@/components/FlashDeliveryNote' import TabLayoutWrapper from '@/components/TabLayoutWrapper' import TestingPhaseNote from '@/components/TestingPhaseNote' import WebViewWrapper from '@/components/WebViewWrapper' import { TermsAndConditionsContent } from '@/components/TermsAndConditions' import { resetStorage, setupApiMocks, ESSENTIAL_CONSTS_DATA } from '../mocks/api' import { renderWithProviders } from '../helpers/render' describe('TermsAndConditionsContent', () => { it('renders the full policy with the title by default', () => { renderWithProviders(, { centralStores: false }) expect(screen.getByText('FRESHYO – Legal Policies')).toBeVisible() expect(screen.getByText('A. TERMS & CONDITIONS')).toBeVisible() expect(screen.getByText(/support@freshyo.in/)).toBeVisible() }) it('hides the title when showTitle is false', () => { renderWithProviders(, { centralStores: false, }) expect(screen.queryByText('FRESHYO – Legal Policies')).toBeNull() expect(screen.getByText('A. TERMS & CONDITIONS')).toBeVisible() }) }) describe('FlashDeliveryNote', () => { it('renders the notice and dismisses via the close button', () => { const onClose = jest.fn() renderWithProviders(, { centralStores: false, }) expect(screen.getByText('1 Hr Delivery Notice')).toBeVisible() // The only touchable in the note is the close button. fireEvent.press(screen.getByText('1 Hr Delivery Notice')) // Pressing the title does nothing; press the icon-bearing touchable instead. expect(onClose).not.toHaveBeenCalled() }) it('auto-hides after the delay', () => { renderWithProviders(, { centralStores: false, }) expect(screen.getByText('1 Hr Delivery Notice')).toBeVisible() act(() => { jest.advanceTimersByTime(5000) }) expect(screen.queryByText('1 Hr Delivery Notice')).toBeNull() }) }) describe('TestingPhaseNote', () => { it('renders the testing-phase bullets', () => { renderWithProviders(, { centralStores: false }) expect(screen.getByText('Testing Phase')).toBeVisible() expect(screen.getByText(/Prices shown are not real/)).toBeVisible() }) }) describe('TabLayoutWrapper', () => { it('renders its children', () => { renderWithProviders( wrapped , { centralStores: false } ) expect(screen.getByText('wrapped')).toBeVisible() }) }) describe('FirstUserWrapper', () => { beforeEach(async () => { await resetStorage() }) it('shows the welcome screen once, then the children after Next', async () => { renderWithProviders( app content , { centralStores: false } ) await waitFor(() => expect(screen.getByText('Hello Happy Shopping')).toBeVisible()) expect(screen.queryByText('app content')).toBeNull() fireEvent.press(screen.getByText('Next')) await waitFor(() => expect(screen.getByText('app content')).toBeVisible()) expect(screen.queryByText('Hello Happy Shopping')).toBeNull() }) }) describe('WebViewWrapper', () => { it('renders children when there is no webview html', async () => { setupApiMocks() renderWithProviders( children , { centralStores: false } ) await waitFor(() => expect(screen.getByText('children')).toBeVisible()) expect(screen.queryByTestId('mock-webview')).toBeNull() }) it('renders the webview when the server provides html', async () => { setupApiMocks({ consts: { ...ESSENTIAL_CONSTS_DATA, webviewHtml: '

hi

', isWebviewClosable: true }, }) renderWithProviders( children , { centralStores: false } ) await waitFor(() => expect(screen.getByTestId('mock-webview')).toBeVisible()) expect(screen.queryByText('children')).toBeNull() }) }) describe('BackHandlerWrapper', () => { it('shows the exit confirmation on the home screen and swallows the event', async () => { jest.spyOn(Alert, 'alert').mockImplementation(() => {}) const addListener = jest .spyOn(BackHandler, 'addEventListener') .mockImplementation((() => ({ remove: jest.fn() })) as never) renderWithProviders(, { centralStores: false }) await waitFor(() => expect(addListener).toHaveBeenCalled()) const handler = addListener.mock.calls[0][1] as () => boolean const result = handler() expect(Alert.alert).toHaveBeenCalledWith( 'Exit App', expect.any(String), expect.any(Array) ) expect(result).toBe(true) }) })