Skip to content

Commit 2c04b8a

Browse files
DF-946: DateParts field earliest and latest date options (#422)
* Extend getValidatorDate to consider earliest and latest date options * Bump @defra/forms-model to v3.0.676
1 parent 2223d9a commit 2c04b8a

4 files changed

Lines changed: 87 additions & 44 deletions

File tree

package-lock.json

Lines changed: 5 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
},
8888
"license": "SEE LICENSE IN LICENSE",
8989
"dependencies": {
90-
"@defra/forms-model": "^3.0.674",
90+
"@defra/forms-model": "^3.0.676",
9191
"@defra/hapi-tracing": "^1.29.0",
9292
"@defra/interactive-map": "^0.0.22-alpha",
9393
"@elastic/ecs-pino-format": "^1.5.0",

src/server/plugins/engine/components/DatePartsField.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,62 @@ describe('DatePartsField', () => {
822822
}
823823
]
824824
},
825+
{
826+
description: 'Earliest date option',
827+
component: {
828+
title: 'Example date parts field',
829+
name: 'myComponent',
830+
type: ComponentType.DatePartsField,
831+
options: {
832+
earliestDate: format(OneDayInPast, 'yyyy-MM-dd')
833+
}
834+
} satisfies DatePartsFieldComponent,
835+
assertions: [
836+
{
837+
input: getFormData(TwoDaysInPast),
838+
output: {
839+
value: getFormData(TwoDaysInPast),
840+
errors: [
841+
expect.objectContaining({
842+
text: `Example date parts field must be the same as or after ${format(OneDayInPast, 'd MMMM yyyy')}`
843+
})
844+
]
845+
}
846+
},
847+
{
848+
input: getFormData(today),
849+
output: { value: getFormData(today) }
850+
}
851+
]
852+
},
853+
{
854+
description: 'Latest date option',
855+
component: {
856+
title: 'Example date parts field',
857+
name: 'myComponent',
858+
type: ComponentType.DatePartsField,
859+
options: {
860+
latestDate: format(OneDayInFuture, 'yyyy-MM-dd')
861+
}
862+
} satisfies DatePartsFieldComponent,
863+
assertions: [
864+
{
865+
input: getFormData(TwoDaysInFuture),
866+
output: {
867+
value: getFormData(TwoDaysInFuture),
868+
errors: [
869+
expect.objectContaining({
870+
text: `Example date parts field must be the same as or before ${format(OneDayInFuture, 'd MMMM yyyy')}`
871+
})
872+
]
873+
}
874+
},
875+
{
876+
input: getFormData(today),
877+
output: { value: getFormData(today) }
878+
}
879+
]
880+
},
825881
{
826882
description: 'Optional fields',
827883
component: {

0 commit comments

Comments
 (0)