Skip to content

Commit

Permalink
Merge branch 'main' into fix/add_client_side_validation_to_forms
Browse files Browse the repository at this point in the history
  • Loading branch information
dsamojlenko authored Oct 31, 2024
2 parents 68fff1f + 66b45d7 commit e5666d0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { redirect } from "next/navigation";
import { CognitoIdentityProviderServiceException } from "@aws-sdk/client-cognito-identity-provider";
import { hasError } from "@lib/hasError";
import { handleErrorById } from "@lib/auth/cognito";
import { isValidGovEmail } from "@lib/validation/validation";

export interface ErrorStates {
authError?: {
Expand Down Expand Up @@ -37,7 +38,7 @@ const validate = async (
v.toLowerCase(),
v.toTrimmed(),
v.minLength(1, t("input-validation.required", { ns: "common" })),
v.email(t("input-validation.email", { ns: "common" })),
v.custom((input) => isValidGovEmail(input), t("input-validation.validGovEmail")),
]),
password: v.string([
v.minLength(1, t("input-validation.required", { ns: "common" })),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ const validate = async (
v.toLowerCase(),
v.toTrimmed(),
v.minLength(1, t("input-validation.required", { ns: "common" })),
v.email(t("input-validation.email", { ns: "common" })),
v.custom(
(input) => isValidGovEmail(input),
t("signUpRegistration.fields.username.error.validGovEmail")
),
v.custom((input) => isValidGovEmail(input), t("input-validation.validGovEmail")),
]),
password: v.string([
v.minLength(1, t("input-validation.required", { ns: "common" })),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const validateInitialResetForm = async (
v.toLowerCase(),
v.toTrimmed(),
v.minLength(1, t("input-validation.required")),
v.email(t("input-validation.email")),
v.custom((input) => isValidGovEmail(input), t("input-validation.validGovEmail")),
]),
});
Expand Down Expand Up @@ -90,7 +89,6 @@ const validateQuestionChallengeForm = async (
v.toLowerCase(),
v.toTrimmed(),
v.minLength(1, t("input-validation.required")),
v.email(t("input-validation.email")),
v.custom((input) => isValidGovEmail(input), t("input-validation.validGovEmail")),
]),
});
Expand All @@ -113,7 +111,6 @@ const validatePasswordResetForm = async (
v.toLowerCase(),
v.toTrimmed(),
v.minLength(1, t("input-validation.required")),
v.email(t("input-validation.email")),
v.custom((input) => isValidGovEmail(input), t("input-validation.validGovEmail")),
]),
password: v.string([
Expand Down
5 changes: 4 additions & 1 deletion cypress/e2e/login_page.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ describe("Login Page", () => {
cy.get("button[type='submit']").should("be.visible");
cy.get("button[type='submit']").click();
cy.get("[id='errorMessageusername']").should("be.visible");
cy.get("[id='errorMessageusername']").should("contain", "Enter a valid email address.");
cy.get("[id='errorMessageusername']").should(
"contain",
"Enter a valid government email address."
);
});
it("Displays no error message when submitting a valid email", () => {
cy.typeInField("input[id='username']", "[email protected]");
Expand Down
7 changes: 5 additions & 2 deletions cypress/e2e/register_page.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ describe("Register Page", () => {
it("Error on submitting a form with an invalid email", () => {
cy.typeInField("input[id='username']", "myemail@email");
cy.get("[type='submit']").click();
cy.get("[id='errorMessageusername']").should("contain", "Enter a valid email address.");
cy.get("[id='errorMessageusername']").should(
"contain",
"Enter a valid government email address."
);
});
it("Error on submitting a form with a non government email", () => {
cy.typeInField("input[id='username']", "[email protected]");
cy.get("[type='submit']").click();
cy.get("[id='errorMessageusername']").should(
"contain",
"This field must be a valid federal government email"
"Enter a valid government email address."
);
});
it("No error on submitting a form with a valid government email", () => {
Expand Down
1 change: 1 addition & 0 deletions lib/tests/validation/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ describe("Gov Email domain validator", () => {
["[email protected]", false],
["[email protected]", true],
["[email protected]", true],
["test.with'[email protected]", true],
])(`Should return true if email is valid (testing "%s")`, async (email, isValid) => {
expect(isValidGovEmail(email)).toBe(isValid);
});
Expand Down

0 comments on commit e5666d0

Please sign in to comment.