From 22fb1cf6a2d023c22e189b6dfa0920c22ab7be59 Mon Sep 17 00:00:00 2001 From: David Liu Date: Sun, 12 Jan 2025 11:08:08 -0500 Subject: [PATCH] Updates after initial review --- .../Components/Result/submission_selector.jsx | 13 -------- .../graders_distribution_modal.test.jsx | 1 - .../__tests__/student_table.test.jsx | 5 +-- .../submission_file_upload_modal.test.jsx | 3 +- .../__tests__/submission_selector.test.jsx | 33 ++++++++++--------- 5 files changed, 22 insertions(+), 33 deletions(-) diff --git a/app/javascript/Components/Result/submission_selector.jsx b/app/javascript/Components/Result/submission_selector.jsx index 6981b764c0..a1bef0da93 100644 --- a/app/javascript/Components/Result/submission_selector.jsx +++ b/app/javascript/Components/Result/submission_selector.jsx @@ -178,19 +178,6 @@ export class SubmissionSelector extends React.Component { return ""; } - const url = Routes.next_grouping_course_result_path(this.props.course_id, this.props.result_id); - - const progressBarWidth = - this.props.num_collected > 0 ? this.props.num_marked / this.props.num_collected : 1; - let progressBarColour; - if (progressBarWidth > 0.75) { - progressBarColour = "green"; - } else if (progressBarWidth > 0.35) { - progressBarColour = "#FBC02D"; - } else { - progressBarColour = "#FE2A2A"; - } - let meterLow = 0; let meterHigh = 1; if (this.props.num_collected !== null && this.props.num_collected !== undefined) { diff --git a/app/javascript/Components/__tests__/graders_distribution_modal.test.jsx b/app/javascript/Components/__tests__/graders_distribution_modal.test.jsx index 88b236a562..11f9d96794 100644 --- a/app/javascript/Components/__tests__/graders_distribution_modal.test.jsx +++ b/app/javascript/Components/__tests__/graders_distribution_modal.test.jsx @@ -13,7 +13,6 @@ const createExampleForm = () => { describe("GraderDistributionModal", () => { let props; const form1 = createExampleForm(); - beforeEach(() => { props = { graders: [ diff --git a/app/javascript/Components/__tests__/student_table.test.jsx b/app/javascript/Components/__tests__/student_table.test.jsx index d8b09100c7..ca1d6a8aab 100644 --- a/app/javascript/Components/__tests__/student_table.test.jsx +++ b/app/javascript/Components/__tests__/student_table.test.jsx @@ -41,7 +41,6 @@ describe("For the StudentTable component's states and props", () => { it("returns true when the row's section index equals to the selected value", () => { // Sets data.sections - debugger; wrapper.current.wrapped.state.data.sections = {1: "LEC0101", 2: "LEC0201"}; // Sample row const sample_row = {section: 1}; @@ -190,7 +189,9 @@ describe("For the StudentTable's display of students", () => { expect(cells[5]).toEqual(student.id_number); expect(cells[6]).toEqual(sections_sample[student.section] || ""); expect(cells[7]).toEqual(`${student.remaining_grace_credits} / ${student.grace_credits}`); - expect(cells[8]).toEqual(!student.hidden ? "Active" : "Inactive"); + expect(cells[8]).toEqual( + !student.hidden ? I18n.t("roles.active") : I18n.t("roles.inactive") + ); return; } } diff --git a/app/javascript/Components/__tests__/submission_file_upload_modal.test.jsx b/app/javascript/Components/__tests__/submission_file_upload_modal.test.jsx index 7b6bcaad2f..4a12d6df56 100644 --- a/app/javascript/Components/__tests__/submission_file_upload_modal.test.jsx +++ b/app/javascript/Components/__tests__/submission_file_upload_modal.test.jsx @@ -267,7 +267,7 @@ describe("For the SubmissionFileUploadModal", () => { expect(mockOnSubmit).toHaveBeenCalledWith([{name: "file.py"}], undefined, false, "q1.py"); }); - it("should not call onSubmit prop when extensions don't match and user cancels", async () => { + it.only("should not call onSubmit prop when extensions don't match and user cancels", async () => { // Mock window.confirm to return false window.confirm = jest.fn(() => false); @@ -275,6 +275,7 @@ describe("For the SubmissionFileUploadModal", () => { target: {files: [{name: "file1.txt"}]}, }); await userEvent.selectOptions(renameToInput, "q1.py"); + await userEvent.click(submit); // Ensure onSubmit is not called expect(mockOnSubmit).not.toHaveBeenCalled(); diff --git a/app/javascript/Components/__tests__/submission_selector.test.jsx b/app/javascript/Components/__tests__/submission_selector.test.jsx index eb90c12ee6..348ecd1479 100644 --- a/app/javascript/Components/__tests__/submission_selector.test.jsx +++ b/app/javascript/Components/__tests__/submission_selector.test.jsx @@ -1,4 +1,5 @@ -import {fireEvent, render, screen} from "@testing-library/react"; +import {render, screen} from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; import {SubmissionSelector} from "../Result/submission_selector"; @@ -27,6 +28,7 @@ const basicProps = { available_tags: [], can_release: false, course_id: 1, + criterionSummaryData: [], current_tags: [], filterData: INITIAL_FILTER_MODAL_STATE, fullscreen: false, @@ -63,18 +65,18 @@ describe("SubmissionSelector", () => { expect(screen.queryByTestId("submission-selector-container")).toBeNull(); }); - it("should call nextSubmission when the next-button is pressed", () => { + it("should call nextSubmission when the next-button is pressed", async () => { render(); const button = screen.getByTitle(I18n.t("results.next_submission"), {exact: false}); - fireEvent.click(button); + await userEvent.click(button); expect(props.nextSubmission).toHaveBeenCalled(); }); - it("should call previousSubmission when the next-button is pressed", () => { + it("should call previousSubmission when the next-button is pressed", async () => { render(); const button = screen.getByTitle(I18n.t("results.previous_submission"), {exact: false}); - fireEvent.click(button); + await userEvent.click(button); expect(props.previousSubmission).toHaveBeenCalled(); }); @@ -84,14 +86,13 @@ describe("SubmissionSelector", () => { expect(screen.getByText(props.group_name)).toBeTruthy(); }); - it.skip("should show filter modal when filter-button is pressed", () => { + it("should show filter modal when filter-button is pressed", async () => { render(); const button = screen.getByTitle(I18n.t("results.filter_submissions")); - fireEvent.click(button); + await userEvent.click(button); - expect( - screen.queryByRole("heading", {name: I18n.t("results.filter_submissions")}) - ).toBeTruthy(); + const modal = await screen.findByRole("dialog", {hidden: true}); + expect(modal.classList.contains("filter-modal")).toBeTruthy(); }); it("should pass correct values to the progress meter", () => { @@ -118,19 +119,19 @@ describe("SubmissionSelector", () => { expect(screen.getByText(expected_display)).toBeTruthy(); }); - it("can toggle into fullscreen", () => { + it("can toggle into fullscreen", async () => { render(); const button = screen.getByTitle(I18n.t("results.fullscreen_enter"), {exact: false}); - fireEvent.click(button); + await userEvent.click(button); expect(props.toggleFullscreen).toHaveBeenCalled(); }); - it("can toggle out of fullscreen", () => { + it("can toggle out of fullscreen", async () => { props.fullscreen = true; render(); const button = screen.getByTitle(I18n.t("results.fullscreen_exit"), {exact: false}); - fireEvent.click(button); + await userEvent.click(button); expect(props.toggleFullscreen).toHaveBeenCalled(); }); @@ -166,13 +167,13 @@ describe("SubmissionSelector", () => { expect(element).toBeEnabled(); }); - it("should call props.setReleasedToStudents when release button is clicked", () => { + it("should call props.setReleasedToStudents when release button is clicked", async () => { props.marking_state = "complete"; props.released_to_students = false; props.can_release = true; render(); const element = screen.getByRole("button", {name: I18n.t("submissions.release_marks")}); - fireEvent.click(element); + await userEvent.click(element); expect(props.setReleasedToStudents).toHaveBeenCalled(); });