|
| 1 | +import "@testing-library/jest-dom"; |
| 2 | +import { screen } from "@testing-library/react"; |
| 3 | +import SubmissionCard from "@/components/cards/Submission"; |
| 4 | +import { useRouter } from "next/router"; |
| 5 | +import { submission } from "@__mocks__/fixtures/challenge"; |
| 6 | +import { renderWithRedux } from "@__mocks__/renderWithRedux"; |
| 7 | + |
| 8 | +jest.mock("next/router", () => ({ |
| 9 | + useRouter: jest.fn(), |
| 10 | +})); |
| 11 | + |
| 12 | + |
| 13 | +describe("SubmissionCard", () => { |
| 14 | + beforeEach(() => { |
| 15 | + (useRouter as jest.Mock).mockReturnValue({ |
| 16 | + asPath: "/submissions", |
| 17 | + push: jest.fn(), |
| 18 | + }); |
| 19 | + }); |
| 20 | + |
| 21 | + it("renders the submission card with correct content", () => { |
| 22 | + renderWithRedux( |
| 23 | + <SubmissionCard submission={submission}> |
| 24 | + <div>testing children</div> |
| 25 | + </SubmissionCard> |
| 26 | + ); |
| 27 | + expect(screen.getByTestId("submissionId")).toBeInTheDocument(); |
| 28 | + expect(screen.getByText("Submission")).toBeInTheDocument(); |
| 29 | + expect(screen.getByText("testing children")).toBeInTheDocument(); |
| 30 | + }); |
| 31 | + |
| 32 | + it("displays evaluation points when available", () => { |
| 33 | + renderWithRedux(<SubmissionCard submission={submission} />); |
| 34 | + expect(screen.getByTestId("badgeId")).toBeInTheDocument(); |
| 35 | + expect(screen.getByText("8")).toBeInTheDocument(); |
| 36 | + expect(screen.getByText("submissions.evaluation.points")).toBeInTheDocument(); |
| 37 | + }); |
| 38 | + |
| 39 | + it("displays feedback count when available", () => { |
| 40 | + renderWithRedux(<SubmissionCard submission={submission} />); |
| 41 | + expect(screen.getByText("3")).toBeInTheDocument(); |
| 42 | + expect(screen.getByText("submissions.feedback.feedbacks")).toBeInTheDocument(); |
| 43 | + }); |
| 44 | +}); |
0 commit comments