Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into migration-deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Action authored and GitHub Action committed May 16, 2024
2 parents 2a6c3ae + c93d9a8 commit a988ea8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const FieldCheckboxes = ({
value: optionValue,
label: optionLabel,
children,
link: optionLink,
...optionProps
},
index
Expand All @@ -116,7 +117,12 @@ const FieldCheckboxes = ({
{boldLabel ? (
<StyledLabel>{optionLabel}</StyledLabel>
) : (
optionLabel
<Fragment key={optionLabel}>
{optionLabel}
{optionLink && (
<Fragment key={optionLink}>{optionLink}</Fragment>
)}
</Fragment>
)}
</Checkbox>
{value.includes(optionValue) && !!children ? children : null}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import React from 'react'
import { H1 } from '@govuk-react/heading'
import { Details, ListItem, UnorderedList } from 'govuk-react'
import styled from 'styled-components'

import FieldCheckboxes from '../FieldCheckboxes'
import Form from '../../../Form'

const StyledDetails = styled(Details)({
margin: 0,
})

const options = [
{
label: 'Italy',
Expand Down Expand Up @@ -134,6 +140,26 @@ export const CheckboxesExclusive = () => (
label: 'No, I will not be travelling to any of these countries',
value: 'no',
},
{
label: 'Yes, I will travelling to any of these countries',
value: 'yes',
link: (
<StyledDetails
summary="Is included a territorial independent countries?"
data-test="some-list-of-territorial-countries"
>
<p>List of territorial countries:</p>
<UnorderedList listStyleType="bullet">
<ListItem>French Guiana</ListItem>
<ListItem>Madeira and Azores</ListItem>
<ListItem>
Balearic Islands(Ibiza, Formentera, Mallorca and Canary
Islands)
</ListItem>
</UnorderedList>
</StyledDetails>
),
},
]}
/>
<pre>{JSON.stringify(form, null, 2)}</pre>
Expand Down
25 changes: 24 additions & 1 deletion test/functional/cypress/specs/export-win/win-details-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('Win details', () => {
})
})

it('should render Type of win ', () => {
it('should render Type of win checkbox options', () => {
assertFieldCheckboxes({
element: winDetails.winType,
legend: 'Type of win',
Expand All @@ -132,6 +132,29 @@ describe('Win details', () => {
})
})

it('should render Type of win detailed summary name', () => {
assertFieldCheckboxes({
element: winDetails.winType,
legend: 'Type of win',
options: [
{
label: 'Export',
checked: false,
},
{
label: 'Business success',
checked: false,
link: 'What is business success?',
},
{
label: 'Outward Direct Investment (ODI)',
checked: false,
link: 'What is an ODI?',
},
],
})
})

it('should render the Breakdowns component for each win type', () => {
cy.get(winDetails.winType).as('winType')

Expand Down
8 changes: 6 additions & 2 deletions test/functional/cypress/support/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,14 @@ const assertFieldCheckboxes = ({ element, legend, hint, options = [] }) => {
.each((label, index) => {
// Each label wraps an input
cy.get(label)
.should('have.text', options[index].label)
.should('contain', options[index].label)
.find('input[type="checkbox"]')
.should(options[index].checked ? 'be.checked' : 'not.be.checked')
.should('have.attr', 'aria-label', options[index].label)
.should(options[index].checked ? 'be.checked' : 'not.be.checked')

const link = options[index].link
// Optional options field parameter
link && cy.get(label).find('summary').should('contain', link)
})
}

Expand Down

0 comments on commit a988ea8

Please sign in to comment.