Skip to content

Commit 3af62ca

Browse files
committed
test: 반복 일정 단일 삭제 테스트코드 수정
1 parent e3aa4ce commit 3af62ca

File tree

2 files changed

+48
-23
lines changed

2 files changed

+48
-23
lines changed

src/__mocks__/handlersUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export const setupMockHandlerRecurryingDeletion = () => {
194194
{
195195
id: '2',
196196
title: '삭제할 이벤트',
197-
date: '2025-10-15',
197+
date: '2025-10-22',
198198
startTime: '09:00',
199199
endTime: '10:00',
200200
description: '삭제할 이벤트입니다',

src/__tests__/recurringEvent.spec.tsx

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createTheme, CssBaseline, ThemeProvider } from '@mui/material';
2-
import { render, screen, within } from '@testing-library/react';
2+
import { render, screen, waitFor, within } from '@testing-library/react';
33
import userEvent, { UserEvent } from '@testing-library/user-event';
44
import { SnackbarProvider } from 'notistack';
55
import { ReactElement } from 'react';
@@ -363,52 +363,77 @@ describe('반복 일정 기능', () => {
363363

364364
describe('반복 일정 단일 삭제', () => {
365365
it('반복 일정 중 하나를 삭제하면 해당 일정만 삭제된다', async () => {
366-
vi.setSystemTime(new Date('2025-08-01')); // 테스트 기준 날짜
367-
// Given: 기존 이벤트가 존재
366+
vi.setSystemTime(new Date('2025-10-01')); // 테스트 기준 날짜
367+
368+
// Given: 서로 다른 날짜의 반복 일정 2개가 존재
368369
setupMockHandlerRecurryingDeletion();
369370
const { user } = setup(<App />);
370371

371-
// When: 삭제할 이벤트 클릭 후 삭제
372-
await user.click(screen.getByText('삭제할 이벤트'));
373-
await user.click(screen.getByRole('button', { name: //i }));
372+
// 초기 상태: 두 날짜의 이벤트가 모두 존재함을 확인
373+
expect(await screen.findByText('2025-10-15')).toBeInTheDocument(); // 첫 번째 일정
374+
expect(await screen.findByText('2025-10-22')).toBeInTheDocument(); // 두 번째 일정
374375

375-
// Then: 선택한 이벤트만 삭제되고 화면에서 사라짐
376-
expect(screen.queryByText('삭제할 이벤트')).not.toBeInTheDocument();
376+
// When: 첫 번째 이벤트 삭제
377377
const eventList = within(screen.getByTestId('event-list'));
378-
expect(eventList.getAllByTestId('RepeatIcon')).toHaveLength(1);
378+
const deleteButtons = await eventList.findAllByTestId('DeleteIcon');
379+
await user.click(deleteButtons[0]);
380+
381+
// Then: 첫 번째 일정(2025-10-15)만 삭제되고, 두 번째 일정(2025-10-22)은 남아있음
382+
await waitFor(() => {
383+
expect(eventList.queryByText('2025-10-15')).not.toBeInTheDocument(); // 삭제됨
384+
expect(eventList.getByText('2025-10-22')).toBeInTheDocument(); // 남아있음
385+
});
386+
387+
// 전체 이벤트 개수도 2개에서 1개로 감소
388+
expect(eventList.queryAllByText('삭제할 이벤트')).toHaveLength(1);
379389
});
380390

381391
it('반복 일정 중 하나를 삭제해도 다른 반복 일정들은 영향받지 않는다', async () => {
382-
vi.setSystemTime(new Date('2025-08-01')); // 테스트 기준 날짜
383-
// Given: 기존 이벤트 여러 개가 존재
392+
vi.setSystemTime(new Date('2025-10-01')); // 테스트 기준 날짜
393+
394+
// Given: 기존 이벤트 2개가 존재
384395
setupMockHandlerRecurryingDeletion();
385396
const { user } = setup(<App />);
386397

398+
const eventList = within(screen.getByTestId('event-list'));
399+
400+
// 초기 상태: 2개의 반복 일정이 존재함을 확인
401+
expect(await eventList.findAllByText('삭제할 이벤트')).toHaveLength(2);
402+
expect(await eventList.findAllByTestId('RepeatIcon')).toHaveLength(2);
403+
387404
// When: 첫 번째 이벤트 삭제
388-
await user.click(screen.getByText('삭제할 이벤트'));
389-
await user.click(screen.getByRole('button', { name: //i }));
405+
const deleteButtons = await eventList.findAllByTestId('DeleteIcon');
406+
await user.click(deleteButtons[0]);
390407

391-
// Then: 다른 이벤트는 그대로 존재
392-
expect(screen.getByText('남은 이벤트')).toBeInTheDocument();
393-
const eventList = within(screen.getByTestId('event-list'));
394-
expect(eventList.getAllByTestId('RepeatIcon')).toHaveLength(1);
408+
// Then: 하나만 삭제되고 나머지 반복 일정은 그대로 존재
409+
await waitFor(() => {
410+
expect(eventList.queryAllByText('삭제할 이벤트')).toHaveLength(1);
411+
expect(eventList.queryAllByTestId('RepeatIcon')).toHaveLength(1);
412+
});
395413
});
396414

397415
it('단일 삭제된 일정은 캘린더뷰와 리스트뷰에 즉시 반영된다', async () => {
398-
vi.setSystemTime(new Date('2025-08-01')); // 테스트 기준 날짜
416+
vi.setSystemTime(new Date('2025-10-01')); // 테스트 기준 날짜
399417
// Given: 삭제할 이벤트 존재
400418
setupMockHandlerRecurryingDeletion();
401419
const { user } = setup(<App />);
402420

403421
// When: 삭제 버튼 클릭
404-
await user.click(screen.getByText('삭제할 이벤트'));
405-
await user.click(screen.getByRole('button', { name: //i }));
422+
const eventList = within(screen.getByTestId('event-list'));
423+
const deleteButton = await eventList.findAllByTestId('DeleteIcon');
424+
await user.click(deleteButton[0]);
406425

407426
// Then: 캘린더뷰와 리스트뷰에서 즉시 삭제 반영
408427
const calendarView = within(screen.getByTestId('month-view'));
409428
const listView = within(screen.getByTestId('event-list'));
410-
expect(calendarView.queryAllByRole('img', { name: /repeat-event-icon/i })).toHaveLength(1);
411-
expect(listView.queryAllByRole('img', { name: /repeat-event-icon/i })).toHaveLength(1);
429+
await waitFor(() => {
430+
expect(listView.queryAllByText('삭제할 이벤트')).toHaveLength(1);
431+
});
432+
433+
// 캘린더뷰에서도 1개만 남아있는지 확인
434+
await waitFor(() => {
435+
expect(calendarView.queryAllByText('삭제할 이벤트')).toHaveLength(1);
436+
});
412437
});
413438
});
414439
});

0 commit comments

Comments
 (0)