-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
1,705 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.