freshyo/apps/admin-ui/tests/app/index.test.tsx
2026-10-20 00:31:05 +05:30

42 lines
1.5 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Catalogue section 3.3 — Index route (`app/index.tsx`).
*/
import React from 'react'
import { ActivityIndicator } from 'react-native'
import Index from '@/app/index'
import { renderWithProviders } from '../helpers/test-utils'
import { resetAllMocks } from '../helpers/reset'
import { router } from '../mocks/expo-router-mock'
jest.mock('@/components/context/staff-auth-context', () => require('../mocks/staff-auth-context'))
// eslint-disable-next-line import/first
import { __setStaffState } from '../mocks/staff-auth-context'
describe('Index route (AINDEX-01..03)', () => {
beforeEach(() => resetAllMocks())
it('AINDEX-01: shows a spinner while auth is loading', () => {
__setStaffState({ isLoading: true, isLoggedIn: false, staff: null })
const view = renderWithProviders(<Index />, { auth: false })
expect(view.UNSAFE_getByType(ActivityIndicator)).toBeTruthy()
expect(router.replace).not.toHaveBeenCalled()
})
it('AINDEX-02: redirects a signed-in staff member to the dashboard', () => {
__setStaffState({ isLoading: false, isLoggedIn: true, staff: { id: 3, name: 'Admin One', regionId: 1 } })
renderWithProviders(<Index />, { auth: false })
expect(router.replace).toHaveBeenCalledWith('/(drawer)/dashboard')
})
it('AINDEX-03: redirects a signed-out visitor to login', () => {
__setStaffState({ isLoading: false, isLoggedIn: false, staff: null })
renderWithProviders(<Index />, { auth: false })
expect(router.replace).toHaveBeenCalledWith('/login')
})
})