Skip to content

Commit

Permalink
Add tests for SetPasscode screen
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-username committed Mar 29, 2018
1 parent 8bf8bb0 commit ee03f03
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/screens/SetPasscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PasscodeForm from '../components/PasscodeForm';
import { setPasscode, getCurrentPasscode } from '../redux/modules/settings';
import { hashString } from '../utils/crypto';

class SetPasscode extends React.Component {
export class SetPasscode extends React.Component {
static navigationOptions = {
title: 'Set Passcode',
};
Expand All @@ -15,7 +15,7 @@ class SetPasscode extends React.Component {
}
}

const mapDispatchToProps = (dispatch, ownProps) => ({
export const mapDispatchToProps = (dispatch, ownProps) => ({
handlePasscodeSubmit(passcode) {
dispatch(setPasscode(hashString(passcode)));
ownProps.navigation.goBack();
Expand Down
38 changes: 38 additions & 0 deletions src/screens/SetPasscode.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';

import {
SetPasscode,
mapDispatchToProps as dispatchProps,
} from './SetPasscode';

import { SET_PASSCODE } from '../redux/modules/settings';

describe('SetPasscode screen test', () => {
it('should render as expected', () => {
const wrapper = shallow(<SetPasscode />);
expect(wrapper).toMatchSnapshot();
});

describe('mapDispatchToProps test', () => {
it('should set the hashed passcode on submit and go back one route', () => {
const dispatchMock = jest.fn();
const ownPropsMock = {
navigation: {
goBack: jest.fn(),
},
};
const props = dispatchProps(dispatchMock, ownPropsMock);
props.handlePasscodeSubmit('password');
expect(dispatchMock.mock.calls.length).toBe(1);
expect(dispatchMock.mock.calls[0]).toEqual([
{
passcodeHash:
'5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8',
type: SET_PASSCODE,
},
]);

expect(ownPropsMock.navigation.goBack.mock.calls.length).toBe(1);
});
});
});
3 changes: 3 additions & 0 deletions src/screens/__snapshots__/SetPasscode.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SetPasscode screen test should render as expected 1`] = `<PasscodeForm />`;

0 comments on commit ee03f03

Please sign in to comment.