Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/components/range-editor/range-editor.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import '@testing-library/jest-dom';
import React from "react"
import { render, screen } from "../../test-utils"
import userEvent from '@testing-library/user-event'
import RangeEditor from "./range-editor"
import { expect, it, vi } from "vitest"

it('can enter negative value to a numeric input', async () => {
const mockOnChangeFn = vi.fn()
const user = userEvent.setup()

render(
<RangeEditor
value={0}
onChange={mockOnChangeFn}
/>
)

const numberInput = screen.getByRole('spinbutton')
expect(numberInput).toBeInTheDocument()

await user.clear(numberInput)
await user.type(numberInput, '-5')
await user.tab()

expect(mockOnChangeFn).toHaveBeenCalledWith(-5)
})
2 changes: 1 addition & 1 deletion src/components/range-editor/range-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const RangeEditor: FunctionComponent<RangeProps & Omit<InputHTMLAttributes<HTMLI
<input
type="number"
className={cx('form-control', { 'ms-1': showRange })}
value={currentValue}
value={Number.isNaN(currentValue) ? '' : currentValue}
step={valueStep}
onChange={(e) => setCurrentValue(e.target.valueAsNumber)}
onBlur={() => onChange(currentValue)}
Expand Down