-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00dde47
commit 26f732e
Showing
23 changed files
with
406 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
editor.planx.uk/src/@planx/components/Checklist/model.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { checklistInputValidationSchema } from "./model"; | ||
|
||
describe("Checklist - validation", () => { | ||
describe("optional checklist fields in schema", () => { | ||
const validationSchema = checklistInputValidationSchema({ | ||
data: { | ||
options: [ | ||
{ id: "test1", data: { text: "Test 1", val: "test1" } }, | ||
{ id: "test2", data: { text: "Test 2", val: "test2" } }, | ||
], | ||
allRequired: true, | ||
}, | ||
required: false, | ||
}); | ||
|
||
it("does not validate fields without a value", async () => { | ||
const undefinedResult = await validationSchema.validate(undefined); | ||
expect(undefinedResult).toBeUndefined(); | ||
|
||
const arrayResult = await validationSchema.validate([]); | ||
expect(arrayResult).toHaveLength(0); | ||
}); | ||
|
||
it("validates optional fields with a value", async () => { | ||
await expect(() => validationSchema.validate(["test1"])).rejects.toThrow( | ||
/All options must be checked/ | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
editor.planx.uk/src/@planx/components/NumberInput/model.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { numberInputValidationSchema } from "./model"; | ||
|
||
describe("validation", () => { | ||
describe("optional number fields in schema", () => { | ||
const validationSchema = numberInputValidationSchema({ | ||
data: { title: "test", isInteger: true }, | ||
required: false, | ||
}); | ||
|
||
it("does not validate fields without a value", async () => { | ||
const result = await validationSchema.validate(undefined); | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it("validates optional fields with a value", async () => { | ||
await expect(() => | ||
validationSchema.validate("not a number") | ||
).rejects.toThrow(/Enter a positive number/); | ||
|
||
await expect(() => validationSchema.validate("12.34")).rejects.toThrow( | ||
/Enter a whole number/ | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.