|
| 1 | +import Evaluations from "@/components/sections/submissions/Evaluation"; |
| 2 | +import { challenge, submission } from "@__mocks__/fixtures/challenge"; |
| 3 | +import { colors } from "@__mocks__/fixtures/colors"; |
| 4 | +import { renderWithRedux } from "@__mocks__/renderWithRedux"; |
| 5 | +import "@testing-library/jest-dom"; |
| 6 | +import { screen } from "@testing-library/react"; |
| 7 | + |
| 8 | +jest.mock("next/router", () => ({ |
| 9 | + useRouter: () => ({ |
| 10 | + asPath: "next", |
| 11 | + }), |
| 12 | +})); |
| 13 | + |
| 14 | +const mockEvaluationState = { |
| 15 | + ui: { colors: colors, locked: false, showReferralPopup: false, showJobOffersPopup: false }, |
| 16 | + submissions: { |
| 17 | + current: { |
| 18 | + ...submission, |
| 19 | + }, |
| 20 | + list: [submission], |
| 21 | + text: "", |
| 22 | + }, |
| 23 | + challenges: { current: challenge, list: [challenge], submission: submission, loading: false }, |
| 24 | +}; |
| 25 | + |
| 26 | +describe("Evaluations", () => { |
| 27 | + it("Should render evaluations", () => { |
| 28 | + renderWithRedux(<Evaluations />, mockEvaluationState); |
| 29 | + const evaluations = screen.getByTestId("evaluationsId"); |
| 30 | + expect(evaluations).toBeInTheDocument(); |
| 31 | + }); |
| 32 | + |
| 33 | + it("Should render RatingRubric when the challenge is present", () => { |
| 34 | + renderWithRedux(<Evaluations />, mockEvaluationState); |
| 35 | + const ratingCriteriaName = challenge.ratingCriteria[0].name; |
| 36 | + const ratingRubric = screen.getByText(ratingCriteriaName); |
| 37 | + expect(ratingRubric).toBeInTheDocument(); |
| 38 | + }); |
| 39 | + |
| 40 | + it("Should conditionally render reward information when evaluation reward is present and the challenge is not a hackathon", () => { |
| 41 | + const nonHackathonState = { |
| 42 | + ...mockEvaluationState, |
| 43 | + challenges: { |
| 44 | + ...mockEvaluationState.challenges, |
| 45 | + current: { ...challenge, isHackathon: false }, |
| 46 | + }, |
| 47 | + }; |
| 48 | + |
| 49 | + renderWithRedux(<Evaluations />, nonHackathonState); |
| 50 | + const token = submission.evaluation?.reward?.token; |
| 51 | + if (token) { |
| 52 | + expect(screen.getByText(token)).toBeInTheDocument(); |
| 53 | + } |
| 54 | + }); |
| 55 | + |
| 56 | + it("Should conditionally render reward information when evaluation.reward is present and challenge is a hackathon", () => { |
| 57 | + const hackathonState = { |
| 58 | + ...mockEvaluationState, |
| 59 | + challenges: { |
| 60 | + ...mockEvaluationState.challenges, |
| 61 | + current: { ...challenge, isHackathon: true }, |
| 62 | + }, |
| 63 | + }; |
| 64 | + |
| 65 | + renderWithRedux(<Evaluations />, hackathonState); |
| 66 | + expect(screen.getByText("USD")).toBeInTheDocument(); |
| 67 | + expect(screen.getByText("communities.challenge.evaluation.message.nominated")).toBeInTheDocument(); |
| 68 | + }); |
| 69 | +}); |
0 commit comments