From 119d7c0a29d48acad8f6a5d1636ae30f4fb403fd Mon Sep 17 00:00:00 2001 From: Jungmin Date: Mon, 21 Oct 2024 14:12:47 +0900 Subject: [PATCH] remove vitest file --- src/app/(auth)/components/LoginForm.test.tsx | 107 -------------- src/app/(auth)/components/SignupForm.test.tsx | 118 ---------------- .../components/ProgressTracker.test.tsx | 15 -- src/app/dashboard/components/Sidebar.test.tsx | 127 ----------------- src/components/CreateNewTodo.test.tsx | 131 ------------------ 5 files changed, 498 deletions(-) delete mode 100644 src/app/(auth)/components/LoginForm.test.tsx delete mode 100644 src/app/(auth)/components/SignupForm.test.tsx delete mode 100644 src/app/dashboard/components/ProgressTracker.test.tsx delete mode 100644 src/app/dashboard/components/Sidebar.test.tsx delete mode 100644 src/components/CreateNewTodo.test.tsx diff --git a/src/app/(auth)/components/LoginForm.test.tsx b/src/app/(auth)/components/LoginForm.test.tsx deleted file mode 100644 index 6a81a15..0000000 --- a/src/app/(auth)/components/LoginForm.test.tsx +++ /dev/null @@ -1,107 +0,0 @@ -// import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; -// import userEvent from "@testing-library/user-event"; -// import { fireEvent, render, screen, waitFor } from "@testing-library/react"; -// import { vi } from "vitest"; -// import { toast } from "react-toastify"; - -// import { login } from "@/utils/authUtils"; - -// import LoginForm from "./LoginForm"; - -// vi.mock("next/navigation", () => ({ -// useRouter: () => ({ -// push: vi.fn(), -// }), -// })); - -// vi.mock("@/utils/authUtils", () => ({ -// login: vi.fn(), -// })); - -// vi.mock("react-toastify", () => ({ -// toast: { -// success: vi.fn(), -// error: vi.fn(), -// }, -// })); - -// const user = userEvent.setup(); - -// const mockLogin = vi.mocked(login); - -// const createWrapper = () => { -// const queryClient = new QueryClient(); - -// const Wrapper = ({ children }: { children: React.ReactNode }) => ( -// {children} -// ); - -// // displayName 설정 -// Wrapper.displayName = "QueryClientProviderWrapper"; - -// return Wrapper; -// }; - -// describe("회원가입 양식", () => { -// beforeEach(() => { -// vi.clearAllMocks(); -// }); - -// it("로그인 양식이 렌더링되는지 확인한다", () => { -// render(, { wrapper: createWrapper() }); - -// expect(screen.getByRole("form", { name: "로그인 양식" })).toBeInTheDocument(); -// expect(screen.getByLabelText("이메일")).toBeInTheDocument(); -// expect(screen.getByLabelText("비밀번호")).toBeInTheDocument(); -// expect(screen.getByRole("button", { name: "로그인" })).toBeInTheDocument(); -// }); - -// it("비밀번호 입력 시 최소 길이 오류 메시지 표시", async () => { -// render(, { wrapper: createWrapper() }); - -// fireEvent.change(screen.getByPlaceholderText("이메일"), { -// target: { value: "test@example.com" }, -// }); - -// fireEvent.change(screen.getByPlaceholderText("비밀번호"), { -// target: { value: "short" }, -// }); - -// user.click(screen.getByText("로그인")); - -// expect(await screen.findByText("비밀번호는 최소 8자 이상이어야 합니다.")).toBeInTheDocument(); -// }); - -// it("유효성 확인 후 회원가입 버튼 클릭", async () => { -// mockLogin.mockResolvedValueOnce({}); // 로그인 성공 시 반환할 값 설정 - -// render(, { wrapper: createWrapper() }); - -// await user.type(screen.getByLabelText("이메일"), "qq@naver.com"); -// await user.type(screen.getByLabelText("비밀번호"), "012345678"); -// await user.click(screen.getByRole("button", { name: "로그인" })); - -// await waitFor(() => { -// expect(mockLogin).toHaveBeenCalledWith("qq@naver.com", "012345678"); -// expect(toast.success).toHaveBeenCalledWith("로그인 되었습니다."); -// }); -// }); - -// it("로그인 실패 시 오류 메시지 표시합니다.", async () => { -// mockLogin.mockRejectedValueOnce({ -// response: { -// status: 404, -// }, -// }); - -// render(, { wrapper: createWrapper() }); - -// await user.type(screen.getByLabelText("이메일"), "jj@example.com"); -// await user.type(screen.getByLabelText("비밀번호"), "01234567"); -// await user.click(screen.getByRole("button", { name: "로그인" })); - -// await waitFor(() => { -// expect(toast.error).toHaveBeenCalledWith("가입되지 않은 이메일입니다."); -// }); -// }); -// }); diff --git a/src/app/(auth)/components/SignupForm.test.tsx b/src/app/(auth)/components/SignupForm.test.tsx deleted file mode 100644 index 23a0943..0000000 --- a/src/app/(auth)/components/SignupForm.test.tsx +++ /dev/null @@ -1,118 +0,0 @@ -// import React from "react"; -// import { render, screen, waitFor } from "@testing-library/react"; -// import userEvent from "@testing-library/user-event"; -// import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; -// import { toast } from "react-toastify"; -// import { vi } from "vitest"; - -// import { postUser } from "@/api/authAPI"; - -// import SignupForm from "./SignupForm"; - -// vi.mock("next/navigation", () => ({ -// useRouter: () => ({ -// push: vi.fn(), -// }), -// })); - -// vi.mock("@/api/authAPI", () => ({ -// postUser: vi.fn(), -// })); - -// vi.mock("react-toastify", () => ({ -// toast: { -// success: vi.fn(), -// error: vi.fn(), -// }, -// })); - -// const user = userEvent.setup(); - -// const mockPostUser = postUser; - -// const createWrapper = () => { -// const queryClient = new QueryClient(); - -// const Wrapper = ({ children }: { children: React.ReactNode }) => ( -// {children} -// ); - -// // displayName 설정 -// Wrapper.displayName = "QueryClientProviderWrapper"; - -// return Wrapper; -// }; - -// describe("회원가입 양식", () => { -// beforeEach(() => { -// vi.clearAllMocks(); -// }); - -// it("회원가입 양식 렌더링", () => { -// render(, { wrapper: createWrapper() }); - -// expect(screen.getByLabelText("닉네임")).toBeInTheDocument(); -// expect(screen.getByLabelText("아이디")).toBeInTheDocument(); -// expect(screen.getByLabelText("비밀번호")).toBeInTheDocument(); -// expect(screen.getByLabelText("비밀번호 확인")).toBeInTheDocument(); -// expect(screen.getByRole("button", { name: "회원가입하기" })).toBeInTheDocument(); -// }); - -// it("입력이 틀렸을 때, 오류 메시지를 표시합니다", async () => { -// render(, { wrapper: createWrapper() }); - -// await user.click(screen.getByRole("button", { name: "회원가입하기" })); - -// await waitFor(() => { -// expect(screen.getByText("닉네임은 최소 2자 이상이어야 합니다.")).toBeInTheDocument(); -// expect(screen.getByText("유효한 이메일 주소를 입력해 주세요.")).toBeInTheDocument(); -// expect(screen.getByText("비밀번호는 최소 8자 이상이어야 합니다.")).toBeInTheDocument(); -// expect(screen.getByText("비밀번호 확인은 최소 8자 이상이어야 합니다.")).toBeInTheDocument(); -// }); -// }); - -// it("유효성 확인 후 회원가입 버튼 클릭", async () => { -// mockPostUser.mockResolvedValueOnce({}); - -// render(, { wrapper: createWrapper() }); - -// await user.type(screen.getByLabelText("닉네임"), "testuser"); -// await user.type(screen.getByLabelText("아이디"), "test@example.com"); -// await user.type(screen.getByLabelText("비밀번호"), "password123"); -// await user.type(screen.getByLabelText("비밀번호 확인"), "password123"); - -// await user.click(screen.getByRole("button", { name: "회원가입하기" })); - -// await waitFor(() => { -// expect(mockPostUser).toHaveBeenCalledWith({ -// nickname: "testuser", -// email: "test@example.com", -// password: "password123", -// passwordConfirm: "password123", -// }); -// expect(toast.success).toHaveBeenCalledWith("회원가입이 완료되었습니다."); -// }); -// }); - -// it("API 호출에 실패할 때 오류 메시지를 표시합니다", async () => { -// mockPostUser.mockRejectedValueOnce({ -// response: { -// status: 409, -// }, -// }); - -// render(, { wrapper: createWrapper() }); -// const user = userEvent.setup(); - -// await user.type(screen.getByLabelText("닉네임"), "testuser"); -// await user.type(screen.getByLabelText("아이디"), "test@example.com"); -// await user.type(screen.getByLabelText("비밀번호"), "password123"); -// await user.type(screen.getByLabelText("비밀번호 확인"), "password123"); - -// await user.click(screen.getByRole("button", { name: "회원가입하기" })); - -// await waitFor(() => { -// expect(toast.error).toHaveBeenCalledWith("이미 사용 중인 이메일입니다."); -// }); -// }); -// }); diff --git a/src/app/dashboard/components/ProgressTracker.test.tsx b/src/app/dashboard/components/ProgressTracker.test.tsx deleted file mode 100644 index 70fcf3c..0000000 --- a/src/app/dashboard/components/ProgressTracker.test.tsx +++ /dev/null @@ -1,15 +0,0 @@ -// import { render, screen } from "@testing-library/react"; -// import { describe, it, expect, vi } from "vitest"; - -// import ProgressTracker from "./ProgressTracker"; - -// describe("ProgressTracker 컴포넌트 테스트", () => { -// it("렌더링 확인", () => { -// const setprogressValue = vi.fn(); -// render(); - -// const progressText = screen.getByText("내 진행 상황"); - -// expect(progressText).toBeInTheDocument(); -// }); -// }); diff --git a/src/app/dashboard/components/Sidebar.test.tsx b/src/app/dashboard/components/Sidebar.test.tsx deleted file mode 100644 index ee530cc..0000000 --- a/src/app/dashboard/components/Sidebar.test.tsx +++ /dev/null @@ -1,127 +0,0 @@ -// import { useRouter } from "next/navigation"; -// import { expect, vi } from "vitest"; -// import { fireEvent, render, screen, waitFor } from "@testing-library/react"; -// import userEvent from "@testing-library/user-event"; - -// import { useAuthStore } from "@/store/authStore"; -// import { GoalType, useGoalStore } from "@/store/goalStore"; -// import CreateNewTodo from "@/components/CreateNewTodo"; -// import { logout } from "@/utils/authUtils"; - -// import SideBar from "./Sidebar"; - -// export const mockGoals: GoalType[] = [ -// { -// id: 1, -// teamId: "FESI3-5", -// title: "스타벅스 가기", -// userId: 1, -// createdAt: "", -// updatedAt: "", -// }, -// { -// id: 2, -// teamId: "FESI3-5", -// title: "이삭 토스트 가기", -// userId: 1, -// createdAt: "", -// updatedAt: "", -// }, -// ]; - -// // Next.js의 navigation과 Image 컴포넌트 모킹 -// vi.mock("next/navigation", () => ({ -// useRouter: vi.fn(() => ({ -// push: vi.fn(), -// })), -// usePathname: () => "/mocked/path", -// })); - -// vi.mock("next/image", () => ({ -// default: vi.fn(() => null), -// })); - -// // 스토어와 유틸리티 함수 모킹 -// vi.mock("@/store/goalStore", () => ({ -// useGoalStore: vi.fn(), -// })); - -// vi.mock("@/store/authStore", () => ({ -// useAuthStore: vi.fn(), -// })); - -// vi.mock("@/utils/authUtils", () => ({ -// logout: vi.fn(), -// })); - -// describe("SideBar 컴포넌트", () => { -// const mockPush = vi.fn(); -// const mockRefreshGoals = vi.fn(); -// const mockAddGoal = vi.fn(); -// const mockUser = { name: "테스트 사용자", email: "test@example.com" }; - -// beforeEach(() => { -// vi.clearAllMocks(); -// useRouter.mockReturnValue({ -// push: mockPush, -// }); -// useGoalStore.mockReturnValue({ -// goals: [{ id: 1, title: "오늘의 할 일" }], -// refreshGoals: mockRefreshGoals, -// addGoal: mockAddGoal, -// }); -// useAuthStore.mockReturnValue({ user: mockUser }); -// render( {}} goal={mockGoals[0]} />); -// }); - -// it("사이드바가 렌더링됩니다", async () => { -// render(); -// expect(screen.getByText("대시보드")).toBeInTheDocument(); -// expect(screen.getByText("+ 새 할 일")).toBeInTheDocument(); -// expect(screen.getByTestId("sidebar-goal-heading")).toBeInTheDocument(); - -// // 목표가 비동기로 로드되므로 findByText 사용 -// expect(await screen.findByText("스타벅스 가기")).toBeInTheDocument(); -// }); - -// it("로그아웃 클릭 시 로그아웃되어 / 경로로 갑니다.", async () => { -// logout.mockResolvedValue(true); -// render(); - -// const logoutButton = screen.getByText("로그아웃"); -// await fireEvent.click(logoutButton); - -// expect(logout).toHaveBeenCalled(); - -// await waitFor(() => { -// expect(mockPush).toHaveBeenCalledWith("/"); -// }); -// }); - -// it("새 목표 추가 기능이 작동합니다", async () => { -// render(); - -// const newGoalButton = screen.getByText("+ 새 목표"); -// await userEvent.click(newGoalButton); - -// const input = screen.getByRole("textbox", { name: "새목표" }); -// await userEvent.type(input, "cypress까지 달리기"); -// fireEvent.submit(input); - -// expect(mockAddGoal).toHaveBeenCalledWith("cypress까지 달리기"); -// }); - -// it("사이드바 토글 기능이 작동합니다", async () => { -// render(); - -// const toggleButton = screen.getByTestId("main-sidebar-button"); -// await userEvent.click(toggleButton); - -// expect(screen.getByTestId("slim-sidebar-button")).toBeInTheDocument(); -// }); - -// it("컴포넌트 마운트 시 목표 새로고침합니다", () => { -// render(); -// expect(mockRefreshGoals).toHaveBeenCalled(); -// }); -// }); diff --git a/src/components/CreateNewTodo.test.tsx b/src/components/CreateNewTodo.test.tsx deleted file mode 100644 index 3da492b..0000000 --- a/src/components/CreateNewTodo.test.tsx +++ /dev/null @@ -1,131 +0,0 @@ -// import { vi } from "vitest"; -// import { fireEvent, render, screen, waitFor } from "@testing-library/react"; -// import userEvent from "@testing-library/user-event"; -// import { toast } from "react-toastify"; - -// import { editTodo, postFile, postTodos } from "@/api/todoAPI"; -// import { getGoal } from "@/api/goalAPI"; - -// import CreateNewTodo from "./CreateNewTodo"; - -// // next/navigation module 모킹 -// vi.mock("next/navigation", () => ({ -// usePathname: vi.fn(() => "/goals/1"), -// })); - -// // API 모킹 -// vi.mock("@/api/goalAPI", () => ({ -// getGoal: vi.fn(), -// })); - -// vi.mock("@/api/todoAPI", () => ({ -// editTodo: vi.fn(), -// postFile: vi.fn(), -// postTodos: vi.fn(), -// })); - -// // react-toastify 모킹 -// vi.mock("react-toastify", () => ({ -// toast: { -// success: vi.fn(), -// error: vi.fn(), -// }, -// })); - -// describe("CreateNewTodo", () => { -// const mockCloseCreateNewTodo = vi.fn(); -// const mockOnUpdate = vi.fn(); - -// beforeEach(() => { -// vi.clearAllMocks(); -// }); - -// it("렌더링", () => { -// render(); -// expect(screen.getByLabelText("할 일의 제목")).toBeInTheDocument(); -// expect(screen.getByText("파일 업로드")).toBeInTheDocument(); -// expect(screen.getByText("링크 첨부")).toBeInTheDocument(); -// expect(screen.getByText("목표를 선택해주세요")).toBeInTheDocument(); -// }); - -// it("제목 입력 하기", async () => { -// render(); -// const titleInput = screen.getByLabelText("할 일의 제목"); -// await userEvent.type(titleInput, "빨래 하기"); -// expect(titleInput).toHaveValue("빨래 하기"); -// }); - -// it("파일 업로드 하기", async () => { -// const mockFile = new File(["테스트할 파일이에요."], "test.txt", { type: "text/plain" }); -// postFile.mockResolvedValue({ url: "http://example.com/test.txt" }); - -// render(); -// const fileInput = screen.getByLabelText("파일을 업로드해주세요"); -// await userEvent.upload(fileInput, mockFile); - -// expect(postFile).toHaveBeenCalledWith(mockFile); -// await waitFor(() => { -// expect(screen.getByText("test.txt")).toBeInTheDocument(); -// }); -// }); - -// it("링크 업로드 하기", async () => { -// render(); -// const linkAttachButton = screen.getByText("링크 첨부"); -// fireEvent.click(linkAttachButton); - -// expect(linkAttachButton).toHaveStyle("background-color: rgba(0, 0, 0, 0)"); -// }); - -// it("목표 기본 값으로 세팅하기", async () => { -// const mockGoal = { id: 1, title: "오늘의 할 일", teamId: "FESI3-5", userId: 1, createdAt: "", updatedAt: "" }; -// getGoal.mockResolvedValue(mockGoal); - -// render(); - -// await waitFor(() => { -// expect(getGoal).toHaveBeenCalledWith(1); -// expect(screen.getByText("오늘의 할 일")).toBeInTheDocument(); -// }); -// }); - -// it("새 할 일 제출하기", async () => { -// const mockGoal = { id: 1, title: "오늘의 할 일", teamId: "FESI3-5", userId: 1, createdAt: "", updatedAt: "" }; -// getGoal.mockResolvedValue(mockGoal); -// postTodos.mockResolvedValue({ id: 1, title: "노래 선정", goal: mockGoal }); - -// render(); - -// await userEvent.type(screen.getByLabelText("할 일의 제목"), "노래 선정"); -// await userEvent.click(screen.getByText("확인")); - -// expect(postTodos).toHaveBeenCalledWith("노래 선정", null, null, 1); -// expect(toast.success).toHaveBeenCalledWith("할 일이 성공적으로 생성되었습니다"); -// expect(mockCloseCreateNewTodo).toHaveBeenCalled(); -// }); - -// it("할 일 수정하기", async () => { -// const mockGoal = { id: 1, title: "오늘의 할 일", teamId: "FESI3-5", userId: 1, createdAt: "", updatedAt: "" }; -// const mockTodo = { id: 1, title: "노래 선정", goal: mockGoal, fileUrl: null, linkUrl: null }; -// editTodo.mockResolvedValue(mockTodo); - -// render( -// , -// ); - -// await userEvent.clear(screen.getByLabelText("할 일의 제목")); -// await userEvent.type(screen.getByLabelText("할 일의 제목"), "노래를 정해보자"); -// await userEvent.click(screen.getByText("수정")); - -// expect(editTodo).toHaveBeenCalledWith("노래를 정해보자", 1, null, null, 1); -// expect(mockOnUpdate).toHaveBeenCalledWith(mockTodo); -// expect(mockCloseCreateNewTodo).toHaveBeenCalled(); -// }); -// });