import React from
'react'
import {shallow} from
'enzyme'
import PriceList from
'../PriceList'
import {items,categories} from
'../../containers/Home'
import Ionicon from
'react-ionicons'
const itemsWidthCategory = items.map(item => {
item.category = categories[item.cid]
return
item
})
const props = {
items:itemsWidthCategory,
onModifyItem:jest.fn(),
onDeleteItem:jest.fn()
}
describe(
'test PriceList component '
, () => {
let wrapper
beforeEach(()=>{
wrapper = shallow(<PriceList {...props} />)
})
it(
'should render the component to match snapshot'
,()=>{
expect(wrapper).toMatchSnapshot()
})
it(
'should render correct price items length'
,()=>{
expect(wrapper.find(
'.list-group-item'
).length).toEqual(itemsWidthCategory.length)
})
it(
'should render correct icon and price for each item'
,()=>{
const iconLists = wrapper.find(
'.list-group-item'
).first().find(Ionicon)
expect(iconLists.length).toEqual(3)
expect(iconLists.first().props().icon).toEqual(itemsWidthCategory[0].category.iconName)
})
it(
'should trigger the correct function callbacks'
,()=>{
const firstItem = wrapper.find(
'.list-group-item'
).first()
firstItem.find(
'.modify'
).simulate(
'click'
)
expect(props.onModifyItem).toHaveBeenCalledWith(itemsWidthCategory[0])
firstItem.find(
'.delete'
).simulate(
'click'
)
expect(props.onDeleteItem).toHaveBeenCalledWidth()
})
});