mirror of
https://github.com/langgenius/dify.git
synced 2026-02-01 00:21:14 +08:00
Some checks are pending
autofix.ci / autofix (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
Main CI Pipeline / Check Changed Files (push) Waiting to run
Main CI Pipeline / API Tests (push) Blocked by required conditions
Main CI Pipeline / Web Tests (push) Blocked by required conditions
Main CI Pipeline / Style Check (push) Waiting to run
Main CI Pipeline / VDB Tests (push) Blocked by required conditions
Main CI Pipeline / DB Migration Test (push) Blocked by required conditions
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
92 lines
2.9 KiB
TypeScript
92 lines
2.9 KiB
TypeScript
import { fireEvent, render, screen } from '@testing-library/react'
|
|
import { InputNumber } from './index'
|
|
|
|
describe('InputNumber Component', () => {
|
|
const defaultProps = {
|
|
onChange: vi.fn(),
|
|
}
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it('renders input with default values', () => {
|
|
render(<InputNumber {...defaultProps} />)
|
|
const input = screen.getByRole('spinbutton')
|
|
expect(input).toBeInTheDocument()
|
|
})
|
|
|
|
it('handles increment button click', () => {
|
|
render(<InputNumber {...defaultProps} value={5} />)
|
|
const incrementBtn = screen.getByRole('button', { name: /increment/i })
|
|
|
|
fireEvent.click(incrementBtn)
|
|
expect(defaultProps.onChange).toHaveBeenCalledWith(6)
|
|
})
|
|
|
|
it('handles decrement button click', () => {
|
|
render(<InputNumber {...defaultProps} value={5} />)
|
|
const decrementBtn = screen.getByRole('button', { name: /decrement/i })
|
|
|
|
fireEvent.click(decrementBtn)
|
|
expect(defaultProps.onChange).toHaveBeenCalledWith(4)
|
|
})
|
|
|
|
it('respects max value constraint', () => {
|
|
render(<InputNumber {...defaultProps} value={10} max={10} />)
|
|
const incrementBtn = screen.getByRole('button', { name: /increment/i })
|
|
|
|
fireEvent.click(incrementBtn)
|
|
expect(defaultProps.onChange).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('respects min value constraint', () => {
|
|
render(<InputNumber {...defaultProps} value={0} min={0} />)
|
|
const decrementBtn = screen.getByRole('button', { name: /decrement/i })
|
|
|
|
fireEvent.click(decrementBtn)
|
|
expect(defaultProps.onChange).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('handles direct input changes', () => {
|
|
render(<InputNumber {...defaultProps} />)
|
|
const input = screen.getByRole('spinbutton')
|
|
|
|
fireEvent.change(input, { target: { value: '42' } })
|
|
expect(defaultProps.onChange).toHaveBeenCalledWith(42)
|
|
})
|
|
|
|
it('handles empty input', () => {
|
|
render(<InputNumber {...defaultProps} value={1} />)
|
|
const input = screen.getByRole('spinbutton')
|
|
|
|
fireEvent.change(input, { target: { value: '' } })
|
|
expect(defaultProps.onChange).toHaveBeenCalledWith(0)
|
|
})
|
|
|
|
it('handles invalid input', () => {
|
|
render(<InputNumber {...defaultProps} />)
|
|
const input = screen.getByRole('spinbutton')
|
|
|
|
fireEvent.change(input, { target: { value: 'abc' } })
|
|
expect(defaultProps.onChange).toHaveBeenCalledWith(0)
|
|
})
|
|
|
|
it('displays unit when provided', () => {
|
|
const unit = 'px'
|
|
render(<InputNumber {...defaultProps} unit={unit} />)
|
|
expect(screen.getByText(unit)).toBeInTheDocument()
|
|
})
|
|
|
|
it('disables controls when disabled prop is true', () => {
|
|
render(<InputNumber {...defaultProps} disabled />)
|
|
const input = screen.getByRole('spinbutton')
|
|
const incrementBtn = screen.getByRole('button', { name: /increment/i })
|
|
const decrementBtn = screen.getByRole('button', { name: /decrement/i })
|
|
|
|
expect(input).toBeDisabled()
|
|
expect(incrementBtn).toBeDisabled()
|
|
expect(decrementBtn).toBeDisabled()
|
|
})
|
|
})
|