Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ interface RegistrationEmailPreferenceProps {

type EmailPreferenceDescriptions = {
assignments: string;
news: string;
events: string;
newsAndUpdates: string;
};

export const RegistrationEmailPreference = ({
Expand All @@ -26,16 +25,15 @@ export const RegistrationEmailPreference = ({
const preferences = [
{
key: "assignments",
label: "Assignments",
property: "ASSIGNMENTS",
condition: userRole === "STUDENT",
},
{ key: "news", property: "NEWS_AND_UPDATES" },
{ key: "events", property: "EVENTS" },
{ key: "newsAndUpdates", label: "News and Updates", property: "NEWS_AND_UPDATES" },
];
const isaacEmailPreferenceDescriptions: EmailPreferenceDescriptions = {
assignments: "Receive assignment notifications from your teacher.",
news: "Be the first to know about new topics, new platform features, and our fantastic competition giveaways.",
events: "Get valuable updates on our free student workshops happening near you.",
newsAndUpdates: "Be the first to know about new topics, platform features, competitions and free student events.",
};

return (
Expand All @@ -50,7 +48,7 @@ export const RegistrationEmailPreference = ({
const description = isaacEmailPreferenceDescriptions[preference.key as keyof EmailPreferenceDescriptions];
return preference.condition === undefined || preference.condition ? (
<tr key={index}>
<td>{preference.key.charAt(0).toUpperCase() + preference.key.slice(1)}</td>
<td>{preference.label}</td>
<td className="d-none d-sm-table-cell">{description}</td>
<td className="text-center">
<TrueFalseRadioInput
Expand Down
3 changes: 1 addition & 2 deletions src/app/components/elements/panels/UserEmailPreferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ export const UserEmailPreference = ({
<p>
Get important information about the Isaac {SITE_SUBJECT_TITLE} programme delivered to your inbox. These settings
can be changed at any time. Expect a monthly newsletter featuring news, updates, and event announcements.
Assignment notifications will be sent as needed by your teacher.{" "}
{userIsStudent && "Assignment notifications will be sent as needed by your teacher."}
{userIsStudent && " Assignment notifications will be sent as needed by your teacher."}
</p>
<FormGroup className="overflow-auto">
<Table className="mb-0">
Expand Down
2 changes: 1 addition & 1 deletion src/app/services/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export const getPasswordInfo = (password: string) => {
export const validateEmailPreferences = (emailPreferences?: UserEmailPreferences | null) => {
return (
emailPreferences &&
[emailPreferences.ASSIGNMENTS, emailPreferences.EVENTS, emailPreferences.NEWS_AND_UPDATES].reduce(
[emailPreferences.ASSIGNMENTS, emailPreferences.NEWS_AND_UPDATES].reduce(
// Make sure all expected values are either true or false
(prev, next) => prev && (next === true || next === false),
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ import { TestUserRole, renderTestEnvironment } from "../../../utils";

describe("RegistrationEmailPreference", () => {
const mockSetEmailPreferences = jest.fn();
const preferences = ["NEWS_AND_UPDATES", "ASSIGNMENTS", "EVENTS"];
const preferences = ["NEWS_AND_UPDATES", "ASSIGNMENTS"];

const getOptions = {
assignments: () => screen.getByText("Assignments"),
news: () => screen.getByText("News"),
events: () => screen.getByText("Events"),
newsAndUpdates: () => screen.getByText("News and Updates"),
assignmentsDescription: () => screen.getByText("Receive assignment notifications from your teacher."),
newsDescription: () =>
newsAndUpdatesDescription: () =>
screen.getByText(
"Be the first to know about new topics, new platform features, and our fantastic competition giveaways.",
"Be the first to know about new topics, platform features, competitions and free student events.",
),
eventsDescription: () => screen.getByText("Get valuable updates on our free student workshops happening near you."),
};

const setupTest = (role: TestUserRole, props = {}) => {
Expand All @@ -36,24 +34,17 @@ describe("RegistrationEmailPreference", () => {

it("renders correct options for student registration", () => {
setupTest("STUDENT");
const { assignments, news, events, assignmentsDescription, newsDescription, eventsDescription } = getOptions;
const allOptions = [
assignments(),
assignmentsDescription(),
news(),
newsDescription(),
events(),
eventsDescription(),
];
const { assignments, newsAndUpdates, assignmentsDescription, newsAndUpdatesDescription } = getOptions;
const allOptions = [assignments(), assignmentsDescription(), newsAndUpdates(), newsAndUpdatesDescription()];
allOptions.forEach((option) => {
expect(option).toBeInTheDocument();
});
});

it("renders correct options for teacher registration", () => {
setupTest("TEACHER");
const { news, newsDescription, events, eventsDescription } = getOptions;
[news(), newsDescription(), events(), eventsDescription()].forEach((option) => {
const { newsAndUpdates, newsAndUpdatesDescription } = getOptions;
[newsAndUpdates(), newsAndUpdatesDescription()].forEach((option) => {
expect(option).toBeInTheDocument();
});
const assignmentsOption = screen.queryByText("Assignments");
Expand All @@ -79,14 +70,14 @@ describe("RegistrationEmailPreference", () => {
it("if form submission is attempted but not all preferences are selected, affected options are marked as invalid, and 'required' feedback shows", () => {
setupTest("STUDENT", {
submissionAttempted: true,
emailPreferences: { ASSIGNMENTS: false, EVENTS: true },
emailPreferences: { ASSIGNMENTS: false },
});
const newsPreferenceTrueLabel = screen.getByLabelText(/Yes.*for NEWS_AND_UPDATES/);
const newsPreferenceFalseLabel = screen.getByLabelText(/No.*for NEWS_AND_UPDATES/);
expect(newsPreferenceTrueLabel).toBeInvalid();
expect(newsPreferenceFalseLabel).toBeInvalid();
const emailPreferenceFeedback = screen.getByText("required", {
selector: "#news-feedback",
selector: "#newsAndUpdates-feedback",
});
expect(emailPreferenceFeedback).toBeInTheDocument();
});
Expand All @@ -96,7 +87,6 @@ describe("RegistrationEmailPreference", () => {
submissionAttempted: true,
emailPreferences: {
ASSIGNMENTS: false,
EVENTS: true,
NEWS_AND_UPDATES: true,
},
});
Expand Down
5 changes: 2 additions & 3 deletions src/test/pages/StudentRegistration.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe("Student Registration", () => {
examBoard,
assignmentPreferences,
newsPreferences,
events,
// events,
submitButton,
recaptcha,
} = formFields;
Expand All @@ -66,7 +66,7 @@ describe("Student Registration", () => {
examBoard(),
assignmentPreferences(),
newsPreferences(),
events(),
// events(),
submitButton(),
recaptcha(),
].forEach((each) => expect(each).toBeVisible());
Expand Down Expand Up @@ -110,7 +110,6 @@ describe("Student Registration", () => {
EMAIL_PREFERENCE: {
NEWS_AND_UPDATES: false,
ASSIGNMENTS: true,
EVENTS: false,
},
}),
expect.objectContaining([
Expand Down
3 changes: 0 additions & 3 deletions src/test/pages/TeacherRegistration.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ describe("Teacher Registration", () => {
stage,
examBoard,
newsPreferences,
events,
submitButton,
verificationInfo,
additionalInfo,
Expand All @@ -103,7 +102,6 @@ describe("Teacher Registration", () => {
stage(),
examBoard(),
newsPreferences(),
events(),
submitButton(),
verificationInfo(),
additionalInfo(),
Expand Down Expand Up @@ -172,7 +170,6 @@ describe("Teacher Registration", () => {
EMAIL_PREFERENCE: {
NEWS_AND_UPDATES: false,
ASSIGNMENTS: true,
EVENTS: false,
},
}),
expect.objectContaining([
Expand Down
5 changes: 0 additions & 5 deletions src/test/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ export const getFormFields = () => {
verificationInfo: () => screen.getByRole("textbox", { name: /url of a page/i }),
assignmentPreferences: () => screen.queryByRole("cell", { name: /receive assignment/i }),
newsPreferences: () => screen.getByRole("radio", { name: /no for news_and_updates/i }),
events: () => screen.getByRole("radio", { name: /no for events/i }),
additionalInfo: () => screen.getByRole("textbox", { name: /any other information/i }),
otherInfo: () => screen.getByRole("textbox", { name: /other information/i }),
submitButton: () => screen.getByRole("button", { name: "Register my account" }),
Expand All @@ -209,7 +208,6 @@ export const fillFormCorrectly = async (correctly: boolean, role: "teacher" | "s
stage,
verificationInfo,
newsPreferences,
events,
otherInfo,
recaptcha,
} = formFields;
Expand All @@ -223,7 +221,6 @@ export const fillFormCorrectly = async (correctly: boolean, role: "teacher" | "s
await fillTextField(password(), registrationUserData.password);
await fillTextField(confirmPassword(), registrationUserData.password);
await userEvent.click(newsPreferences());
await userEvent.click(events());
await userEvent.click(noSchool());
await selectOption(stage(), registrationUserData.stage);
await fillTextField(otherInfo(), "extra information");
Expand All @@ -249,7 +246,6 @@ export const fillFormCorrectly = async (correctly: boolean, role: "teacher" | "s
password,
confirmPassword,
newsPreferences,
events,
recaptcha,
} = formFields;
await fillTextField(givenName(), registrationUserData.givenName);
Expand All @@ -263,7 +259,6 @@ export const fillFormCorrectly = async (correctly: boolean, role: "teacher" | "s
await fillTextField(password(), registrationUserData.password);
await fillTextField(confirmPassword(), registrationUserData.password);
await userEvent.click(newsPreferences());
await userEvent.click(events());
} else {
await fillTextField(password(), registrationUserData.wrongPassword);
await fillTextField(confirmPassword(), registrationUserData.wrongPassword);
Expand Down
Loading