Skip to content

Commit

Permalink
test: Modal 리팩토링을 위한 게임 시작 테스트 코드 작성 #272
Browse files Browse the repository at this point in the history
  • Loading branch information
rbgksqkr committed Sep 20, 2024
1 parent f23bc37 commit db07003
Showing 1 changed file with 47 additions and 0 deletions.
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();
});
});
});

0 comments on commit db07003

Please sign in to comment.