Skip to content

Commit

Permalink
updates for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
charmingduchess committed Jan 7, 2025
1 parent f214b45 commit 97ceacc
Show file tree
Hide file tree
Showing 14 changed files with 189 additions and 129 deletions.
106 changes: 106 additions & 0 deletions __tests__/fixtures/react-i18next-fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
export const mockConfirmation = {
title: "congrats title",
description: {
part1: "congrats part1",
part2: "congrats part2",
part3: "congrats part3",
},
nextSteps: {
explore: "congrats explore",
borrow: "congrats borrow",
updates: "congrats updates",
more: "congrats more",
},
};
export const mockPersonal = {
title: "Step 1 of 5: Personal Information",
firstName: {
label: "First Name",
},
lastName: {
label: "Last Name",
},
birthdate: {
label: "Date of Birth",
},
ageGate: "Yes, I am over 13 years old.",
email: {
label: "Email Address",
},
eCommunications: {
labelText:
"Yes, I would like to receive information about NYPL's programs and services",
},
};
export const mockLocation = {
address: {
title: "Home Address",
line1: { label: "Street Address" },
line2: { label: "Apartment / Suite" },
city: { label: "City" },
state: { label: "State", instruction: "2-letter abbreviation" },
postalCode: {
label: "Postal Code",
instruction: "5 or 9-digit postal code",
},
},
};
export const mockAccount = {
title: "Step 4 of 5: Customize Your Account",
description:
"Create a username and password so you can log in and manage your account or access an array of our digital resources. Your username should be unique.",
username: {
label: "Username",
instruction: "5-25 alphanumeric characters. No special characters.",
checkButton: "Check if username is available",
},
password: {
label: "Password",
instruction:
"We encourage you to select a strong password that includes: at least 8 characters, a mixture of uppercase and lowercase letters, a mixture of letters and numbers, and at least one special character <i>except</i> period (.) <br />Example: MyLib1731@<br />Password cannot contain common patterns such as consecutively repeating a character three or more times, e.g. aaaatf54 or repeating a pattern, e.g. abcabcab",
},
verifyPassword: {
label: "Verify Password",
instruction: "8-32 characters",
},
showPassword: "Show Password",
library: {
selectLibrary: "Select a home library:",
placeholder: "Type a library name, such as Parkchester Library",
title: "Home Library",
description: {
part1:
"Choosing a home library will help us make sure you&apos;re getting everything you need from a branch that&apos;s most convenient for you.",
part2:
"You can skip this step and update it at any point through your account.",
},
},
};
export const mockReview = {
title: "Step 5 of 5: Confirm Your Information",
description:
"Make sure all the information you’ve entered is correct. If needed, you can still make changes before you submit your application.",
section: {
personal: "Personal Information",
address: {
label: "Address",
location: "Location",
home: "Home",
work: "Work",
},
homeLibrary: "Home Library",
},
createAccount: "Create Your Account",
receiveNewsletter: "Receive information about NYPL's programs and services",
yes: "Yes",
no: "No",
nextStep:
"After you submit your application, you will see a confirmation page with your account information, and you will be able to log in and request books and materials.",
};
export const mockButton = {
start: "Get Started",
edit: "Edit",
submit: "Submit",
next: "Next",
previous: "Previous",
};
166 changes: 48 additions & 118 deletions __tests__/library-card_review.test.tsx
Original file line number Diff line number Diff line change
@@ -1,105 +1,32 @@
import { render, screen } from "@testing-library/react";
import { axe } from "jest-axe";
import React from "react";
import {
mockConfirmation,
mockPersonal,
mockAccount,
mockReview,
mockButton,
mockLocation,
} from "./fixtures/react-i18next-fixtures";
import router from "next/router";

import ReviewPage from "../pages/review";
import { TestProviderWrapper, mockTFunction } from "../testHelper/utils";

jest.mock("next/router", () => {
const mockRouter = jest.requireActual("next-router-mock");
return { ...mockRouter, push: jest.fn() };
});

jest.mock("react-i18next", () => {
const en = {
personal: {
title: "Step 1 of 5: Personal Information",
firstName: {
label: "First Name",
},
lastName: {
label: "Last Name",
},
birthdate: {
label: "Date of Birth",
},
ageGate: "Yes, I am over 13 years old.",
email: {
label: "Email Address",
},
eCommunications: {
labelText:
"Yes, I would like to receive information about NYPL's programs and services",
},
},
location: {
address: {
title: "Home Address",
line1: { label: "Street Address" },
line2: { label: "Apartment / Suite" },
city: { label: "City" },
state: { label: "State", instruction: "2-letter abbreviation" },
postalCode: {
label: "Postal Code",
instruction: "5 or 9-digit postal code",
},
},
},
account: {
title: "Step 4 of 5: Customize Your Account",
description:
"Create a username and password so you can log in and manage your account or access an array of our digital resources. Your username should be unique.",
username: {
label: "Username",
instruction: "5-25 alphanumeric characters. No special characters.",
checkButton: "Check if username is available",
},
password: {
label: "Password",
instruction:
"We encourage you to select a strong password that includes: at least 8 characters, a mixture of uppercase and lowercase letters, a mixture of letters and numbers, and at least one special character <i>except</i> period (.) <br />Example: MyLib1731@<br />Password cannot contain common patterns such as consecutively repeating a character three or more times, e.g. aaaatf54 or repeating a pattern, e.g. abcabcab",
},
verifyPassword: {
label: "Verify Password",
instruction: "8-32 characters",
},
showPassword: "Show Password",
library: {
selectLibrary: "Select a home library:",
placeholder: "Type a library name, such as Parkchester Library",
title: "Home Library",
description: {
part1:
"Choosing a home library will help us make sure you&apos;re getting everything you need from a branch that&apos;s most convenient for you.",
part2:
"You can skip this step and update it at any point through your account.",
},
},
},
review: {
title: "Step 5 of 5: Confirm Your Information",
description:
"Make sure all the information you’ve entered is correct. If needed, you can still make changes before you submit your application.",
section: {
personal: "Personal Information",
address: {
label: "Address",
location: "Location",
home: "Home",
work: "Work",
},
homeLibrary: "Home Library",
},
createAccount: "Create Your Account",
receiveNewsletter:
"Receive information about NYPL's programs and services",
yes: "Yes",
no: "No",
nextStep:
"After you submit your application, you will see a confirmation page with your account information, and you will be able to log in and request books and materials.",
},
button: {
start: "Get Started",
edit: "Edit",
submit: "Submit",
next: "Next",
previous: "Previous",
},
confirmation: mockConfirmation,
personal: mockPersonal,
account: mockAccount,
review: mockReview,
button: mockButton,
location: mockLocation,
};
return {
// this mock makes sure any components using the translate hook can use it without a warning being shown
Expand All @@ -108,36 +35,39 @@ jest.mock("react-i18next", () => {
}),
};
});
jest.mock("next/router", () => ({
useRouter() {
return {
route: "/",
pathname: "",
query: { lang: "en" },
asPath: "",
};
},
}));

describe("ReviewPage", () => {
let container;
beforeEach(() => {
const utils = render(
<TestProviderWrapper>
<ReviewPage />
</TestProviderWrapper>
);
describe("general tests", () => {
let container;
beforeEach(() => {
const utils = render(
<TestProviderWrapper>
<ReviewPage />
</TestProviderWrapper>
);

container = utils.container;
});
container = utils.container;
});

test("passes axe accessibility test", async () => {
expect(await axe(container)).toHaveNoViolations();
});

test("passes axe accessibility test", async () => {
expect(await axe(container)).toHaveNoViolations();
test("renders a title and description", () => {
expect(
screen.getByText("Step 5 of 5: Confirm Your Information")
).toBeInTheDocument();
});
});

test("renders a title and description", () => {
expect(
screen.getByText("Step 5 of 5: Confirm Your Information")
).toBeInTheDocument();
describe("redirects", () => {
test("redirects if user has already logged in", async () => {
render(
<TestProviderWrapper>
<ReviewPage hasUserAlreadyRegistered={true} />
</TestProviderWrapper>
);
setTimeout(() => expect(router.push).toHaveBeenCalled(), 50);
});
});
});
7 changes: 6 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ module.exports = {
"!**/node_modules/**",
],
setupFilesAfterEnv: ["<rootDir>/testHelper/browser.ts"],
testPathIgnorePatterns: ["/node_modules/", "/.next/", ".spec"],
testPathIgnorePatterns: [
"/node_modules/",
"/.next/",
".spec",
"/__tests__/fixtures/*",
],
// A map from regular expressions to paths to transformers
transform: {
// Use babel-jest to transpile tests with the next/babel preset
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,8 @@
"lint-staged": {
"*.{js,jsx,ts,tsx}": "eslint --cache --fix",
"*.{js,jsx,ts,tsx,css,md}": "prettier --write"
},
"devDependencies": {
"next-router-mock": "^0.9.13"
}
}
2 changes: 1 addition & 1 deletion pages/account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { useRouter } from "next/router";

interface AccountPageProps {
hasUserAlreadyRegistered: boolean;
hasUserAlreadyRegistered?: boolean;
}

function AccountPage({
Expand Down
2 changes: 1 addition & 1 deletion pages/address-verification/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { useRouter } from "next/router";

interface AddressVerificationPageProps {
hasUserAlreadyRegistered: boolean;
hasUserAlreadyRegistered?: boolean;
}

function AddressVerificationPage({
Expand Down
1 change: 1 addition & 0 deletions pages/congrats/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { homePageRedirect } from "../../src/utils/utils";
import { cookieDomain } from "../../appConfig";

function ConfirmationPage(): JSX.Element {
console.log("render confirmation");
const { state } = useFormDataContext();
const formResults: FormResults = state.results;
const { t } = useTranslation("common");
Expand Down
2 changes: 1 addition & 1 deletion pages/location/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useRouter } from "next/router";

interface PageProps {
location: string;
hasUserAlreadyRegistered: boolean;
hasUserAlreadyRegistered?: boolean;
}

function AddressPage({
Expand Down
2 changes: 1 addition & 1 deletion pages/personal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { useRouter } from "next/router";

interface PersonalInformationProps {
hasUserAlreadyRegistered: boolean;
hasUserAlreadyRegistered?: boolean;
}

function PersonalInformationPage({
Expand Down
Loading

0 comments on commit 97ceacc

Please sign in to comment.