All files / src/__test__ index.spec-set.js

100% Statements 132/132
100% Branches 6/6
100% Functions 19/19
100% Lines 130/130
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183              16x 12x 2x     2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x     2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x     2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x     2x 2x 2x       2x 2x 2x 2x     2x 2x 2x 2x 2x 2x 2x     2x 2x 2x 2x 2x 2x     2x 2x 2x 2x 2x 2x 2x 2x     2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x     2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x     2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x     2x 2x 2x             2x 2x 2x     2x 2x 2x           2x 2x 2x     2x 2x 2x            
import React from 'react'
import { shallow, mount, render } from 'enzyme'
import { expect } from 'chai'
import { Dummy, Item, BreadcrumbsProvider, withBreadcrumbsItem } from '../index'
 
export default function spec(TestApp, advanced) {
 
const runAllTimers = advanced ? () => {} : () => jest.runAllTimers()
const useFakeTimers = advanced ? () => {} : () => jest.useFakeTimers()
const usage = advanced ? 'advanced' : 'simple'
 
 
describe(`breadcrumbs ${usage} usage`, function() {
  it("can replace prop `to`", function() {
    useFakeTimers()
    const wrapper = mount(<TestApp/>)
    runAllTimers()
    expect(wrapper.find('a')).to.have.length(3)
    expect(wrapper.find('a').at(0).props().href).to.equal('/')
    expect(wrapper.find('a').at(1).props().href).to.equal('/user')
    expect(wrapper.find('a').at(2).props().href).to.equal('/user/profile')
    wrapper.find('.changeProfileUrl').simulate('click')
    runAllTimers()
    expect(wrapper.find('a')).to.have.length(3)
    expect(wrapper.find('a').at(0).props().href).to.equal('/')
    expect(wrapper.find('a').at(1).props().href).to.equal('/user')
    expect(wrapper.find('a').at(2).props().href).to.equal('/user/settings')
    wrapper.find('.restoreProfileUrl').simulate('click')
    runAllTimers()
    expect(wrapper.find('a')).to.have.length(3)
    expect(wrapper.find('a').at(0).props().href).to.equal('/')
    expect(wrapper.find('a').at(1).props().href).to.equal('/user')
    expect(wrapper.find('a').at(2).props().href).to.equal('/user/profile')
    wrapper.unmount()
  })
 
  it("can remove item", function() {
    useFakeTimers()
    const wrapper = mount(<TestApp/>)
    runAllTimers()
    expect(wrapper.find('a')).to.have.length(3)
    expect(wrapper.find('a').at(0).props().href).to.equal('/')
    expect(wrapper.find('a').at(1).props().href).to.equal('/user')
    expect(wrapper.find('a').at(2).props().href).to.equal('/user/profile')
    wrapper.find('.removeProfile').simulate('click')
    runAllTimers()
    expect(wrapper.find('a')).to.have.length(2)
    expect(wrapper.find('a').at(0).props().href).to.equal('/')
    expect(wrapper.find('a').at(1).props().href).to.equal('/user')
    wrapper.unmount()
  })
 
  it("can render separator", function() {
    useFakeTimers()
    const wrapper = mount(<TestApp separator={<a>/</a>} />)
    runAllTimers()
    expect(wrapper.find('a')).to.have.length(5)
    expect(wrapper.find('a').at(0).props().href).to.equal('/')
    expect(wrapper.find('a').at(1).props().children).to.equal('/')
    expect(wrapper.find('a').at(2).props().href).to.equal('/user')
    expect(wrapper.find('a').at(3).props().children).to.equal('/')
    expect(wrapper.find('a').at(4).props().href).to.equal('/user/profile')
    wrapper.unmount()
  })
 
  it("can specify container props", function() {
    useFakeTimers()
    const wrapper = mount(<TestApp
      container={"article"}
      containerProps={{data:"containerProps"}}
    />)
    runAllTimers()
    expect(wrapper.find('a')).to.have.length(3)
    expect(wrapper.find('article')).to.have.length(1)
    expect(wrapper.find('article').at(0).props().data).to.equal('containerProps')
  })
 
  it("can render one item", function() {
    useFakeTimers()
    const wrapper = mount(<TestApp onlyOneItem />)
    runAllTimers()
    expect(wrapper.find('a')).to.have.length(1)
    expect(wrapper.find('a').at(0).props().href).to.equal('/')
    wrapper.unmount()
  })
 
  it("can render no any item", function() {
    useFakeTimers()
    const wrapper = mount(<TestApp noAnyItem />)
    runAllTimers()
    expect(wrapper.find('a')).to.have.length(0)
    wrapper.unmount()
  })
 
  it("pass react component in props", function() {
    useFakeTimers()
    const wrapper = mount(<TestApp reactComponentInProps/>)
    runAllTimers()
    expect(wrapper.find('a')).to.have.length(3)
    expect(wrapper.find('b')).to.have.length(1)
    expect(wrapper.find('b').props().children).to.equal('Home Bold')
    wrapper.unmount()
  });
 
  it("replace another element with same props", function() {
    useFakeTimers()
    const wrapper = mount(<TestApp/>)
    runAllTimers()
    expect(wrapper.find('a')).to.have.length(3)
    expect(wrapper.find('a').at(0).props().href).to.equal('/')
    expect(wrapper.find('a').at(0).props().children).to.equal('Home')
    wrapper.find('.replaceAnotherSame').simulate('click')
    runAllTimers()
    expect(wrapper.find('a')).to.have.length(3)
    expect(wrapper.find('a').at(0).props().href).to.equal('/')
    expect(wrapper.find('a').at(0).props().children).to.equal('Home Another')
    wrapper.unmount()
  });
 
  it("can rename props", function() {
    useFakeTimers()
    const wrapper = mount(<TestApp renameProps={{}} />)
    runAllTimers()
    expect(wrapper.find('a')).to.have.length(3)
    expect(wrapper.find('a').at(0).props()).to.not.have.property("href")
    expect(wrapper.find('a').at(0).props().to).to.equal('/')
    expect(wrapper.find('a').at(1).props()).to.not.have.property("href")
    expect(wrapper.find('a').at(1).props().to).to.equal('/user')
    expect(wrapper.find('a').at(2).props()).to.not.have.property("href")
    expect(wrapper.find('a').at(2).props().to).to.equal('/user/profile')
    wrapper.unmount()
  })
 
  it("can duplicate props", function() {
    useFakeTimers()
    const wrapper = mount(<TestApp renameProps={{}} duplicateProps={{to:"href"}} />)
    runAllTimers()
    expect(wrapper.find('a')).to.have.length(3)
    expect(wrapper.find('a').at(0).props().to).to.equal('/')
    expect(wrapper.find('a').at(0).props().href).to.equal('/')
    expect(wrapper.find('a').at(1).props().to).to.equal('/user')
    expect(wrapper.find('a').at(1).props().href).to.equal('/user')
    expect(wrapper.find('a').at(2).props().to).to.equal('/user/profile')
    expect(wrapper.find('a').at(2).props().href).to.equal('/user/profile')
    wrapper.unmount()
  })
 
  it("container is not visible if hideIfEmpty", function() {
    useFakeTimers()
    const wrapper = mount(
      <TestApp
        hideIfEmpty
        noAnyItem
        containerProps={{ className: 'crumbs-wrapper' }}
      />
    )
    runAllTimers()
    expect(wrapper.find('.crumbs-wrapper')).to.have.length(0)
    wrapper.unmount()
  })
 
  it("container is visible if no hideIfEmpty", function() {
    useFakeTimers()
    const wrapper = mount(
      <TestApp
        noAnyItem
        containerProps={{ className: 'crumbs-wrapper' }}
      />
    )
    runAllTimers()
    expect(wrapper.find('.crumbs-wrapper')).to.have.length(1)
    wrapper.unmount()
  })
 
it("have dummy components", function() {
    expect(Dummy()).to.be.null
    expect(Item()).to.be.null
  })
})
 
 
} // spec()