Skip to content

Commit

Permalink
Merge pull request #157 from tteokbokki-master/Weekly
Browse files Browse the repository at this point in the history
Test/#154 ν…ŒμŠ€νŠΈμ½”λ“œ μž‘μ„±
  • Loading branch information
YIMSEBIN authored Nov 15, 2024
2 parents 6e19f8b + 898a666 commit 2df9fe2
Show file tree
Hide file tree
Showing 2 changed files with 212 additions and 0 deletions.
146 changes: 146 additions & 0 deletions src/pages/apply/applypage/__test__/ApplyPage.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import { renderWithProviders } from '@/__test__/test-utils';
import { server } from '@/mocks/server';
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
import ApplyPage from '../ApplyPage';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { fireEvent, screen, act } from '@testing-library/react';

const queryClient = new QueryClient();

describe('ApplyPage μ»΄ν¬λ„ŒνŠΈ ν…ŒμŠ€νŠΈ', () => {
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

beforeEach(() => {
vi.clearAllMocks();
});

const renderApplyForm = () => {
return renderWithProviders(
<QueryClientProvider client={queryClient}>
<ApplyPage />
</QueryClientProvider>,
);
};

it('λͺ¨λ“  ν•„λ“œλ₯Ό μ˜¬λ°”λ₯΄κ²Œ μž…λ ₯ν•œ 경우 λ²„νŠΌμ΄ μ •μƒμ μœΌλ‘œ ν΄λ¦­λœλ‹€', async () => {
renderApplyForm();

const nameInput = screen.getByPlaceholderText('이름을 μž…λ ₯ν•΄μ£Όμ„Έμš”.');
const addressInput = screen.getByPlaceholderText('μ£Όμ†Œλ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš” (예: λŒ€μ „κ΄‘μ—­μ‹œ μœ μ„±κ΅¬ ꢁ동)');
const phoneNumberInput = screen.getByPlaceholderText('번호λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš” (예: 010-0000-0000)');
const motivationInput = screen.getByPlaceholderText('지원동기λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”');

await act(async () => {
fireEvent.change(nameInput, { target: { value: '이재용' } });
fireEvent.change(addressInput, { target: { value: 'λŒ€μ „κ΄‘μ—­μ‹œ μœ μ„±κ΅¬ ꢁ동' } });
fireEvent.change(phoneNumberInput, { target: { value: '010-1234-1234' } });
fireEvent.change(motivationInput, { target: { value: 'μ•ˆλ…•' } });
});

const submitButton = screen.getByRole('button', { name: 'μ§€μ›ν•˜κΈ°' });
await act(async () => {
fireEvent.click(submitButton);
});

expect(submitButton).toBeEnabled();
});

it('잘λͺ»λœ μ „ν™”λ²ˆν˜Έ ν˜•μ‹μ„ μž…λ ₯ν•˜λ©΄ μ—λŸ¬ λ©”μ‹œμ§€λ₯Ό ν‘œμ‹œν•œλ‹€', async () => {
renderApplyForm();

const nameInput = screen.getByPlaceholderText('이름을 μž…λ ₯ν•΄μ£Όμ„Έμš”.');
const addressInput = screen.getByPlaceholderText('μ£Όμ†Œλ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš” (예: λŒ€μ „κ΄‘μ—­μ‹œ μœ μ„±κ΅¬ ꢁ동)');
const phoneNumberInput = screen.getByPlaceholderText('번호λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš” (예: 010-0000-0000)');
const motivationInput = screen.getByPlaceholderText('지원동기λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”');
const submitButton = screen.getByRole('button', { name: 'μ§€μ›ν•˜κΈ°' });

await act(async () => {
fireEvent.change(nameInput, { target: { value: '이재용' } });
fireEvent.change(addressInput, { target: { value: 'λŒ€μ „κ΄‘μ—­μ‹œ μœ μ„±κ΅¬ ꢁ동' } });
fireEvent.change(phoneNumberInput, { target: { value: '1234' } });
fireEvent.change(motivationInput, { target: { value: 'μ•ˆλ…•' } });
fireEvent.click(submitButton);
});

const errorMessage = screen.getByText('μ˜¬λ°”λ₯Έ μ „ν™”λ²ˆν˜Έ ν˜•μ‹μ΄ μ•„λ‹™λ‹ˆλ‹€. (예: 010-0000-0000)');
expect(errorMessage).toBeInTheDocument();
});

it('이름을 μž…λ ₯ν•˜μ§€ μ•ŠμœΌλ©΄ μœ νš¨μ„± μ—λŸ¬ λ©”μ‹œμ§€λ₯Ό ν‘œμ‹œν•œλ‹€', async () => {
renderApplyForm();

const addressInput = screen.getByPlaceholderText('μ£Όμ†Œλ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš” (예: λŒ€μ „κ΄‘μ—­μ‹œ μœ μ„±κ΅¬ ꢁ동)');
const phoneNumberInput = screen.getByPlaceholderText('번호λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš” (예: 010-0000-0000)');
const motivationInput = screen.getByPlaceholderText('지원동기λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”');
const submitButton = screen.getByRole('button', { name: 'μ§€μ›ν•˜κΈ°' });

await act(async () => {
fireEvent.change(addressInput, { target: { value: 'λŒ€μ „κ΄‘μ—­μ‹œ μœ μ„±κ΅¬ ꢁ동' } });
fireEvent.change(phoneNumberInput, { target: { value: '010-1234-5678' } });
fireEvent.change(motivationInput, { target: { value: 'μ•ˆλ…•' } });
fireEvent.click(submitButton);
});

const errorMessage = await screen.findByText('이름을(λ₯Ό) μž…λ ₯ν•΄μ£Όμ„Έμš”!');
expect(errorMessage).toBeInTheDocument();
});

it('μ£Όμ†Œλ₯Ό μž…λ ₯ν•˜μ§€ μ•ŠμœΌλ©΄ μœ νš¨μ„± μ—λŸ¬ λ©”μ‹œμ§€λ₯Ό ν‘œμ‹œν•œλ‹€', async () => {
renderApplyForm();

const nameInput = screen.getByPlaceholderText('이름을 μž…λ ₯ν•΄μ£Όμ„Έμš”.');
const phoneNumberInput = screen.getByPlaceholderText('번호λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš” (예: 010-0000-0000)');
const motivationInput = screen.getByPlaceholderText('지원동기λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”');
const submitButton = screen.getByRole('button', { name: 'μ§€μ›ν•˜κΈ°' });

await act(async () => {
fireEvent.change(nameInput, { target: { value: '이재용' } });
fireEvent.change(phoneNumberInput, { target: { value: '010-1234-5678' } });
fireEvent.change(motivationInput, { target: { value: 'μ„±μ‹€νžˆ μž„ν•˜κ² μŠ΅λ‹ˆλ‹€.' } });
fireEvent.click(submitButton);
});

const errorMessage = await screen.findByText('μ£Όμ†Œμ„(λ₯Ό) μž…λ ₯ν•΄μ£Όμ„Έμš”!');
expect(errorMessage).toBeInTheDocument();
});

it('번호λ₯Ό μž…λ ₯ν•˜μ§€ μ•ŠμœΌλ©΄ μœ νš¨μ„± μ—λŸ¬ λ©”μ‹œμ§€λ₯Ό ν‘œμ‹œν•œλ‹€', async () => {
renderApplyForm();

const nameInput = screen.getByPlaceholderText('이름을 μž…λ ₯ν•΄μ£Όμ„Έμš”.');
const addressInput = screen.getByPlaceholderText('μ£Όμ†Œλ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš” (예: λŒ€μ „κ΄‘μ—­μ‹œ μœ μ„±κ΅¬ ꢁ동)');
const motivationInput = screen.getByPlaceholderText('지원동기λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”');
const submitButton = screen.getByRole('button', { name: 'μ§€μ›ν•˜κΈ°' });

await act(async () => {
fireEvent.change(nameInput, { target: { value: '이재용' } });
fireEvent.change(addressInput, { target: { value: 'λŒ€μ „κ΄‘μ—­μ‹œ μœ μ„±κ΅¬ ꢁ동' } });
fireEvent.change(motivationInput, { target: { value: 'ν•˜μ΄' } });
fireEvent.click(submitButton);
});

const errorMessage = await screen.findByText('λ²ˆν˜Έμ„(λ₯Ό) μž…λ ₯ν•΄μ£Όμ„Έμš”!');
expect(errorMessage).toBeInTheDocument();
});

it('지원동기λ₯Ό μž…λ ₯ν•˜μ§€ μ•ŠμœΌλ©΄ μœ νš¨μ„± μ—λŸ¬ λ©”μ‹œμ§€λ₯Ό ν‘œμ‹œν•œλ‹€', async () => {
renderApplyForm();

const nameInput = screen.getByPlaceholderText('이름을 μž…λ ₯ν•΄μ£Όμ„Έμš”.');
const addressInput = screen.getByPlaceholderText('μ£Όμ†Œλ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš” (예: λŒ€μ „κ΄‘μ—­μ‹œ μœ μ„±κ΅¬ ꢁ동)');
const phoneNumberInput = screen.getByPlaceholderText('번호λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš” (예: 010-0000-0000)');
const submitButton = screen.getByRole('button', { name: 'μ§€μ›ν•˜κΈ°' });

await act(async () => {
fireEvent.change(nameInput, { target: { value: '이재용' } });
fireEvent.change(addressInput, { target: { value: 'λŒ€μ „κ΄‘μ—­μ‹œ μœ μ„±κ΅¬ ꢁ동' } });
fireEvent.change(phoneNumberInput, { target: { value: '010-1234-5678' } });
fireEvent.click(submitButton);
});

const errorMessage = await screen.findByText('지원동기을(λ₯Ό) μž…λ ₯ν•΄μ£Όμ„Έμš”!');
expect(errorMessage).toBeInTheDocument();
});
});
66 changes: 66 additions & 0 deletions src/pages/resume/__test__/Resume.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { renderWithProviders } from '@/__test__/test-utils';
import { server } from '@/mocks/server';
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
import Resume from '../Resume';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { fireEvent, screen, act } from '@testing-library/react';

const queryClient = new QueryClient();

describe('Resume μ»΄ν¬λ„ŒνŠΈ ν…ŒμŠ€νŠΈ', () => {
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

beforeEach(() => {
vi.clearAllMocks();
});

const renderResumeForm = () => {
return renderWithProviders(
<QueryClientProvider client={queryClient}>
<Resume />
</QueryClientProvider>,
);
};

it('λͺ¨λ“  ν•„λ“œλ₯Ό μ˜¬λ°”λ₯΄κ²Œ μž…λ ₯ν•œ 경우 λ²„νŠΌμ΄ λˆŒλ¦°λ‹€', async () => {
renderResumeForm();

const nameInput = screen.getByPlaceholderText('이름을 μž…λ ₯ν•˜μ„Έμš”.');
const addressInput = screen.getByPlaceholderText('μ£Όμ†Œλ₯Ό μž…λ ₯ν•˜μ„Έμš”.');
const phoneNumberInput = screen.getByPlaceholderText('010-0000-0000 ν˜•μ‹μ˜ 번호λ₯Ό μž…λ ₯ν•˜μ„Έμš”.');
const careerInput = screen.getByPlaceholderText('κ²½λ ₯을 μž…λ ₯ν•˜μ„Έμš”.');
const introductionTextarea = screen.getByPlaceholderText('μžκΈ°μ†Œκ°œλ₯Ό μž…λ ₯ν•˜μ„Έμš”.');

await act(async () => {
fireEvent.change(nameInput, { target: { value: '이재용' } });
fireEvent.change(addressInput, { target: { value: 'μ„œμšΈμ‹œ 강남ꡬ' } });
fireEvent.change(phoneNumberInput, { target: { value: '010-1234-5678' } });
fireEvent.change(careerInput, { target: { value: '3λ…„' } });
fireEvent.change(introductionTextarea, { target: { value: '돈 쀘' } });
});

const submitButton = screen.getByRole('button', { name: 'μ œμΆœν•˜κΈ°' });
await act(async () => {
fireEvent.click(submitButton);
});

expect(submitButton).toBeEnabled();
});

it('잘λͺ»λœ μ „ν™”λ²ˆν˜Έ ν˜•μ‹μ„ μž…λ ₯ν•˜λ©΄ μ—λŸ¬ λ©”μ‹œμ§€λ₯Ό ν‘œμ‹œν•œλ‹€', async () => {
renderResumeForm();

const phoneNumberInput = screen.getByPlaceholderText('010-0000-0000 ν˜•μ‹μ˜ 번호λ₯Ό μž…λ ₯ν•˜μ„Έμš”.');
const submitButton = screen.getByRole('button', { name: 'μ œμΆœν•˜κΈ°' });

await act(async () => {
fireEvent.change(phoneNumberInput, { target: { value: '1234' } });
fireEvent.click(submitButton);
});

const errorMessage = await screen.findByText('μ˜¬λ°”λ₯Έ μ „ν™”λ²ˆν˜Έ ν˜•μ‹μ΄ μ•„λ‹™λ‹ˆλ‹€. (예: 010-0000-0000)');
expect(errorMessage).toBeInTheDocument();
});
});

0 comments on commit 2df9fe2

Please sign in to comment.