-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
7dd1128
commit 791537c
Showing
3 changed files
with
92 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
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,83 @@ | ||
import React from 'react'; | ||
|
||
import { Auth } from './Auth'; | ||
|
||
describe('Auth screen test', () => { | ||
it('should render as expected', () => { | ||
const wrapper = shallow(<Auth />, { | ||
disableLifecycleMethods: true, | ||
}); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
it('should redirect to Home route if passcode protection is off', () => { | ||
const navMock = { | ||
navigate: jest.fn(), | ||
dispatch: jest.fn(), | ||
}; | ||
const wrapper = shallow( | ||
<Auth requirePasscode={false} navigation={navMock} /> | ||
); | ||
expect(navMock.navigate.mock.calls.length).toBe(1); | ||
expect(navMock.navigate.mock.calls[0][0]).toBe('Home'); | ||
expect(navMock.dispatch.mock.calls[0][0]).toEqual({ | ||
type: 'Navigation/RESET', | ||
index: 0, | ||
key: undefined, | ||
actions: [{ type: 'Navigation/NAVIGATE', routeName: 'Home' }], | ||
}); | ||
}); | ||
|
||
it('should not redirect to Home route if passcode protection is on', () => { | ||
const navMock = { | ||
navigate: jest.fn(), | ||
dispatch: jest.fn(), | ||
}; | ||
const wrapper = shallow( | ||
<Auth requirePasscode={true} navigation={navMock} /> | ||
); | ||
expect(navMock.navigate.mock.calls.length).toBe(0); | ||
}); | ||
|
||
it('should throw an error if entered passcode is invalid and not redirect to Home', () => { | ||
const navMock = { | ||
navigate: jest.fn(), | ||
dispatch: jest.fn(), | ||
}; | ||
const wrapper = shallow( | ||
<Auth | ||
requirePasscode={true} | ||
currentPasscode="5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8" | ||
navigation={navMock} | ||
/> | ||
); | ||
|
||
wrapper.instance()._isPasscodeValid('notpassword'); | ||
expect(wrapper.state('error')).toEqual('Passcode Invalid!'); | ||
expect(navMock.navigate.mock.calls.length).toBe(0); | ||
}); | ||
|
||
it('should redirect to Home if passcode entered is valid', () => { | ||
const navMock = { | ||
navigate: jest.fn(), | ||
dispatch: jest.fn(), | ||
}; | ||
const wrapper = shallow( | ||
<Auth | ||
requirePasscode={true} | ||
currentPasscode="5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8" | ||
navigation={navMock} | ||
/> | ||
); | ||
wrapper.instance()._isPasscodeValid('password'); | ||
expect(wrapper.state('error')).toEqual(null); | ||
expect(navMock.navigate.mock.calls.length).toBe(1); | ||
expect(navMock.navigate.mock.calls[0][0]).toBe('Home'); | ||
expect(navMock.dispatch.mock.calls[0][0]).toEqual({ | ||
type: 'Navigation/RESET', | ||
index: 0, | ||
key: undefined, | ||
actions: [{ type: 'Navigation/NAVIGATE', routeName: 'Home' }], | ||
}); | ||
}); | ||
}); |
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,8 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Auth screen test should render as expected 1`] = ` | ||
<PasscodeAuth | ||
error={null} | ||
handlePasscodeSubmit={[Function]} | ||
/> | ||
`; |