Skip to content

Commit

Permalink
feat(parental-leave): Allow specific number of days from actual birth…
Browse files Browse the repository at this point in the history
… date (#17010)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
veronikasif and kodiakhq[bot] authored Nov 25, 2024
1 parent 49cd9ac commit 0e418d4
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,95 @@ describe('ParentalLeaveService', () => {
},
])
})
it('Should return date_of_birth_months if actualDateOfBirth, useLength is NO and endDateAdjustLength includes YES', async () => {
const application = createApplication()

set(application, 'answers.periods', [
{
ratio: '100',
endDate: '2025-07-16',
startDate: '2025-07-02',
useLength: 'no',
firstPeriodStart: 'actualDateOfBirth',
endDateAdjustLength: ['yes'],
},
{
ratio: '100',
endDate: '2025-07-31',
startDate: '2025-07-17',
useLength: 'no',
firstPeriodStart: 'specificDate',
},
])
const periods = get(application.answers, 'periods') as object as Period[]
const rights = 'M-S-GR,ORLOF-FBF'

const res = parentalLeaveService.createPeriodsDTO(periods, true, rights)

expect(res).toEqual([
{
from: 'date_of_birth_months',
to: '2025-07-16',
ratio: 'D15',
approved: false,
paid: false,
rightsCodePeriod: rights,
},
{
from: '2025-07-17',
to: '2025-07-31',
ratio: 'D14',
approved: false,
paid: false,
rightsCodePeriod: rights,
},
])
})

it('Should return date_of_birth if actualDateOfBirth, useLength is NO and endDateAdjustLength does not include YES', async () => {
const application = createApplication()

set(application, 'answers.periods', [
{
ratio: '100',
endDate: '2025-07-16',
startDate: '2025-07-02',
useLength: 'no',
firstPeriodStart: 'actualDateOfBirth',
endDateAdjustLength: [],
},
{
ratio: '100',
endDate: '2025-07-31',
startDate: '2025-07-17',
useLength: 'no',
firstPeriodStart: 'specificDate',
},
])
const periods = get(application.answers, 'periods') as object as Period[]
const rights = 'M-S-GR,ORLOF-FBF'

const res = parentalLeaveService.createPeriodsDTO(periods, true, rights)

expect(res).toEqual([
{
from: 'date_of_birth',
to: '2025-07-16',
ratio: 'D15',
approved: false,
paid: false,
rightsCodePeriod: rights,
},
{
from: '2025-07-17',
to: '2025-07-31',
ratio: 'D14',
approved: false,
paid: false,
rightsCodePeriod: rights,
},
])
})
})

describe('createRightsDTO', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ export class ParentalLeaveService extends BaseTemplateApiService {
isFirstPeriod,
isActualDateOfBirth,
period.useLength || '',
period.endDateAdjustLength?.includes(YES) || false,
period,
),
to: period.endDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,12 @@ export const getFromDate = (
isFirstPeriod: boolean,
isActualDateOfBirth: boolean,
useLength: string,
endDateAdjustLength: boolean,
period: AnswerPeriod,
) => {
return isFirstPeriod && isActualDateOfBirth && useLength === YES
return isFirstPeriod &&
isActualDateOfBirth &&
(useLength === YES || (useLength === NO && endDateAdjustLength))
? apiConstants.actualDateOfBirthMonths
: isFirstPeriod && isActualDateOfBirth
? apiConstants.actualDateOfBirth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
NO_ANSWER,
extractRepeaterIndexFromField,
getErrorViaPath,
getValueViaPath,
} from '@island.is/application/core'
import {
FieldBaseProps,
Expand All @@ -13,12 +14,16 @@ import {
FieldTypes,
MaybeWithApplicationAndField,
} from '@island.is/application/types'
import { DateFormField } from '@island.is/application/ui-fields'
import {
DateFormField,
CheckboxFormField,
} from '@island.is/application/ui-fields'
import { useLocale } from '@island.is/localization'
import { FieldDescription } from '@island.is/shared/form-fields'
import { Box } from '@island.is/island-ui/core'

import { parentalLeaveFormMessages } from '../../lib/messages'
import { YES, StartDateOptions } from '../../constants'

type FieldPeriodEndDateProps = {
field: {
Expand All @@ -38,6 +43,11 @@ export const PeriodEndDate: FC<
const { title, props } = field
const currentIndex = extractRepeaterIndexFromField(field)
const fieldId = `periods[${currentIndex}].endDate`
const lengthFieldId = `periods[${currentIndex}].endDateAdjustLength`
const currentFirstPeriodStart = getValueViaPath(
application.answers,
`periods[${currentIndex}].firstPeriodStart`,
) as StartDateOptions
const error = getErrorViaPath(errors as FieldErrors<FieldValues>, fieldId)

useEffect(() => {
Expand Down Expand Up @@ -79,6 +89,28 @@ export const PeriodEndDate: FC<
defaultValue: NO_ANSWER,
}}
/>
{currentFirstPeriodStart === StartDateOptions.ACTUAL_DATE_OF_BIRTH && (
<CheckboxFormField
application={application}
field={{
type: FieldTypes.CHECKBOX,
component: FieldComponents.CHECKBOX,
title: '',
id: lengthFieldId,
children: undefined,
backgroundColor: 'blue',
width: 'full',
large: true,
defaultValue: [YES],
options: [
{
value: YES,
label: parentalLeaveFormMessages.endDate.adjustPeriodLength,
},
],
}}
/>
)}
</>
)
}
7 changes: 7 additions & 0 deletions libs/application/templates/parental-leave/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,13 @@ export const parentalLeaveFormMessages = {
defaultMessage: 'Veldu lokadag tímabilsins',
description: 'Pick the end date',
},
adjustPeriodLength: {
id: 'pl.application:end.date.adjust.period.length',
defaultMessage:
'Ef barnið fæðist á annarri dagsetningu en áætlað er óska ég eftir að lengd tímabilsins aðlagist út frá raunverulegum fæðingardegi barnsins.',
description:
"If the child is born on a different date than estimated, I request that the period length be adjusted based on the child's actual date of birth.",
},
}),

startDate: defineMessages({
Expand Down
1 change: 1 addition & 0 deletions libs/application/templates/parental-leave/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export interface Period {
paid?: boolean
approved?: boolean
months?: number
endDateAdjustLength?: string[]
}

export interface Payment {
Expand Down

0 comments on commit 0e418d4

Please sign in to comment.