This repository has been archived by the owner on Jun 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added test * fixed flow * inlined click handler * improved test text as requested in review * removed typing as it's a typescript definition * updated snapshot
- Loading branch information
Showing
3 changed files
with
145 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* eslint-disable flowtype/require-valid-file-annotation */ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { remote } from 'electron'; // Mocked | ||
import EjectButton, { dialogOptions, dialogCallback } from './EjectButton'; | ||
import BigClickableButton from '../BigClickableButton'; | ||
|
||
const { dialog } = remote; | ||
|
||
describe('EjectButton component', () => { | ||
let wrapper; | ||
let clickHandler; | ||
|
||
beforeEach(() => { | ||
clickHandler = jest.fn(); | ||
wrapper = shallow(<EjectButton onClick={clickHandler} />); | ||
}); | ||
|
||
it('should render without being pressed (not running)', () => { | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render as pressed (running)', () => { | ||
wrapper.setProps({ isRunning: true }); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
describe('Confirm dialog', () => { | ||
let ejectButton; | ||
beforeEach(() => { | ||
ejectButton = wrapper.find(BigClickableButton); | ||
ejectButton.simulate('click'); | ||
}); | ||
|
||
it('should display dialog', () => { | ||
expect(dialog.showMessageBox).toBeCalledWith( | ||
dialogOptions, | ||
expect.anything() | ||
); | ||
}); | ||
|
||
it('should call clickHandler if confirmed', () => { | ||
dialogCallback.call(wrapper.instance(), 0); | ||
expect(clickHandler.mock.calls.length).toBe(1); | ||
}); | ||
|
||
it('should dismiss with-out calling clickHandler', () => { | ||
dialogCallback.call(wrapper.instance(), 1); | ||
expect(clickHandler.mock.calls.length).toBe(0); | ||
}); | ||
}); | ||
}); |
68 changes: 68 additions & 0 deletions
68
src/components/EjectButton/__snapshots__/EjectButton.test.js.snap
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,68 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EjectButton component should render as pressed (running) 1`] = ` | ||
<BigClickableButton | ||
colors={ | ||
Array [ | ||
"#651fff", | ||
"#304FFE", | ||
] | ||
} | ||
height={34} | ||
isOn={true} | ||
onClick={[Function]} | ||
thickness={6} | ||
width={40} | ||
> | ||
<Icon | ||
fill="currentColor" | ||
icon={ | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"attribs": Object { | ||
"d": "M5 17h14v2H5zm7-12L5.33 15h13.34z", | ||
}, | ||
"name": "path", | ||
}, | ||
], | ||
"viewBox": "0 0 24 24", | ||
} | ||
} | ||
size={24} | ||
/> | ||
</BigClickableButton> | ||
`; | ||
|
||
exports[`EjectButton component should render without being pressed (not running) 1`] = ` | ||
<BigClickableButton | ||
colors={ | ||
Array [ | ||
"#651fff", | ||
"#304FFE", | ||
] | ||
} | ||
height={34} | ||
onClick={[Function]} | ||
thickness={6} | ||
width={40} | ||
> | ||
<Icon | ||
fill="currentColor" | ||
icon={ | ||
Object { | ||
"children": Array [ | ||
Object { | ||
"attribs": Object { | ||
"d": "M5 17h14v2H5zm7-12L5.33 15h13.34z", | ||
}, | ||
"name": "path", | ||
}, | ||
], | ||
"viewBox": "0 0 24 24", | ||
} | ||
} | ||
size={24} | ||
/> | ||
</BigClickableButton> | ||
`; |