Skip to content

Commit

Permalink
test: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
salmanm committed Oct 20, 2021
1 parent fcc2612 commit a7d57c6
Show file tree
Hide file tree
Showing 5 changed files with 1,705 additions and 1 deletion.
63 changes: 63 additions & 0 deletions src/screens/TypeScreen.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from 'react'
import { mocked } from 'ts-jest/utils'
import { fireEvent } from '@testing-library/react-native'

import { getMockedNavigation, renderWithTheme } from '../../test/utils'
import { useSecrets } from '../context/SecretsContext'

import { TypeScreen } from './TypeScreen'

const useSecretsMocked = mocked(useSecrets)

describe('TypeScreen', () => {
afterEach(() => {
jest.clearAllMocks()
})

const setup = () => {
const navigation = getMockedNavigation<'Type'>()
return renderWithTheme(<TypeScreen navigation={navigation} />)
}

it('should match snapshot', () => {
const view = setup()

expect(view).toMatchSnapshot()
})

it('does not allow adding secret on button click when input is empty', () => {
const addStub = jest.fn()
useSecretsMocked.mockReturnValue({
add: addStub,
} as unknown as ReturnType<typeof useSecrets>)

const { getByA11yLabel } = setup()

fireEvent.press(getByA11yLabel('Add secret'))

expect(addStub).toHaveBeenCalledTimes(0)
})

it('calls add secret on button click', () => {
const addStub = jest.fn()
useSecretsMocked.mockReturnValue({
add: addStub,
} as unknown as ReturnType<typeof useSecrets>)

const { getByA11yLabel } = setup()

fireEvent.changeText(getByA11yLabel('Issuer'), 'Issuer A')
fireEvent.changeText(getByA11yLabel('Secret'), 'mysecret')
fireEvent.changeText(getByA11yLabel('Account'), 'My Account')

fireEvent.press(getByA11yLabel('Add secret'))

expect(addStub).toHaveBeenCalledTimes(1)
expect(addStub).toHaveBeenCalledWith({
account: 'My Account',
issuer: 'Issuer A',
secret: 'mysecret',
uid: '11-22-33-44',
})
})
})
Loading

0 comments on commit a7d57c6

Please sign in to comment.