Skip to content
Merged
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
132 changes: 132 additions & 0 deletions tests/components/notes/NoteDetailContent.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import { screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { useNoteQuery } from "@/hooks/queries/notes";
import NoteDetailContent from "@/app/(protected)/notes/_components/NoteDetailContent";
import { renderWithQueryClient } from "tests/test-utils";

jest.mock("@/hooks/queries/notes");

describe("NoteDetailContent", () => {
const setup = (noteId = 1, options?: { hasLink?: boolean }) => {
const mockNote = {
id: 1,
title: "์ฒซ ๋ฒˆ์งธ ๋…ธํŠธ",
content: JSON.stringify({
type: "doc",
content: [
{
type: "paragraph",
content: [{ type: "text", text: "์ฒซ ๋ฒˆ์งธ ๋…ธํŠธ ๋‚ด์šฉ" }],
},
],
}),
linkUrl:
options?.hasLink === false
? null
: "https://ko.wikipedia.org/wiki/์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ",
linkMetadata:
options?.hasLink === false
? null
: {
url: "https://ko.wikipedia.org/wiki/์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ",
title: "์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ - ์œ„ํ‚ค๋ฐฑ๊ณผ",
description:
"์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ๊ฐ์ฒด ๊ธฐ๋ฐ˜์˜ ์Šคํฌ๋ฆฝํŠธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ž…๋‹ˆ๋‹ค.",
image: null,
},
todo: {
id: 1,
title: "ํ•  ์ผ 1",
done: false,
fileUrl: null,
linkUrl: null,
},
goal: {
id: 1,
title: "๋ชฉํ‘œ 1",
},
createdAt: "2026-01-18T09:00:00Z",
updatedAt: "2026-01-18T10:00:00Z",
teamId: "team-1",
userId: 1,
};

jest.mocked(useNoteQuery).mockReturnValue({
data: mockNote,
} as unknown as ReturnType<typeof useNoteQuery>);

renderWithQueryClient(<NoteDetailContent noteId={noteId} />);

return {
mockNote,
};
};

beforeEach(() => {
jest.clearAllMocks();
});

describe("๊ธฐ๋ณธ UI ๋ Œ๋”๋ง", () => {
it("๋…ธํŠธ ์ œ๋ชฉ์ด ํ‘œ์‹œ๋œ๋‹ค", () => {
setup();

const title = screen.getByText("์ฒซ ๋ฒˆ์งธ ๋…ธํŠธ");
expect(title).toBeInTheDocument();
});

it("๋ชฉํ‘œ์™€ ํ• ์ผ ์ •๋ณด๊ฐ€ ํ‘œ์‹œ๋œ๋‹ค", () => {
setup();

const goalTitle = screen.getByText("๋ชฉํ‘œ 1");
const todoTitle = screen.getByText("ํ•  ์ผ 1");

expect(goalTitle).toBeInTheDocument();
expect(todoTitle).toBeInTheDocument();
});
});

describe("๋งํฌ ๊ธฐ๋Šฅ", () => {
it("๋งํฌ ๋ฏธ๋ฆฌ๋ณด๊ธฐ๊ฐ€ ํ‘œ์‹œ๋œ๋‹ค", () => {
setup();

const linkTitle = screen.getByText("์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ - ์œ„ํ‚ค๋ฐฑ๊ณผ");
expect(linkTitle).toBeInTheDocument();
});

it("๋งํฌ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ํด๋ฆญ ์‹œ ์ž„๋ฒ ๋“œ๊ฐ€ ์—ด๋ฆฐ๋‹ค", async () => {
const user = userEvent.setup();
setup();

const linkPreview = screen.getByText("์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ - ์œ„ํ‚ค๋ฐฑ๊ณผ");
await user.click(linkPreview);

const iframe = screen.getByTitle("์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ - ์œ„ํ‚ค๋ฐฑ๊ณผ");
expect(iframe).toBeInTheDocument();
expect(iframe).toHaveAttribute(
"src",
"https://ko.wikipedia.org/wiki/์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ",
);
});

it("์ž„๋ฒ ๋“œ ๋‹ซ๊ธฐ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ์ž„๋ฒ ๋“œ๊ฐ€ ๋‹ซํžŒ๋‹ค", async () => {
const user = userEvent.setup();
setup();

const linkPreview = screen.getByText("์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ - ์œ„ํ‚ค๋ฐฑ๊ณผ");
await user.click(linkPreview);

const closeButton = screen.getByLabelText("๋‹ซ๊ธฐ");
await user.click(closeButton);

const iframe = screen.queryByTitle("์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ - ์œ„ํ‚ค๋ฐฑ๊ณผ");
expect(iframe).not.toBeInTheDocument();
});

it("๋งํฌ๊ฐ€ ์—†์œผ๋ฉด ๋งํฌ ๋ฏธ๋ฆฌ๋ณด๊ธฐ๊ฐ€ ํ‘œ์‹œ๋˜์ง€ ์•Š๋Š”๋‹ค", () => {
setup(1, { hasLink: false });

const linkPreview = screen.queryByText("์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ - ์œ„ํ‚ค๋ฐฑ๊ณผ");
expect(linkPreview).not.toBeInTheDocument();
});
});
});