Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FE] Implement Glossary Page and Tag Type Pages #694

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/src/components/SubtypeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/TagType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export default function SubtypePage() {
{/* Render the description based on typeId */}
<div className="mb-6 text-lg text-gray-700">{description}</div>

{/* Tags in this Category Section */}
{/* Tags in this type */}
<h2 className="mb-4 text-2xl font-semibold text-gray-800">
Tags in This Category:
</h2>
Expand Down
79 changes: 79 additions & 0 deletions frontend/src/routes/glossary.test.tsx
Original file line number Diff line number Diff line change
@@ -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(
<MemoryRouter initialEntries={["/glossary"]}>
<Routes>
<Route path="/glossary" element={<GlossaryPage />} />
</Routes>
</MemoryRouter>,
);

// Check if glossary title is rendered
expect(screen.getByText(/Explore Various Tag Types/i)).toBeInTheDocument();
});

it("renders tag counts and descriptions correctly", () => {
render(
<MemoryRouter initialEntries={["/glossary"]}>
<Routes>
<Route path="/glossary" element={<GlossaryPage />} />
</Routes>
</MemoryRouter>,
);
});

it("renders error alert when there is an error", () => {
(useSearchTags as Mock).mockReturnValue({
data: null,
isLoading: false,
error: new Error("Something went wrong"),
});

render(
<MemoryRouter initialEntries={["/glossary"]}>
<Routes>
<Route path="/glossary" element={<GlossaryPage />} />
</Routes>
</MemoryRouter>,
);
});
});
1 change: 1 addition & 0 deletions frontend/src/routes/glossary.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
];
Expand Down
Loading