Skip to content

Commit

Permalink
chore: improve tests in UseBiometry, update snapshots in ToggleButton
Browse files Browse the repository at this point in the history
Signed-off-by: Nguyen, Tom CITZ:EX <[email protected]>
  • Loading branch information
Nguyen, Tom CITZ:EX authored and Nguyen, Tom CITZ:EX committed Nov 5, 2024
1 parent fd2ab60 commit 2f9ef84
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`ToggleButton Component renders correctly when disabled 1`] = `
accessibilityState={
Object {
"busy": undefined,
"checked": undefined,
"checked": false,
"disabled": false,
"expanded": undefined,
"selected": undefined,
Expand Down Expand Up @@ -100,7 +100,7 @@ exports[`ToggleButton Component renders correctly when enabled 1`] = `
accessibilityState={
Object {
"busy": undefined,
"checked": undefined,
"checked": true,
"disabled": false,
"expanded": undefined,
"selected": undefined,
Expand Down Expand Up @@ -193,7 +193,7 @@ exports[`ToggleButton Component renders correctly when not available 1`] = `
accessibilityState={
Object {
"busy": undefined,
"checked": undefined,
"checked": false,
"disabled": true,
"expanded": undefined,
"selected": undefined,
Expand Down
61 changes: 9 additions & 52 deletions packages/legacy/core/__tests__/screens/UseBiometry.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import authContext from '../contexts/auth'
import timeTravel from '../helpers/timetravel'
import { BasicAppContext } from '../helpers/app'
import { Linking } from 'react-native'
import { useTranslation } from 'react-i18next'
import { testDefaultState } from '../contexts/store'
import { StoreProvider } from '../../App/contexts/store'
import { RESULTS, check, request } from 'react-native-permissions'
Expand All @@ -27,8 +26,6 @@ const customStore = {
},
}

const { t } = useTranslation()

describe('UseBiometry Screen', () => {
beforeAll(() => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand Down Expand Up @@ -88,20 +85,16 @@ describe('UseBiometry Screen', () => {
</BasicAppContext>
)

await waitFor(() => {
timeTravel(1000)
})

const useBiometryToggle = await tree.getByTestId(testIdWithKey('ToggleBiometrics'))
const useBiometryToggle = tree.getByTestId(testIdWithKey('ToggleBiometrics'))

await waitFor(async () => {
await fireEvent(useBiometryToggle, 'valueChange', true)
fireEvent(useBiometryToggle, 'valueChange', true)
})

const continueButton = await tree.getByTestId(testIdWithKey('Continue'))
const continueButton = tree.getByTestId(testIdWithKey('Continue'))

await waitFor(async () => {
await fireEvent(continueButton, 'press')
fireEvent(continueButton, 'press')
})

expect(useBiometryToggle).not.toBeNull()
Expand All @@ -122,10 +115,6 @@ describe('UseBiometry Screen', () => {
</BasicAppContext>
)

await waitFor(() => {
timeTravel(1000)
})

const toggleButton = getByTestId(testIdWithKey('ToggleBiometrics'))
expect(toggleButton.props.accessibilityState.disabled).toBe(false)
})
Expand All @@ -141,10 +130,6 @@ describe('UseBiometry Screen', () => {
</BasicAppContext>
)

await waitFor(() => {
timeTravel(1000)
})

const toggleButton = getByTestId(testIdWithKey('ToggleBiometrics'))
expect(toggleButton.props.accessibilityState.disabled).toBe(false)
})
Expand All @@ -166,10 +151,6 @@ describe('UseBiometry Screen', () => {
</BasicAppContext>
</StoreProvider>
)

await waitFor(() => {
timeTravel(1000)
})

const toggleButton = getByTestId(testIdWithKey('ToggleBiometrics'))

Expand All @@ -193,10 +174,6 @@ describe('UseBiometry Screen', () => {
</StoreProvider>
)

await waitFor(() => {
timeTravel(1000)
})

const toggleButton = getByTestId(testIdWithKey('ToggleBiometrics'))

await waitFor(() => {
Expand All @@ -219,18 +196,14 @@ describe('UseBiometry Screen', () => {
</StoreProvider>
)

await waitFor(() => {
timeTravel(1000)
})

const toggleButton = getByTestId(testIdWithKey('ToggleBiometrics'))

await waitFor(() => {
fireEvent(toggleButton, 'press')
})

expect(getByText(t('Biometry.SetupBiometricsTitle'))).toBeTruthy()
expect(getByText(t('Biometry.SetupBiometricsDesc'))).toBeTruthy()
expect(getByText('Biometry.SetupBiometricsTitle')).toBeTruthy()
expect(getByText('Biometry.SetupBiometricsDesc')).toBeTruthy()
// Toggle should remain off
expect(toggleButton.props.accessibilityState.checked).toBe(false)
})
Expand All @@ -248,18 +221,14 @@ describe('UseBiometry Screen', () => {
</StoreProvider>
)

await waitFor(() => {
timeTravel(1000)
})

const toggleButton = getByTestId(testIdWithKey('ToggleBiometrics'))

await waitFor(() => {
fireEvent(toggleButton, 'press')
})

expect(getByText(t('Biometry.AllowBiometricsTitle'))).toBeTruthy()
expect(getByText(t('Biometry.AllowBiometricsDesc'))).toBeTruthy()
expect(getByText('Biometry.AllowBiometricsTitle')).toBeTruthy()
expect(getByText('Biometry.AllowBiometricsDesc')).toBeTruthy()
// Toggle should remain off
expect(toggleButton.props.accessibilityState.checked).toBe(false)
})
Expand All @@ -278,10 +247,6 @@ describe('UseBiometry Screen', () => {
</StoreProvider>
)

await waitFor(() => {
timeTravel(1000)
})

const toggleButton = getByTestId(testIdWithKey('ToggleBiometrics'))

await waitFor(() => {
Expand All @@ -307,10 +272,6 @@ describe('UseBiometry Screen', () => {
</StoreProvider>
)

await waitFor(() => {
timeTravel(1000)
})

const toggleButton = getByTestId(testIdWithKey('ToggleBiometrics'))

await waitFor(() => {
Expand All @@ -337,10 +298,6 @@ describe('UseBiometry Screen', () => {
</StoreProvider>
)

await waitFor(() => {
timeTravel(1000)
})

// Trigger the settings popup
const toggleButton = getByTestId(testIdWithKey('ToggleBiometrics'))

Expand All @@ -349,7 +306,7 @@ describe('UseBiometry Screen', () => {
})

// Press the Open Settings button
const openSettingsButton = getByText(t('Biometry.OpenSettings'))
const openSettingsButton = getByText('Biometry.OpenSettings')
await waitFor(() => {
fireEvent(openSettingsButton, 'press')
})
Expand Down

0 comments on commit 2f9ef84

Please sign in to comment.