Skip to content

Commit

Permalink
snack bar unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor R. Braga de Sales Mascarenhasm committed Mar 13, 2019
1 parent 6ba9e91 commit 85b2e73
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 6 deletions.
4 changes: 3 additions & 1 deletion spec/__snapshots__/aboutApp.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ ShallowWrapper {
"getChildContext": Object {
"calledByRenderer": false,
},
"getDerivedStateFromProps": true,
"getDerivedStateFromProps": Object {
"hasShouldComponentUpdateBug": false,
},
"getSnapshotBeforeUpdate": true,
"setState": Object {
"skipsComponentDidUpdateOnNullish": true,
Expand Down
4 changes: 3 additions & 1 deletion spec/__snapshots__/basicAuth.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,9 @@ ShallowWrapper {
"getChildContext": Object {
"calledByRenderer": false,
},
"getDerivedStateFromProps": true,
"getDerivedStateFromProps": Object {
"hasShouldComponentUpdateBug": false,
},
"getSnapshotBeforeUpdate": true,
"setState": Object {
"skipsComponentDidUpdateOnNullish": true,
Expand Down
4 changes: 3 additions & 1 deletion spec/__snapshots__/downloadManager.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ ShallowWrapper {
"getChildContext": Object {
"calledByRenderer": false,
},
"getDerivedStateFromProps": true,
"getDerivedStateFromProps": Object {
"hasShouldComponentUpdateBug": false,
},
"getSnapshotBeforeUpdate": true,
"setState": Object {
"skipsComponentDidUpdateOnNullish": true,
Expand Down
4 changes: 3 additions & 1 deletion spec/__snapshots__/loadingScreen.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ ShallowWrapper {
"getChildContext": Object {
"calledByRenderer": false,
},
"getDerivedStateFromProps": true,
"getDerivedStateFromProps": Object {
"hasShouldComponentUpdateBug": false,
},
"getSnapshotBeforeUpdate": true,
"setState": Object {
"skipsComponentDidUpdateOnNullish": true,
Expand Down
4 changes: 3 additions & 1 deletion spec/__snapshots__/screenPicker.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,9 @@ ShallowWrapper {
"getChildContext": Object {
"calledByRenderer": false,
},
"getDerivedStateFromProps": true,
"getDerivedStateFromProps": Object {
"hasShouldComponentUpdateBug": false,
},
"getSnapshotBeforeUpdate": true,
"setState": Object {
"skipsComponentDidUpdateOnNullish": true,
Expand Down
4 changes: 3 additions & 1 deletion spec/__snapshots__/screenSharingIndicator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ ShallowWrapper {
"getChildContext": Object {
"calledByRenderer": false,
},
"getDerivedStateFromProps": true,
"getDerivedStateFromProps": Object {
"hasShouldComponentUpdateBug": false,
},
"getSnapshotBeforeUpdate": true,
"setState": Object {
"skipsComponentDidUpdateOnNullish": true,
Expand Down
61 changes: 61 additions & 0 deletions spec/__snapshots__/snackBar.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`snack bar should render correctly 1`] = `
ShallowWrapper {
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <SnackBar />,
Symbol(enzyme.__renderer__): Object {
"batchedUpdates": [Function],
"checkPropTypes": [Function],
"getNode": [Function],
"render": [Function],
"simulateError": [Function],
"simulateEvent": [Function],
"unmount": [Function],
},
Symbol(enzyme.__node__): Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {},
"ref": null,
"rendered": null,
"type": "div",
},
Symbol(enzyme.__nodes__): Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {},
"ref": null,
"rendered": null,
"type": "div",
},
],
Symbol(enzyme.__options__): Object {
"adapter": ReactSixteenAdapter {
"options": Object {
"enableComponentDidUpdateOnSetState": true,
"legacyContextMode": "parent",
"lifecycles": Object {
"componentDidUpdate": Object {
"onSetState": true,
},
"getChildContext": Object {
"calledByRenderer": false,
},
"getDerivedStateFromProps": Object {
"hasShouldComponentUpdateBug": false,
},
"getSnapshotBeforeUpdate": true,
"setState": Object {
"skipsComponentDidUpdateOnNullish": true,
},
},
},
},
},
Symbol(enzyme.__childContext__): null,
}
`;
56 changes: 56 additions & 0 deletions spec/snackBar.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { shallow } from 'enzyme';
import * as React from 'react';
import SnackBar from '../src/renderer/components/snack-bar';
import { ipcRenderer } from './__mocks__/electron';

describe('snack bar', () => {
beforeEach(() => {
jest.useFakeTimers();
jest.restoreAllMocks();
});
// events label
const onEventLabel = 'on';
const removeListenerEventLabel = 'removeListener';
const windowEnterFullScreenEventLabel = 'window-enter-full-screen';
const windowLeaveFullScreenEventLabel = 'window-leave-full-screen';

it('should render correctly', () => {
const wrapper = shallow(React.createElement(SnackBar));
expect(wrapper).toMatchSnapshot();
});

it('should call mount correctly', () => {
const spy = jest.spyOn(ipcRenderer, onEventLabel);
shallow(React.createElement(SnackBar));
expect(spy).nthCalledWith(1, windowEnterFullScreenEventLabel, expect.any(Function));
expect(spy).nthCalledWith(2, windowLeaveFullScreenEventLabel, expect.any(Function));
});

it('should call unmount correctly', () => {
const spy = jest.spyOn(ipcRenderer, removeListenerEventLabel);
shallow(React.createElement(SnackBar)).unmount();
expect(spy).nthCalledWith(1, windowEnterFullScreenEventLabel, expect.any(Function));
expect(spy).nthCalledWith(2, windowLeaveFullScreenEventLabel, expect.any(Function));
});

it('should call `removeSnackBar` correctly', () => {
const spy = jest.spyOn(SnackBar.prototype, 'setState');
const expectedValue = { show: false };
shallow(React.createElement(SnackBar));
ipcRenderer.send(windowLeaveFullScreenEventLabel, null);
expect(spy).lastCalledWith(expectedValue);
jest.runOnlyPendingTimers();
});

it('should call `showSnackBar` correctly', () => {
const spy = jest.spyOn(SnackBar.prototype, 'setState');
const expectedValueFirst = { show: true };
const expectedValueSecond = { show: false };
shallow(React.createElement(SnackBar));
ipcRenderer.send(windowEnterFullScreenEventLabel, null);
expect(setTimeout).lastCalledWith(expect.any(Function), 3000);
expect(spy).nthCalledWith(1, expectedValueFirst);
jest.runOnlyPendingTimers();
expect(spy).nthCalledWith(2, expectedValueSecond);
});
});

0 comments on commit 85b2e73

Please sign in to comment.