Skip to content

Commit

Permalink
snack bar unit test (finos#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
VICTOR RAPHAEL BRAGA DE SALES MASCARENHAS authored and KiranNiranjan committed Mar 28, 2019
1 parent 50eaea3 commit b2b10b5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
3 changes: 3 additions & 0 deletions spec/__snapshots__/snackBar.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`snack bar should render correctly 1`] = `<div />`;
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 b2b10b5

Please sign in to comment.