-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7357 from uktrade/fix/export-win-no-contact
Fix a bug when export wins dashboard crashed when there were no company_contacts
- Loading branch information
Showing
5 changed files
with
50 additions
and
13 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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react' | ||
import Link from '@govuk-react/link' | ||
|
||
import urls from '../../../../lib/urls' | ||
|
||
const ContactLink = ({ name, id }) => ( | ||
<Link href={urls.contacts.details(id)}>{name}</Link> | ||
) | ||
|
||
const Contact = ({ | ||
win: { company_contacts: [contact] = [], customer_name }, | ||
}) => (contact ? <ContactLink {...contact} /> : customer_name || 'Not set') | ||
|
||
export default Contact |
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
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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react' | ||
|
||
import Contact from '../../../../../src/client/modules/ExportWins/Status/Contact' | ||
|
||
describe('Contact', () => { | ||
;['John Doe', 'Andy Pipkin', 'Lou Todd'].forEach((name) => { | ||
it('should render a link to ${name} if company_contacts is not empty', () => { | ||
const id = `id-of-${name}` | ||
|
||
cy.mount(<Contact win={{ company_contacts: [{ name, id }] }} />) | ||
|
||
cy.get('a') | ||
.should('have.text', name) | ||
.and('have.attr', 'href', `/contacts/${id}/details`) | ||
}) | ||
|
||
it('should render customer_name if company_contacts empty', () => { | ||
cy.mount(<Contact win={{ customer_name: name }} />) | ||
|
||
cy.get('a').should('not.exist') | ||
cy.contains(RegExp(`^${name}$`)) | ||
}) | ||
}) | ||
|
||
it("should render 'Not set' by default", () => { | ||
cy.mount(<Contact win={{}} />) | ||
|
||
cy.get('a').should('not.exist') | ||
cy.contains(RegExp(`^Not set$`)) | ||
}) | ||
}) |