|
| 1 | +import '@testing-library/jest-dom' |
| 2 | +import { render, screen } from '@testing-library/react' |
| 3 | + |
| 4 | +import { Chip } from './Chip' |
| 5 | + |
| 6 | +describe('Chip Component', () => { |
| 7 | + test('renders the Chip component with correct label', () => { |
| 8 | + // Chip 컴포넌트가 올바른 라벨을 렌더링하는지 확인합니다. |
| 9 | + render(<Chip label='모집 중' />) |
| 10 | + const chipElement = screen.getByText(/모집 중/i) |
| 11 | + expect(chipElement).toBeInTheDocument() |
| 12 | + }) |
| 13 | + |
| 14 | + test('applies correct styles for each label', () => { |
| 15 | + // 각 라벨에 대해 올바른 스타일이 적용되는지 확인합니다. |
| 16 | + const labelStyles = { |
| 17 | + '모집 중': 'bg-blue-100 text-blue-500', |
| 18 | + '모집 완료': 'bg-gray-200 text-gray-600', |
| 19 | + 스터디: 'bg-green-100 text-green-500', |
| 20 | + 프로젝트: 'bg-purple-100 text-purple-500', |
| 21 | + 멘토링: 'bg-red-100 text-red-500', |
| 22 | + 기술: 'bg-blue-100 text-blue-500', |
| 23 | + 커리어: 'bg-pink-100 text-pink-500', |
| 24 | + 기타: 'bg-orange-100 text-orange-500', |
| 25 | + } |
| 26 | + |
| 27 | + Object.entries(labelStyles).forEach(([label, expectedClasses]) => { |
| 28 | + render(<Chip label={label} />) |
| 29 | + const chipElement = screen.getByText(label) |
| 30 | + |
| 31 | + // expectedClasses에 포함된 각 클래스가 chipElement에 포함되는지 확인합니다. |
| 32 | + expectedClasses.split(' ').forEach(className => { |
| 33 | + expect(chipElement).toHaveClass(className) |
| 34 | + }) |
| 35 | + }) |
| 36 | + }) |
| 37 | + |
| 38 | + test('applies additional className passed as prop', () => { |
| 39 | + // className prop을 통해 추가된 클래스가 Chip 컴포넌트에 적용되는지 확인합니다. |
| 40 | + render(<Chip label='기술' className='custom-class' />) |
| 41 | + const chipElement = screen.getByText(/기술/i) |
| 42 | + expect(chipElement).toHaveClass('custom-class') |
| 43 | + }) |
| 44 | + |
| 45 | + test('applies base styles correctly', () => { |
| 46 | + // 기본 스타일이 Chip 컴포넌트에 올바르게 적용되는지 확인합니다. |
| 47 | + render(<Chip label='커리어' />) |
| 48 | + const chipElement = screen.getByText(/커리어/i) |
| 49 | + expect(chipElement).toHaveClass( |
| 50 | + 'flex', |
| 51 | + 'h-28', |
| 52 | + 'items-center', |
| 53 | + 'justify-center', |
| 54 | + 'rounded-4', |
| 55 | + 'px-6', |
| 56 | + 'text-body3', |
| 57 | + 'font-medium' |
| 58 | + ) |
| 59 | + }) |
| 60 | + |
| 61 | + test('applies default styles when label is not in styleByLabel', () => { |
| 62 | + // styleByLabel에 없는 라벨에 대해 기본 스타일이 적용되는지 확인합니다. |
| 63 | + render(<Chip label='기타 라벨' />) |
| 64 | + const chipElement = screen.getByText(/기타 라벨/i) |
| 65 | + expect(chipElement).toHaveClass('bg-gray-200', 'text-gray-500') |
| 66 | + }) |
| 67 | +}) |
0 commit comments