-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from zagdang/feat/input
Input UI 설정, 스토리 북 및 테스트 코드 작성
- Loading branch information
Showing
13 changed files
with
250 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: UI Unit Test | ||
|
||
permissions: | ||
pull-requests: write | ||
contents: read | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
branches: [main, develop] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: packages/ui | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18' | ||
|
||
- name: Set up Yarn 2 (Berry) | ||
run: | | ||
corepack enable | ||
corepack prepare [email protected] --activate | ||
- name: Install dependencies | ||
run: yarn install --immutable | ||
|
||
- name: Run tests with coverage | ||
run: yarn test --coverage | ||
|
||
- name: Get Coverage Info | ||
id: coverage | ||
run: | | ||
COVERAGE_REPORT=$(cat coverage/coverage-summary.json) | ||
echo "statements=$(echo $COVERAGE_REPORT | jq -r '.total.statements.pct')" >> $GITHUB_OUTPUT | ||
echo "branches=$(echo $COVERAGE_REPORT | jq -r '.total.branches.pct')" >> $GITHUB_OUTPUT | ||
echo "functions=$(echo $COVERAGE_REPORT | jq -r '.total.functions.pct')" >> $GITHUB_OUTPUT | ||
echo "lines=$(echo $COVERAGE_REPORT | jq -r '.total.lines.pct')" >> $GITHUB_OUTPUT | ||
- name: Comment PR with Coverage | ||
uses: thollander/actions-comment-pull-request@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
message: | | ||
## Test Coverage Report 📊 | ||
- Statements: ${{ steps.coverage.outputs.statements }}% | ||
- Branches: ${{ steps.coverage.outputs.branches }}% | ||
- Functions: ${{ steps.coverage.outputs.functions }}% | ||
- Lines: ${{ steps.coverage.outputs.lines }}% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Input.stories.tsx | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import React from 'react'; | ||
|
||
import { Input } from './input'; | ||
|
||
import { Button } from '@/components'; | ||
|
||
const meta = { | ||
title: 'Components/Input', | ||
component: Input, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: ['autodocs'], | ||
} satisfies Meta<typeof Input>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Input>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
placeholder: 'Enter text...', | ||
}, | ||
}; | ||
|
||
export const Widths: Story = { | ||
decorators: [ | ||
(Story) => ( | ||
<div className="min-w-[600px] p-4"> | ||
<div className="space-y-4"> | ||
<div className="w-full"> | ||
<p className="text-sm text-gray-500 mb-2">Full width (default)</p> | ||
<Story /> | ||
</div> | ||
<div className="w-96"> | ||
<p className="text-sm text-gray-500 mb-2">w-96</p> | ||
<Input placeholder="Width: 24rem" /> | ||
</div> | ||
<div className="w-72"> | ||
<p className="text-sm text-gray-500 mb-2">w-72</p> | ||
<Input placeholder="Width: 18rem" /> | ||
</div> | ||
<div className="w-1/2"> | ||
<p className="text-sm text-gray-500 mb-2">w-1/2</p> | ||
<Input placeholder="Width: 50%" /> | ||
</div> | ||
</div> | ||
</div> | ||
), | ||
], | ||
args: { | ||
placeholder: 'Full width input...', | ||
}, | ||
}; | ||
|
||
export const Disabled: Story = { | ||
args: { | ||
placeholder: 'Disabled input', | ||
disabled: true, | ||
}, | ||
}; | ||
|
||
export const WithValue_Controlled: Story = { | ||
render: () => { | ||
const [value, setValue] = React.useState('Sample text'); | ||
|
||
return ( | ||
<div className="flex gap-2"> | ||
<Input | ||
value={value} | ||
onChange={(e) => setValue(e.target.value)} | ||
placeholder="Type to change..." | ||
/> | ||
<Button onClick={() => alert(`Current value: ${value}`)}>Check</Button> | ||
</div> | ||
); | ||
}, | ||
}; | ||
|
||
export const WithType: Story = { | ||
args: { | ||
type: 'password', | ||
placeholder: 'Enter password', | ||
}, | ||
}; | ||
|
||
export const WithError: Story = { | ||
args: { | ||
className: 'border-error', | ||
placeholder: 'Error state', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Input.test.tsx | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { Input } from './input'; | ||
|
||
describe('Input Component', () => { | ||
it('renders correctly', () => { | ||
render(<Input placeholder="Test input" />); | ||
const input = screen.getByPlaceholderText('Test input'); | ||
expect(input).toBeInTheDocument(); | ||
}); | ||
|
||
it('accepts value changes', () => { | ||
render(<Input />); | ||
const input = screen.getByRole('textbox'); | ||
|
||
fireEvent.change(input, { target: { value: 'Test value' } }); | ||
expect(input).toHaveValue('Test value'); | ||
}); | ||
|
||
it('forwards ref correctly', () => { | ||
const ref = React.createRef<HTMLInputElement>(); | ||
render(<Input ref={ref} />); | ||
expect(ref.current).toBeInstanceOf(HTMLInputElement); | ||
}); | ||
|
||
it('handles disabled state', () => { | ||
render(<Input disabled />); | ||
const input = screen.getByRole('textbox'); | ||
expect(input).toBeDisabled(); | ||
}); | ||
|
||
it('handles different input types', () => { | ||
render(<Input type="email" />); | ||
const input = screen.getByRole('textbox'); | ||
expect(input).toHaveAttribute('type', 'email'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as React from 'react'; | ||
|
||
import { cn } from '@/lib/utils'; | ||
|
||
const Input = React.forwardRef<HTMLInputElement, React.ComponentProps<'input'>>( | ||
({ className, type, ...props }, ref) => { | ||
return ( | ||
<input | ||
type={type} | ||
className={cn( | ||
'flex h-10 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm', | ||
className, | ||
)} | ||
ref={ref} | ||
{...props} | ||
/> | ||
); | ||
}, | ||
); | ||
Input.displayName = 'Input'; | ||
|
||
export { Input }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { Button as default } from './Button/button'; | ||
export { Button } from './Button/button'; | ||
export { Input } from './Input/input'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters