From fe3db3cdab6240a973240602be776987fb7eaa9b Mon Sep 17 00:00:00 2001 From: Sudhanshu Date: Sun, 25 Feb 2024 12:41:35 +0530 Subject: [PATCH] - Add test case for #814 --- test/library/input.spec.js | 9 +++++++-- test/library/keypress_and_caret.spec.js | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/test/library/input.spec.js b/test/library/input.spec.js index dafd976b..c3e2bc7a 100644 --- a/test/library/input.spec.js +++ b/test/library/input.spec.js @@ -531,13 +531,18 @@ describe('NumberFormat as input', () => { it('should contain currentTarget on focus event', async () => { let currentTarget; const { input } = await render( - {currentTarget = e.currentTarget}}/>, + { + 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() { diff --git a/test/library/keypress_and_caret.spec.js b/test/library/keypress_and_caret.spec.js index 93af0482..1ae35933 100644 --- a/test/library/keypress_and_caret.spec.js +++ b/test/library/keypress_and_caret.spec.js @@ -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, @@ -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( + , + ); + + + 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();