Skip to content

Commit

Permalink
Fix/tests (#446)
Browse files Browse the repository at this point in the history
* fix: coverage

* fix: coverage

* add: tests

* add: action tests

* fix: add better test description

* fix: coverage

* fix: snapshot
  • Loading branch information
shayc authored Jun 10, 2019
1 parent f86dfcc commit 1b3aa60
Show file tree
Hide file tree
Showing 9 changed files with 363 additions and 7 deletions.
16 changes: 16 additions & 0 deletions src/components/App/__tests__/App.actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ describe('actions', () => {
expect(actions.updateDisplaySettings(payload)).toEqual(expectedAction);
});

it('should create an action to update display settings - default payload', () => {
const expectedAction = {
type: types.UPDATE_DISPLAY_SETTINGS,
payload: {}
};
expect(actions.updateDisplaySettings()).toEqual(expectedAction);
});

it('should create an action to update navigation settings', () => {
const payload = {};
const expectedAction = {
Expand All @@ -20,6 +28,14 @@ describe('actions', () => {
expect(actions.updateNavigationSettings(payload)).toEqual(expectedAction);
});

it('should create an action to update navigation settings - default payload', () => {
const expectedAction = {
type: types.UPDATE_NAVIGATION_SETTINGS,
payload: {}
};
expect(actions.updateNavigationSettings()).toEqual(expectedAction);
});

it('should create an action to finish first user visit', () => {
const expectedAction = {
type: types.FINISH_FIRST_VISIT
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';

import { shallowMatchSnapshot } from '../../../../common/test_utils';
import Information from '../Information';

jest.mock('../Information.messages', () => ({
heading: {
id: 'cboard.components.AuthScreenInformation.heading',
defaultMessage: 'Cboard'
},
text: {
id: 'cboard.components.AuthScreenInformation.text',
defaultMessage: 'Sign up to sync your settings!'
}
}));

describe('AuthScreen Information tests', () => {
test('default renderer', () => {
shallowMatchSnapshot(<Information />);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AuthScreen Information tests default renderer 1`] = `
<React.Fragment>
<WithStyles(Typography)
align="center"
className="AuthScreen__heading"
variant="h2"
>
<FormattedMessage
defaultMessage="Cboard"
id="cboard.components.AuthScreenInformation.heading"
values={Object {}}
/>
</WithStyles(Typography)>
<WithStyles(Typography)
align="center"
className="AuthScreen__heading"
variant="body1"
>
<FormattedMessage
defaultMessage="Sign up to sync your settings!"
id="cboard.components.AuthScreenInformation.text"
values={Object {}}
/>
</WithStyles(Typography)>
</React.Fragment>
`;
175 changes: 175 additions & 0 deletions src/components/Communicator/__tests__/Communicator.actions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import * as actions from '../Communicator.actions';
import * as types from '../Communicator.constants';

describe('actions', () => {
it('should create an action to import communicator', () => {
const payload = {};

const expectedAction = {
type: types.IMPORT_COMMUNICATOR,
payload
};
expect(actions.importCommunicator(payload)).toEqual(expectedAction);
});

it('should create an action to create communicator', () => {
const payload = {};
const expectedAction = {
type: types.CREATE_COMMUNICATOR,
payload
};
expect(actions.createCommunicator(payload)).toEqual(expectedAction);
});

it('should create an action to edit communicator', () => {
const payload = {};
const expectedAction = {
type: types.EDIT_COMMUNICATOR,
payload
};
expect(actions.editCommunicator(payload)).toEqual(expectedAction);
});

it('should create an action to delete communicator', () => {
const id = {};
const expectedAction = {
type: types.DELETE_COMMUNICATOR,
payload: id
};
expect(actions.deleteCommunicator(id)).toEqual(expectedAction);
});

it('should create an action to change communicator', () => {
const id = {};
const expectedAction = {
type: types.CHANGE_COMMUNICATOR,
payload: id
};
expect(actions.changeCommunicator(id)).toEqual(expectedAction);
});

it('should create an action to add board communicator', () => {
const boardId = {};
const expectedAction = {
type: types.ADD_BOARD_COMMUNICATOR,
boardId
};
expect(actions.addBoardCommunicator(boardId)).toEqual(expectedAction);
});

it('should create an action to delete board communicator', () => {
const boardId = {};
const expectedAction = {
type: types.DELETE_BOARD_COMMUNICATOR,
boardId
};
expect(actions.deleteBoardCommunicator(boardId)).toEqual(expectedAction);
});

it('should create an action to replace board communicator', () => {
const prevBoardId = '10';
const nextBoardId = '20';

const expectedAction = {
type: types.REPLACE_BOARD_COMMUNICATOR,
prevBoardId,
nextBoardId
};
expect(actions.replaceBoardCommunicator(prevBoardId, nextBoardId)).toEqual(
expectedAction
);
});

it('should create an action to get API success', () => {
const communicators = {};
const expectedAction = {
type: types.GET_API_MY_COMMUNICATORS_SUCCESS,
communicators
};
expect(actions.getApiMyCommunicatorsSuccess(communicators)).toEqual(
expectedAction
);
});

it('should create an action to get API started', () => {
const expectedAction = {
type: types.GET_API_MY_COMMUNICATORS_STARTED
};
expect(actions.getApiMyCommunicatorsStarted()).toEqual(expectedAction);
});

it('should create an action to get API failure', () => {
const message = 'dummy message';
const expectedAction = {
type: types.GET_API_MY_COMMUNICATORS_FAILURE,
message
};
expect(actions.getApiMyCommunicatorsFailure(message)).toEqual(
expectedAction
);
});

it('should create an action to create API success', () => {
const communicator = {};
const communicatorId = '10';

const expectedAction = {
type: types.CREATE_API_COMMUNICATOR_SUCCESS,
communicator,
communicatorId
};

expect(
actions.createApiCommunicatorSuccess(communicator, communicatorId)
).toEqual(expectedAction);
});

it('should create an action to create API started', () => {
const expectedAction = {
type: types.CREATE_API_COMMUNICATOR_STARTED
};
expect(actions.createApiCommunicatorStarted()).toEqual(expectedAction);
});

it('should create an action to create API failure', () => {
const message = 'dummy message';
const expectedAction = {
type: types.CREATE_API_COMMUNICATOR_FAILURE,
message
};

expect(actions.createApiCommunicatorFailure(message)).toEqual(
expectedAction
);
});

it('should create an action to update API success', () => {
const communicator = {};
const expectedAction = {
type: types.UPDATE_API_COMMUNICATOR_SUCCESS,
communicator
};
expect(actions.updateApiCommunicatorSuccess(communicator)).toEqual(
expectedAction
);
});

it('should create an action to update API started', () => {
const expectedAction = {
type: types.UPDATE_API_COMMUNICATOR_STARTED
};
expect(actions.updateApiCommunicatorStarted()).toEqual(expectedAction);
});

it('should create an action to update API failure', () => {
const message = 'dummy message';
const expectedAction = {
type: types.UPDATE_API_COMMUNICATOR_FAILURE,
message
};

expect(actions.updateApiCommunicatorFailure(message)).toEqual(
expectedAction
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as actions from '../Notifications.actions';
import * as types from '../Notifications.constants';

describe('actions', () => {
it('should create an action to show notifications', () => {
const message = 'dummy message';

const expectedAction = {
type: types.SHOW_NOTIFICATION,
message,
open: true
};
expect(actions.showNotification(message)).toEqual(expectedAction);
});

it('should create an action to hide notification', () => {
const expectedAction = {
type: types.HIDE_NOTIFICATION,
open: false
};
expect(actions.hideNotification()).toEqual(expectedAction);
});
});
2 changes: 1 addition & 1 deletion src/components/UI/LockToggle/LockToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const propTypes = {
locked: PropTypes.bool
};

function LockToggle(props) {
export function LockToggle(props) {
const { intl, locked, ...rest } = props;

const lockButtonLabel = locked
Expand Down
38 changes: 36 additions & 2 deletions src/components/UI/LockToggle/LockToggle.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
import React from 'react';
import { shallowMatchSnapshot } from '../../../common/test_utils';
import { mount } from 'enzyme';
import LockOutlinedIcon from '@material-ui/icons/LockOutlined';
import LockOpenIcon from '@material-ui/icons/LockOpen';

import { shallowMatchSnapshot } from '../../../common/test_utils';
import LockToggle from './LockToggle';

jest.mock('./LockToggle.messages', () => ({
lock: {
id: 'cboard.components.LockToggle.lock',
defaultMessage: 'Lock'
},
unlock: {
id: 'cboard.components.LockToggle.unlock',
defaultMessage: 'Unlock'
}
}));

describe('LockToggle tests', () => {
test('default renderer', () => {
it('default renderer', () => {
shallowMatchSnapshot(<LockToggle onClick={() => {}} />);
});

it('should render with unlocked icon', () => {
const props = {
onClick: () => {},
locked: false
};
const wrapper = mount(<LockToggle {...props} />);

expect(wrapper.find(LockOpenIcon)).toHaveLength(1);
});

it('should render with locked icon', () => {
const props = {
onClick: () => {},
locked: true
};
const wrapper = mount(<LockToggle {...props} />);

expect(wrapper.find(LockOutlinedIcon)).toHaveLength(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,42 @@ import * as actions from '../ScannerProvider.actions';
import * as types from '../ScannerProvider.constants';

describe('actions', () => {
it('should create an action to REPLACE_ME', () => {
it('should create an action to activate scanner', () => {
const expectedAction = {
type: types.ACTIVATE_SCANNER
};
expect(actions.activateScanner()).toEqual(expectedAction);
});

it('should create an action to REPLACE_ME', () => {
it('should create an action to deactivate scanner', () => {
const expectedAction = {
type: types.DEACTIVATE_SCANNER
};
expect(actions.deactivateScanner()).toEqual(expectedAction);
});

it('should create an action to REPLACE_ME', () => {
it('should create an action to toggle scanner', () => {
const expectedAction = {
type: types.TOGGLE_SCANNER
};

expect(actions.toggleScanner()).toEqual(expectedAction);
});

it('should create an action to REPLACE_ME', () => {
it('should create an action to update scanner settings', () => {
const payload = {};
const expectedAction = {
type: types.UPDATE_SCANNER_SETTINGS,
payload
};
expect(actions.updateScannerSettings(payload)).toEqual(expectedAction);
});

it('should create an action to update scanner settings - default payload', () => {
const expectedAction = {
type: types.UPDATE_SCANNER_SETTINGS,
payload: {}
};
expect(actions.updateScannerSettings()).toEqual(expectedAction);
});
});
Loading

0 comments on commit 1b3aa60

Please sign in to comment.