Skip to content

Commit

Permalink
CLS2-1015: Conditionally hide/show "Add Investment Project" button fr…
Browse files Browse the repository at this point in the history
…om EYB Lead (#7276)

* remove investment project button from eyb lead

* Remove button if investment_projects are returned by the API

* Test the button not being shown

* Update to fakers and tests

Co-authored-by: Santosh Dasari <santosh.dasari@digita.trade.gov.uk>

---------

Co-authored-by: Samuele Mattiuzzo <1381563+samuele-mattiuzzo@users.noreply.github.com>
Co-authored-by: Santosh Dasari <santosh.dasari@digita.trade.gov.uk>
  • Loading branch information
3 people authored Oct 31, 2024
1 parent fa64217 commit bf343ce
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/client/components/Layout/EYBLeadLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,24 @@ const EYBLeadLayout = ({ id, children }) => {
</GridCol>
<GridCol setWith="one-third">
<StyledButtonContainer>
{eybLead.company && (
<Button
as={StyledButtonLink}
data-test="button-add-investment-project"
href={
!eybLead.company
? `/investments/projects/create`
: eybLead.company.archived ||
eybLead.company.ukBased
? null
: `/investments/projects/create/${eybLead.company.id}?eyb-lead-id=${eybLead.id}`
}
aria-label={`Add investment project`}
>
Add investment project
</Button>
)}
{eybLead.company &&
!eybLead.investmentProjects?.length && (
<Button
as={StyledButtonLink}
data-test="button-add-investment-project"
href={
!eybLead.company
? `/investments/projects/create`
: eybLead.company.archived ||
eybLead.company.ukBased
? null
: `/investments/projects/create/${eybLead.company.id}?eyb-lead-id=${eybLead.id}`
}
aria-label={`Add investment project`}
>
Add investment project
</Button>
)}
</StyledButtonContainer>
</GridCol>
</GridRow>
Expand Down
5 changes: 5 additions & 0 deletions test/functional/cypress/fakers/eyb-leads.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ const eybLeadFaker = (overrides = {}) => ({
area: ALBERTA,
country: CANADA,
},
investment_projects: [
{
id: faker.string.uuid(),
},
],
...overrides,
})

Expand Down
32 changes: 32 additions & 0 deletions test/functional/cypress/specs/investments/eyb-lead-details-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('EYB lead details', () => {
telephone_number: '01234567890',
landing_timeframe: 'In the next 6 months',
company_website: 'fake.website.com',
investment_projects: [],
})
beforeEach(() => {
setup(eybLeadWithValues)
Expand Down Expand Up @@ -208,4 +209,35 @@ describe('EYB lead details', () => {
cy.get('[data-test="button-add-investment-project"]').should('not.exist')
})
})
context(
'When viewing an EYB lead with company and investment projects associated',
() => {
const eybLeadWithCompanyAndInvestmentProjects = eybLeadFaker({
company: {
name: 'Mars',
id: 'fc752802-e454-4c7c-bbfd-4bdd84759b84',
},
investment_projects: [
{
id: 'fc752802-e454-4c7c-bbfd-4bdd84759b84',
},
],
})
beforeEach(() => {
setup(eybLeadWithCompanyAndInvestmentProjects)
cy.visit(
investments.eybLeads.details(
eybLeadWithCompanyAndInvestmentProjects.id
)
)
cy.wait('@getEYBLeadDetails')
})

it('should not render the `Add investment project` button', () => {
cy.get('[data-test="button-add-investment-project"]').should(
'not.exist'
)
})
}
)
})

0 comments on commit bf343ce

Please sign in to comment.