-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for FieldGuide, FieldGuideButton, HelpIcon. Fix store tests.
- Loading branch information
Sarah Allen
committed
Apr 2, 2019
1 parent
7b0c384
commit b3069e0
Showing
6 changed files
with
159 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { shallow, mount } from 'enzyme' | ||
import React from 'react' | ||
import FieldGuide from './FieldGuide' | ||
import FieldGuideItem from './components/FieldGuideItem' | ||
import FieldGuideItems from './components/FieldGuideItems' | ||
import { FieldGuideMediumFactory } from '../../../../../../../test/factories' | ||
|
||
const medium = FieldGuideMediumFactory.build() | ||
const items = [ | ||
{ | ||
title: 'Cat', | ||
icon: medium.id, | ||
content: 'lorem ipsum' | ||
}, | ||
{ | ||
title: 'Dog', | ||
content: 'Foo bar' | ||
}, | ||
{ title: 'Iguana', content: 'hello' }, | ||
{ title: 'Koala', content: '' }, | ||
{ title: 'Dragon', content: 'Why is this here?' } | ||
] | ||
|
||
describe('Component > FieldGuide', function () { | ||
it('should render without crashing', function () { | ||
const wrapper = shallow( | ||
<FieldGuide.wrappedComponent | ||
items={items} | ||
/>) | ||
expect(wrapper).to.be.ok | ||
}) | ||
|
||
it('should render FieldGuideItems if there is not an active item', function () { | ||
const wrapper = shallow( | ||
<FieldGuide.wrappedComponent | ||
items={items} | ||
/>) | ||
expect(wrapper.find(FieldGuideItems)).to.have.lengthOf(1) | ||
expect(wrapper.find(FieldGuideItem)).to.have.lengthOf(0) | ||
}) | ||
|
||
it('should render FieldGuideItem if there is an active item', function () { | ||
const wrapper = shallow( | ||
<FieldGuide.wrappedComponent | ||
activeItem={0} | ||
items={items} | ||
/>) | ||
expect(wrapper.find(FieldGuideItems)).to.have.lengthOf(0) | ||
expect(wrapper.find(FieldGuideItem)).to.have.lengthOf(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
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,89 @@ | ||
import { shallow, mount } from 'enzyme' | ||
import sinon from 'sinon' | ||
import React from 'react' | ||
import FieldGuideButton, { ButtonLabel } from './FieldGuideButton' | ||
import { FieldGuideFactory, FieldGuideMediumFactory } from '../../../../../../../test/factories' | ||
|
||
const medium = FieldGuideMediumFactory.build() | ||
const items = [ | ||
{ | ||
title: 'Cat', | ||
icon: medium.id, | ||
content: 'lorem ipsum' | ||
}, | ||
{ | ||
title: 'Dog', | ||
content: 'Foo bar' | ||
}, | ||
{ title: 'Iguana', content: 'hello' }, | ||
{ title: 'Koala', content: '' }, | ||
{ title: 'Dragon', content: 'Why is this here?' } | ||
] | ||
const fieldGuide = FieldGuideFactory.build({ items }) | ||
const fieldGuideWithoutItems = FieldGuideFactory.build() | ||
|
||
describe('Component > FieldGuideButton', function () { | ||
it('should render without crashing', function () { | ||
const wrapper = shallow( | ||
<FieldGuideButton.wrappedComponent | ||
fieldGuide={fieldGuide} | ||
setModalVisibility={() => {}} | ||
/>) | ||
expect(wrapper).to.be.ok | ||
}) | ||
|
||
it('should disable the button if there isn\'t a field guide', function () { | ||
const wrapper = shallow( | ||
<FieldGuideButton.wrappedComponent | ||
setModalVisibility={() => { }} | ||
/>) | ||
expect(wrapper.props().disabled).to.be.true | ||
}) | ||
|
||
it('should disable the button if the field guide doesn\'t have items', function () { | ||
const wrapper = shallow( | ||
<FieldGuideButton.wrappedComponent | ||
fieldGuide={fieldGuideWithoutItems} | ||
setModalVisibility={() => { }} | ||
/>) | ||
expect(wrapper.props().disabled).to.be.true | ||
}) | ||
|
||
it('should enable the button if the field guide has items', function () { | ||
const wrapper = shallow( | ||
<FieldGuideButton.wrappedComponent | ||
fieldGuide={fieldGuide} | ||
setModalVisibility={() => { }} | ||
/>) | ||
expect(wrapper.props().disabled).to.be.false | ||
}) | ||
|
||
it('should render a ButtonLabel for the label', function () { | ||
const wrapper = shallow( | ||
<FieldGuideButton.wrappedComponent | ||
fieldGuide={fieldGuide} | ||
setModalVisibility={() => { }} | ||
/>) | ||
|
||
expect(wrapper.props().label.type).to.equal(ButtonLabel) | ||
}) | ||
|
||
it('should call setModalVisibility on click', function () { | ||
const setModalVisibilitySpy = sinon.spy() | ||
const wrapper = shallow( | ||
<FieldGuideButton.wrappedComponent | ||
fieldGuide={fieldGuide} | ||
setModalVisibility={setModalVisibilitySpy} | ||
/>) | ||
|
||
wrapper.simulate('click') | ||
expect(setModalVisibilitySpy).to.have.been.calledOnceWith(true) | ||
}) | ||
|
||
describe('Component > ButtonLabel', function () { | ||
it('should render without crashing', function () { | ||
const wrapper = shallow(<ButtonLabel />) | ||
expect(wrapper).to.be.ok | ||
}) | ||
}) | ||
}) |
10 changes: 10 additions & 0 deletions
10
.../components/Classifier/components/FieldGuide/components/FieldGuideButton/HelpIcon.spec.js
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,10 @@ | ||
import { shallow, mount } from 'enzyme' | ||
import React from 'react' | ||
import HelpIcon from './HelpIcon' | ||
|
||
describe('Component > HelpIcon', function () { | ||
it('should render without crashing', function () { | ||
const wrapper = shallow(<HelpIcon />) | ||
expect(wrapper).to.be.ok | ||
}) | ||
}) |
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