diff --git a/src/frontend/package.json b/src/frontend/package.json index ad42a1bd..bddbf83e 100644 --- a/src/frontend/package.json +++ b/src/frontend/package.json @@ -8,6 +8,7 @@ "dev": "vite dev", "start": "vite", "typecheck": "tsc", + "test": "vitest", "check": "yarn formatter && yarn lint:fix", "lint": "eslint \"src/**/*.{ts,tsx}\"", "lint:fix": "eslint --fix \"src/**/*.{ts,tsx}\"", @@ -52,6 +53,7 @@ "@storybook/react-vite": "^8.5.0", "@storybook/test": "^8.5.0", "@tanstack/eslint-plugin-query": "^5.66.1", + "@testing-library/react": "^16.2.0", "@types/node": "^20", "@types/react": "^19.0.1", "@types/react-dom": "^19.0.1", @@ -65,6 +67,7 @@ "eslint-plugin-storybook": "^0.11.2", "eslint-plugin-unused-imports": "^4.1.4", "globals": "^15.14.0", + "jsdom": "^26.0.0", "msw": "^2.7.1", "prettier": "^3.4.2", "sharp": "^0.33.5", diff --git a/src/frontend/src/components/auth-input/auth-input.spec.tsx b/src/frontend/src/components/auth-input/auth-input.spec.tsx new file mode 100644 index 00000000..580df71c --- /dev/null +++ b/src/frontend/src/components/auth-input/auth-input.spec.tsx @@ -0,0 +1,44 @@ +import { render, screen } from '@testing-library/react' +import { describe, expect, it } from 'vitest' + +import AuthInput from './index' + +describe('AuthInput', () => { + it('should render', () => { + render() + + const label = screen.getByText('Email') + expect(label).not.toBeNull() + }) + + it('should render error message', () => { + render( + + ) + + const error = screen.getByText('Invalid email') + expect(error).not.toBeNull() + }) + + it('should render required message', () => { + render( + + ) + + const required = screen.getByText('*') + expect(required).not.toBeNull() + }) + + it('should render input', () => { + render() + + const input = screen.getByRole('textbox') + expect(input).not.toBeNull() + }) +}) diff --git a/src/frontend/src/components/avatar/avatar.spec.tsx b/src/frontend/src/components/avatar/avatar.spec.tsx new file mode 100644 index 00000000..3def9ab7 --- /dev/null +++ b/src/frontend/src/components/avatar/avatar.spec.tsx @@ -0,0 +1,32 @@ +import { render, screen } from '@testing-library/react' +import { describe, expect, it } from 'vitest' + +import Avatar from './index' + +describe('Avatar', () => { + it('should render without avatar url', () => { + render( + + ) + const img = screen.getByRole('img') + expect(img.getAttribute('src')).toBe('/image/common/default-avatar.png') + }) + + it('should render with avatar url', () => { + render( + + ) + const img = screen.getByRole('img') + expect(img.getAttribute('src')).toBe('/homepage/hero-character.png') + }) +}) diff --git a/src/frontend/src/components/check-box/check-box.spec.tsx b/src/frontend/src/components/check-box/check-box.spec.tsx new file mode 100644 index 00000000..fde68871 --- /dev/null +++ b/src/frontend/src/components/check-box/check-box.spec.tsx @@ -0,0 +1,62 @@ +import { fireEvent, render, screen } from '@testing-library/react' +import { describe, expect, it, vi } from 'vitest' + +import CheckBox from './index' + +describe('CheckBox', () => { + const onChange = vi.fn() + it('should render', () => { + render( + + ) + + const checkBox = screen.getByRole('checkbox') + expect(checkBox).not.toBeNull() + }) + + it('should render checked', () => { + render( + + ) + + const checkBox = screen.getByRole('checkbox') + expect(checkBox).not.toBeNull() + }) + + it('should render label', () => { + render( + + ) + + const label = screen.getByText('Checkbox') + expect(label).not.toBeNull() + }) + + it('should call onChange', () => { + const onChange = vi.fn() + render( + + ) + + const checkBox = screen.getByRole('checkbox') + fireEvent.click(checkBox) + + expect(onChange).toHaveBeenCalled() + }) +}) diff --git a/src/frontend/src/components/date-input/dete-input.spec.tsx b/src/frontend/src/components/date-input/dete-input.spec.tsx new file mode 100644 index 00000000..08722121 --- /dev/null +++ b/src/frontend/src/components/date-input/dete-input.spec.tsx @@ -0,0 +1,74 @@ +import { fireEvent, render, screen } from '@testing-library/react' +import { describe, expect, it, vi } from 'vitest' + +import DateInput from './index' + +describe('DateInput', () => { + const setDate = vi.fn() + it('should render', () => { + render( + + ) + + const label = screen.getByText('Date') + expect(label).not.toBeNull() + }) + + it('should call setDate', () => { + render( + + ) + + const selectBoxYear = screen.getAllByRole('combobox')[0] + fireEvent.click(selectBoxYear) + + const option1 = screen.getByText('2025') + fireEvent.click(option1) + + const selectBoxMonth = screen.getAllByRole('combobox')[1] + fireEvent.click(selectBoxMonth) + + const option2 = screen.getByText('1월') + fireEvent.click(option2) + + const selectBoxDay = screen.getAllByRole('combobox')[2] + fireEvent.click(selectBoxDay) + + const option3 = screen.getByText('30') + fireEvent.click(option3) + + expect(setDate).toHaveBeenCalledWith('2025-01-30') + }) + + it('should render error', () => { + render( + + ) + + const error = screen.getByText('Error') + expect(error).not.toBeNull() + }) + + it('should render required', () => { + render( + + ) + + const required = screen.getByText('*') + expect(required).not.toBeNull() + }) +}) diff --git a/src/frontend/src/components/select-box/index.tsx b/src/frontend/src/components/select-box/index.tsx index 6225f117..e1b2e7b2 100644 --- a/src/frontend/src/components/select-box/index.tsx +++ b/src/frontend/src/components/select-box/index.tsx @@ -91,10 +91,13 @@ const SelectBox = ({ ) : null}
-
+
+ ({ {...props} />