Skip to content

Commit eb6ae3f

Browse files
committed
test(input-otp): add another focus test
1 parent 97649a0 commit eb6ae3f

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

core/src/components/input-otp/test/basic/input-otp.e2e.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
190190
await expect(inputOtp).toHaveJSProperty('value', '1');
191191

192192
// Focus should be on the 2nd input box
193-
const secondInput = page.locator('ion-input-otp input').nth(1);
194-
await expect(secondInput).toBeFocused();
193+
await expect(inputBoxes.nth(1)).toBeFocused();
195194
});
196195

197196
test('should update the 3rd input value and shift the values to the right when typing in the 3rd box containing a value', async ({ page }) => {
@@ -217,7 +216,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
217216
await expect(inputOtp).toHaveJSProperty('value', '1293');
218217

219218
// Focus should remain on the 3rd input box
220-
await expect(thirdInput).toBeFocused();
219+
await expect(inputBoxes.nth(2)).toBeFocused();
221220
});
222221

223222
test('should update the 2nd input value when typing in the 2nd box containing a value', async ({ page }) => {
@@ -243,7 +242,7 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
243242
await expect(inputOtp).toHaveJSProperty('value', '1934');
244243

245244
// Focus should remain on the 2nd input box
246-
await expect(secondInput).toBeFocused();
245+
await expect(inputBoxes.nth(1)).toBeFocused();
247246
});
248247
});
249248

@@ -289,6 +288,23 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
289288
const lastInput = page.locator('ion-input-otp input').last();
290289
await expect(lastInput).toBeFocused();
291290
});
291+
292+
test('should focus the next input otp component when tabbed from the 2nd input box', async ({ page }) => {
293+
await page.setContent(
294+
`
295+
<ion-input-otp id="first" value="12">Description</ion-input-otp>
296+
<ion-input-otp id="second">Description</ion-input-otp>
297+
`,
298+
config
299+
);
300+
301+
await page.keyboard.press('Tab');
302+
await page.keyboard.press('ArrowLeft');
303+
await page.keyboard.press('Tab');
304+
305+
const secondInputOtpFirstInput = page.locator('#second input').first();
306+
await expect(secondInputOtpFirstInput).toBeFocused();
307+
});
292308
});
293309

294310
test.describe(title('input-otp: backspace functionality'), () => {
@@ -435,6 +451,9 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
435451
await expect(inputBoxes.nth(1)).toHaveValue('2');
436452
await expect(inputBoxes.nth(2)).toHaveValue('');
437453
await expect(inputBoxes.nth(3)).toHaveValue('');
454+
455+
// Focus should be on the 3rd input box
456+
await expect(inputBoxes.nth(2)).toBeFocused();
438457
});
439458

440459
test('should paste text into the last two input boxes when pasting 2 digits after typing 2 digits', async ({

0 commit comments

Comments
 (0)