Skip to content

Commit

Permalink
test: implement unit tests for frontend components
Browse files Browse the repository at this point in the history
  • Loading branch information
Raine-Yang-UofT committed Feb 6, 2025
1 parent 3a18459 commit cd0d1c6
Showing 1 changed file with 69 additions and 1 deletion.
70 changes: 69 additions & 1 deletion app/javascript/Components/__tests__/assignment_summary.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import {AssignmentSummaryTable} from "../assignment_summary_table";
import {render, screen, fireEvent} from "@testing-library/react";
import {render, screen, fireEvent, waitFor} from "@testing-library/react";

describe("For the AssignmentSummaryTable's display of inactive groups", () => {
let groups_sample;
Expand Down Expand Up @@ -95,3 +95,71 @@ describe("For the AssignmentSummaryTable's display of inactive groups", () => {
expect(screen.queryByText(/group_0001/)).not.toBeInTheDocument();
});
});

describe("For the AssignmentSummaryTable's display of an assignment with automated testing", () => {
beforeEach(() => {
fetch.mockReset();
fetch.mockResolvedValueOnce(
Promise.resolve({
ok: true,
json: jest.fn().mockResolvedValueOnce({
data: [],
criteriaColumns: [],
numAssigned: 0,
numMarked: 0,
enableTest: true,
ltiDeployments: [],
}),
})
);

render(
<AssignmentSummaryTable
assignment_id={1}
course_id={1}
is_instructor={true}
lti_deployments={[]}
/>
);
});

it("should render the Download Test Results button", async () => {
await waitFor(() => {
expect(screen.getByText(/download test results/i)).toBeInTheDocument();
});
});
});

describe("For the AssignmentSummaryTable's display of an assignment without automated testing", () => {
beforeEach(() => {
fetch.mockReset();
fetch.mockResolvedValueOnce(
Promise.resolve({
ok: true,
json: jest.fn().mockResolvedValueOnce({
data: [],
criteriaColumns: [],
numAssigned: 0,
numMarked: 0,
enableTest: false,
ltiDeployments: [],
}),
})
);

render(
<AssignmentSummaryTable
assignment_id={1}
course_id={1}
is_instructor={true}
lti_deployments={[]}
/>
);
});

it("should not render the Download Test Results button", async () => {
await waitFor(() => {
expect(screen.queryByText(/download test results/i)).not.toBeInTheDocument();
});
});
});

0 comments on commit cd0d1c6

Please sign in to comment.