Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PersonalSchedule Form Description Optional #54

Merged
merged 7 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -84,9 +84,7 @@ function PersonalScheduleForm({
id="description"
type="text"
isInvalid={Boolean(errors.description)}
{...register("description", {
required: "Description is required.",
})}
{...register("description")}
/>
<Form.Control.Feedback type="invalid">
{errors.description?.message}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export default function PersonalSchedulesCreatePage() {
method: "POST",
params: {
name: personalSchedule.name,
description: personalSchedule.description,
description: personalSchedule.description
? personalSchedule.description
: "",
quarter: personalSchedule.quarter,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ export default function PersonalSchedulesEditPage() {
data: {
user: personalSchedule.user,
name: personalSchedule.name,
description: personalSchedule.description,
description: personalSchedule.description
? personalSchedule.description
: "",
quarter: personalSchedule.quarter,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ describe("PersonalScheduleForm tests", () => {
fireEvent.click(submitButton);

expect(await screen.findByText(/Name is required./)).toBeInTheDocument();
expect(screen.getByText(/Description is required./)).toBeInTheDocument();
});

test("No Error messages on good input", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import CourseDetailsIndexPage from "main/pages/CourseDetails/CourseDetailsIndexP
import { apiCurrentUserFixtures } from "fixtures/currentUserFixtures";
import { systemInfoFixtures } from "fixtures/systemInfoFixtures";
import { personalSectionsFixtures } from "fixtures/personalSectionsFixtures";
import { gradeHistoryFixtures } from "fixtures/gradeHistoryFixtures";

const mockToast = jest.fn();
jest.mock("react-toastify", () => {
Expand Down Expand Up @@ -56,6 +57,11 @@ describe("Course Details Index Page tests", () => {
params: { qtr: "20221", enrollCode: "06619" },
})
.reply(200, personalSectionsFixtures.singleSection);
axiosMock
.onGet("/api/gradehistory/search", {
params: { subjectArea: "CHEM", courseNumber: "184" },
})
.reply(200, gradeHistoryFixtures.threeGrades);
});

const queryClient = new QueryClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,60 @@ describe("PersonalSchedulesCreatePage tests", () => {
);
// expect(mockNavigate).toBeCalledWith({ "to": "/personalschedules/list" });
});
test("filling the form with no description gives no error", async () => {
const queryClient = new QueryClient();
const personalSchedule = {
id: 17,
name: "SampName",
quarter: "W08",
};

axiosMock
.onPost("/api/personalschedules/post")
.reply(202, personalSchedule);

render(
<QueryClientProvider client={queryClient}>
<MemoryRouter>
<PersonalSchedulesCreatePage />
</MemoryRouter>
</QueryClientProvider>,
);

expect(
await screen.findByTestId("PersonalScheduleForm-name"),
).toBeInTheDocument();

const nameField = screen.getByTestId("PersonalScheduleForm-name");
//const quarterField = document.querySelector("#PersonalScheduleForm-quarter");
phamaiden marked this conversation as resolved.
Show resolved Hide resolved
const quarterField = document.querySelector(
"#PersonalScheduleForm-quarter",
);
//const selectQuarter = getByLabelText("Quarter")
phamaiden marked this conversation as resolved.
Show resolved Hide resolved
const submitButton = screen.getByTestId("PersonalScheduleForm-submit");

fireEvent.change(nameField, { target: { value: "SampName" } });
fireEvent.change(quarterField, { target: { value: "20124" } });
//userEvent.selectOptions(selectQuarter, "20124");
phamaiden marked this conversation as resolved.
Show resolved Hide resolved

expect(submitButton).toBeInTheDocument();

fireEvent.click(submitButton);

await waitFor(() => expect(axiosMock.history.post.length).toBe(1));

expect(quarterField).toHaveValue("20124");
//expect(setQuarter).toBeCalledWith("20124"); //need this and axiosMock below?
phamaiden marked this conversation as resolved.
Show resolved Hide resolved

expect(axiosMock.history.post[0].params).toEqual({
name: "SampName",
description: "",
quarter: "20124",
});

expect(mockToast).toBeCalledWith(
"New personalSchedule Created - id: 17 name: SampName",
);
expect(mockNavigate).toBeCalledWith({ to: "/personalschedules/list" });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -298,5 +298,75 @@ describe("PersonalSchedulesEditPage tests", () => {
screen.queryByTestId(`${testId}-cell-row-0-col-id`),
).not.toBeInTheDocument();
});
test("updates correctly without description", async () => {
render(
<QueryClientProvider client={queryClient}>
<MemoryRouter>
<PersonalSchedulesEditPage />
</MemoryRouter>
</QueryClientProvider>,
);

await screen.findByTestId("PersonalScheduleForm-id");

const idField = screen.getByTestId("PersonalScheduleForm-id");
const nameField = screen.getByTestId("PersonalScheduleForm-name");
const descriptionField = screen.getByTestId(
"PersonalScheduleForm-description",
);
const quarterField = screen.getByTestId("PersonalScheduleForm-quarter");
const submitButton = screen.getByTestId("PersonalScheduleForm-submit");

expect(idField).toBeInTheDocument();
expect(idField).toHaveValue("17");

expect(nameField).toBeInTheDocument();
expect(nameField).toHaveValue("CS156");

expect(descriptionField).toBeInTheDocument();
expect(descriptionField).toHaveValue("My Winter Courses");

expect(quarterField).toBeInTheDocument();

expect(quarterField).toHaveValue("W22");
expect(submitButton).toHaveTextContent("Update");

fireEvent.change(nameField, { target: { value: "Winter Courses" } });
fireEvent.change(descriptionField, {
target: { value: "" },
});
fireEvent.click(submitButton);

await waitFor(() => expect(mockToast).toBeCalled());
expect(mockToast).toBeCalledWith(
"PersonalSchedule Updated - id: 17 name: Winter Courses",
);

expect(mockNavigate).toBeCalledWith({ to: "/personalschedules/list" });

expect(axiosMock.history.put.length).toBe(1); // times called
expect(axiosMock.history.put[0].params).toEqual({ id: 17 });
expect(axiosMock.history.put[0].data).toBe(
JSON.stringify({
user: {
id: 1,
email: "phtcon@ucsb.edu",
googleSub: "115856948234298493496",
pictureUrl:
"https://lh3.googleusercontent.com/-bQynVrzVIrU/AAAAAAAAAAI/AAAAAAAAAAA/AMZuucmkGuVsELD1ZeV5iDUAUfe6_K-p8w/s96-c/photo.jpg",
fullName: "Phill Conrad",
givenName: "Phill",
familyName: "Conrad",
emailVerified: true,
locale: "en",
hostedDomain: "ucsb.edu",
admin: true,
},
name: "Winter Courses",
description: "",
quarter: "20221",
}),
); // posted object
});
});
});
Loading