-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: updates to public-form related components
- Loading branch information
1 parent
533f2a1
commit 41f11b9
Showing
21 changed files
with
853 additions
and
466 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { describe, it, expect } from "vitest"; | ||
|
||
import { SINValidator } from "./validation"; | ||
import { lengthValidator, SINValidator } from "./validation"; | ||
import { emailValidator, postalCodeValidator } from "./validation.ts"; | ||
|
||
describe("Validation", () => { | ||
describe("Email", () => { | ||
const validEmails = [ | ||
"", | ||
"[email protected]", | ||
"email#[email protected]", | ||
"[email protected]", | ||
|
@@ -56,7 +57,13 @@ describe("Validation", () => { | |
}); | ||
|
||
describe("SIN", () => { | ||
const validSINs = ["130692544", "130 692 544", "130-692-544", "1 3 0 6 9 2 5 4 4"]; | ||
const validSINs = [ | ||
"", | ||
"130692544", | ||
"130 692 544", | ||
"130-692-544", | ||
"1 3 0 6 9 2 5 4 4", | ||
]; | ||
const invalidSINs = ["130692543", "130 692 543", "130-692-543", "1 3 0 6 9 2 5 4 3"]; | ||
|
||
const validate = SINValidator(); | ||
|
@@ -77,7 +84,7 @@ describe("Validation", () => { | |
}); | ||
|
||
describe("Postal code", () => { | ||
const validPostalCodes = ["M4B2J8", "M4B 2J8", "M4B-2J8"]; | ||
const validPostalCodes = ["", "M4B2J8", "M4B 2J8", "M4B-2J8"]; | ||
const invalidPostalCodes = ["T7D2HG", "T7D299", "T7D2H"]; | ||
|
||
const validate = postalCodeValidator(); | ||
|
@@ -96,4 +103,59 @@ describe("Validation", () => { | |
}); | ||
} | ||
}); | ||
|
||
describe("Length", () => { | ||
describe("Optional", () => { | ||
const validValues = ["", "123456"]; | ||
const invalidValues = ["12345"]; | ||
|
||
const validate = lengthValidator({ min: 6, optional: true }); | ||
|
||
for (const val of validValues) { | ||
it(`${val} should be valid`, () => { | ||
const msg = validate(val); | ||
expect(msg).toBe(""); | ||
}); | ||
} | ||
|
||
for (const val of invalidValues) { | ||
it(`${val} should be invalid`, () => { | ||
const msg = validate(val); | ||
expect(msg).not.toBe(""); | ||
}); | ||
} | ||
}); | ||
|
||
describe("Required", () => { | ||
const validValues = ["123456"]; | ||
const invalidValues = ["", "12345"]; | ||
const validate = lengthValidator({ min: 6, optional: false }); | ||
|
||
for (const val of validValues) { | ||
it(`${val} should be valid`, () => { | ||
const msg = validate(val); | ||
expect(msg).toBe(""); | ||
}); | ||
} | ||
|
||
for (const val of invalidValues) { | ||
it(`${val} should be invalid`, () => { | ||
const msg = validate(val); | ||
expect(msg).not.toBe(""); | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
describe("Date", () => { | ||
it("needs a test"); | ||
}); | ||
|
||
describe("Regex", () => { | ||
it("needs a test"); | ||
}); | ||
|
||
describe("Phone", () => { | ||
it("needs a test"); | ||
}); | ||
}); |
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
Oops, something went wrong.