From bf996861e9c215b8cd02fb49dc5321d6435eeaf4 Mon Sep 17 00:00:00 2001 From: Nadzeya Ivashchanka Date: Thu, 14 Jan 2021 17:04:03 +0300 Subject: [PATCH] #24 pageContent component tests --- .../equipment-table/equipment-row.js | 6 +- src/components/page-content/page-content.js | 2 +- .../page-content/page-content.test.js | 98 +++++++++++++++++++ 3 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 src/components/page-content/page-content.test.js diff --git a/src/components/equipment-table/equipment-row.js b/src/components/equipment-table/equipment-row.js index fb86061..35b7602 100644 --- a/src/components/equipment-table/equipment-row.js +++ b/src/components/equipment-table/equipment-row.js @@ -18,19 +18,19 @@ const EquipmentRow = (props) => { } return ( -
+
{name}
{costInGp} gp
{weightValue}
-
-
diff --git a/src/components/page-content/page-content.js b/src/components/page-content/page-content.js index ba34f51..6aa2e73 100644 --- a/src/components/page-content/page-content.js +++ b/src/components/page-content/page-content.js @@ -53,7 +53,7 @@ const PageContent = ({ editingItem, setEditingItem, itemAddToList, itemEditData case 'mainView': default: content = ( -
+
{/* */} onEditing(id)} /> diff --git a/src/components/page-content/page-content.test.js b/src/components/page-content/page-content.test.js new file mode 100644 index 0000000..66ff7e1 --- /dev/null +++ b/src/components/page-content/page-content.test.js @@ -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().dive() +} + +const mountSetup = (initialState = {}) => { + const store = storeFactory(initialState) + return mount() +} + +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) + }) +})