Skip to content

Commit

Permalink
test : test케이스 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
eun-hak committed Jun 30, 2024
1 parent 32cbb59 commit d49d4eb
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/components/sign/sign.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React from 'react';
import { act, render, fireEvent, screen } from '@testing-library/react';
import SigninForm from './signin/SigninForm';
// import { signin } from '@/api/auth/auth.post.api';
// import { useRouter } from 'next/navigation';
// import { setCookie } from '@/utils/cookies';
// import { useMutation } from '@tanstack/react-query';

jest.mock('@/api/auth/auth.post.api');
jest.mock('next/navigation', () => ({ useRouter: jest.fn() }));
jest.mock('@/utils/cookies', () => ({ setCookie: jest.fn() }));
jest.mock('@tanstack/react-query', () => ({ useMutation: jest.fn() }));

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

const mockMutate = jest.fn();
jest.mock('@tanstack/react-query', () => ({
useMutation: () => ({
mutate: mockMutate,
mutateAsync: jest.fn(),
data: undefined,
error: undefined,
isLoading: false
})
}));

describe('SigninForm Component', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('로그인 성공 시 홈페이지로 리다이렉트', async () => {
render(<SigninForm />);
const emailInput = screen.getByPlaceholderText('이메일을 입력해주세요.');
const passwordInput = screen.getByPlaceholderText('비밀번호를 입력해주세요.');
const submitButton = screen.getByText('로그인');

await act(async () => {
fireEvent.change(emailInput, { target: { value: '[email protected]' } });
fireEvent.change(passwordInput, { target: { value: 'wrongPassword' } });
fireEvent.click(submitButton);
});

// await waitFor(() => expect(mockPush).toHaveBeenCalledWith('/'));
});

it('잘못된 이메일 또는 비밀번호 입력 시 에러 메시지 표시', async () => {
// mockMutate.mockImplementationOnce((_, { onError }) => {
// onError(new Error('*아이디 혹은 비밀번호가 일치하지 않습니다'));
// });

render(<SigninForm />);
const emailInput = screen.getByPlaceholderText('이메일을 입력해주세요.');
const passwordInput = screen.getByPlaceholderText('비밀번호를 입력해주세요.');
const submitButton = screen.getByText('로그인');
await act(async () => {
fireEvent.change(emailInput, { target: { value: '[email protected]' } });
fireEvent.change(passwordInput, { target: { value: 'wrongPassword' } });
fireEvent.click(submitButton);
});
// await waitFor(() =>
// expect(
// screen.getByText('*아이디 혹은 비밀번호가 일치하지 않습니다')
// ).toBeInTheDocument()
// );
});
});

0 comments on commit d49d4eb

Please sign in to comment.