From db07003d7de3613a4755cf3ab0379c5a6ae27b12 Mon Sep 17 00:00:00 2001 From: rbgksqkr Date: Fri, 20 Sep 2024 17:21:55 +0900 Subject: [PATCH] =?UTF-8?q?test:=20Modal=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EA=B2=8C=EC=9E=84=20?= =?UTF-8?q?=EC=8B=9C=EC=9E=91=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1=20#272?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StartButton/StartButtonContainer.test.tsx | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 frontend/src/components/StartButtonContainer/StartButton/StartButtonContainer.test.tsx diff --git a/frontend/src/components/StartButtonContainer/StartButton/StartButtonContainer.test.tsx b/frontend/src/components/StartButtonContainer/StartButton/StartButtonContainer.test.tsx new file mode 100644 index 000000000..5891d8e9d --- /dev/null +++ b/frontend/src/components/StartButtonContainer/StartButton/StartButtonContainer.test.tsx @@ -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(, { initializeState }); + }; + + renderWithRecoilState(true); + + const startButton = await screen.findByRole('button', { name: '시작' }); + await user.click(startButton); + + await waitFor(() => { + const closeIcon = screen.getByAltText('닫기 버튼'); + expect(closeIcon).toBeInTheDocument(); + }); + }); +});