{"size": 2528, "ext": "js", "max_stars_repo_path": "packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/components/FieldGuideItems/FieldGuideItemAnchor.spec.js", "max_stars_repo_name": "AnansiOmega/front-end-monorepo", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/components/FieldGuideItems/FieldGuideItemAnchor.spec.js", "max_issues_repo_name": "AnansiOmega/front-end-monorepo", "max_issues_repo_issues_event_min_datetime": "2021-02-23T22:58:18.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-23T22:58:18.000Z", "max_forks_repo_path": "packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/components/FieldGuideItems/FieldGuideItemAnchor.spec.js", "max_forks_repo_name": "AnansiOmega/front-end-monorepo", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 29.0574712644, "max_line_length": 74, "alphanum_fraction": 0.6455696203}
import { shallow } from 'enzyme'
import sinon from 'sinon'
import React from 'react'
import { observable } from 'mobx'
import { Markdownz } from '@zooniverse/react-components'
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 item = {
  title: 'Cat',
  icon: medium.id,
  content: 'lorem ipsum'
}
const itemIndex = 0

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

  it('should use AnchorLabel as the label', function () {
    const wrapper = shallow(
      <FieldGuideItemAnchor.wrappedComponent
        icons={attachedMedia}
        item={item}
        itemIndex={itemIndex}
        setActiveItemIndex={() => { }}
      />)
    expect(wrapper.props().label.type).to.equal(AnchorLabel)
  })

  it('should call setActiveItemIndex on click', function () {
    const setActiveItemIndexSpy = sinon.spy()
    const wrapper = shallow(
      <FieldGuideItemAnchor.wrappedComponent
        icons={attachedMedia}
        item={item}
        itemIndex={itemIndex}
        setActiveItemIndex={setActiveItemIndexSpy}
      />)

    wrapper.simulate('click', { preventDefault: () => {} })
    expect(setActiveItemIndexSpy).to.have.been.calledOnceWith(itemIndex)
  })

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

    it('should render the item title as markdown', function () {
      const wrapper = shallow(
        <AnchorLabel
          icons={attachedMedia}
          item={item}
        />)
      expect(wrapper.find(Markdownz).contains(item.title)).to.be.true()
    })

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

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