-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Modal 리팩토링을 위한 게임 시작 테스트 코드 작성 #272
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
frontend/src/components/StartButtonContainer/StartButton/StartButtonContainer.test.tsx
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,47 @@ | ||
import { screen, waitFor } from '@testing-library/react'; | ||
import { userEvent } from '@testing-library/user-event'; | ||
import { http, HttpResponse } from 'msw'; | ||
import type { MutableSnapshot } from 'recoil'; | ||
|
||
import StartButtonContainer from '../StartButtonContainer'; | ||
|
||
import { ERROR_MESSAGE } from '@/constants/message'; | ||
import { MOCK_API_URL } from '@/constants/url'; | ||
import { server } from '@/mocks/server'; | ||
import { memberInfoState } from '@/recoil/atom'; | ||
import { customRender } from '@/utils/test-utils'; | ||
|
||
describe('StartButtonContainer', () => { | ||
it('시작 버튼을 클릭했을 때, 게임 시작 API에서 에러가 발생하면 알림 모달이 뜬다.', async () => { | ||
const user = userEvent.setup(); | ||
server.use( | ||
http.patch(MOCK_API_URL.startGame, async () => { | ||
return HttpResponse.json( | ||
{ | ||
errorCode: 'NOT_READY_ROOM', | ||
message: ERROR_MESSAGE.NOT_READY_ROOM, | ||
}, | ||
{ status: 400 }, | ||
); | ||
}), | ||
); | ||
|
||
const renderWithRecoilState = (isMaster: boolean) => { | ||
const initializeState = (snap: MutableSnapshot) => { | ||
snap.set(memberInfoState, { memberId: 1, nickname: 'Test User', isMaster }); | ||
}; | ||
|
||
customRender(<StartButtonContainer />, { initializeState }); | ||
}; | ||
|
||
renderWithRecoilState(true); | ||
|
||
const startButton = await screen.findByRole('button', { name: '시작' }); | ||
await user.click(startButton); | ||
|
||
await waitFor(() => { | ||
const closeIcon = screen.getByAltText('닫기 버튼'); | ||
expect(closeIcon).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |