Skip to content

label instead of value for summary and summary2 on group #3398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/layout/Checkboxes/MultipleChoiceSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function MultipleChoiceSummary({ targetNode }: IMultipleChoiceSummaryProp
.map((row) => (!relativeSimpleBindingPath ? true : dot.pick(relativeSimpleBindingPath, row)));

const data = dataModelBindings.group
? displayRows
? getCommaSeparatedOptionsToText(displayRows?.join(','), options, langAsString)
: getCommaSeparatedOptionsToText(rawFormData.simpleBinding, options, langAsString);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/layout/Checkboxes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Checkboxes extends CheckboxesDef {
.map((row) => (!relativeSimpleBindingPath ? true : dot.pick(relativeSimpleBindingPath, row)));

const data = dataModelBindings.group
? displayRows
? getCommaSeparatedOptionsToText(displayRows?.join(','), options, langAsString)
: getCommaSeparatedOptionsToText(formData?.simpleBinding, options, langAsString);

return Object.values(data).join(', ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ export const MultipleValueSummary = ({
.map((row) => (!relativeSimpleBindingPath ? true : dot.pick(relativeSimpleBindingPath, row)));

const displayValues = dataModelBindings.group
? displayRows
? Object.values(getCommaSeparatedOptionsToText(displayRows?.join(','), options, langAsString))
: Object.values(getCommaSeparatedOptionsToText(rawFormData.simpleBinding, options, langAsString));

const validations = useUnifiedValidationsForNode(componentNode);
const errors = validationsOfSeverity(validations, 'error');

Expand Down
68 changes: 68 additions & 0 deletions test/e2e/integration/component-library/checkboxes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,51 @@ describe('Checkboxes component', () => {
.find('span.fds-paragraph') // Targets the span with the summary text
.should('have.text', expectedText);
});
it('Renders the summary2 component with correct text for Checkboxes with group, hard deletion and Number', () => {
cy.interceptLayout('ComponentLayouts', (component) => {
if (component.type === 'Checkboxes' && component.id === 'CheckboxesPage-Checkboxes2') {
component.deletionStrategy = 'hard';
component.dataModelBindings.checked = undefined;
component.optionsId = 'personsNumber';
}
});
cy.startAppInstance(appFrontend.apps.componentLibrary, { authenticationLevel: '2' });
cy.gotoNavPage('Avkryssningsbokser');

const checkboxes = '[data-componentid=CheckboxesPage-Checkboxes2]';
const summary2 = '[data-componentid=CheckboxesPage-Header-Summary2-Component2]';

const checkboxText1 = 'Karoline';
const checkboxText2 = 'Kåre';
const checkboxText3 = 'Johanne';
const checkboxText4 = 'Kari';
const checkboxText5 = 'Petter';

//Check options in checkboxes component
cy.get(checkboxes).contains('label', checkboxText1).prev('input[type="checkbox"]').click();
cy.get(checkboxes).contains('label', checkboxText2).prev('input[type="checkbox"]').click();
cy.get(checkboxes).contains('label', checkboxText3).prev('input[type="checkbox"]').click();
cy.get(checkboxes).contains('label', checkboxText4).prev('input[type="checkbox"]').click();
cy.get(checkboxes).contains('label', checkboxText5).prev('input[type="checkbox"]').click();

//Uncheck
cy.get(checkboxes).contains('label', checkboxText4).prev('input[type="checkbox"]').click();
cy.get(checkboxes).contains('label', checkboxText5).prev('input[type="checkbox"]').click();

//Check that checkboxes is correct
cy.get(checkboxes).contains('label', checkboxText1).prev('input[type="checkbox"]').should('be.checked');
cy.get(checkboxes).contains('label', checkboxText2).prev('input[type="checkbox"]').should('be.checked');
cy.get(checkboxes).contains('label', checkboxText3).prev('input[type="checkbox"]').should('be.checked');
cy.get(checkboxes).contains('label', checkboxText4).prev('input[type="checkbox"]').should('not.be.checked');
cy.get(checkboxes).contains('label', checkboxText5).prev('input[type="checkbox"]').should('not.be.checked');

const expectedText = [checkboxText1, checkboxText2, checkboxText3].join(', ');

cy.get(`div${summary2}`)
.next()
.find('span.fds-paragraph') // Targets the span with the summary text
.should('have.text', expectedText);
});

//Required
it('Required validation shows when chekcbox is selected with simpleBinding', () => {
Expand Down Expand Up @@ -395,6 +440,29 @@ describe('Checkboxes component', () => {
const checkboxText1 = 'Karoline';
cy.contains('label', checkboxText1).prev('input[type="checkbox"]').check();

cy.get(checkboxes).contains('span', 'Du må fylle ut hva skal kjøretøyet brukes til?').should('not.exist');
});
it('Required validation shows when chekcbox is selected with group, hard delete and Number', () => {
cy.interceptLayout('ComponentLayouts', (component) => {
if (component.type === 'Checkboxes' && component.id === 'CheckboxesPage-Checkboxes2') {
component.required = true;
component.deletionStrategy = 'hard';
component.dataModelBindings.checked = undefined;
component.optionsId = 'personsNumber';
}
});
cy.startAppInstance(appFrontend.apps.componentLibrary, { authenticationLevel: '2' });
cy.gotoNavPage('Oppsummering 2.0');
cy.findByRole('button', { name: 'Send inn' }).click();
cy.gotoNavPage('Avkryssningsbokser');

const checkboxes = '[data-componentid=CheckboxesPage-Checkboxes2]';

cy.get(checkboxes).contains('span', 'Du må fylle ut hva skal kjøretøyet brukes til?').should('exist');

const checkboxText1 = 'Karoline';
cy.contains('label', checkboxText1).prev('input[type="checkbox"]').check();

cy.get(checkboxes).contains('span', 'Du må fylle ut hva skal kjøretøyet brukes til?').should('not.exist');
});
});