Skip to content

Commit

Permalink
#24 pageContent component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paleika committed Jan 14, 2021
1 parent 65c64f7 commit bf99686
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/components/equipment-table/equipment-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ const EquipmentRow = (props) => {
}

return (
<div className="flex-row" key={id}>
<div className="flex-row" key={id} data-test="equipment-row-component">
<div className="flex-cell first">
{name}
</div>
<div className="flex-cell">{costInGp} gp</div>
<div className="flex-cell fixed-width basis-3 text-center">{weightValue}</div>
<div className="flex-cell fixed-width basis-1">
<button className="link-button" onClick={() => onEdit(id)} >
<button className="link-button" onClick={() => onEdit(id)} data-test="edit-button">
<i className="push-shadow text-primary fas fa-edit"></i>
</button>
</div>
<div className="flex-cell fixed-width basis-1">
<button className="link-button" onClick={() => onRemove(id)} >
<button className="link-button" onClick={() => onRemove(id)} data-test="remove-button">
<i className="push-shadow text-danger fas fa-trash"></i>
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/page-content/page-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const PageContent = ({ editingItem, setEditingItem, itemAddToList, itemEditData
case 'mainView':
default:
content = (
<div className="card-body">
<div className="card-body" data-test="main-page">
<ControlsPanel onAdding={onAdding} />
{/* <MoneyTable /> */}
<EquipmentTable onEditing={(id) => onEditing(id)} />
Expand Down
98 changes: 98 additions & 0 deletions src/components/page-content/page-content.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import React from 'react'
import { shallow, mount } from 'enzyme'
import { storeFactory } from '../../utils/test-utils'
import { Provider } from 'react-redux'

import PageContent from './page-content'

const shallowSetup = (initialState = {}) => {
const store = storeFactory(initialState)
return shallow(<PageContent store={store} />).dive()
}

const mountSetup = (initialState = {}) => {
const store = storeFactory(initialState)
return mount(<Provider store={store} ><PageContent /></Provider>)
}

describe('rendering testing', () => {
describe('renders correct elements depending on view', () => {
let wrapper

test('renders main view on app mount', () => {
wrapper = shallowSetup().dive()
const mainViewContent = wrapper.find('[data-test="main-page"]')
expect(mainViewContent.length).toBe(1)
})

test('renders form to add item for addingView', () => {
wrapper = mountSetup()
const addItemButton = wrapper.find('[data-test="add-button"]')
addItemButton.simulate('click')
const addItemInput = wrapper.find('input[name="name"]')
expect(addItemInput.prop('value')).toBe('')
})

test('renders form to add item for addingView', () => {
const initialState = {
main: {
equipment: {
editingItem: 0,
weightUnits: {
bulksWeight: 1,
lightCount: 0,
negligibleCount: 0
},
data: [{
id: 0,
name: 'The thing',
amount: 1,
slot: 'slotless',
costInGp: 0.2,
weight: 1,
weightRadio: 'bulk',
description: ''
}]
}
}
}
wrapper = mountSetup(initialState)
const editItemButton = wrapper.find('[data-test="equipment-row-component"] button[data-test="edit-button"]')
editItemButton.simulate('click')
const editItemInput = wrapper.find('input[name="name"]')
expect(editItemInput.prop('value')).toBe(initialState.main.equipment.data[0].name)
})
})
})

describe('redux props testing', () => {
let wrapper

beforeEach(() => {
wrapper = shallowSetup()
})

test('has editingItems prop', () => {
const initialState = {
main: {
equipment: {
editingItem: 0
}
}
}
wrapper = shallowSetup(initialState)
expect(wrapper.prop('editingItem')).toBe(initialState.main.equipment.editingItem)
})

test('has itemAddToList prop', () => {
expect(wrapper.prop('itemAddToList')).toBeInstanceOf(Function)
})

test('has itemEditData prop', () => {
expect(wrapper.prop('itemEditData')).toBeInstanceOf(Function)
})

test('has setEditingItem prop', () => {
expect(wrapper.prop('setEditingItem')).toBeInstanceOf(Function)
})
})

0 comments on commit bf99686

Please sign in to comment.