Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #190 from ictsc/feature/add_notification_page_unit…
Browse files Browse the repository at this point in the history
…_test

add: NoticesPage の 単体 テストを追加
  • Loading branch information
K-shir0 authored Jul 13, 2023
2 parents db87cf0 + 873cb80 commit 7d640bc
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions __test__/pages/notices.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import "@testing-library/jest-dom";

import { render, screen } from "@testing-library/react";
import { Mock, vi } from "vitest";

import useNotice from "@/hooks/notice";
import Notices from "@/pages/notices";
import { testNotice } from "@/types/Notice";

vi.mock("@/hooks/notice");
vi.mock("@/components/Navbar", () => ({
__esModule: true,
default: () => <div data-testid="navbar" />,
}));
vi.mock("@/components/NotificationCard", () => ({
__esModule: true,
default: () => <div data-testid="notification-card" />,
}));

beforeEach(() => {
// toHaveBeenCalledTimes がテストごとにリセットされるようにする
vi.clearAllMocks();
});

describe("Notices", () => {
test("画面が表示されることを確認する", async () => {
// setup
(useNotice as Mock).mockReturnValue({
notices: [testNotice],
isLoading: false,
});

// when
render(<Notices />);

// then
expect(screen.getByTestId("navbar")).toBeInTheDocument();
expect(screen.getByTestId("notification-card")).toBeInTheDocument();

// verify
expect(useNotice).toHaveBeenCalledTimes(1);
});

test("通知が取得中の場合、ローディング画面が表示されることを確認する", async () => {
// setup
(useNotice as Mock).mockReturnValue({
notices: [testNotice],
isLoading: true,
});

// when
render(<Notices />);

// then
expect(screen.getByTestId("navbar")).toBeInTheDocument();
expect(screen.queryByTestId("notification-card")).not.toBeInTheDocument();

// verify
expect(useNotice).toHaveBeenCalledTimes(1);
});
});

0 comments on commit 7d640bc

Please sign in to comment.