-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: spice up
SelectionToolbarItem
(#225)
- Loading branch information
1 parent
75d066d
commit 3292d43
Showing
5 changed files
with
113 additions
and
34 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
82 changes: 82 additions & 0 deletions
82
apis/nucleus/src/components/__tests__/selectiontoolbaritem.spec.jsx
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,82 @@ | ||
import React from 'react'; | ||
import { create, act } from 'react-test-renderer'; | ||
import { IconButton, Button, MenuItem } from '@material-ui/core'; | ||
|
||
const SvgIcon = () => 'svgicon'; | ||
|
||
const [{ default: SelectionToolbarItem }] = aw.mock( | ||
[ | ||
[require.resolve('@nebula.js/ui/theme'), () => ({ makeStyles: () => () => ({ icon: 'icon' }) })], | ||
[require.resolve('@nebula.js/ui/icons/SvgIcon'), () => SvgIcon], | ||
], | ||
['../SelectionToolbarItem'] | ||
); | ||
|
||
describe('<SelectionToolbarItem />', () => { | ||
let sandbox; | ||
let renderer; | ||
let render; | ||
beforeEach(() => { | ||
sandbox = sinon.createSandbox(); | ||
render = async (item, layout) => { | ||
await act(async () => { | ||
renderer = create(<SelectionToolbarItem item={item} layout={layout} />); | ||
}); | ||
}; | ||
}); | ||
afterEach(() => { | ||
sandbox.restore(); | ||
renderer.unmount(); | ||
}); | ||
it('should render default', async () => { | ||
const action = sandbox.spy(); | ||
await render({ action }); | ||
const types = renderer.root.findAllByType(IconButton); | ||
expect(types).to.have.length(1); | ||
types[0].props.onClick(); | ||
expect(action.callCount).to.equal(1); | ||
}); | ||
it('should listen on changed', async () => { | ||
const action = sandbox.spy(); | ||
const getSvgIconShape = sandbox.spy(); | ||
const on = sandbox.spy(); | ||
const removeListener = sandbox.spy(); | ||
const enabled = sandbox.stub().returns(true); | ||
await render({ on, removeListener, action, enabled, getSvgIconShape }); | ||
const types = renderer.root.findAllByType(IconButton); | ||
expect(types).to.have.length(1); | ||
expect(types[0].props.disabled).to.equal(false); | ||
enabled.returns(false); | ||
on.callArg(1); | ||
expect(types[0].props.disabled).to.equal(true); | ||
}); | ||
it('should render button', async () => { | ||
const action = sandbox.spy(); | ||
await render({ type: 'button', label: 'foo', color: 'purple', action }); | ||
const types = renderer.root.findAllByType(Button); | ||
expect(types).to.have.length(1); | ||
expect(types[0].props).to.containSubset({ | ||
title: 'foo', | ||
variant: 'contained', | ||
style: { | ||
backgroundColor: 'purple', | ||
}, | ||
}); | ||
types[0].props.onClick(); | ||
expect(action.callCount).to.equal(1); | ||
}); | ||
it('should render button with svg icon', async () => { | ||
const getSvgIconShape = sandbox.spy(); | ||
await render({ type: 'button', label: 'foo', color: 'purple', getSvgIconShape }); | ||
const types = renderer.root.findAllByType(Button); | ||
expect(types[0].props.children).to.equal('svgicon'); | ||
}); | ||
it('should render menu icon button', async () => { | ||
const action = sandbox.spy(); | ||
await render({ type: 'menu-icon-button', action }); | ||
const types = renderer.root.findAllByType(MenuItem); | ||
expect(types).to.have.length(1); | ||
types[0].props.onClick(); | ||
expect(action.callCount).to.equal(1); | ||
}); | ||
}); |
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