-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3133bf6
commit ec6d6de
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
packages/mui-base/src/unstable_useNumberInput/useNumberInput2.test.tsx
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,41 @@ | ||
import * as React from 'react'; | ||
import { expect } from 'chai'; | ||
import { spy } from 'sinon'; | ||
import { createRenderer, screen, fireEvent } from '@mui/internal-test-utils'; | ||
import { unstable_useNumberInput as useNumberInput } from '@mui/base/unstable_useNumberInput'; | ||
|
||
describe('useNumberInput2', () => { | ||
const { clock, render } = createRenderer(); | ||
|
||
describe('press and hold', () => { | ||
clock.withFakeTimers(); | ||
|
||
it('should call onChange continuously', () => { | ||
const handleChange = spy(); | ||
function NumberInput(props: { defaultValue: number }) { | ||
const { getInputProps, getIncrementButtonProps } = useNumberInput({ | ||
...props, | ||
onChange: handleChange, | ||
}); | ||
|
||
return ( | ||
<div role="group"> | ||
<button {...getIncrementButtonProps()} data-testid="incrementBtn" /> | ||
<input data-testid="test-input" {...getInputProps()} /> | ||
</div> | ||
); | ||
} | ||
render(<NumberInput defaultValue={0} />); | ||
|
||
const incrementBtn = screen.getByTestId('incrementBtn'); | ||
|
||
fireEvent.mouseDown(incrementBtn); | ||
|
||
clock.tick(100); | ||
clock.tick(100); | ||
clock.runToLast(); | ||
|
||
expect(handleChange.callCount).to.equal(3); | ||
}); | ||
}); | ||
}); |