Skip to content

Commit

Permalink
test: add testcode for MonthCalendar Container
Browse files Browse the repository at this point in the history
  • Loading branch information
CSKIM999 committed Mar 9, 2024
1 parent b166d1e commit f56dfc0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/__test__/components/MonthBody.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jest.mock("next/navigation", () => ({
}),
}));

describe("Monthview", () => {
describe("Component - Monthview", () => {
it("연월 정보가 없는 경우에도 MonthBody는 정상적으로 렌더링된다", () => {
render(<MonthBody year={undefined} month={undefined} />);

Expand Down
30 changes: 30 additions & 0 deletions src/__test__/container/MonthCalendar.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { MONTH_BODY, MONTH_HEADER } from "@/constants/testId";
import MonthCalendar from "@/container/MonthCalendar";
import "@testing-library/jest-dom";
import { render, screen } from "@testing-library/react";

jest.mock("next/navigation", () => ({
useRouter: () => ({
push: jest.fn(),
}),
}));

describe("Container - MonthCalendar", () => {
it("연월 정보가 없는 경우에도 MonthCalendar는 정상적으로 렌더링된다", () => {
render(<MonthCalendar searchParams={{}} />);
const monthBody = screen.getByTestId(MONTH_BODY);
const monthHeader = screen.getByTestId(MONTH_HEADER);
expect(monthBody).toBeInTheDocument();
expect(monthHeader).toBeInTheDocument();
});

it("윤년의 정보가 주어져도 2월 29일은 정상적으로 렌더링 된다", () => {
render(<MonthCalendar searchParams={{ year: "2024", month: "2" }} />);
const monthBody = screen.getByTestId(MONTH_BODY);
const monthHeader = screen.getByTestId(MONTH_HEADER);
expect(monthBody).toBeInTheDocument();
expect(monthHeader).toBeInTheDocument();
const feb29 = screen.getByText("2/29");
expect(feb29).toBeInTheDocument();
});
});
3 changes: 2 additions & 1 deletion src/components/MonthView/MonthHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"use client";

import { MONTH_HEADER } from "@/constants/testId";
import React from "react";

const days = ["일", "월", "화", "수", "목", "금", "토"];

const MonthHeader = () => {
return (
<div className="flex w-full divide-x-[1px] border-b">
<div data-testid={MONTH_HEADER} className="flex w-full divide-x-[1px] border-b">
{days.map((day, index) => (
<div key={index} className="flex flex-1 justify-end">
{day}
Expand Down
1 change: 1 addition & 0 deletions src/constants/testId.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const ROOT_ID = "root-layout";
export const MONTH_BODY = "month-body";
export const MONTH_HEADER = "month-header";

0 comments on commit f56dfc0

Please sign in to comment.