-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Test/#137 ๋ฉ์ธํ์ด์ง, ๋ก๊ทธ์ธ, ํ์๊ฐ์ ํ ์คํธ์ฝ๋ ๊ตฌํ
- Loading branch information
Showing
12 changed files
with
1,028 additions
and
48 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import '@testing-library/jest-dom'; | ||
|
||
Object.defineProperty(window, 'matchMedia', { | ||
writable: true, | ||
value: (query: string) => ({ | ||
matches: false, | ||
media: query, | ||
onchange: null, | ||
addListener: () => {}, | ||
removeListener: () => {}, | ||
addEventListener: () => {}, | ||
removeEventListener: () => {}, | ||
dispatchEvent: () => false, | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { render } from '@testing-library/react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import AppProviders from '@/components/providers/index.provider'; | ||
import { ReactElement } from 'react'; | ||
|
||
export function renderWithProviders(ui: ReactElement) { | ||
return render( | ||
<MemoryRouter> | ||
<AppProviders>{ui}</AppProviders> | ||
</MemoryRouter>, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { describe, it, expect, vi, beforeEach, MockedFunction } from 'vitest'; | ||
import { screen, fireEvent } from '@testing-library/react'; | ||
import { SignInButton } from '../SignIn/components/SignInButton'; | ||
import { useGoogleOAuth } from '../SignIn/hooks/useGoogleOAuth'; | ||
import { renderWithProviders } from '@/__test__/test-utils'; | ||
|
||
vi.mock('../SignIn/hooks/useGoogleOAuth'); | ||
|
||
describe('SignInButton ์ปดํฌ๋ํธ', () => { | ||
const mockRedirectToGoogleLogin = vi.fn(); | ||
const mockedUseGoogleOAuth = useGoogleOAuth as MockedFunction<typeof useGoogleOAuth>; | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
mockedUseGoogleOAuth.mockReturnValue({ | ||
isLoading: false, | ||
redirectToGoogleLogin: mockRedirectToGoogleLogin, | ||
}); | ||
}); | ||
|
||
it('๊ตฌ๊ธ ๋ก๊ทธ์ธ ๋ฒํผ์ด ์ฌ๋ฐ๋ฅด๊ฒ ๋ ๋๋ง๋๋ค', () => { | ||
renderWithProviders(<SignInButton />); | ||
|
||
const buttonElement = screen.getByRole('button', { name: /Sign up with Google/i }); | ||
expect(buttonElement).toBeInTheDocument(); | ||
|
||
const googleIcon = screen.getByTestId('google-icon'); | ||
expect(googleIcon).toBeInTheDocument(); | ||
}); | ||
|
||
it('๋ฒํผ ํด๋ฆญ ์ redirectToGoogleLogin ํจ์๊ฐ ํธ์ถ๋๋ค', () => { | ||
renderWithProviders(<SignInButton />); | ||
|
||
const buttonElement = screen.getByRole('button', { name: /Sign up with Google/i }); | ||
fireEvent.click(buttonElement); | ||
|
||
expect(mockRedirectToGoogleLogin).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
import { screen } from '@testing-library/react'; | ||
import ConditionalRenderer from '../components/ConditionalRenderer'; | ||
import { userLocalStorage } from '@/utils/storage'; | ||
import { UserData } from '@/types'; | ||
import { renderWithProviders } from '@/__test__/test-utils'; | ||
|
||
const mockEmployeeUser = { type: 'employee', profileImage: 'userProfileImage', name: 'userName' } as UserData; | ||
const mockEmployerUser = { type: 'employer', profileImage: 'employerProfileImage', name: 'employerName' } as UserData; | ||
|
||
describe('ConditionalRenderer ์ปดํฌ๋ํธ', () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('userType์ด "employee"์ผ ๋ Worker ์ปดํฌ๋ํธ๋ฅผ ๋ ๋๋งํ๋ค', async () => { | ||
vi.spyOn(userLocalStorage, 'getUser').mockReturnValue(mockEmployeeUser); | ||
|
||
renderWithProviders(<ConditionalRenderer />); | ||
|
||
expect(screen.queryByText('home.greeting.heading')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('userType์ด "employer"์ผ ๋ Employer ์ปดํฌ๋ํธ๋ฅผ ๋ ๋๋งํ๋ค', () => { | ||
vi.spyOn(userLocalStorage, 'getUser').mockReturnValue(mockEmployerUser); | ||
|
||
renderWithProviders(<ConditionalRenderer />); | ||
|
||
const headingText = screen.getByText('home.greeting.heading'); | ||
const buttonText = screen.getByText('home.greeting.button'); | ||
|
||
expect(headingText).toBeInTheDocument(); | ||
expect(buttonText).toBeInTheDocument(); | ||
}); | ||
|
||
it('userType์ด undefined์ผ ๋ Worker ์ปดํฌ๋ํธ๋ฅผ ๋ ๋๋งํ๋ค', () => { | ||
vi.spyOn(userLocalStorage, 'getUser').mockReturnValue(undefined); | ||
|
||
renderWithProviders(<ConditionalRenderer />); | ||
|
||
expect(screen.queryByText('home.greeting.heading')).not.toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { describe, it, expect, vi, beforeEach, beforeAll, afterEach, afterAll } from 'vitest'; | ||
import { renderHook, act, waitFor } from '@testing-library/react'; | ||
import { useRecruitmentData } from '../hooks/useRecruitmentData'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import { server } from '@mocks/server'; | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
describe('useRecruitmentData ํ ํ ์คํธ', () => { | ||
beforeAll(() => server.listen()); | ||
afterEach(() => server.resetHandlers()); | ||
afterAll(() => server.close()); | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
const renderUseRecruitmentDataHook = (initialFilter = 'all') => { | ||
return renderHook(() => useRecruitmentData(initialFilter), { | ||
wrapper: ({ children }) => <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>, | ||
}); | ||
}; | ||
|
||
it('๊ธฐ๋ณธ ํํฐ๋ก ๋ชจ๋ ๋ชจ์ง ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์จ๋ค', async () => { | ||
const { result } = renderUseRecruitmentDataHook('all'); | ||
|
||
await waitFor(() => { | ||
expect(result.current.recruitmentList.content).toHaveLength(3); | ||
expect(result.current.recruitmentList.content[0].companyName).toBe('์นด์นด์ค'); | ||
}); | ||
}); | ||
|
||
it('ํํฐ๋ฅผ ๋ณ๊ฒฝํ์ ๋ ๋ชจ์ง ๋ฐ์ดํฐ๊ฐ ์ ๋ฐ์ดํธ ๋๋ค', async () => { | ||
const { result } = renderUseRecruitmentDataHook('all'); | ||
|
||
await waitFor(() => { | ||
expect(result.current.recruitmentList.content).toHaveLength(3); | ||
}); | ||
|
||
act(() => { | ||
result.current.handleFilterChange('salary'); | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(result.current.recruitmentList.content).toHaveLength(3); | ||
expect(result.current.recruitmentList.content[0].companyName).toBe('์นด์นด์ค'); | ||
}); | ||
}); | ||
|
||
it('ํ์ด์ง๋ฅผ ๋ณ๊ฒฝํ์ ๋ ํ์ด์ง ๋ฒํธ๊ฐ ์ ๋ฐ์ดํธ ๋๋ค', async () => { | ||
const { result } = renderUseRecruitmentDataHook('all'); | ||
|
||
await waitFor(() => { | ||
expect(result.current.page).toBe(0); | ||
}); | ||
|
||
act(() => { | ||
result.current.handlePageChange(1); | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(result.current.page).toBe(1); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { setupServer } from 'msw/node'; | ||
import { handlers } from './handlers'; | ||
|
||
export const server = setupServer(...handlers); |
Oops, something went wrong.