Skip to content

Commit

Permalink
Update tests, add test for confirmation screen
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Lippa <[email protected]>
  • Loading branch information
LippaC-OPS committed Jan 23, 2025
1 parent 42ab907 commit 4980b42
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 34 deletions.
4 changes: 2 additions & 2 deletions packages/legacy/core/App/screens/PINChangeConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const PINChangeConfirmation: React.FC = () => {
return (
<KeyboardView>
<View style={style.screenContainer}>
<InfoBox
<InfoBox
notificationType={InfoBoxType.Success}
description={t('PINChangeConfirmation.AlertSubText')}
title={t('PINChangeConfirmation.AlertTitle')}
Expand All @@ -38,7 +38,7 @@ const PINChangeConfirmation: React.FC = () => {
<Button
title={t('PINChangeConfirmation.PrimaryCta')}
buttonType={ButtonType.Primary}
testID={testIdWithKey('PINChangeConfirmation.PrimaryCta')}
testID={testIdWithKey('GoToHomeButton')}
accessibilityLabel={t('PINChangeConfirmation.PrimaryCta')}
onPress={() => {
navigation.getParent()?.navigate(TabStacks.HomeStack, { screen: Screens.Home })
Expand Down
62 changes: 30 additions & 32 deletions packages/legacy/core/__tests__/screens/PINChange.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,36 @@ import { container } from 'tsyringe'
import { ContainerProvider } from '../../App/container-api'

describe('PINChange Screen', () => {
beforeEach(() => {
jest.clearAllMocks()
})
beforeEach(() => {
jest.clearAllMocks()
})

test('PIN change renders correctly', async () => {
const main = new MainContainer(container.createChildContainer()).init()
const route = {
params: {
updatePin: true,
},
} as any
const tree = render(
<ContainerProvider value={main}>
<StoreProvider
initialState={{
...defaultState,
}}
>
<AuthContext.Provider value={authContext}>
<PINCreate route={route} navigation={jest.fn() as any} setAuthenticated={jest.fn()} explainedStatus={true} />
</AuthContext.Provider>
</StoreProvider>
</ContainerProvider>
)
test('PIN change renders correctly', async () => {
const main = new MainContainer(container.createChildContainer()).init()
const route = {
params: {
updatePin: true,
},
} as any
const tree = render(
<ContainerProvider value={main}>
<StoreProvider
initialState={{
...defaultState,
}}
>
<AuthContext.Provider value={authContext}>
<PINCreate route={route} navigation={jest.fn() as any} setAuthenticated={jest.fn()} explainedStatus={true} />
</AuthContext.Provider>
</StoreProvider>
</ContainerProvider>
)

// Causes RangeError: Invalid string length
// expect(tree).toMatchSnapshot()
const oldPinInput = tree.getByTestId(testIdWithKey('EnterOldPIN'))
const newPinInput1 = tree.getByTestId(testIdWithKey('EnterPIN'))
const newPinInput2 = tree.getByTestId(testIdWithKey('ReenterPIN'))
expect(oldPinInput).not.toBe(null)
expect(newPinInput1).not.toBe(null)
expect(newPinInput2).not.toBe(null)
})
// Causes RangeError: Invalid string length
// expect(tree).toMatchSnapshot()
const newPinInput1 = tree.getByTestId(testIdWithKey('EnterPIN'))
const newPinInput2 = tree.getByTestId(testIdWithKey('ReenterPIN'))
expect(newPinInput1).not.toBe(null)
expect(newPinInput2).not.toBe(null)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { render } from '@testing-library/react-native'
import React from 'react'

import { AuthContext } from '../../App/contexts/auth'
import { StoreProvider, defaultState } from '../../App/contexts/store'
import PINChangeConfirmation from '../../App/screens/PINChangeConfirmation'
import { testIdWithKey } from '../../App/utils/testable'
import authContext from '../contexts/auth'
import { MainContainer } from '../../App/container-impl'
import { container } from 'tsyringe'
import { ContainerProvider } from '../../App/container-api'

describe('PINChange Screen', () => {
beforeEach(() => {
jest.clearAllMocks()
})

test('PIN change renders correctly', async () => {
const main = new MainContainer(container.createChildContainer()).init()
const tree = render(
<ContainerProvider value={main}>
<StoreProvider
initialState={{
...defaultState,
}}
>
<AuthContext.Provider value={authContext}>
<PINChangeConfirmation />
</AuthContext.Provider>
</StoreProvider>
</ContainerProvider>
)

// Causes RangeError: Invalid string length
// expect(tree).toMatchSnapshot()
const confirmationInfoBoxTitle = tree.getByTestId(testIdWithKey('HeaderText'))
const confirmationInfoBoxSubtext = tree.getByTestId(testIdWithKey('BodyText'))
const backToHomeButton = tree.getByTestId(testIdWithKey('GoToHomeButton'))
expect(confirmationInfoBoxTitle).not.toBe(null)
expect(confirmationInfoBoxSubtext).not.toBe(null)
expect(backToHomeButton).not.toBe(null)
})
})

0 comments on commit 4980b42

Please sign in to comment.