Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
fix recently broken unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lieut-data committed Apr 3, 2018
1 parent e480ec1 commit b209749
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
6 changes: 5 additions & 1 deletion components/profile_popover/profile_popover.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ class ProfilePopover extends React.Component {
delete popoverProps.hasMention;
delete popoverProps.dispatch;
delete popoverProps.enableWebrtc;
delete popoverProps.enableTimezone;

let webrtc;
const userMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
Expand Down Expand Up @@ -283,7 +284,10 @@ class ProfilePopover extends React.Component {
}

dataContent.push(
<hr className='divider divider--expanded'/>
<hr
key='user-popover-hr'
className='divider divider--expanded'
/>
);

if (this.props.user.position) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exports[`components/delete_post_modal should match snapshot for delete_post_moda
"remove": [Function],
}
}
onExited={[Function]}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
Expand Down Expand Up @@ -122,7 +122,7 @@ exports[`components/delete_post_modal should match snapshot for delete_post_moda
"remove": [Function],
}
}
onExited={[Function]}
onExited={[MockFunction]}
onHide={[Function]}
renderBackdrop={[Function]}
restoreFocus={true}
Expand Down Expand Up @@ -209,4 +209,4 @@ exports[`components/delete_post_modal should match snapshot for delete_post_moda
</button>
</ModalFooter>
</Modal>
`;
`;
33 changes: 21 additions & 12 deletions tests/components/delete_post_modal.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {browserHistory} from 'utils/browser_history';
import DeletePostModal from 'components/delete_post_modal/delete_post_modal.jsx';

describe('components/delete_post_modal', () => {
function emptyFunction() {} //eslint-disable-line no-empty-function

const post = {
id: '123',
message: 'test',
Expand All @@ -23,9 +21,10 @@ describe('components/delete_post_modal', () => {
commentCount: 0,
isRHS: false,
actions: {
deletePost: emptyFunction,
deletePost: jest.fn(),
deleteAndRemovePost: jest.fn(),
},
onHide: emptyFunction,
onHide: jest.fn(),
};

test('should match snapshot for delete_post_modal with 0 comments', () => {
Expand Down Expand Up @@ -56,26 +55,36 @@ describe('components/delete_post_modal', () => {

test('should have called actions.deleteAndRemovePost when handleDelete is called', async () => {
browserHistory.push = jest.fn();
const actions = {deleteAndRemovePost: jest.fn()};
actions.deleteAndRemovePost.mockReturnValueOnce({data: true});
const props = {...baseProps, actions};
const deleteAndRemovePost = jest.fn().mockReturnValueOnce({data: true});
const props = {
...baseProps,
actions: {
deleteAndRemovePost,
},
};
const wrapper = shallow(
<DeletePostModal {...props}/>
);

wrapper.setState({show: true});
wrapper.instance().handleDelete();

await expect(actions.deleteAndRemovePost).toHaveBeenCalledTimes(1);
expect(actions.deleteAndRemovePost).toHaveBeenCalledWith(props.post);
await expect(deleteAndRemovePost).toHaveBeenCalledTimes(1);
expect(deleteAndRemovePost).toHaveBeenCalledWith(props.post);
expect(wrapper.state('show')).toEqual(false);
});

test('should call browserHistory.push on handleDelete with post.id === focusedPostId && channelName', async () => {
browserHistory.push = jest.fn();
const actions = {deleteAndRemovePost: jest.fn()};
actions.deleteAndRemovePost.mockReturnValueOnce({data: true});
const props = {...baseProps, actions, focusedPostId: '123', channelName: 'channel_name', teamName: 'team_name'};
const props = {
...baseProps,
focusedPostId: '123',
channelName: 'channel_name',
teamName: 'team_name',
actions: {
deleteAndRemovePost: jest.fn().mockReturnValueOnce({data: true}),
},
};
const wrapper = shallow(
<DeletePostModal {...props}/>
);
Expand Down
4 changes: 4 additions & 0 deletions tests/components/user_settings/user_settings_display.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ describe('components/user_settings/display/UserSettingsDisplay', () => {
automaticTimezone: 'America/New_York',
manualTimezone: '',
},
actions: {
getSupportedTimezones: jest.fn(),
autoUpdateTimezone: jest.fn(),
},
};

test('should match snapshot, no active section', () => {
Expand Down
3 changes: 1 addition & 2 deletions tests/plugins/__snapshots__/pluggable.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,13 @@ exports[`plugins/Pluggable should match snapshot with no overridden component 1`
>
<Popover
bsClass="popover"
enableTimezone={false}
id="user-profile-popover"
placement="right"
theme={Object {}}
title="@undefined"
>
<div
className="popover right"
enableTimezone={false}
id="user-profile-popover"
role="tooltip"
style={
Expand Down Expand Up @@ -114,6 +112,7 @@ exports[`plugins/Pluggable should match snapshot with no overridden component 1`
/>
<hr
className="divider divider--expanded"
key="user-popover-hr"
/>
<div
className="popover__row first"
Expand Down

0 comments on commit b209749

Please sign in to comment.