This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
generated from rsksmart/react-app-rif-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix existing (delete) test that now found two buttons - Write test for upgrade state changes - Add missing reducer tests for types/payloads
- Loading branch information
1 parent
953b277
commit 7d46c06
Showing
2 changed files
with
60 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import React from 'react' | ||
import { shallow, mount } from 'enzyme' | ||
import { act } from 'react-dom/test-utils' | ||
import DeclarativeDetailsDisplay from './DeclarativeDetailsDisplay' | ||
import { DataVaultKey } from '../../state/reducers/datavault' | ||
|
||
|
@@ -9,13 +10,18 @@ describe('Component: DeclarativeDetailsDisplay', () => { | |
NAME: [{ id: '5', content: 'Jesse Clark' }] | ||
} | ||
|
||
const mockedAttributes = { | ||
deleteValue: jest.fn(), | ||
swapValue: jest.fn() | ||
} | ||
|
||
it('renders the component', () => { | ||
const wrapper = shallow(<DeclarativeDetailsDisplay details={mockDeclarativeDetials} deleteValue={jest.fn()} />) | ||
const wrapper = shallow(<DeclarativeDetailsDisplay details={mockDeclarativeDetials} {...mockedAttributes} />) | ||
expect(wrapper).toBeDefined() | ||
}) | ||
|
||
it('shows the content in a row', () => { | ||
const wrapper = shallow(<DeclarativeDetailsDisplay details={mockDeclarativeDetials} deleteValue={jest.fn()} />) | ||
const wrapper = shallow(<DeclarativeDetailsDisplay details={mockDeclarativeDetials} {...mockedAttributes} />) | ||
expect(wrapper.find('tbody').children()).toHaveLength(2) | ||
|
||
expect(wrapper.find('tr').at(1).find('td').at(0).text()).toBe('EMAIL') | ||
|
@@ -28,16 +34,46 @@ describe('Component: DeclarativeDetailsDisplay', () => { | |
NAME: [] | ||
} | ||
|
||
const wrapper = shallow(<DeclarativeDetailsDisplay details={mockDetails} deleteValue={jest.fn()} />) | ||
const wrapper = shallow(<DeclarativeDetailsDisplay details={mockDetails} {...mockedAttributes} />) | ||
expect(wrapper.find('tbody').children()).toHaveLength(1) | ||
}) | ||
|
||
it('handles delete click', () => { | ||
const deleteValue = jest.fn() | ||
const wrapper = mount(<DeclarativeDetailsDisplay details={mockDeclarativeDetials} deleteValue={deleteValue} />) | ||
it('handles delete click', async () => { | ||
const deleteFunction = jest.fn() | ||
const deleteValue = (key: string, id: string) => new Promise((resolve) => resolve(deleteFunction(key, id))) | ||
const wrapper = mount(<DeclarativeDetailsDisplay details={mockDeclarativeDetials} deleteValue={deleteValue} swapValue={jest.fn()} />) | ||
|
||
wrapper.find('.content-row').at(0).find('button.delete').simulate('click') | ||
|
||
await act(async () => { | ||
await wrapper.find('.delete-modal').find('.column').at(1).find('button').simulate('click') | ||
|
||
expect(deleteFunction).toBeCalledTimes(1) | ||
expect(deleteFunction).toBeCalledWith('EMAIL', '1') | ||
}) | ||
}) | ||
|
||
it('handles swap click', async () => { | ||
const editFunction = jest.fn() | ||
const swapValue = (key:string, content: string, id: string) => new Promise((resolve) => resolve(editFunction(key, content, id))) | ||
const wrapper = mount(<DeclarativeDetailsDisplay details={mockDeclarativeDetials} deleteValue={jest.fn()} swapValue={swapValue} />) | ||
|
||
wrapper.find('.content-row').at(0).find('button.edit').simulate('click') | ||
expect(wrapper.find('textarea').props().value).toBe('[email protected]') | ||
|
||
await act(async () => { | ||
await wrapper.find('.edit-modal').find('button.submit').simulate('click') | ||
wrapper.update() | ||
expect(wrapper.find('.modal-content').find('div.alert.error').text()).toBe('New value is the same as the old.') | ||
|
||
wrapper.find('textarea.line').simulate('change', { target: { value: '[email protected]' } }) | ||
expect(wrapper.find('textarea').props().value).toBe('[email protected]') | ||
|
||
await wrapper.find('.edit-modal').find('button.submit').simulate('click') | ||
wrapper.update() | ||
|
||
wrapper.find('.content-row').at(0).find('button').simulate('click') | ||
wrapper.find('.delete-modal').find('.column').at(1).find('button').simulate('click') | ||
expect(deleteValue).toBeCalledWith('EMAIL', '1') | ||
expect(editFunction).toBeCalledTimes(1) | ||
expect(editFunction).toBeCalledWith('EMAIL', '[email protected]', '1') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters