From 67126f2df1677778f37982ceb8f51070da99e1f5 Mon Sep 17 00:00:00 2001 From: mhenriette Date: Thu, 23 May 2024 11:52:45 +0200 Subject: [PATCH 1/7] feat: add community tests --- __mocks__/bounty.ts | 11 ++ __mocks__/challenge.ts | 150 ++++++++++++++++++ __mocks__/community.ts | 57 +++++++ __mocks__/course.ts | 133 ++++++++++++++++ __mocks__/referrals.ts | 37 +++++ __mocks__/scoreboard.ts | 19 +++ .../communities/_partials/Header.test.tsx | 34 ++++ .../communities/_partials/Section.test.tsx | 29 ++++ .../communities/overview/Courses.test.tsx | 19 +++ .../communities/overview/MainHeader.test.tsx | 14 ++ .../communities/overview/Sidebar.test.tsx | 21 +++ .../communities/overview/Wrapper.test.tsx | 23 +++ .../_partials/SectionWrapper.test.tsx | 31 ++++ .../overview/scoreboard/Filter.test.tsx | 57 +++++++ .../_partials/FilterOption.test.tsx | 20 +++ .../overview/scoreboard/index.test.tsx | 50 ++++++ src/components/cards/course/index.tsx | 6 +- .../communities/_partials/Section.tsx | 2 +- .../communities/overview/MainHeader.tsx | 8 +- .../sections/communities/overview/Sidebar.tsx | 8 +- .../sections/communities/overview/Wrapper.tsx | 5 +- .../overview/scoreboard/Filter.tsx | 4 +- .../communities/overview/scoreboard/index.tsx | 8 +- src/types/bounty.d.ts | 2 +- src/types/community.d.ts | 4 +- src/types/course.d.ts | 4 +- tsconfig.json | 3 +- 27 files changed, 739 insertions(+), 20 deletions(-) create mode 100644 __mocks__/bounty.ts create mode 100644 __mocks__/challenge.ts create mode 100644 __mocks__/community.ts create mode 100644 __mocks__/course.ts create mode 100644 __mocks__/referrals.ts create mode 100644 __mocks__/scoreboard.ts create mode 100644 __tests__/components/sections/communities/_partials/Header.test.tsx create mode 100644 __tests__/components/sections/communities/_partials/Section.test.tsx create mode 100644 __tests__/components/sections/communities/overview/Courses.test.tsx create mode 100644 __tests__/components/sections/communities/overview/MainHeader.test.tsx create mode 100644 __tests__/components/sections/communities/overview/Sidebar.test.tsx create mode 100644 __tests__/components/sections/communities/overview/Wrapper.test.tsx create mode 100644 __tests__/components/sections/communities/overview/_partials/SectionWrapper.test.tsx create mode 100644 __tests__/components/sections/communities/overview/scoreboard/Filter.test.tsx create mode 100644 __tests__/components/sections/communities/overview/scoreboard/_partials/FilterOption.test.tsx create mode 100644 __tests__/components/sections/communities/overview/scoreboard/index.test.tsx diff --git a/__mocks__/bounty.ts b/__mocks__/bounty.ts new file mode 100644 index 00000000..96be6792 --- /dev/null +++ b/__mocks__/bounty.ts @@ -0,0 +1,11 @@ + +export const mockTrailer = { + summary: "trailer summary", + description: "trailer descriptio", + video: "trailer video", + duration: 4, + info: { + items: ["item 1", "item 2"], + title: "info title", + }, +}; \ No newline at end of file diff --git a/__mocks__/challenge.ts b/__mocks__/challenge.ts new file mode 100644 index 00000000..f41a7873 --- /dev/null +++ b/__mocks__/challenge.ts @@ -0,0 +1,150 @@ +import { mockFormat, mockCertificateData, mockCourse, mockLearningModule, mockRatingCriteria } from "./course"; +import { mockCommunity, metadata } from "./community"; +import { reward } from "./reward"; +import { KYCSTATUS } from "@/store/feature/kyc.slice"; +import { Submission, User } from "@/types/bounty"; +import { AdditionalInfo } from "@/types/course"; +import { TEAM_FORMATION } from "@/constants/challengeInfo"; +import { Team, TeamMember } from "@/types/challenge"; + +export const mockUser = (): User => ({ + id: "user_id", + ref: "ref", + created_at: new Date("2022-05-01T12:00:00Z"), + firstName: "John Doe", + displayName: "John Doe", + uid: "uuid-uuido-232-dex0232-2331", + joined: "14 days ago", + disabled: false, + reputation: 0, + username: "", + lastName: "", + emailVerified: false, + email: "", + kycStatus: KYCSTATUS.PENDING, +}); + +export const mockAdditionalInfo: {[type: string]: AdditionalInfo } = { + "type": {type: "additional type", text: "additional text"}, +} + +export const challenge = () => ({ + id: "challenge", + ref: "challenge ref", + created_at: new Date("2022-05-01T12:00:00Z"), + updated_at: new Date("2022-05-01T12:00:00Z"), + hint: "Hint", + name: "challenge name", + format: mockFormat, + description: "challenge description", + course: mockCourse, + type: "course", + isTeamChallenge: false, + objectives: ["objectives 1", "Objectives 2", "Objectives 3", "Objectives 4"], + threshold: 8, + community: mockCommunity, + reviewTime: 9, + metadata: metadata, + level: 58, + courses: [mockCourse], + learningModules: [mockLearningModule], + expiresAt: "2025", + reward: reward, + certificateIcon: "certificate", + certificateData: mockCertificateData, + ratingCriteria: [mockRatingCriteria], + timestamp: 6, + maxPoints: 299, + minPoints: 9, + rewards: [reward], + feedbacks: {}, + feedbackInfo: [{}], + bestSubmissions: [{}], + teamLimit: 5, + isHackathon: false, + additionalInfo: { + [TEAM_FORMATION]: { + type: 'teamFormation', + text: 'Form your team details here' + } + } +}); + +export const submission = (): Submission => ({ + length: 0, + id: "submission_id", + ref: "reference", + created_at: new Date("2022-05-01T12:00:00Z"), + updated_at: new Date("2022-05-01T12:00:00Z"), + link: "/submissions/reference", + community: mockCommunity, + user_id: "user_id", + challenge: challenge(), + text: "Submission", + reviewDeadline: new Date(), + metadata: { + evaluation: "", + applicableReward: { + ref: "", + amount: 0, + updated_at: "", + challenge: "", + created_at: "", + id: "", + type: "", + community: "", + timestamp: 0, + token: "", + }, + reviewed: false, + feedbacks: 0, + language: "", + }, + timestamp: 0, + user: mockUser(), + reviewable: false, + status: "", + reward: reward, + map: function () { + throw new Error("Function not implemented."); + }, +}); + +export const mockInvite = { + created_at: "tuesday", + id: "invite", + ref: "invitation ref", + status: "invitation status", + team_ref: "team reference", + timestamp: 3, + updated_at: "wednesday", + user: mockUser(), + user_id: "user id", +} + +export const mockTeamMember: TeamMember = { + created_at: "created_at", + id: "id", + joined_on: "joined_on", + ref: "ref", + team_ref: "team reference", + timestamp: 3, + updated_at: "wednesday", + user: mockUser(), +} + +export const mockTeam: Team = { + challenge: challenge(), + challenge_ref: "challenge ref", + created_at: "created at", + id: "id", + locked: true, + name: "Master", + organizer: mockUser(), + organizer_id: "organizer id", + invites: [mockInvite], + members: [mockTeamMember], + ref: "", + timestamp: "", + updated_at: "" +} \ No newline at end of file diff --git a/__mocks__/community.ts b/__mocks__/community.ts new file mode 100644 index 00000000..48a4db2f --- /dev/null +++ b/__mocks__/community.ts @@ -0,0 +1,57 @@ +import { Community } from "@/types/community"; +import { colors } from "./colors"; + +export const metadata = { + invite_id: "abc123", + submissions: 5, + bestSubmissions: ["submission1", "submission2"], + feedbacks: 10, + name: "Project XYZ", + issuedOn: "2024-01-29T12:00:00Z", + image: "image_url", + title: "Title of the project", + description: "Description of the project", + narrative: "Narrative of the project", + recipientName: "John Doe", + issuerName: "Jane Smith", + comment: "This is a comment", + linkToWork: "link_to_work", + submission: "submission_details", +}; + +const reward = { + id: "123456789", + ref: "ref123", + created_at: new Date("2024-01-29T08:00:00Z"), + updated_at: new Date("2024-01-29T08:30:00Z"), + challenge: "Challenge Name", + type: "SUBMISSION", + community: "Community Name", + token: "Token ID", + stable: true, + amount: 100, + timestamp: 1643424000, +}; + +export const mockCommunity: Community = { + id: "ew-43", + ref: "community/ref", + created_at: new Date("2022-05-01T12:00:00Z"), + updated_at: new Date("2022-05-01T12:00:00Z"), + summary: "this is the summary", + icon: "public/img/communities/aeternity.svg", + name: "aeternity", + image: "public/img/communities/aeternity.svg", + colors: colors, + slug: "ae", + active: true, + description: "this is a aeternity community", + metadata, + timestamp: 182044800000, + rewards: [reward], + reward, + courses: 3, + duration: 4, + can_mint_certificates: true, + challenges: 3, +}; \ No newline at end of file diff --git a/__mocks__/course.ts b/__mocks__/course.ts new file mode 100644 index 00000000..ca736769 --- /dev/null +++ b/__mocks__/course.ts @@ -0,0 +1,133 @@ +import { Course, Format, LearningModule, Material } from "@/types/course"; +import { mockTrailer } from "./bounty"; + + +export const Introduction = { + text: "course intro", +}; + +export const mockCertificateData = { + narrative: "course certificate", + icon: "certificate icon", +}; + +export const Rubric = { + id: "id", + ref: "rubric references", + created_at: "Wednesday", + updated_at: "Thursday", + challenge: "Challenge", + text: "Challenge text", + type: "challenge type", + order: 89, + points: 90, + timestamp: 73, + typeSlug: "slug", +}; + +export const mockRatingCriteria = { + name: "rating criteria", + order: 4, + rubric: [Rubric], + maxPoints: 78, +}; + +enum MaterialType { + ADDITIONAL = "ADDITIONAL", + MARKDOWN = "MARKDOWN", + TEXT = "TEXT", + ARTICLE = "ARTICLE", + "EMBEDDED-VIDEO" = "EMBEDDED-VIDEO", +} +export const mockMaterial: Material = { + duration: 3, + subtitle: "material subtitle", + link: "material link", + description: "material description", + title: "material title", + type: MaterialType.ADDITIONAL, + list: [{ link: "Link 1" }], +}; + +export const InteractiveModule = { + ref: "interactive module ref", + title: "interactive module title", + text: "interative text", + closing: { + text: "closing", + title: "title", + }, + items: [ + { + text: "text", + title: "title", + options: { + text: "text", + isCorrect: true, + }, + question: { + title: "question title", + answers: ["answer 1", "answer 2"], + correct: 2, + }, + }, + ], +}; + +export const mockLearningModule: LearningModule = { + id: "learningModule id", + ref: "learning module reference", + created_at: new Date("2022-05-01T12:00:00Z"), + updated_at: new Date("2022-05-01T12:00:00Z"), + duration: 4, + description: "learning module description", + objectives: ["objective 1, objective 2"], + title: "learning module title", + community: "learning module community", + materials: [mockMaterial], + timestamp: 3, + order: 4, + course: "Learning module course", + interactiveModules: [InteractiveModule], +}; + +export const mockCourse: Course = { + id: "course", + ref: "course ref", + created_at: new Date("2022-05-01T12:00:00Z"), + updated_at: new Date("2022-05-01T12:00:00Z"), + duration: 3, + summary: "Course description", + level: 3, + name: "course name", + description: "Course description", + objectives: ["course description", "course objectives"], + locale: "English", + community: "community", + slug: "course description slug", + introduction: Introduction, + active: true, + certificateIcon: "certificate", + certificateData: mockCertificateData, + timestamp: 0, + learningModules: [mockLearningModule], + trailer: mockTrailer, + disclaimer: "Course", + items: ["item 1", "item 2"], + faq: [ + { + description: "faq description", + title: "faq title", + }, + ], + prerequisite: { + items: ["item 1", "item 2"], + hint: "prerequisite hint", + }, +}; + +export const mockFormat: Format = { + githubLink: true, + text: true, + disclaimer: true, +}; \ No newline at end of file diff --git a/__mocks__/referrals.ts b/__mocks__/referrals.ts new file mode 100644 index 00000000..f41dca81 --- /dev/null +++ b/__mocks__/referrals.ts @@ -0,0 +1,37 @@ +import { Referral, UserReferral } from "@/types/community"; +import { mockCommunity } from "./community"; +import { challenge, mockUser, submission as getMockSubmission } from "./challenge"; + + +const referralSubmission = () => Object.assign(getMockSubmission(), { challengeData: challenge(), link: "referral-link" }); +const userReferral: UserReferral = Object.assign(mockUser(), { submissions: [referralSubmission()] }); + +export const mockReferral = (): Referral => ({ + id: "", + name: "", + ref: "", + created_at: new Date("2022-05-01T12:00:00Z"), + updated_at: new Date("2022-05-01T12:00:00Z"), + title: "", + community: mockCommunity, + timestamp: 0, + reward: { + id: "", + ref: "", + created_at: new Date("2022-05-01T12:00:00Z"), + updated_at: new Date("2022-05-01T12:00:00Z"), + challenge: "", + type: "", + community: "", + token: "", + stable: false, + fiatCurrency: undefined, + amount: 0, + timestamp: 0, + distribution: undefined, + }, + challenge: challenge(), + submissions: [getMockSubmission()], + rewarded: false, + user: userReferral, +}); \ No newline at end of file diff --git a/__mocks__/scoreboard.ts b/__mocks__/scoreboard.ts new file mode 100644 index 00000000..0db536f3 --- /dev/null +++ b/__mocks__/scoreboard.ts @@ -0,0 +1,19 @@ +import { Scoreboard } from "@/types/scoreboard"; +import { mockUser } from "./challenge"; + +export const mockScoreboard: Scoreboard = { + id: "id", + ref: "ref", + created_at: "Monday", + updated_at: "February", + score: 3, + user_id: "user_id", + submissions: 3, + submissionPoints: 4, + feedbacks: 0, + type: "feedback", + entity: "feedback entity", + feedbackPoints: 0, + timestamp: 4, + user: mockUser(), +} \ No newline at end of file diff --git a/__tests__/components/sections/communities/_partials/Header.test.tsx b/__tests__/components/sections/communities/_partials/Header.test.tsx new file mode 100644 index 00000000..56eb36f3 --- /dev/null +++ b/__tests__/components/sections/communities/_partials/Header.test.tsx @@ -0,0 +1,34 @@ +import Header from "@/components/sections/communities/_partials/Header"; +import { render, screen } from "@testing-library/react"; +import "@testing-library/jest-dom"; + +describe("Header", () => { + it("renders the Header with Props", () => { + render(
); + expect(screen.getByText("Test Description")).toBeInTheDocument(); + expect(screen.getByText("Test Title")).toBeInTheDocument(); + expect(screen.getByText("Test Subtitle")).toBeInTheDocument(); + expect(screen.getByText("Hackathon")).toBeInTheDocument(); + }); + + it("does not render subtitle when not provided", () => { + render(
); + expect(screen.queryByText("Test Subtitle")).not.toBeInTheDocument(); + }); + + it("conditionally renders the description", () => { + render(
); + expect(screen.getByText("Test Description")).toBeInTheDocument(); + }); + + it("renders 'TEAM' tag when isTeamChallenge is true and isHackathon is false", () => { + render(
); + expect(screen.getByText("TEAM")).toBeInTheDocument(); + }); + + it("does not render 'TEAM' or 'Hackathon' tag when isTeamChallenge is false", () => { + render(
); + expect(screen.queryByText("TEAM")).not.toBeInTheDocument(); + expect(screen.queryByText("Hackathon")).not.toBeInTheDocument(); + }); +}); diff --git a/__tests__/components/sections/communities/_partials/Section.test.tsx b/__tests__/components/sections/communities/_partials/Section.test.tsx new file mode 100644 index 00000000..1f1721d1 --- /dev/null +++ b/__tests__/components/sections/communities/_partials/Section.test.tsx @@ -0,0 +1,29 @@ +import Section from "@/components/sections/communities/_partials/Section"; +import "@testing-library/jest-dom"; +import { render, screen } from "@testing-library/react"; + +describe("section", () => { + it("should render section", () => { + render(
); + const communitySection = screen.getByTestId("sectionId"); + expect(communitySection).toBeInTheDocument(); + }); + + it("should render section with title and subtitle", () => { + render(
); + const communitySectionTitle = screen.getByText("section title"); + expect(communitySectionTitle).toBeInTheDocument(); + const communitySectionSubTitle = screen.getByText("section subtitle"); + expect(communitySectionSubTitle).toBeInTheDocument(); + }); + + it("should render with children", () => { + render( +
+
community section child
+
+ ); + const communitySectionChildren = screen.getByText("community section child"); + expect(communitySectionChildren).toBeInTheDocument(); + }); +}); diff --git a/__tests__/components/sections/communities/overview/Courses.test.tsx b/__tests__/components/sections/communities/overview/Courses.test.tsx new file mode 100644 index 00000000..89a07791 --- /dev/null +++ b/__tests__/components/sections/communities/overview/Courses.test.tsx @@ -0,0 +1,19 @@ +import "@testing-library/jest-dom"; +import { screen } from "@testing-library/react"; +import { CoursesOverview } from "@/components/sections/communities/overview/Courses"; +import { renderWithRedux } from "@__mocks__/renderWithRedux"; +import { mockCourse } from "@__mocks__/course"; +import { mockCommunity } from "@__mocks__/community"; + +describe("CoursesOverview", () => { + it("renders the courses overview section with course cards", () => { + renderWithRedux(, { + courses: { current: mockCourse, list: [mockCourse], content: mockCourse.community, count: 1, menus: [] }, + community: { current: mockCommunity, list: [mockCommunity], courses: [mockCourse], status: "succeeded", error: "" }, + }); + expect(screen.getByText("communities.overview.courses.title")).toBeInTheDocument(); + [mockCourse].forEach((course) => { + expect(screen.getByText(course.name)).toBeInTheDocument(); + }); + }); +}); diff --git a/__tests__/components/sections/communities/overview/MainHeader.test.tsx b/__tests__/components/sections/communities/overview/MainHeader.test.tsx new file mode 100644 index 00000000..31c79962 --- /dev/null +++ b/__tests__/components/sections/communities/overview/MainHeader.test.tsx @@ -0,0 +1,14 @@ +import "@testing-library/jest-dom"; +import { screen } from "@testing-library/react"; +import CommunitySection from "@/components/sections/communities/overview/MainHeader"; +import { renderWithRedux } from "@__mocks__/renderWithRedux"; + +describe("MainHeader", () => { + it("displays the header", () => { + renderWithRedux(); + + expect(screen.getByTestId("mainHeaderId")).toBeInTheDocument(); + expect(screen.getByText("communities.submissions")).toBeInTheDocument(); + expect(screen.getByText("communities.feedbacks")).toBeInTheDocument(); + }); +}); diff --git a/__tests__/components/sections/communities/overview/Sidebar.test.tsx b/__tests__/components/sections/communities/overview/Sidebar.test.tsx new file mode 100644 index 00000000..6d258da4 --- /dev/null +++ b/__tests__/components/sections/communities/overview/Sidebar.test.tsx @@ -0,0 +1,21 @@ +import "@testing-library/jest-dom"; +import { screen } from "@testing-library/react"; +import { renderWithRedux } from "@__mocks__/renderWithRedux"; +import Sidebar from "@/components/sections/communities/overview/Sidebar"; +import { mockCourse } from "@__mocks__/course"; +import { mockCommunity } from "@__mocks__/community"; + +jest.mock("next/router", () => ({ + useRouter: () => ({ + asPath: "next", + }), +})); + +describe("Sidebar", () => { + it("displays the sidebar", () => { + renderWithRedux(, { community: { current: mockCommunity, list: [mockCommunity], courses: [mockCourse], status: "succeeded", error: "" } }); + expect(screen.getByTestId("sidebarId")).toBeInTheDocument(); + expect(screen.getByText("communities.overview.challenges.title")).toBeInTheDocument(); + expect(screen.getByText("communities.overview.challenges.description")).toBeInTheDocument(); + }); +}); diff --git a/__tests__/components/sections/communities/overview/Wrapper.test.tsx b/__tests__/components/sections/communities/overview/Wrapper.test.tsx new file mode 100644 index 00000000..681f5e51 --- /dev/null +++ b/__tests__/components/sections/communities/overview/Wrapper.test.tsx @@ -0,0 +1,23 @@ +import "@testing-library/jest-dom"; +import { screen } from "@testing-library/react"; +import { renderWithRedux } from "@__mocks__/renderWithRedux"; +import Wrapper from "@/components/sections/communities/overview/Wrapper"; + +jest.mock("next/router", () => ({ + useRouter: () => ({ + asPath: "next", + }), +})); + +describe("Wrapper", () => { + it("displays the wrapper", () => { + renderWithRedux( + Test Filter}> +
Wrappper test
+
+ ); + expect(screen.getByTestId("wrapperId")).toBeInTheDocument(); + expect(screen.getByText("Wrappper test")).toBeInTheDocument(); + expect(screen.getByText("Test Filter")).toBeInTheDocument(); + }); +}); diff --git a/__tests__/components/sections/communities/overview/_partials/SectionWrapper.test.tsx b/__tests__/components/sections/communities/overview/_partials/SectionWrapper.test.tsx new file mode 100644 index 00000000..3fb4ea71 --- /dev/null +++ b/__tests__/components/sections/communities/overview/_partials/SectionWrapper.test.tsx @@ -0,0 +1,31 @@ +import { render, screen } from "@testing-library/react"; +import "@testing-library/jest-dom"; +import { SectionWrapper } from "@/components/sections/communities/overview/_partials/SectionWrapper"; + +describe("SectionWrapper", () => { + it("renders with title and description", () => { + const title = "Test Title"; + const description = "Test Description"; + render( + +
Test Children
+
+ ); + + expect(screen.getByText(title)).toBeInTheDocument(); + expect(screen.getByText(description)).toBeInTheDocument(); + expect(screen.getByText("Test Children")).toBeInTheDocument(); + }); + + it("renders without title and description", () => { + render( + +
Test Children
+
+ ); + + expect(screen.queryByText("Test Title")).not.toBeInTheDocument(); + expect(screen.queryByText("Test Description")).not.toBeInTheDocument(); + expect(screen.getByText("Test Children")).toBeInTheDocument(); + }); +}); diff --git a/__tests__/components/sections/communities/overview/scoreboard/Filter.test.tsx b/__tests__/components/sections/communities/overview/scoreboard/Filter.test.tsx new file mode 100644 index 00000000..b598fb94 --- /dev/null +++ b/__tests__/components/sections/communities/overview/scoreboard/Filter.test.tsx @@ -0,0 +1,57 @@ +import Filters, { filterOptions, sortingOptions } from "@/components/sections/communities/overview/scoreboard/Filter"; +import "@testing-library/jest-dom"; +import { fireEvent, screen } from "@testing-library/react"; +import { useRouter } from "next/router"; +import { renderWithRedux } from "@__mocks__/renderWithRedux"; + +jest.mock("next/router", () => ({ + useRouter: jest.fn(), +})); + +describe("Filter", () => { + const mockRouter = { + query: { slug: "test-slug" }, + locale: "en", + push: jest.fn(), + }; + + beforeEach(() => { + (useRouter as jest.Mock).mockReturnValue(mockRouter); + }); + + it("renders filter options", () => { + renderWithRedux(); + expect(screen.getByText("Filter by")).toBeInTheDocument(); + filterOptions.forEach((option) => { + expect(screen.getByText(option.label)).toBeInTheDocument(); + expect(screen.getByDisplayValue(option.value)).toBeInTheDocument(); + }); + }); + + it("updates filter options on change on filter", () => { + renderWithRedux(); + filterOptions.forEach((option) => { + const value = screen.getByDisplayValue(option.value); + fireEvent.change(value, { target: { value: "new filter option" } }); + expect(value.getAttribute("value")).toContain("new filter option"); + }); + }); + + it("renders sort options", () => { + renderWithRedux(); + expect(screen.getByText("Sort")).toBeInTheDocument(); + sortingOptions.forEach((option) => { + expect(screen.getByText(option.label)).toBeInTheDocument(); + expect(screen.getByDisplayValue(option.value)).toBeInTheDocument(); + }); + }); + + it("updates filter options on change on sort", () => { + renderWithRedux(); + sortingOptions.forEach((option) => { + const value = screen.getByDisplayValue(option.value); + fireEvent.change(value, { target: { value: "new filter option" } }); + expect(value.getAttribute("value")).toContain("new filter option"); + }); + }); +}); diff --git a/__tests__/components/sections/communities/overview/scoreboard/_partials/FilterOption.test.tsx b/__tests__/components/sections/communities/overview/scoreboard/_partials/FilterOption.test.tsx new file mode 100644 index 00000000..7226fb4e --- /dev/null +++ b/__tests__/components/sections/communities/overview/scoreboard/_partials/FilterOption.test.tsx @@ -0,0 +1,20 @@ +import { render, screen } from "@testing-library/react"; +import "@testing-library/jest-dom"; +import FilterOption from "@/components/sections/communities/overview/scoreboard/_partials/FilterOption"; + +describe("FilterOption", () => { + it("renders with label and is not checked by default", () => { + const label = "Test Label"; + render(); + + expect(screen.getByLabelText(label)).toBeInTheDocument(); + expect(screen.getByRole("radio")).not.toBeChecked(); + }); + + it("should be disabled when value matches data", () => { + const label = "Test Label"; + render(); + const radio = screen.getByRole("radio"); + expect(radio).toBeDisabled(); + }); +}); diff --git a/__tests__/components/sections/communities/overview/scoreboard/index.test.tsx b/__tests__/components/sections/communities/overview/scoreboard/index.test.tsx new file mode 100644 index 00000000..6fae3345 --- /dev/null +++ b/__tests__/components/sections/communities/overview/scoreboard/index.test.tsx @@ -0,0 +1,50 @@ +import "@testing-library/jest-dom"; +import { fireEvent, screen } from "@testing-library/react"; +import { renderWithRedux } from "@__mocks__/renderWithRedux"; +import ScoreboardOverview from "@/components/sections/communities/overview/scoreboard"; +import { mockScoreboard } from "@__mocks__/scoreboard"; + +jest.mock("next/router", () => ({ + useRouter: () => ({ + pathname: "next", + }), +})); +describe("ScoreboardOverview", () => { + let items = 3; + + const loadMore = () => { + items = items + 10; + }; + + it("displays the scoreboard overview", () => { + renderWithRedux(, { + scoreboard: { list: [mockScoreboard], loading: true, filterBy: "" }, + }); + expect(screen.getByTestId("scoreboardId")).toBeInTheDocument(); + }); + + it("renders scoreboard cards when not loading and list is not empty", () => { + renderWithRedux(, { + scoreboard: { list: [mockScoreboard], loading: false, filterBy: "" }, + }); + if ([mockScoreboard] && [mockScoreboard].length !== 0) { + [mockScoreboard].slice(0, items).forEach((item) => { + expect(screen.getByText(item.user.displayName)).toBeInTheDocument(); + }); + } else { + expect(screen.getByText("communities.scoreboard.empty-state.title")).toBeInTheDocument(); + } + }); + + it("renders button when items are less that the list size", () => { + renderWithRedux(, { + scoreboard: { list: [mockScoreboard], loading: false, filterBy: "" }, + }); + if (items < [mockScoreboard].length) { + const button = screen.getByTestId("button"); + expect(button).toBeInTheDocument(); + fireEvent.click(button); + expect(loadMore).toHaveBeenCalled(); + } + }); +}); diff --git a/src/components/cards/course/index.tsx b/src/components/cards/course/index.tsx index 9954440a..73657b65 100644 --- a/src/components/cards/course/index.tsx +++ b/src/components/cards/course/index.tsx @@ -34,7 +34,7 @@ interface CourseCardProps { export default function CourseCard({ course, community }: CourseCardProps): ReactElement { const { t } = useTranslation(); - const path = `/communities/${community.slug}/courses/${course.slug}`; + const path = `/communities/${community?.slug}/courses/${course.slug}`; const reward = course?.challenge?.rewards?.find((entity) => entity.type === "SUBMISSION"); return ( @@ -74,8 +74,8 @@ export default function CourseCard({ course, community }: CourseCardProps): Reac {t(`course.challenge.certificate`)} +
{title &&

{title}

}

{subtitle}

{children}
diff --git a/src/components/sections/communities/overview/MainHeader.tsx b/src/components/sections/communities/overview/MainHeader.tsx index 69fdedf0..d5fe37cb 100644 --- a/src/components/sections/communities/overview/MainHeader.tsx +++ b/src/components/sections/communities/overview/MainHeader.tsx @@ -4,6 +4,10 @@ import { useTranslation } from "next-i18next"; import Image from "next/image"; import { ReactElement } from "react"; +interface CommunitySectionProps { + testId?: string; +} + /** * Represents the Community Section * @date 4/13/2023 - 5:56:41 AM @@ -11,7 +15,7 @@ import { ReactElement } from "react"; * @export * @returns {ReactElement} */ -export default function CommunitySection(): ReactElement { +export default function CommunitySection({ testId }: CommunitySectionProps): ReactElement { const { t } = useTranslation(); const community = useSelector((state) => state.communities.current); @@ -20,7 +24,7 @@ export default function CommunitySection(): ReactElement { return (
-
+

{community?.name}

diff --git a/src/components/sections/communities/overview/Sidebar.tsx b/src/components/sections/communities/overview/Sidebar.tsx index 6c56d0d9..94ed1ed0 100644 --- a/src/components/sections/communities/overview/Sidebar.tsx +++ b/src/components/sections/communities/overview/Sidebar.tsx @@ -3,6 +3,10 @@ import Link from "next/link"; import { useRouter } from "next/router"; import { useTranslation } from "next-i18next"; +interface SidebarProps { + testId?: string; +} + /** * @interface SidebarProps * @description The props for the Sidebar component. @@ -13,7 +17,7 @@ import { useTranslation } from "next-i18next"; * @param {} SidebarProps - The props for the Sidebar component. * @returns JSX.Element - The rendered Sidebar component. */ -export default function Sidebar(): JSX.Element { +export default function Sidebar({ testId }: SidebarProps): JSX.Element { const currentCommunity = useSelector((state) => state.communities.current); const hasCurrentCommunity = !!currentCommunity; // Check if currentCommunity exists const router = useRouter(); @@ -32,7 +36,7 @@ export default function Sidebar(): JSX.Element { const mainLink = hasCurrentCommunity ? `/communities/${currentCommunity.slug}` : ""; return ( -
+
{t("communities.overview.challenges.title")}
diff --git a/src/components/sections/communities/overview/Wrapper.tsx b/src/components/sections/communities/overview/Wrapper.tsx index cc010ac7..6b7da4fe 100644 --- a/src/components/sections/communities/overview/Wrapper.tsx +++ b/src/components/sections/communities/overview/Wrapper.tsx @@ -11,6 +11,7 @@ import Section from "@/components/ui/Section"; interface WrapperProps { children: ReactNode; filter?: ReactNode; + testId?: string } /** @@ -19,9 +20,9 @@ interface WrapperProps { * @returns {JSX.Element} A styled Wrapper component containing a MainHeaderSection, CommunitySidebar, * optional filter component, and children content. */ -export default function Wrapper({ children, filter }: WrapperProps): JSX.Element { +export default function Wrapper({ children, filter, testId }: WrapperProps): JSX.Element { return ( -
+
diff --git a/src/components/sections/communities/overview/scoreboard/Filter.tsx b/src/components/sections/communities/overview/scoreboard/Filter.tsx index 8bc9770a..5caad803 100644 --- a/src/components/sections/communities/overview/scoreboard/Filter.tsx +++ b/src/components/sections/communities/overview/scoreboard/Filter.tsx @@ -25,7 +25,7 @@ interface Option { * @type {Option[]} */ -const filterOptions: Option[] = [ + export const filterOptions: Option[] = [ { label: "All", value: "all", @@ -51,7 +51,7 @@ const filterOptions: Option[] = [ * @type {Option[]} */ -const sortingOptions: Option[] = [ + export const sortingOptions: Option[] = [ { label: "Reputation", value: "score", diff --git a/src/components/sections/communities/overview/scoreboard/index.tsx b/src/components/sections/communities/overview/scoreboard/index.tsx index 4631284e..3e5a899b 100644 --- a/src/components/sections/communities/overview/scoreboard/index.tsx +++ b/src/components/sections/communities/overview/scoreboard/index.tsx @@ -6,6 +6,10 @@ import { ReactElement, useState } from "react"; import Loader from "@/components/ui/Loader"; import EmptyState from "@/components/ui/EmptyState"; +interface ScoreboardOverviewProps { + testId?: string; +} + /** * Scoreboard Overview index component * @date 4/13/2023 - 10:12:04 AM @@ -14,7 +18,7 @@ import EmptyState from "@/components/ui/EmptyState"; * @returns {ReactElement} */ -export default function ScoreboardOverview(): ReactElement { +export default function ScoreboardOverview({ testId }: ScoreboardOverviewProps): ReactElement { const { t } = useTranslation(); const { list, loading } = useSelector((state) => state.scoreboard); @@ -27,7 +31,7 @@ export default function ScoreboardOverview(): ReactElement { return ( <> {loading ? ( -
+
) : list && list.length !== 0 ? ( diff --git a/src/types/bounty.d.ts b/src/types/bounty.d.ts index 8d08459a..909b665a 100644 --- a/src/types/bounty.d.ts +++ b/src/types/bounty.d.ts @@ -154,7 +154,7 @@ export interface User { connected?: boolean; }; kycStatus: KYCSTATUS; - referrals: Referral; + referrals?: [Referral]; } export interface UserMetadata { diff --git a/src/types/community.d.ts b/src/types/community.d.ts index 00e756ca..8ddedfd1 100644 --- a/src/types/community.d.ts +++ b/src/types/community.d.ts @@ -22,8 +22,8 @@ export interface Community { challenges: number; duration: number; items?: any[]; - challenge: Challenge; - submission: Submission; + challenge?: Challenge; + submission?: Submission; can_mint_certificates: boolean; } diff --git a/src/types/course.d.ts b/src/types/course.d.ts index 26237f2c..a9b5755a 100644 --- a/src/types/course.d.ts +++ b/src/types/course.d.ts @@ -23,7 +23,7 @@ export type Course = { learningModules: LearningModule[]; challenge?: Challenge; challenges?: Challenge[]; - translations: any[]; + translations?: any[]; trailer: Trailer; disclaimer: string; items?: string[]; @@ -106,7 +106,7 @@ export type Rubric = { points: number; timestamp: number; typeSlug: string; - [key: string]: any; + [key?: string]: any; }; export type Format = { diff --git a/tsconfig.json b/tsconfig.json index 9bdac449..d051c8ae 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,7 +16,8 @@ "incremental": true, "paths": { "@/*": ["./src/*"], - "react": ["./node_modules/@types/react"] + "react": ["./node_modules/@types/react"], + "@__mocks__/*": ["./__mocks__/*"] } }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "src/components/sections/learning-modules/_partials/MarkDown.jsx", "jest.config.js"], From e72e5132e8913e5d76bf9754b795bfe97bc81532 Mon Sep 17 00:00:00 2001 From: mhenriette Date: Tue, 4 Jun 2024 10:49:31 +0200 Subject: [PATCH 2/7] fix: improve the community tests --- .../communities/overview/Courses.test.tsx | 4 +- .../overview/scoreboard/Filter.test.tsx | 49 ++++++++++++++----- .../_partials/FilterOption.test.tsx | 1 - .../overview/scoreboard/index.test.tsx | 4 +- .../communities/_partials/Section.tsx | 5 +- src/types/course.d.ts | 4 +- 6 files changed, 47 insertions(+), 20 deletions(-) diff --git a/__tests__/components/sections/communities/overview/Courses.test.tsx b/__tests__/components/sections/communities/overview/Courses.test.tsx index 89a07791..f468ab80 100644 --- a/__tests__/components/sections/communities/overview/Courses.test.tsx +++ b/__tests__/components/sections/communities/overview/Courses.test.tsx @@ -13,7 +13,9 @@ describe("CoursesOverview", () => { }); expect(screen.getByText("communities.overview.courses.title")).toBeInTheDocument(); [mockCourse].forEach((course) => { - expect(screen.getByText(course.name)).toBeInTheDocument(); + const courseElement = screen.getByText(course.name); + expect(courseElement).toBeInTheDocument(); + expect(courseElement.textContent).toBe(course.name); }); }); }); diff --git a/__tests__/components/sections/communities/overview/scoreboard/Filter.test.tsx b/__tests__/components/sections/communities/overview/scoreboard/Filter.test.tsx index b598fb94..b1b83b2b 100644 --- a/__tests__/components/sections/communities/overview/scoreboard/Filter.test.tsx +++ b/__tests__/components/sections/communities/overview/scoreboard/Filter.test.tsx @@ -1,33 +1,52 @@ import Filters, { filterOptions, sortingOptions } from "@/components/sections/communities/overview/scoreboard/Filter"; import "@testing-library/jest-dom"; import { fireEvent, screen } from "@testing-library/react"; -import { useRouter } from "next/router"; import { renderWithRedux } from "@__mocks__/renderWithRedux"; -jest.mock("next/router", () => ({ - useRouter: jest.fn(), -})); - -describe("Filter", () => { +jest.mock("next/router", () => { const mockRouter = { query: { slug: "test-slug" }, locale: "en", push: jest.fn(), }; + return { + useRouter: jest.fn().mockReturnValue(mockRouter), + }; +}); - beforeEach(() => { - (useRouter as jest.Mock).mockReturnValue(mockRouter); - }); +describe("Filter", () => { it("renders filter options", () => { renderWithRedux(); expect(screen.getByText("Filter by")).toBeInTheDocument(); filterOptions.forEach((option) => { - expect(screen.getByText(option.label)).toBeInTheDocument(); - expect(screen.getByDisplayValue(option.value)).toBeInTheDocument(); + const labelElement = screen.getByText(option.label) + const valueElement = screen.getByDisplayValue(option.value) + expect(labelElement).toBeInTheDocument(); + expect(labelElement.textContent).toBe(option.label) + expect(valueElement).toBeInTheDocument(); + expect(valueElement.getAttribute("value")).toBe(option.value) }); }); + it("renders default filter and sort values", () => { + renderWithRedux(); + const defaultFilter = screen.getByDisplayValue("all"); + const defaultSort = screen.getByDisplayValue("score"); + expect(defaultFilter).toBeChecked(); + expect(defaultSort).toBeChecked(); + }); + + it("disables filter options when value matches data", () => { + renderWithRedux(); + filterOptions.forEach((option) => { + const valueElement = screen.getByDisplayValue(option.value); + if (option.value === "all") { + expect(valueElement).toBeDisabled(); + } + }); + }); + it("updates filter options on change on filter", () => { renderWithRedux(); filterOptions.forEach((option) => { @@ -41,8 +60,12 @@ describe("Filter", () => { renderWithRedux(); expect(screen.getByText("Sort")).toBeInTheDocument(); sortingOptions.forEach((option) => { - expect(screen.getByText(option.label)).toBeInTheDocument(); - expect(screen.getByDisplayValue(option.value)).toBeInTheDocument(); + const labelElement = screen.getByText(option.label) + const optionElement = screen.getByDisplayValue(option.value) + expect(labelElement).toBeInTheDocument(); + expect(labelElement.textContent).toBe(option.label); + expect(optionElement).toBeInTheDocument(); + expect(optionElement.getAttribute("value")).toBe(option.value); }); }); diff --git a/__tests__/components/sections/communities/overview/scoreboard/_partials/FilterOption.test.tsx b/__tests__/components/sections/communities/overview/scoreboard/_partials/FilterOption.test.tsx index 7226fb4e..47f181da 100644 --- a/__tests__/components/sections/communities/overview/scoreboard/_partials/FilterOption.test.tsx +++ b/__tests__/components/sections/communities/overview/scoreboard/_partials/FilterOption.test.tsx @@ -6,7 +6,6 @@ describe("FilterOption", () => { it("renders with label and is not checked by default", () => { const label = "Test Label"; render(); - expect(screen.getByLabelText(label)).toBeInTheDocument(); expect(screen.getByRole("radio")).not.toBeChecked(); }); diff --git a/__tests__/components/sections/communities/overview/scoreboard/index.test.tsx b/__tests__/components/sections/communities/overview/scoreboard/index.test.tsx index 6fae3345..203a14f6 100644 --- a/__tests__/components/sections/communities/overview/scoreboard/index.test.tsx +++ b/__tests__/components/sections/communities/overview/scoreboard/index.test.tsx @@ -29,7 +29,9 @@ describe("ScoreboardOverview", () => { }); if ([mockScoreboard] && [mockScoreboard].length !== 0) { [mockScoreboard].slice(0, items).forEach((item) => { - expect(screen.getByText(item.user.displayName)).toBeInTheDocument(); + const displayNameElement = screen.getByText(item.user.displayName); + expect(displayNameElement).toBeInTheDocument(); + expect(displayNameElement).toHaveTextContent(item.user.displayName) }); } else { expect(screen.getByText("communities.scoreboard.empty-state.title")).toBeInTheDocument(); diff --git a/src/components/sections/communities/_partials/Section.tsx b/src/components/sections/communities/_partials/Section.tsx index 251aaa63..f75ad043 100644 --- a/src/components/sections/communities/_partials/Section.tsx +++ b/src/components/sections/communities/_partials/Section.tsx @@ -16,6 +16,7 @@ interface SectionProps { className?: string; hideSubtitleOnMobile?: boolean; children?: ReactNode; + testId?:string } /** @@ -33,9 +34,9 @@ interface SectionProps { } * @returns {ReactElement} */ -export default function Section({ title, titleBold = true, subtitle, id, hideSubtitleOnMobile = false, children, className }: SectionProps): ReactElement { +export default function Section({ title, testId="sectionId", titleBold = true, subtitle, id, hideSubtitleOnMobile = false, children, className }: SectionProps): ReactElement { return ( -
+
{title &&

{title}

}

{subtitle}

{children}
diff --git a/src/types/course.d.ts b/src/types/course.d.ts index a9b5755a..26237f2c 100644 --- a/src/types/course.d.ts +++ b/src/types/course.d.ts @@ -23,7 +23,7 @@ export type Course = { learningModules: LearningModule[]; challenge?: Challenge; challenges?: Challenge[]; - translations?: any[]; + translations: any[]; trailer: Trailer; disclaimer: string; items?: string[]; @@ -106,7 +106,7 @@ export type Rubric = { points: number; timestamp: number; typeSlug: string; - [key?: string]: any; + [key: string]: any; }; export type Format = { From 9a7c4968107555f4789f178d940392360c9f0a89 Mon Sep 17 00:00:00 2001 From: mhenriette Date: Tue, 4 Jun 2024 12:18:56 +0200 Subject: [PATCH 3/7] fix: connect label to its respective radio button --- .../overview/scoreboard/_partials/FilterOption.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/sections/communities/overview/scoreboard/_partials/FilterOption.tsx b/src/components/sections/communities/overview/scoreboard/_partials/FilterOption.tsx index 455c7a28..d5c63e2b 100644 --- a/src/components/sections/communities/overview/scoreboard/_partials/FilterOption.tsx +++ b/src/components/sections/communities/overview/scoreboard/_partials/FilterOption.tsx @@ -31,11 +31,13 @@ interface FilterOptionProps extends HTMLProps { */ export default function FilterOption({ label = "", value = "", data = "", name = "", ...props }: FilterOptionProps): ReactElement { const isChecked = useMemo(() => value.toString().toLowerCase() === data.toLowerCase(), [data, value]); + const id = `filter-option-${value}`; return (
- +
); - const communitySectionChildren = screen.getByText("community section child"); - expect(communitySectionChildren).toBeInTheDocument(); + expect(screen.getByText("community section child")).toBeInTheDocument(); }); }); diff --git a/__tests__/components/sections/communities/overview/MainHeader.test.tsx b/__tests__/components/sections/communities/overview/MainHeader.test.tsx index 31c79962..1ae80c61 100644 --- a/__tests__/components/sections/communities/overview/MainHeader.test.tsx +++ b/__tests__/components/sections/communities/overview/MainHeader.test.tsx @@ -2,12 +2,24 @@ import "@testing-library/jest-dom"; import { screen } from "@testing-library/react"; import CommunitySection from "@/components/sections/communities/overview/MainHeader"; import { renderWithRedux } from "@__mocks__/renderWithRedux"; +import { mockCommunity } from "@__mocks__/community"; +import { mockCourse } from "@__mocks__/course"; +import { CommunitiesState } from "@/store/feature/community.slice"; describe("MainHeader", () => { - it("displays the header", () => { - renderWithRedux(); - - expect(screen.getByTestId("mainHeaderId")).toBeInTheDocument(); + const communityMockState = { + communities: { current: mockCommunity, courses: [mockCourse], list: [mockCommunity], status: "succeeded" as CommunitiesState["status"], error: null }, + }; + it("renders community section component", () => { + renderWithRedux(, communityMockState); + expect(screen.getByRole("heading", {name:mockCommunity.name})).toBeInTheDocument(); + const summaryElements = screen.queryAllByText(mockCommunity.summary); + summaryElements.forEach(element=>{ + expect(element).toBeInTheDocument() + }) + if(mockCommunity.icon){ + expect(screen.getByRole('img')).toBeInTheDocument() + } expect(screen.getByText("communities.submissions")).toBeInTheDocument(); expect(screen.getByText("communities.feedbacks")).toBeInTheDocument(); }); diff --git a/__tests__/components/sections/communities/overview/Sidebar.test.tsx b/__tests__/components/sections/communities/overview/Sidebar.test.tsx index 6d258da4..ebad0dae 100644 --- a/__tests__/components/sections/communities/overview/Sidebar.test.tsx +++ b/__tests__/components/sections/communities/overview/Sidebar.test.tsx @@ -12,10 +12,21 @@ jest.mock("next/router", () => ({ })); describe("Sidebar", () => { + beforeEach(() => { + renderWithRedux(, { communities: { current: mockCommunity, list: [mockCommunity], courses: [mockCourse], status: "succeeded", error: "" } }); + }); + const mainLink = `/communities/${mockCommunity.slug}`; + const scoreboardLink = `/communities/${mockCommunity.slug}/scoreboard`; + it("displays the sidebar", () => { - renderWithRedux(, { community: { current: mockCommunity, list: [mockCommunity], courses: [mockCourse], status: "succeeded", error: "" } }); - expect(screen.getByTestId("sidebarId")).toBeInTheDocument(); expect(screen.getByText("communities.overview.challenges.title")).toBeInTheDocument(); expect(screen.getByText("communities.overview.challenges.description")).toBeInTheDocument(); + expect(screen.getByText("communities.overview.scoreboard.title")).toBeInTheDocument(); + expect(screen.getByText("communities.overview.scoreboard.description")).toBeInTheDocument(); + }); + + it("renders the links correctly", () => { + expect(screen.getByRole("link", { name: "main link" })).toHaveAttribute("href", mainLink); + expect(screen.getByRole("link", { name: "scoreboard link" })).toHaveAttribute("href", scoreboardLink); }); }); diff --git a/__tests__/components/sections/communities/overview/Wrapper.test.tsx b/__tests__/components/sections/communities/overview/Wrapper.test.tsx index 681f5e51..8ddbb1d4 100644 --- a/__tests__/components/sections/communities/overview/Wrapper.test.tsx +++ b/__tests__/components/sections/communities/overview/Wrapper.test.tsx @@ -9,14 +9,17 @@ jest.mock("next/router", () => ({ }), })); + describe("Wrapper", () => { it("displays the wrapper", () => { renderWithRedux( - Test Filter
}> + Test Filter
}>
Wrappper test
); + expect(screen.getByTestId("wrapperId")).toBeInTheDocument(); + expect(screen.getByText("communities.overview.challenges.title")).toBeInTheDocument(); expect(screen.getByText("Wrappper test")).toBeInTheDocument(); expect(screen.getByText("Test Filter")).toBeInTheDocument(); }); diff --git a/__tests__/components/sections/communities/overview/_partials/SectionWrapper.test.tsx b/__tests__/components/sections/communities/overview/_partials/SectionWrapper.test.tsx index 3fb4ea71..cbcd2be7 100644 --- a/__tests__/components/sections/communities/overview/_partials/SectionWrapper.test.tsx +++ b/__tests__/components/sections/communities/overview/_partials/SectionWrapper.test.tsx @@ -11,7 +11,6 @@ describe("SectionWrapper", () => {
Test Children
); - expect(screen.getByText(title)).toBeInTheDocument(); expect(screen.getByText(description)).toBeInTheDocument(); expect(screen.getByText("Test Children")).toBeInTheDocument(); @@ -23,9 +22,8 @@ describe("SectionWrapper", () => {
Test Children
); - - expect(screen.queryByText("Test Title")).not.toBeInTheDocument(); - expect(screen.queryByText("Test Description")).not.toBeInTheDocument(); + expect(screen.queryByText("Test Title")).toBe(null); + expect(screen.queryByText("Test Description")).toBe(null); expect(screen.getByText("Test Children")).toBeInTheDocument(); }); }); diff --git a/__tests__/components/sections/communities/overview/scoreboard/index.test.tsx b/__tests__/components/sections/communities/overview/scoreboard/index.test.tsx index 203a14f6..ac6b08c3 100644 --- a/__tests__/components/sections/communities/overview/scoreboard/index.test.tsx +++ b/__tests__/components/sections/communities/overview/scoreboard/index.test.tsx @@ -17,10 +17,10 @@ describe("ScoreboardOverview", () => { }; it("displays the scoreboard overview", () => { - renderWithRedux(, { + renderWithRedux(, { scoreboard: { list: [mockScoreboard], loading: true, filterBy: "" }, }); - expect(screen.getByTestId("scoreboardId")).toBeInTheDocument(); + expect(screen.getByTestId("loader")).toBeInTheDocument(); }); it("renders scoreboard cards when not loading and list is not empty", () => { diff --git a/src/components/sections/communities/overview/MainHeader.tsx b/src/components/sections/communities/overview/MainHeader.tsx index d5fe37cb..de7889ba 100644 --- a/src/components/sections/communities/overview/MainHeader.tsx +++ b/src/components/sections/communities/overview/MainHeader.tsx @@ -3,11 +3,6 @@ import { useSelector } from "@/hooks/useTypedSelector"; import { useTranslation } from "next-i18next"; import Image from "next/image"; import { ReactElement } from "react"; - -interface CommunitySectionProps { - testId?: string; -} - /** * Represents the Community Section * @date 4/13/2023 - 5:56:41 AM @@ -15,16 +10,15 @@ interface CommunitySectionProps { * @export * @returns {ReactElement} */ -export default function CommunitySection({ testId }: CommunitySectionProps): ReactElement { +export default function CommunitySection(): ReactElement { const { t } = useTranslation(); const community = useSelector((state) => state.communities.current); - const submissions = community?.metadata?.submissions || 0; const feedbacks = community?.metadata?.feedbacks || 0; return (
-
+

{community?.name}

diff --git a/src/components/sections/communities/overview/Sidebar.tsx b/src/components/sections/communities/overview/Sidebar.tsx index ff06635b..166aeb4b 100644 --- a/src/components/sections/communities/overview/Sidebar.tsx +++ b/src/components/sections/communities/overview/Sidebar.tsx @@ -4,10 +4,6 @@ import { useRouter } from "next/router"; import { useTranslation } from "next-i18next"; import classNames from "classnames"; -interface SidebarProps { - testId?: string; -} - /** * @interface SidebarProps * @description The props for the Sidebar component. @@ -18,7 +14,7 @@ interface SidebarProps { * @param {} SidebarProps - The props for the Sidebar component. * @returns JSX.Element - The rendered Sidebar component. */ -export default function Sidebar({ testId }: SidebarProps): JSX.Element { +export default function Sidebar(): JSX.Element { const currentCommunity = useSelector((state) => state.communities.current); const hasCurrentCommunity = !!currentCommunity; // Check if currentCommunity exists const router = useRouter(); @@ -32,20 +28,19 @@ export default function Sidebar({ testId }: SidebarProps): JSX.Element { const isActive = (link: string) => { return router.asPath === link; }; - const scoreboardLink = hasCurrentCommunity ? `/communities/${currentCommunity.slug}/scoreboard` : ""; const mainLink = hasCurrentCommunity ? `/communities/${currentCommunity.slug}` : ""; return ( -
- +
+
{t("communities.overview.challenges.title")}
{t("communities.overview.challenges.description")}
{hasCurrentCommunity && ( - +