@@ -135,7 +135,7 @@ describe('Directive', () => {
135135 } )
136136 } )
137137
138- describe ( ' Cursor updates', ( ) => {
138+ describe . each ( [ [ 'insertText' ] , [ undefined ] ] ) ( ' Cursor updates (inputType = %s) ', ( inputType ) => {
139139 let element
140140
141141 beforeEach ( ( ) => {
@@ -154,7 +154,18 @@ describe('Directive', () => {
154154 const newCursorPos = cursorPos + 1 // one new char inserted before
155155
156156 element . selectionEnd = cursorPos
157- wrapper . find ( 'input' ) . trigger ( 'input' , { inputType : 'insertText' } )
157+ wrapper . find ( 'input' ) . trigger ( 'input' , { inputType } )
158+
159+ expect ( wrapper . element . setSelectionRange ) . toBeCalledWith ( newCursorPos , newCursorPos )
160+ } )
161+
162+ test ( 'Should stay next to the char just inserted' , ( ) => {
163+ element . value = 'ABC1|23'
164+ const cursorPos = element . value . indexOf ( '|' )
165+ const newCursorPos = cursorPos + 1 // one new char inserted before
166+
167+ element . selectionEnd = cursorPos
168+ wrapper . find ( 'input' ) . trigger ( 'input' , { inputType } )
158169
159170 expect ( wrapper . element . setSelectionRange ) . toBeCalledWith ( newCursorPos , newCursorPos )
160171 } )
@@ -165,7 +176,7 @@ describe('Directive', () => {
165176 const newCursorPos = cursorPos + 2 // two new characters after masking
166177
167178 element . selectionEnd = cursorPos
168- wrapper . find ( 'input' ) . trigger ( 'input' , { inputType : 'insertText' } )
179+ wrapper . find ( 'input' ) . trigger ( 'input' , { inputType } )
169180
170181 expect ( wrapper . element . setSelectionRange ) . toBeCalledWith ( newCursorPos , newCursorPos )
171182 } )
@@ -176,7 +187,7 @@ describe('Directive', () => {
176187 const newCursorPos = cursorPos - 1 // needs to move back as 'j' is not an allowed char
177188
178189 element . selectionEnd = cursorPos
179- wrapper . find ( 'input' ) . trigger ( 'input' , { inputType : 'insertText' } )
190+ wrapper . find ( 'input' ) . trigger ( 'input' , { inputType } )
180191
181192 expect ( wrapper . element . setSelectionRange ) . toBeCalledWith ( newCursorPos , newCursorPos )
182193 } )
@@ -189,7 +200,7 @@ describe('Directive', () => {
189200 element . value = 'ABC-1J|2'
190201 const cursorPos = element . value . indexOf ( '|' )
191202 element . selectionEnd = cursorPos
192- wrapper . find ( 'input' ) . trigger ( 'input' , { inputType : 'insertText' } )
203+ wrapper . find ( 'input' ) . trigger ( 'input' , { inputType } )
193204 expect ( wrapper . element . setSelectionRange ) . not . toBeCalled ( )
194205 } )
195206 } )
0 commit comments