Skip to content

Commit 8ef01bc

Browse files
authored
When using group functionality using label instead of value for summary and summary2 (#3398)
1 parent a0936db commit 8ef01bc

File tree

4 files changed

+71
-4
lines changed

4 files changed

+71
-4
lines changed

src/layout/Checkboxes/MultipleChoiceSummary.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function MultipleChoiceSummary({ targetNode }: IMultipleChoiceSummaryProp
3838
.map((row) => (!relativeSimpleBindingPath ? true : dot.pick(relativeSimpleBindingPath, row)));
3939

4040
const data = dataModelBindings.group
41-
? displayRows
41+
? getCommaSeparatedOptionsToText(displayRows?.join(','), options, langAsString)
4242
: getCommaSeparatedOptionsToText(rawFormData.simpleBinding, options, langAsString);
4343

4444
return (

src/layout/Checkboxes/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class Checkboxes extends CheckboxesDef {
6161
.map((row) => (!relativeSimpleBindingPath ? true : dot.pick(relativeSimpleBindingPath, row)));
6262

6363
const data = dataModelBindings.group
64-
? displayRows
64+
? getCommaSeparatedOptionsToText(displayRows?.join(','), options, langAsString)
6565
: getCommaSeparatedOptionsToText(formData?.simpleBinding, options, langAsString);
6666

6767
return Object.values(data).join(', ');

src/layout/Summary2/CommonSummaryComponents/MultipleValueSummary.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ export const MultipleValueSummary = ({
6969
.map((row) => (!relativeSimpleBindingPath ? true : dot.pick(relativeSimpleBindingPath, row)));
7070

7171
const displayValues = dataModelBindings.group
72-
? displayRows
72+
? Object.values(getCommaSeparatedOptionsToText(displayRows?.join(','), options, langAsString))
7373
: Object.values(getCommaSeparatedOptionsToText(rawFormData.simpleBinding, options, langAsString));
74-
7574
const validations = useUnifiedValidationsForNode(componentNode);
7675
const errors = validationsOfSeverity(validations, 'error');
7776

test/e2e/integration/component-library/checkboxes.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,51 @@ describe('Checkboxes component', () => {
333333
.find('span.fds-paragraph') // Targets the span with the summary text
334334
.should('have.text', expectedText);
335335
});
336+
it('Renders the summary2 component with correct text for Checkboxes with group, hard deletion and Number', () => {
337+
cy.interceptLayout('ComponentLayouts', (component) => {
338+
if (component.type === 'Checkboxes' && component.id === 'CheckboxesPage-Checkboxes2') {
339+
component.deletionStrategy = 'hard';
340+
component.dataModelBindings.checked = undefined;
341+
component.optionsId = 'personsNumber';
342+
}
343+
});
344+
cy.startAppInstance(appFrontend.apps.componentLibrary, { authenticationLevel: '2' });
345+
cy.gotoNavPage('Avkryssningsbokser');
346+
347+
const checkboxes = '[data-componentid=CheckboxesPage-Checkboxes2]';
348+
const summary2 = '[data-componentid=CheckboxesPage-Header-Summary2-Component2]';
349+
350+
const checkboxText1 = 'Karoline';
351+
const checkboxText2 = 'Kåre';
352+
const checkboxText3 = 'Johanne';
353+
const checkboxText4 = 'Kari';
354+
const checkboxText5 = 'Petter';
355+
356+
//Check options in checkboxes component
357+
cy.get(checkboxes).contains('label', checkboxText1).prev('input[type="checkbox"]').click();
358+
cy.get(checkboxes).contains('label', checkboxText2).prev('input[type="checkbox"]').click();
359+
cy.get(checkboxes).contains('label', checkboxText3).prev('input[type="checkbox"]').click();
360+
cy.get(checkboxes).contains('label', checkboxText4).prev('input[type="checkbox"]').click();
361+
cy.get(checkboxes).contains('label', checkboxText5).prev('input[type="checkbox"]').click();
362+
363+
//Uncheck
364+
cy.get(checkboxes).contains('label', checkboxText4).prev('input[type="checkbox"]').click();
365+
cy.get(checkboxes).contains('label', checkboxText5).prev('input[type="checkbox"]').click();
366+
367+
//Check that checkboxes is correct
368+
cy.get(checkboxes).contains('label', checkboxText1).prev('input[type="checkbox"]').should('be.checked');
369+
cy.get(checkboxes).contains('label', checkboxText2).prev('input[type="checkbox"]').should('be.checked');
370+
cy.get(checkboxes).contains('label', checkboxText3).prev('input[type="checkbox"]').should('be.checked');
371+
cy.get(checkboxes).contains('label', checkboxText4).prev('input[type="checkbox"]').should('not.be.checked');
372+
cy.get(checkboxes).contains('label', checkboxText5).prev('input[type="checkbox"]').should('not.be.checked');
373+
374+
const expectedText = [checkboxText1, checkboxText2, checkboxText3].join(', ');
375+
376+
cy.get(`div${summary2}`)
377+
.next()
378+
.find('span.fds-paragraph') // Targets the span with the summary text
379+
.should('have.text', expectedText);
380+
});
336381

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

443+
cy.get(checkboxes).contains('span', 'Du må fylle ut hva skal kjøretøyet brukes til?').should('not.exist');
444+
});
445+
it('Required validation shows when chekcbox is selected with group, hard delete and Number', () => {
446+
cy.interceptLayout('ComponentLayouts', (component) => {
447+
if (component.type === 'Checkboxes' && component.id === 'CheckboxesPage-Checkboxes2') {
448+
component.required = true;
449+
component.deletionStrategy = 'hard';
450+
component.dataModelBindings.checked = undefined;
451+
component.optionsId = 'personsNumber';
452+
}
453+
});
454+
cy.startAppInstance(appFrontend.apps.componentLibrary, { authenticationLevel: '2' });
455+
cy.gotoNavPage('Oppsummering 2.0');
456+
cy.findByRole('button', { name: 'Send inn' }).click();
457+
cy.gotoNavPage('Avkryssningsbokser');
458+
459+
const checkboxes = '[data-componentid=CheckboxesPage-Checkboxes2]';
460+
461+
cy.get(checkboxes).contains('span', 'Du må fylle ut hva skal kjøretøyet brukes til?').should('exist');
462+
463+
const checkboxText1 = 'Karoline';
464+
cy.contains('label', checkboxText1).prev('input[type="checkbox"]').check();
465+
398466
cy.get(checkboxes).contains('span', 'Du må fylle ut hva skal kjøretøyet brukes til?').should('not.exist');
399467
});
400468
});

0 commit comments

Comments
 (0)