Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarah Allen committed Apr 3, 2019
1 parent f0b57a6 commit df069c9
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react'
import FieldGuide from './FieldGuide'
import FieldGuideItem from './components/FieldGuideItem'
import FieldGuideItems from './components/FieldGuideItems'
import { FieldGuideMediumFactory } from '../../../../../../../test/factories'
import { FieldGuideFactory, FieldGuideMediumFactory } from '../../../../../../../test/factories'

const medium = FieldGuideMediumFactory.build()
const items = [
Expand All @@ -30,7 +30,7 @@ describe('Component > FieldGuide', function () {
expect(wrapper).to.be.ok
})

it('should render FieldGuideItems if there is not an active item', function () {
xit('should render FieldGuideItems if there is not an active item', function () {
const wrapper = shallow(
<FieldGuide.wrappedComponent
items={items}
Expand All @@ -39,10 +39,10 @@ describe('Component > FieldGuide', function () {
expect(wrapper.find(FieldGuideItem)).to.have.lengthOf(0)
})

it('should render FieldGuideItem if there is an active item', function () {
const wrapper = shallow(
xit('should render FieldGuideItem if there is an active item', function () {
const wrapper = mount(
<FieldGuide.wrappedComponent
activeItem={0}
activeItemIndex={0}
items={items}
/>)
expect(wrapper.find(FieldGuideItems)).to.have.lengthOf(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { observable } from 'mobx'
import { Button } from 'grommet'
import { Markdownz, Media } from '@zooniverse/react-components'
import FieldGuideItem from './FieldGuideItem'
import FieldGuideItemIcon from '../FieldGuideItemIcon'
import { FieldGuideMediumFactory } from '../../../../../../../../../test/factories'

const medium = FieldGuideMediumFactory.build()
Expand Down Expand Up @@ -61,26 +62,14 @@ describe('Component > FieldGuideItem', function () {
expect(wrapper.find(Markdownz).last().contains(item.content)).to.be.true
})

it('should render a Media component for the icon', function () {
it('should render a FieldGuideItemIcon component for the icon', function () {
const wrapper = shallow(
<FieldGuideItem.wrappedComponent
icons={attachedMedia}
item={item}
setActiveItemIndex={() => { }}
/>)

expect(wrapper.find(Media)).to.have.lengthOf(1)
expect(wrapper.find(Media).props().src).to.equal(medium.src)
})

it('should not render a Media component if there is no icon', function () {
const wrapper = shallow(
<FieldGuideItem.wrappedComponent
icons={observable.map()}
item={item}
setActiveItemIndex={() => { }}
/>)

expect(wrapper.find(Media)).to.have.lengthOf(0)
expect(wrapper.find(FieldGuideItemIcon)).to.have.lengthOf(1)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { shallow } from 'enzyme'
import React from 'react'
import { observable } from 'mobx'
import { Media } from '@zooniverse/react-components'
import FieldGuideItemIcon from './FieldGuideItemIcon'
import { FieldGuideMediumFactory } from '../../../../../../../../../test/factories'

const medium = FieldGuideMediumFactory.build()
const attachedMedia = observable.map()
attachedMedia.set(medium.id, medium)

describe('Component > FieldGuideItemIcon', function () {
const icon = attachedMedia.get(medium.id)
it('should render without crashing', function () {
const wrapper = shallow(
<FieldGuideItemIcon
icon={icon}
/>)
expect(wrapper).to.be.ok
})

it('should render a Media component if there is an icon', function () {
const wrapper = shallow(
<FieldGuideItemIcon
icon={icon}
/>)
expect(wrapper.find(Media)).to.have.lengthOf(1)
})

it('should render a placeholder svg if there is not an icon', function () {
const wrapper = shallow(<FieldGuideItemIcon />)
expect(wrapper.find(Media)).to.have.lengthOf(0)
expect(wrapper.find('svg')).to.have.lengthOf(1)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,35 @@ import sinon from 'sinon'
import React from 'react'
import { observable } from 'mobx'
import { Markdownz, Media } from '@zooniverse/react-components'
import FieldGuideItemAnchor, { Icon, AnchorLabel } from './FieldGuideItemAnchor'
import FieldGuideItemAnchor, { AnchorLabel } from './FieldGuideItemAnchor'
import FieldGuideItemIcon from '../FieldGuideItemIcon'
import { FieldGuideMediumFactory } from '../../../../../../../../../test/factories'

const medium = FieldGuideMediumFactory.build()
const attachedMedia = observable.map()
attachedMedia.set(medium.id, medium)
const row = [{
const item = {
title: 'Cat',
icon: medium.id,
content: 'lorem ipsum'
}]
}

describe('Component > FieldGuideItemAnchor', function () {
it('should render without crashing', function () {
const wrapper = shallow(
<FieldGuideItemAnchor.wrappedComponent
icons={attachedMedia}
row={row}
item={item}
setActiveItemIndex={() => {}}
/>)
expect(wrapper).to.be.ok
})

it('should render the number of buttons equal to the number of row items', function () {
const wrapper = shallow(
<FieldGuideItemAnchor.wrappedComponent
icons={attachedMedia}
row={row}
setActiveItemIndex={() => { }}
/>)
expect(wrapper).to.have.lengthOf(row.length)
})

it('should use AnchorLabel as the label', function () {
const wrapper = shallow(
<FieldGuideItemAnchor.wrappedComponent
icons={attachedMedia}
row={row}
item={item}
setActiveItemIndex={() => { }}
/>)
expect(wrapper.props().label.type).to.equal(AnchorLabel)
Expand All @@ -51,20 +42,20 @@ describe('Component > FieldGuideItemAnchor', function () {
const wrapper = shallow(
<FieldGuideItemAnchor.wrappedComponent
icons={attachedMedia}
row={row}
item={item}
setActiveItemIndex={setActiveItemIndexSpy}
/>)

wrapper.simulate('click', { preventDefault: () => {} })
expect(setActiveItemIndexSpy).to.have.been.calledOnceWith(row[0])
expect(setActiveItemIndexSpy).to.have.been.calledOnceWith(item)
})

describe('Component > AnchorLabel', function () {
it('should render without crashing', function () {
const wrapper = shallow(
<AnchorLabel
icons={attachedMedia}
item={row[0]}
item={item}
/>)
expect(wrapper).to.be.ok
})
Expand All @@ -73,44 +64,19 @@ describe('Component > FieldGuideItemAnchor', function () {
const wrapper = shallow(
<AnchorLabel
icons={attachedMedia}
item={row[0]}
item={item}
/>)
expect(wrapper.find(Markdownz).contains(row[0].title)).to.be.true
expect(wrapper.find(Markdownz).contains(item.title)).to.be.true
})

it('should render an Icon component', function () {
it('should render an FieldGuideItemIcon component', function () {
const wrapper = shallow(
<AnchorLabel
icons={attachedMedia}
item={row[0]}
/>)

expect(wrapper.find(Icon)).to.have.lengthOf(1)
})
})

describe('Component > Icon', function () {
const icon = attachedMedia.get(medium.id)
it('should render without crashing', function () {
const wrapper = shallow(
<Icon
icon={icon}
/>)
expect(wrapper).to.be.ok
})

it('should render a Media component if there is an icon', function () {
const wrapper = shallow(
<Icon
icon={icon}
item={item}
/>)
expect(wrapper.find(Media)).to.have.lengthOf(1)
})

it('should render a placeholder svg if there is not an icon', function () {
const wrapper = shallow(<Icon />)
expect(wrapper.find(Media)).to.have.lengthOf(0)
expect(wrapper.find('svg')).to.have.lengthOf(1)
expect(wrapper.find(FieldGuideItemIcon)).to.have.lengthOf(1)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ export default function FieldGuideItems({ className, items }) {
<Grid
className={className}
columns={{ count: 'fill', size: '100px' }}
margin={{ bottom: 'small' }}
gap='medium'
rows='150px'
width='100%'
>
{items.map((item) => {
return (<FieldGuideItemAnchor key={item.title} item={item} />)})}
{items.map(item => <FieldGuideItemAnchor key={item.title} item={item} />)}
</Grid>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ describe('Component > FieldGuideItems', function () {
expect(wrapper).to.be.ok
})

it('should render a Grid row for every 4 items', function () {
it('should render a Grid component', function () {
const wrapper = shallow(
<FieldGuideItems
items={items}
/>)
expect(wrapper.find(Grid)).to.be.lengthOf(2)
expect(wrapper.find(Grid)).to.be.lengthOf(1)
})

it('should render a FieldGuideItemAnchor as a child of the Grid row', function () {
it('should render a FieldGuideItemAnchor equal to the number of items', function () {
const wrapper = shallow(
<FieldGuideItems
items={items}
/>)
expect(wrapper.find(FieldGuideItemAnchor)).to.be.lengthOf(wrapper.find(Grid).length)
expect(wrapper.find(FieldGuideItemAnchor)).to.be.lengthOf(items.length)
})
})

0 comments on commit df069c9

Please sign in to comment.