Skip to content

Commit

Permalink
- Add test case for #814
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yadav committed Feb 25, 2024
1 parent 30461f7 commit fe3db3c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
9 changes: 7 additions & 2 deletions test/library/input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,13 +531,18 @@ describe('NumberFormat as input', () => {
it('should contain currentTarget on focus event', async () => {
let currentTarget;
const { input } = await render(
<NumericFormat value="1234" onFocus={(e) => {currentTarget = e.currentTarget}}/>,
<NumericFormat
value="1234"
onFocus={(e) => {
currentTarget = e.currentTarget;
}}
/>,
);
input.focus();

await wait(0);
expect(currentTarget).not.toBeNull();
})
});

it('should not reset the selection when manually focused on mount', async () => {
function Test() {
Expand Down
21 changes: 21 additions & 0 deletions test/library/keypress_and_caret.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import NumericFormat from '../../src/numeric_format';
import PatternFormat from '../../src/pattern_format';
import NumberFormatBase from '../../src/number_format_base';
import { cleanup, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import {
simulateFocusEvent,
Expand Down Expand Up @@ -182,6 +183,26 @@ describe('Test keypress and caret position changes', () => {
expect(input.selectionStart).toEqual(2);
});

it('should not reset caret position if caret is updated by browser after we set caret position #811', async () => {
// https://codesandbox.io/p/sandbox/recursing-poitras-rxtjkj?file=%2Fsrc%2Findex.test.js%3A15%2C5-15%2C44
const { input } = await render(
<NumericFormat
allowLeadingZeros={false}
allowNegative={false}
decimalSeparator="."
displayType="input"
placeholder="people"
suffix=" people"
valueIsNumericString={false}
/>,
);


await userEvent.type(input, '91');

expect(input.value).toEqual('91 people');
});

describe('Test character insertion', () => {
it('should add any number properly when input is empty without format prop passed', async () => {
const { input } = await render(<NumericFormat thousandSeparator={true} prefix={'$'} />);
Expand Down

0 comments on commit fe3db3c

Please sign in to comment.