Skip to content
This repository has been archived by the owner on Dec 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #153 from uktrade/fix/cannot-find-false
Browse files Browse the repository at this point in the history
fix: Reset cannotFind when selecting entity
  • Loading branch information
yeahfro authored Sep 12, 2019
2 parents 6a1fdb8 + 8c3d2f3 commit 46ddff0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/forms/elements/FieldDnbCompany.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const FieldDnbCompany = ({
}}
onEntityClick={(entity) => {
if (!entity.datahub_company) {
setFieldValue('cannotFind', false)
setFieldValue(name, entity.dnb_company)
goForward()
}
Expand Down
32 changes: 31 additions & 1 deletion src/forms/elements/__tests__/FieldDnbCompany.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import { mount } from 'enzyme'
import { act } from 'react-dom/test-utils'

import ButtonLink from '../../../button-link/ButtonLink'
import CannotFindDetails from '../../../entity-search/CannotFindDetails'
import EntityList from '../../../entity-search/EntityList'
import EntityListItem from '../../../entity-search/EntityListItem'
Expand Down Expand Up @@ -161,12 +162,41 @@ describe('FieldDnbCompany', () => {
wrapper.find('[href="#cannot-find"]').at(1).simulate('click')
})

test('should set the field cannot find', () => {
test('should set the field cannot find to "true"', () => {
expect(wrapper.find('.field-cannot-find').text()).toEqual('true')
})

test('should go to the fourth step', () => {
expect(wrapper.find(Step).at(2).text()).toContain('fourth')
})

describe('when the "Back" button is clicked and a company is selected', () => {
beforeAll(async () => {
wrapper.find(ButtonLink).simulate('click')

wrapper.update()

wrapper.find('Search').simulate('click')

await act(flushPromises)

wrapper.update()

wrapper.find(EntityListItem).at(1).simulate('click')
})

test('should set the field cannot find to "false"', () => {
expect(wrapper.find('.field-cannot-find').text()).toEqual('false')
})

test('should go to the fourth step', () => {
expect(wrapper.find(Step).at(2).text()).toContain('third')
})

test('should set the field value', () => {
const expected = JSON.stringify(entitySearchFixtures.companySearch.results[1].dnb_company)
expect(wrapper.find('.field-value').text()).toEqual(expected)
})
})
})
})

0 comments on commit 46ddff0

Please sign in to comment.