Skip to content

Commit 6b07d0d

Browse files
committed
chore: Modal test 통과
1 parent c9b9870 commit 6b07d0d

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { Modal } from '@shared/ui/Modal/Modal';
2+
import { render, screen } from '@testing-library/react';
3+
import userEvent from '@testing-library/user-event';
4+
5+
describe('Modal', () => {
6+
const setup = (props?: Partial<React.ComponentProps<typeof Modal>>) => {
7+
const onCancel = vi.fn();
8+
const onConfirm = vi.fn();
9+
10+
render(
11+
<Modal
12+
title="해당 게시물을 삭제하시겠어요?"
13+
subtitle="subtitle 1줄"
14+
onCancel={onCancel}
15+
onConfirm={onConfirm}
16+
{...props}
17+
/>
18+
);
19+
20+
return { onCancel, onConfirm };
21+
};
22+
23+
describe('Rendering', () => {
24+
it('title 렌더링', () => {
25+
setup();
26+
expect(screen.getByText('해당 게시물을 삭제하시겠어요?')).toBeInTheDocument();
27+
});
28+
29+
it('subtitle 렌더링', () => {
30+
setup();
31+
expect(screen.getByText('subtitle 1줄')).toBeInTheDocument();
32+
});
33+
34+
it('subtitle이 없을 경우 렌더링되지 않음', () => {
35+
render(<Modal title="제목만 있는 모달" onCancel={vi.fn()} onConfirm={vi.fn()} />);
36+
37+
expect(screen.queryByText('삭제 후에는 복구할 수 없습니다.')).not.toBeInTheDocument();
38+
});
39+
40+
it('취소 / 삭제 버튼 렌더링', () => {
41+
setup();
42+
expect(screen.getByRole('button', { name: '취소' })).toBeInTheDocument();
43+
expect(screen.getByRole('button', { name: '삭제' })).toBeInTheDocument();
44+
});
45+
});
46+
47+
describe('Interaction', () => {
48+
it('취소 버튼 클릭 시 onCancel 호출', async () => {
49+
const user = userEvent.setup();
50+
const { onCancel } = setup();
51+
52+
await user.click(screen.getByRole('button', { name: '취소' }));
53+
expect(onCancel).toHaveBeenCalledTimes(1);
54+
});
55+
56+
it('삭제 버튼 클릭 시 onConfirm 호출', async () => {
57+
const user = userEvent.setup();
58+
const { onConfirm } = setup();
59+
60+
await user.click(screen.getByRole('button', { name: '삭제' }));
61+
expect(onConfirm).toHaveBeenCalledTimes(1);
62+
});
63+
});
64+
65+
describe('Accessibility', () => {
66+
it('버튼은 접근 가능한 role을 가잠', () => {
67+
setup();
68+
expect(screen.getAllByRole('button')).toHaveLength(2);
69+
});
70+
71+
it('Tab 키로 버튼 포커스 이동 가능', async () => {
72+
const user = userEvent.setup();
73+
setup();
74+
75+
await user.tab();
76+
expect(screen.getByRole('button', { name: '취소' })).toHaveFocus();
77+
78+
await user.tab();
79+
expect(screen.getByRole('button', { name: '삭제' })).toHaveFocus();
80+
});
81+
});
82+
});

0 commit comments

Comments
 (0)