Skip to content

Commit

Permalink
Updates after initial review
Browse files Browse the repository at this point in the history
  • Loading branch information
david-yz-liu committed Jan 12, 2025
1 parent 30c19ed commit 22fb1cf
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 33 deletions.
13 changes: 0 additions & 13 deletions app/javascript/Components/Result/submission_selector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const createExampleForm = () => {
describe("GraderDistributionModal", () => {
let props;
const form1 = createExampleForm();

beforeEach(() => {
props = {
graders: [
Expand Down
5 changes: 3 additions & 2 deletions app/javascript/Components/__tests__/student_table.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,15 @@ 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);

await fireEvent.change(fileInput, {
target: {files: [{name: "file1.txt"}]},
});
await userEvent.selectOptions(renameToInput, "q1.py");
await userEvent.click(submit);

// Ensure onSubmit is not called
expect(mockOnSubmit).not.toHaveBeenCalled();
Expand Down
33 changes: 17 additions & 16 deletions app/javascript/Components/__tests__/submission_selector.test.jsx
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -27,6 +28,7 @@ const basicProps = {
available_tags: [],
can_release: false,
course_id: 1,
criterionSummaryData: [],
current_tags: [],
filterData: INITIAL_FILTER_MODAL_STATE,
fullscreen: false,
Expand Down Expand Up @@ -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(<SubmissionSelector {...props} />);
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(<SubmissionSelector {...props} />);
const button = screen.getByTitle(I18n.t("results.previous_submission"), {exact: false});
fireEvent.click(button);
await userEvent.click(button);

expect(props.previousSubmission).toHaveBeenCalled();
});
Expand All @@ -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(<SubmissionSelector {...props} />);
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", () => {
Expand All @@ -118,19 +119,19 @@ describe("SubmissionSelector", () => {
expect(screen.getByText(expected_display)).toBeTruthy();
});

it("can toggle into fullscreen", () => {
it("can toggle into fullscreen", async () => {
render(<SubmissionSelector {...props} />);
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(<SubmissionSelector {...props} />);
const button = screen.getByTitle(I18n.t("results.fullscreen_exit"), {exact: false});
fireEvent.click(button);
await userEvent.click(button);

expect(props.toggleFullscreen).toHaveBeenCalled();
});
Expand Down Expand Up @@ -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(<SubmissionSelector {...props} />);
const element = screen.getByRole("button", {name: I18n.t("submissions.release_marks")});
fireEvent.click(element);
await userEvent.click(element);

expect(props.setReleasedToStudents).toHaveBeenCalled();
});
Expand Down

0 comments on commit 22fb1cf

Please sign in to comment.