From a103f21d17b18999a3e2231121fe48d2e6a28cb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asl=C4=B1=20G=C3=B6k?= Date: Mon, 16 Dec 2024 17:49:53 +0300 Subject: [PATCH 1/3] add glossary test --- frontend/src/routes/glossary.test.tsx | 79 +++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 frontend/src/routes/glossary.test.tsx diff --git a/frontend/src/routes/glossary.test.tsx b/frontend/src/routes/glossary.test.tsx new file mode 100644 index 0000000..3a84833 --- /dev/null +++ b/frontend/src/routes/glossary.test.tsx @@ -0,0 +1,79 @@ +// glossary.test.tsx +import { useSearchTags } from "@/services/api/programmingForumComponents"; +import { TagDetails } from "@/services/api/programmingForumSchemas"; +import { render, screen } from "@testing-library/react"; +import { MemoryRouter, Route, Routes } from "react-router-dom"; +import { beforeEach, describe, expect, it, Mock, vi } from "vitest"; +import GlossaryPage from "./glossary"; + +const mockTagData = vi.hoisted( + () => + ({ + tagId: "1", + name: "javascript", + description: + "A popular programming language primarily used for web development.", + questionCount: 50, + followerCount: 1000, + logoImage: "https://example.com/logo.jpg", + officialWebsite: "https://example.com", + //createdAt: "2023-01-01T00:00:00Z", + }) satisfies TagDetails, +); + +vi.mock("@/services/api/programmingForumComponents", () => ({ + useSearchTags: vi.fn(() => ({ + data: { data: { items: [mockTagData] } }, + isLoading: false, + error: null, + })), +})); + +describe("GlossaryPage", () => { + beforeEach(() => { + (useSearchTags as Mock).mockReturnValue({ + data: { data: { items: [mockTagData] } }, + isLoading: false, + error: null, + }); + }); + + it("renders glossary title correctly", () => { + render( + + + } /> + + , + ); + + // Check if glossary title is rendered + expect(screen.getByText(/Explore Various Tag Types/i)).toBeInTheDocument(); + }); + + it("renders tag counts and descriptions correctly", () => { + render( + + + } /> + + , + ); + }); + + it("renders error alert when there is an error", () => { + (useSearchTags as Mock).mockReturnValue({ + data: null, + isLoading: false, + error: new Error("Something went wrong"), + }); + + render( + + + } /> + + , + ); + }); +}); From 2922edaf7a6dc1eb5f532b32ae93c8251340d98f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asl=C4=B1=20G=C3=B6k?= Date: Mon, 16 Dec 2024 17:51:42 +0300 Subject: [PATCH 2/3] update glossary.tsx --- frontend/src/routes/glossary.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/routes/glossary.tsx b/frontend/src/routes/glossary.tsx index d05b245..7807c27 100644 --- a/frontend/src/routes/glossary.tsx +++ b/frontend/src/routes/glossary.tsx @@ -1,3 +1,4 @@ +//glossary page to display tag types import { TagSubtypeCard } from "@/components/SubtypeCard"; import { useSearchTags } from "@/services/api/programmingForumComponents"; import { TagDetails } from "@/services/api/programmingForumSchemas"; From fb0b52820b7832435d1244ee80c759c2f40258b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asl=C4=B1=20G=C3=B6k?= Date: Mon, 16 Dec 2024 17:54:34 +0300 Subject: [PATCH 3/3] add comments on changed files --- frontend/src/components/SubtypeCard.tsx | 1 + frontend/src/components/TagType.tsx | 2 +- frontend/src/routes/index.tsx | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/SubtypeCard.tsx b/frontend/src/components/SubtypeCard.tsx index 92f0c08..f8ac9a3 100644 --- a/frontend/src/components/SubtypeCard.tsx +++ b/frontend/src/components/SubtypeCard.tsx @@ -3,6 +3,7 @@ import { ArrowRight, Tags } from "lucide-react"; import React from "react"; import { Link } from "react-router-dom"; +//new card component for tag types to display in glossary interface TagSubtypeCardProps { tagSubtype: { typeId: string; diff --git a/frontend/src/components/TagType.tsx b/frontend/src/components/TagType.tsx index 4272fcf..8caac1e 100644 --- a/frontend/src/components/TagType.tsx +++ b/frontend/src/components/TagType.tsx @@ -149,7 +149,7 @@ export default function SubtypePage() { {/* Render the description based on typeId */}
{description}
- {/* Tags in this Category Section */} + {/* Tags in this type */}

Tags in This Category:

diff --git a/frontend/src/routes/index.tsx b/frontend/src/routes/index.tsx index a89fddd..6db81ff 100644 --- a/frontend/src/routes/index.tsx +++ b/frontend/src/routes/index.tsx @@ -69,11 +69,11 @@ export const routes: RouteObject[] = [ Component: CreateTagPage, }, { - path: "/glossary", + path: "/glossary", //added glossary route Component: Glossary, }, { - path: "/tagtype/:typeId", + path: "/tagtype/:typeId", //added tagtype pages' routes Component: TagTypePage, }, ];