From 9b9c517ee82f47343319aadd0898589559e3d38e Mon Sep 17 00:00:00 2001 From: Anders Date: Tue, 5 Nov 2024 16:02:59 +0100 Subject: [PATCH] feat(ChildrenWithAge): add maximum possible value to joint-responsibility & daycare (#4219) --- .../src/components/icon/style/dnb-icon.scss | 2 +- .../ChildrenWithAge/ChildrenWithAge.tsx | 2 + .../__tests__/ChildrenWithAge.test.tsx | 49 +++++++++++++++++++ .../ChildrenWithAge.test.tsx.snap | 10 ++-- 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/packages/dnb-eufemia/src/components/icon/style/dnb-icon.scss b/packages/dnb-eufemia/src/components/icon/style/dnb-icon.scss index df7e26261ed..ce6f11fbeb2 100644 --- a/packages/dnb-eufemia/src/components/icon/style/dnb-icon.scss +++ b/packages/dnb-eufemia/src/components/icon/style/dnb-icon.scss @@ -8,7 +8,7 @@ .dnb-icon { display: inline-block; - // sine we use vertical-align: top on the SVG + // since we use vertical-align: top on the SVG // we have to move center the alignment here again // else basic text afterwards will get aligned on top vertical-align: middle; diff --git a/packages/dnb-eufemia/src/extensions/forms/blocks/ChildrenWithAge/ChildrenWithAge.tsx b/packages/dnb-eufemia/src/extensions/forms/blocks/ChildrenWithAge/ChildrenWithAge.tsx index 134c964f690..4182a009ee2 100644 --- a/packages/dnb-eufemia/src/extensions/forms/blocks/ChildrenWithAge/ChildrenWithAge.tsx +++ b/packages/dnb-eufemia/src/extensions/forms/blocks/ChildrenWithAge/ChildrenWithAge.tsx @@ -141,6 +141,7 @@ function EditContainer({ tr.ChildrenWithAge.dayCareExpenses.required, }} minimum={1} + maximum={1000000} decimalLimit={0} allowNegative={false} /> @@ -174,6 +175,7 @@ function EditContainer({ tr.ChildrenWithAge.jointResponsibilityExpenses.required, }} minimum={1} + maximum={1000000} decimalLimit={0} allowNegative={false} /> diff --git a/packages/dnb-eufemia/src/extensions/forms/blocks/ChildrenWithAge/__tests__/ChildrenWithAge.test.tsx b/packages/dnb-eufemia/src/extensions/forms/blocks/ChildrenWithAge/__tests__/ChildrenWithAge.test.tsx index b360f7871d2..6b2f4e52755 100644 --- a/packages/dnb-eufemia/src/extensions/forms/blocks/ChildrenWithAge/__tests__/ChildrenWithAge.test.tsx +++ b/packages/dnb-eufemia/src/extensions/forms/blocks/ChildrenWithAge/__tests__/ChildrenWithAge.test.tsx @@ -184,6 +184,55 @@ describe('ChildrenWithAge', () => { expect(screen.queryByRole('alert')).not.toBeInTheDocument() }) + it('should not accept values over 1000000 as joint-responsibility expense', async () => { + render( + + ) + + await userEvent.click(document.querySelectorAll('button')[0]) + await userEvent.click(document.querySelectorAll('button')[4]) + await userEvent.type(document.querySelectorAll('input')[2], '10000001') + + const input = document.querySelectorAll('.dnb-input__input')[2] + + fireEvent.blur(input) + + expect(screen.getByRole('alert')).toHaveTextContent( + nbNO['nb-NO'].NumberField.errorMaximum.replace( + '{maximum}', + '1000000' + ) + ) + }) + + it('should not accept values over 1000000 as daycare expense', async () => { + render() + + await userEvent.click(document.querySelectorAll('button')[0]) + await userEvent.click(document.querySelectorAll('button')[5]) + await userEvent.type(document.querySelectorAll('input')[2], '10000001') + + const input = document.querySelectorAll('.dnb-input__input')[2] + + fireEvent.blur(input) + + expect(screen.getByRole('alert')).toHaveTextContent( + nbNO['nb-NO'].NumberField.errorMaximum.replace( + '{maximum}', + '1000000' + ) + ) + + expect(screen.getByRole('alert')).toHaveTextContent( + nbNO['nb-NO'].NumberField.errorMaximum.replace( + '{maximum}', + '1000000' + ) + ) + }) + it('should show summary with Nei when hasChildren changes to false', async () => { render( diff --git a/packages/dnb-eufemia/src/extensions/forms/blocks/ChildrenWithAge/__tests__/__snapshots__/ChildrenWithAge.test.tsx.snap b/packages/dnb-eufemia/src/extensions/forms/blocks/ChildrenWithAge/__tests__/__snapshots__/ChildrenWithAge.test.tsx.snap index 92c012ab23a..e8a459ad2a5 100644 --- a/packages/dnb-eufemia/src/extensions/forms/blocks/ChildrenWithAge/__tests__/__snapshots__/ChildrenWithAge.test.tsx.snap +++ b/packages/dnb-eufemia/src/extensions/forms/blocks/ChildrenWithAge/__tests__/__snapshots__/ChildrenWithAge.test.tsx.snap @@ -15,9 +15,9 @@ exports[`ChildrenWithAge should match snapshot 1`] = ` aria-placeholder="0" aria-required="true" class="dnb-input__input" - id="id-rbq" + id="id-rdu" inputmode="numeric" - name="id-rbq" + name="id-rdu" type="text" />, }, @@ -125,9 +125,9 @@ exports[`ChildrenWithAge should match snapshot 1`] = ` aria-placeholder="0" aria-required="true" class="dnb-input__input" - id="id-rbv" + id="id-re3" inputmode="numeric" - name="id-rbv" + name="id-re3" type="text" />, }, @@ -331,7 +331,7 @@ exports[`ChildrenWithAge should match snapshot 1`] = ` aria-valuenow="2" aria-valuetext="2" class="dnb-input__input" - id="id-rbg" + id="id-rdk" inputmode="numeric" name="countChildren" role="spinbutton"