Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions libs/public-pages/src/pages/create-media-account/cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@ export const cy = {
continueButton: "Parhau",
backToTop: "Yn ôl i'r brig",
errorSummaryTitle: "Mae yna broblem",
errorFullNameRequired: "Nodwch eich enw llawn",
errorEmailInvalid: "Nodwch gyfeiriad e-bost yn y fformat cywir, e.e. [email protected]",
errorEmployerRequired: "Nodwch enw eich cyflogwr",
errorFileRequired: "Dewiswch ffeil yn fformat .jpg, .pdf neu .png",
errorFileSize: "Rhaid i'ch ffeil fod yn llai na 2MB",
errorTermsRequired: "Dewiswch y blwch i gytuno i'r telerau ac amodau"
errorFullNameBlank: "Mae yna broblem - Rhaid llenwi'r maes enw llawn",
errorFullNameWhiteSpace: "Mae yna broblem - Ni ddylai'r maes enw llawn ddechrau gyda gofod",
errorFullNameDoubleWhiteSpace: "Mae yna broblem - Ni ddylai'r maes enw llawn gynnwys gofodau dwbl",
errorFullNameWithoutWhiteSpace: "Mae yna broblem - Bydd angen eich enw llawn i gefnogi eich cais am gyfrif",
errorEmailBlank: "Mae yna broblem - Rhaid llenwi'r maes cyfeiriad e-bost",
errorEmailStartWithWhiteSpace: "Mae yna broblem - Ni all y maes cyfeiriad e-bost ddechrau gyda gofod",
errorEmailDoubleWhiteSpace: "Mae yna broblem - Ni all y maes cyfeiriad e-bost gynnwys gofodau dwbl",
errorEmailInvalid: "Mae yna broblem - Nodwch gyfeiriad e-bost yn y fformat cywir, fel [email protected]",
errorEmployerBlank: "Mae yna broblem - Bydd angen enw eich cyflogwr i gefnogi eich cais am gyfrif",
errorEmployerWhiteSpace: "Mae yna broblem - Ni all y maes cyflogwr ddechrau gyda gofod",
errorEmployerDoubleWhiteSpace: "Mae yna broblem - Ni all y maes cyflogwr gynnwys gofodau dwbl",
errorFileBlank: "Mae yna broblem - Bydd angen tystiolaeth ID i gefnogi eich cais am gyfrif",
errorFileSize: "Mae yna broblem - Rhaid i'r dystiolaeth ID fod yn llai na 2Mbs",
errorFileType: "Mae yna broblem - Rhaid i'r dystiolaeth ID fod yn JPG, PDF neu PNG",
errorTermsRequired: "Mae yna broblem - Rhaid ichi dicio'r blwch i gadarnhau eich bod yn cytuno i'r telerau ac amodau"
};
19 changes: 14 additions & 5 deletions libs/public-pages/src/pages/create-media-account/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@ export const en = {
continueButton: "Continue",
backToTop: "Back to top",
errorSummaryTitle: "There is a problem",
errorFullNameRequired: "There is a problem - Full name field must be populated",
errorEmailInvalid: "There is a problem - Email address field must be populated",
errorEmployerRequired: "There is a problem - Your employers name will be needed to support your application for an account",
errorFileRequired: "There is a problem - We will need ID evidence to support your application for an account",
errorFileSize: "Your file must be smaller than 2MB",
errorFullNameBlank: "There is a problem - Full name field must be populated",
errorFullNameWhiteSpace: "There is a problem - Full name field must not start with a space",
errorFullNameDoubleWhiteSpace: "There is a problem - Full name field must not contain double spaces",
errorFullNameWithoutWhiteSpace: "There is a problem - Your full name will be needed to support your application for an account",
errorEmailBlank: "There is a problem - Email address field must be populated",
errorEmailStartWithWhiteSpace: "There is a problem - Email address field cannot start with a space",
errorEmailDoubleWhiteSpace: "There is a problem - Email address field cannot contain double spaces",
errorEmailInvalid: "There is a problem - Enter an email address in the correct format, like [email protected]",
errorEmployerBlank: "There is a problem - Your employers name will be needed to support your application for an account",
errorEmployerWhiteSpace: "There is a problem - Employer field cannot start with a space",
errorEmployerDoubleWhiteSpace: "There is a problem - Employer field cannot contain double spaces",
errorFileBlank: "There is a problem - We will need ID evidence to support your application for an account",
errorFileSize: "There is a problem - ID evidence needs to be less than 2Mbs",
errorFileType: "There is a problem - ID evidence must be a JPG, PDF or PNG",
errorTermsRequired: "There is a problem - You must check the box to confirm you agree to the terms and conditions."
};
55 changes: 41 additions & 14 deletions libs/public-pages/src/pages/create-media-account/index.njk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,20 @@ describe("create-media-account template", () => {
});

it("should have all error messages", () => {
expect(en.errorFullNameRequired).toBe("There is a problem - Full name field must be populated");
expect(en.errorEmailInvalid).toBe("There is a problem - Email address field must be populated");
expect(en.errorEmployerRequired).toBe("There is a problem - Your employers name will be needed to support your application for an account");
expect(en.errorFileRequired).toBe("There is a problem - We will need ID evidence to support your application for an account");
expect(en.errorFileSize).toBe("Your file must be smaller than 2MB");
expect(en.errorFullNameBlank).toBe("There is a problem - Full name field must be populated");
expect(en.errorFullNameWhiteSpace).toBe("There is a problem - Full name field must not start with a space");
expect(en.errorFullNameDoubleWhiteSpace).toBe("There is a problem - Full name field must not contain double spaces");
expect(en.errorFullNameWithoutWhiteSpace).toBe("There is a problem - Your full name will be needed to support your application for an account");
expect(en.errorEmailBlank).toBe("There is a problem - Email address field must be populated");
expect(en.errorEmailStartWithWhiteSpace).toBe("There is a problem - Email address field cannot start with a space");
expect(en.errorEmailDoubleWhiteSpace).toBe("There is a problem - Email address field cannot contain double spaces");
expect(en.errorEmailInvalid).toBe("There is a problem - Enter an email address in the correct format, like [email protected]");
expect(en.errorEmployerBlank).toBe("There is a problem - Your employers name will be needed to support your application for an account");
expect(en.errorEmployerWhiteSpace).toBe("There is a problem - Employer field cannot start with a space");
expect(en.errorEmployerDoubleWhiteSpace).toBe("There is a problem - Employer field cannot contain double spaces");
expect(en.errorFileBlank).toBe("There is a problem - We will need ID evidence to support your application for an account");
expect(en.errorFileSize).toBe("There is a problem - ID evidence needs to be less than 2Mbs");
expect(en.errorFileType).toBe("There is a problem - ID evidence must be a JPG, PDF or PNG");
expect(en.errorTermsRequired).toBe("There is a problem - You must check the box to confirm you agree to the terms and conditions.");
});
});
Expand Down Expand Up @@ -116,12 +125,21 @@ describe("create-media-account template", () => {
});

it("should have all error messages", () => {
expect(cy.errorFullNameRequired).toBe("Nodwch eich enw llawn");
expect(cy.errorEmailInvalid).toBe("Nodwch gyfeiriad e-bost yn y fformat cywir, e.e. [email protected]");
expect(cy.errorEmployerRequired).toBe("Nodwch enw eich cyflogwr");
expect(cy.errorFileRequired).toBe("Dewiswch ffeil yn fformat .jpg, .pdf neu .png");
expect(cy.errorFileSize).toBe("Rhaid i'ch ffeil fod yn llai na 2MB");
expect(cy.errorTermsRequired).toBe("Dewiswch y blwch i gytuno i'r telerau ac amodau");
expect(cy.errorFullNameBlank).toBe("Mae yna broblem - Rhaid llenwi'r maes enw llawn");
expect(cy.errorFullNameWhiteSpace).toBe("Mae yna broblem - Ni ddylai'r maes enw llawn ddechrau gyda gofod");
expect(cy.errorFullNameDoubleWhiteSpace).toBe("Mae yna broblem - Ni ddylai'r maes enw llawn gynnwys gofodau dwbl");
expect(cy.errorFullNameWithoutWhiteSpace).toBe("Mae yna broblem - Bydd angen eich enw llawn i gefnogi eich cais am gyfrif");
expect(cy.errorEmailBlank).toBe("Mae yna broblem - Rhaid llenwi'r maes cyfeiriad e-bost");
expect(cy.errorEmailStartWithWhiteSpace).toBe("Mae yna broblem - Ni all y maes cyfeiriad e-bost ddechrau gyda gofod");
expect(cy.errorEmailDoubleWhiteSpace).toBe("Mae yna broblem - Ni all y maes cyfeiriad e-bost gynnwys gofodau dwbl");
expect(cy.errorEmailInvalid).toBe("Mae yna broblem - Nodwch gyfeiriad e-bost yn y fformat cywir, fel [email protected]");
expect(cy.errorEmployerBlank).toBe("Mae yna broblem - Bydd angen enw eich cyflogwr i gefnogi eich cais am gyfrif");
expect(cy.errorEmployerWhiteSpace).toBe("Mae yna broblem - Ni all y maes cyflogwr ddechrau gyda gofod");
expect(cy.errorEmployerDoubleWhiteSpace).toBe("Mae yna broblem - Ni all y maes cyflogwr gynnwys gofodau dwbl");
expect(cy.errorFileBlank).toBe("Mae yna broblem - Bydd angen tystiolaeth ID i gefnogi eich cais am gyfrif");
expect(cy.errorFileSize).toBe("Mae yna broblem - Rhaid i'r dystiolaeth ID fod yn llai na 2Mbs");
expect(cy.errorFileType).toBe("Mae yna broblem - Rhaid i'r dystiolaeth ID fod yn JPG, PDF neu PNG");
expect(cy.errorTermsRequired).toBe("Mae yna broblem - Rhaid ichi dicio'r blwch i gadarnhau eich bod yn cytuno i'r telerau ac amodau");
});
});

Expand All @@ -147,11 +165,20 @@ describe("create-media-account template", () => {
"continueButton",
"backToTop",
"errorSummaryTitle",
"errorFullNameRequired",
"errorFullNameBlank",
"errorFullNameWhiteSpace",
"errorFullNameDoubleWhiteSpace",
"errorFullNameWithoutWhiteSpace",
"errorEmailBlank",
"errorEmailStartWithWhiteSpace",
"errorEmailDoubleWhiteSpace",
"errorEmailInvalid",
"errorEmployerRequired",
"errorFileRequired",
"errorEmployerBlank",
"errorEmployerWhiteSpace",
"errorEmployerDoubleWhiteSpace",
"errorFileBlank",
"errorFileSize",
"errorFileType",
"errorTermsRequired"
];

Expand Down
186 changes: 177 additions & 9 deletions libs/public-pages/src/pages/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ describe("validateForm", () => {
const errors = validateForm("", "[email protected]", "BBC News", "on", file, undefined, en);

expect(errors).toHaveLength(1);
expect(errors[0].text).toBe(en.errorFullNameRequired);
expect(errors[0].text).toBe(en.errorFullNameBlank);
expect(errors[0].href).toBe("#fullName");
});

it("should return error for full name exceeding 100 characters", () => {
const longName = "a".repeat(101);
const longName = `${"a".repeat(50)} ${"b".repeat(51)}`;
const file: Express.Multer.File = {
fieldname: "idProof",
originalname: "passport.jpg",
Expand All @@ -61,7 +61,7 @@ describe("validateForm", () => {
const errors = validateForm(longName, "[email protected]", "BBC News", "on", file, undefined, en);

expect(errors).toHaveLength(1);
expect(errors[0].text).toBe(en.errorFullNameRequired);
expect(errors[0].text).toBe(en.errorFullNameBlank);
});

it("should return error for full name with invalid characters", () => {
Expand All @@ -78,10 +78,73 @@ describe("validateForm", () => {
path: ""
};

const errors = validateForm("John123", "[email protected]", "BBC News", "on", file, undefined, en);
const errors = validateForm("John 123", "[email protected]", "BBC News", "on", file, undefined, en);

expect(errors).toHaveLength(1);
expect(errors[0].text).toBe(en.errorFullNameRequired);
expect(errors[0].text).toBe(en.errorFullNameBlank);
});

it("should return error for full name starting with whitespace", () => {
const file: Express.Multer.File = {
fieldname: "idProof",
originalname: "passport.jpg",
encoding: "7bit",
mimetype: "image/jpeg",
size: 1024 * 1024,
buffer: Buffer.from("test"),
stream: null as any,
destination: "",
filename: "",
path: ""
};

const errors = validateForm(" John Smith", "[email protected]", "BBC News", "on", file, undefined, en);

expect(errors).toHaveLength(1);
expect(errors[0].text).toBe(en.errorFullNameWhiteSpace);
expect(errors[0].href).toBe("#fullName");
});

it("should return error for full name with double whitespace", () => {
const file: Express.Multer.File = {
fieldname: "idProof",
originalname: "passport.jpg",
encoding: "7bit",
mimetype: "image/jpeg",
size: 1024 * 1024,
buffer: Buffer.from("test"),
stream: null as any,
destination: "",
filename: "",
path: ""
};

const errors = validateForm("John Smith", "[email protected]", "BBC News", "on", file, undefined, en);

expect(errors).toHaveLength(1);
expect(errors[0].text).toBe(en.errorFullNameDoubleWhiteSpace);
expect(errors[0].href).toBe("#fullName");
});

it("should return error for full name without whitespace", () => {
const file: Express.Multer.File = {
fieldname: "idProof",
originalname: "passport.jpg",
encoding: "7bit",
mimetype: "image/jpeg",
size: 1024 * 1024,
buffer: Buffer.from("test"),
stream: null as any,
destination: "",
filename: "",
path: ""
};

const errors = validateForm("John", "[email protected]", "BBC News", "on", file, undefined, en);

expect(errors).toHaveLength(1);
expect(errors[0].text).toBe(en.errorFullNameWithoutWhiteSpace);
expect(errors[0].href).toBe("#fullName");
});

it("should return error for invalid email", () => {
Expand All @@ -105,6 +168,69 @@ describe("validateForm", () => {
expect(errors[0].href).toBe("#email");
});

it("should return error for email starting with whitespace", () => {
const file: Express.Multer.File = {
fieldname: "idProof",
originalname: "passport.jpg",
encoding: "7bit",
mimetype: "image/jpeg",
size: 1024 * 1024,
buffer: Buffer.from("test"),
stream: null as any,
destination: "",
filename: "",
path: ""
};

const errors = validateForm("John Smith", " [email protected]", "BBC News", "on", file, undefined, en);

expect(errors).toHaveLength(1);
expect(errors[0].text).toBe(en.errorEmailStartWithWhiteSpace);
expect(errors[0].href).toBe("#email");
});

it("should return error for email with double whitespace", () => {
const file: Express.Multer.File = {
fieldname: "idProof",
originalname: "passport.jpg",
encoding: "7bit",
mimetype: "image/jpeg",
size: 1024 * 1024,
buffer: Buffer.from("test"),
stream: null as any,
destination: "",
filename: "",
path: ""
};

const errors = validateForm("John Smith", "john @example.com", "BBC News", "on", file, undefined, en);

expect(errors).toHaveLength(1);
expect(errors[0].text).toBe(en.errorEmailDoubleWhiteSpace);
expect(errors[0].href).toBe("#email");
});

it("should return error for blank email", () => {
const file: Express.Multer.File = {
fieldname: "idProof",
originalname: "passport.jpg",
encoding: "7bit",
mimetype: "image/jpeg",
size: 1024 * 1024,
buffer: Buffer.from("test"),
stream: null as any,
destination: "",
filename: "",
path: ""
};

const errors = validateForm("John Smith", "", "BBC News", "on", file, undefined, en);

expect(errors).toHaveLength(1);
expect(errors[0].text).toBe(en.errorEmailBlank);
expect(errors[0].href).toBe("#email");
});

it("should return error for missing employer", () => {
const file: Express.Multer.File = {
fieldname: "idProof",
Expand All @@ -122,7 +248,7 @@ describe("validateForm", () => {
const errors = validateForm("John Smith", "[email protected]", "", "on", file, undefined, en);

expect(errors).toHaveLength(1);
expect(errors[0].text).toBe(en.errorEmployerRequired);
expect(errors[0].text).toBe(en.errorEmployerBlank);
expect(errors[0].href).toBe("#employer");
});

Expand All @@ -144,14 +270,56 @@ describe("validateForm", () => {
const errors = validateForm("John Smith", "[email protected]", longEmployer, "on", file, undefined, en);

expect(errors).toHaveLength(1);
expect(errors[0].text).toBe(en.errorEmployerRequired);
expect(errors[0].text).toBe(en.errorEmployerBlank);
});

it("should return error for employer starting with whitespace", () => {
const file: Express.Multer.File = {
fieldname: "idProof",
originalname: "passport.jpg",
encoding: "7bit",
mimetype: "image/jpeg",
size: 1024 * 1024,
buffer: Buffer.from("test"),
stream: null as any,
destination: "",
filename: "",
path: ""
};

const errors = validateForm("John Smith", "[email protected]", " BBC News", "on", file, undefined, en);

expect(errors).toHaveLength(1);
expect(errors[0].text).toBe(en.errorEmployerWhiteSpace);
expect(errors[0].href).toBe("#employer");
});

it("should return error for employer with double whitespace", () => {
const file: Express.Multer.File = {
fieldname: "idProof",
originalname: "passport.jpg",
encoding: "7bit",
mimetype: "image/jpeg",
size: 1024 * 1024,
buffer: Buffer.from("test"),
stream: null as any,
destination: "",
filename: "",
path: ""
};

const errors = validateForm("John Smith", "[email protected]", "BBC News", "on", file, undefined, en);

expect(errors).toHaveLength(1);
expect(errors[0].text).toBe(en.errorEmployerDoubleWhiteSpace);
expect(errors[0].href).toBe("#employer");
});

it("should return error for missing file", () => {
const errors = validateForm("John Smith", "[email protected]", "BBC News", "on", undefined, undefined, en);

expect(errors).toHaveLength(1);
expect(errors[0].text).toBe(en.errorFileRequired);
expect(errors[0].text).toBe(en.errorFileBlank);
expect(errors[0].href).toBe("#idProof");
});

Expand All @@ -172,7 +340,7 @@ describe("validateForm", () => {
const errors = validateForm("John Smith", "[email protected]", "BBC News", "on", file, undefined, en);

expect(errors).toHaveLength(1);
expect(errors[0].text).toBe(en.errorFileRequired);
expect(errors[0].text).toBe(en.errorFileType);
});

it("should return error for file too large", () => {
Expand Down
Loading
Loading