102 lines
2.9 KiB
TypeScript
102 lines
2.9 KiB
TypeScript
/**
|
|
* HealthTestWrapper + UpdateChecker.
|
|
* Health asserts common.healthCheck (retry refetches); UpdateChecker is inert on
|
|
* dev builds (__DEV__ is true under jest).
|
|
*/
|
|
|
|
jest.mock('expo-constants', () => ({
|
|
__esModule: true,
|
|
default: { expoConfig: { version: '1.0.0' } },
|
|
}))
|
|
|
|
import React from 'react'
|
|
import { Text } from 'react-native'
|
|
import { fireEvent, screen, waitFor } from '@testing-library/react-native'
|
|
|
|
import HealthTestWrapper from '@/components/HealthTestWrapper'
|
|
import UpdateChecker from '@/components/UpdateChecker'
|
|
import { ESSENTIAL_CONSTS_DATA, resetStorage, setupApiMocks } from '../mocks/api'
|
|
import { procedureCalls } from '../mocks/procedures'
|
|
import { renderWithProviders } from '../helpers/render'
|
|
|
|
describe('HealthTestWrapper', () => {
|
|
beforeEach(async () => {
|
|
await resetStorage()
|
|
})
|
|
|
|
it('renders children when the backend is healthy', async () => {
|
|
setupApiMocks({
|
|
procedures: { 'common.healthCheck': { status: 'ok' } },
|
|
consts: { ...ESSENTIAL_CONSTS_DATA, versionNum: '0.0.1' },
|
|
})
|
|
renderWithProviders(
|
|
<HealthTestWrapper>
|
|
<Text>app content</Text>
|
|
</HealthTestWrapper>,
|
|
{ centralStores: false }
|
|
)
|
|
|
|
await waitFor(() => expect(screen.getByText('app content')).toBeVisible())
|
|
})
|
|
|
|
it('shows the service-unavailable state and retries', async () => {
|
|
const api = setupApiMocks({
|
|
procedures: {
|
|
'common.healthCheck': () => {
|
|
throw new Error('backend down')
|
|
},
|
|
},
|
|
})
|
|
renderWithProviders(
|
|
<HealthTestWrapper>
|
|
<Text>app content</Text>
|
|
</HealthTestWrapper>,
|
|
{ centralStores: false }
|
|
)
|
|
|
|
await waitFor(() => expect(screen.getByText('Service Unavailable')).toBeVisible())
|
|
expect(screen.queryByText('app content')).toBeNull()
|
|
|
|
const before = procedureCalls(api.fetchMock, 'common.healthCheck').length
|
|
fireEvent.press(screen.getByText('Retry'))
|
|
|
|
await waitFor(() =>
|
|
expect(procedureCalls(api.fetchMock, 'common.healthCheck').length).toBeGreaterThan(
|
|
before
|
|
)
|
|
)
|
|
})
|
|
|
|
it('prompts to update when the backend version is ahead', async () => {
|
|
setupApiMocks({
|
|
procedures: { 'common.healthCheck': { status: 'ok' } },
|
|
consts: {
|
|
...ESSENTIAL_CONSTS_DATA,
|
|
versionNum: '99.0.0',
|
|
playStoreUrl: 'https://play.example/app',
|
|
},
|
|
})
|
|
renderWithProviders(
|
|
<HealthTestWrapper>
|
|
<Text>app content</Text>
|
|
</HealthTestWrapper>,
|
|
{ centralStores: false }
|
|
)
|
|
|
|
await waitFor(() => expect(screen.getByText('Update Available')).toBeVisible())
|
|
})
|
|
})
|
|
|
|
describe('UpdateChecker', () => {
|
|
it('renders children and does not check for updates on dev builds', async () => {
|
|
setupApiMocks()
|
|
renderWithProviders(
|
|
<UpdateChecker>
|
|
<Text>app content</Text>
|
|
</UpdateChecker>,
|
|
{ centralStores: false }
|
|
)
|
|
|
|
await waitFor(() => expect(screen.getByText('app content')).toBeVisible())
|
|
})
|
|
})
|