-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Victor R. Braga de Sales Mascarenhasm
committed
Mar 13, 2019
1 parent
6ba9e91
commit 85b2e73
Showing
8 changed files
with
135 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |