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

[Feature] - 여행기 무한 스크롤 관련 테스트 추가 #166

Merged
merged 5 commits into from
Aug 3, 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/.prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"^@type/(.*)$",
"^@apis/(.*)$",
"^@mocks/(.*)$",
"^@queries/(.*)$",
"^@components/(.*)$",
"^@hooks/(.*)$",
"^@constants/(.*)$",
Expand Down
45 changes: 45 additions & 0 deletions frontend/__tests__/mainPage.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { waitFor } from "@testing-library/react";

import { createInfiniteTravelogueHook } from "./utils/createInfiniteTravelogueHook";

describe("메인 페이지", () => {
describe("여행기 무한 스크롤 확인", () => {
it("메인 페이지로 진입했을때 보여지는 여행기는 총 5개이다.", async () => {
const { result } = createInfiniteTravelogueHook();
await waitFor(() => {
expect(result.current.status).toMatch("success");
expect(result.current.travelogues.length).toBe(5);
});
});

it("다음 페이지로 이동할 경우 보여지는 여행기는 총 10개이다.", async () => {
const { result } = createInfiniteTravelogueHook();

await waitFor(() => {
result.current.fetchNextPage();
});

await waitFor(() => {
expect(result.current.status).toMatch("success");
expect(result.current.travelogues.length).toBe(10);
});
});

it("마지막 페이지로 이동할 경우 더 이상 콘텐츠를 확인할 수 없다.", async () => {
const { result } = createInfiniteTravelogueHook();

await waitFor(() => {
result.current.fetchNextPage();
});

await waitFor(() => {
result.current.fetchNextPage();
});

await waitFor(() => {
expect(result.current.status).toMatch("success");
expect(result.current.hasNextPage).toBeFalsy();
});
});
});
});
22 changes: 22 additions & 0 deletions frontend/__tests__/utils/createInfiniteTravelogueHook.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { renderHook } from "@testing-library/react";

import { QueryClient, QueryClientProvider } from "@tanstack/react-query";

import useInfiniteTravelogues from "@queries/useInfiniteTravelogues";

const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: 0,
},
},
});

export const wrapper = ({ children }: React.PropsWithChildren) => (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
);

export const createInfiniteTravelogueHook = () =>
renderHook(() => useInfiniteTravelogues(), {
wrapper,
});
2 changes: 2 additions & 0 deletions frontend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module.exports = {
(https://mswjs.io/docs/migrations/1.x-to-2.x/#frequent-issues)
*/
setupFiles: ["./jest.polyfills.js"],
setupFilesAfterEnv: ["./jest-setup.ts"],

testEnvironmentOptions: {
customExportConditions: [""],
},
Expand Down
Loading
Loading