|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import { configs, test } from '@utils/test/playwright'; |
| 3 | + |
| 4 | +/** |
| 5 | + * Functionality is the same across modes & directions |
| 6 | + */ |
| 7 | +configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => { |
| 8 | + test.describe(title('input-otp: bottom content functionality'), () => { |
| 9 | + test('should not render bottom content if no hint is enabled', async ({ page }) => { |
| 10 | + await page.setContent(`<ion-input-otp> Description </ion-input-otp>`, config); |
| 11 | + |
| 12 | + const bottomEl = page.locator('ion-input-otp .input-otp-bottom'); |
| 13 | + await expect(bottomEl).toHaveCount(0); |
| 14 | + }); |
| 15 | + test('helper text should be visible initially', async ({ page }) => { |
| 16 | + await page.setContent( |
| 17 | + `<ion-input-otp helper-text="Helper text" error-text="Error text">Description</ion-input-otp>`, |
| 18 | + config |
| 19 | + ); |
| 20 | + |
| 21 | + const helperText = page.locator('ion-input-otp .helper-text'); |
| 22 | + const errorText = page.locator('ion-input-otp .error-text'); |
| 23 | + await expect(helperText).toBeVisible(); |
| 24 | + await expect(helperText).toHaveText('Helper text'); |
| 25 | + await expect(errorText).toBeHidden(); |
| 26 | + }); |
| 27 | + test('input-otp should have an aria-describedby attribute when helper text is present', async ({ page }) => { |
| 28 | + await page.setContent( |
| 29 | + `<ion-input-otp helper-text="Helper text" error-text="Error text">Description</ion-input-otp>`, |
| 30 | + config |
| 31 | + ); |
| 32 | + |
| 33 | + const inputOtpGroup = page.locator('ion-input-otp [role="group"]'); |
| 34 | + const helperText = page.locator('ion-input-otp .helper-text'); |
| 35 | + const helperTextId = await helperText.getAttribute('id'); |
| 36 | + const ariaDescribedBy = await inputOtpGroup.getAttribute('aria-describedby'); |
| 37 | + |
| 38 | + expect(ariaDescribedBy).toBe(helperTextId); |
| 39 | + }); |
| 40 | + test('error text should be visible when input-otp is invalid', async ({ page }) => { |
| 41 | + await page.setContent( |
| 42 | + `<ion-input-otp class="ion-invalid ion-touched" helper-text="Helper text" error-text="Error text">Description</ion-input-otp>`, |
| 43 | + config |
| 44 | + ); |
| 45 | + |
| 46 | + const helperText = page.locator('ion-input-otp .helper-text'); |
| 47 | + const errorText = page.locator('ion-input-otp .error-text'); |
| 48 | + await expect(helperText).toBeHidden(); |
| 49 | + await expect(errorText).toBeVisible(); |
| 50 | + await expect(errorText).toHaveText('Error text'); |
| 51 | + }); |
| 52 | + |
| 53 | + test('input-otp should have an aria-describedby attribute when error text is present', async ({ page }) => { |
| 54 | + await page.setContent( |
| 55 | + `<ion-input-otp class="ion-invalid ion-touched" helper-text="Helper text" error-text="Error text">Description</ion-input-otp>`, |
| 56 | + config |
| 57 | + ); |
| 58 | + |
| 59 | + const inputOtpGroup = page.locator('ion-input-otp [role="group"]'); |
| 60 | + const errorText = page.locator('ion-input-otp .error-text'); |
| 61 | + const errorTextId = await errorText.getAttribute('id'); |
| 62 | + const ariaDescribedBy = await inputOtpGroup.getAttribute('aria-describedby'); |
| 63 | + |
| 64 | + expect(ariaDescribedBy).toBe(errorTextId); |
| 65 | + }); |
| 66 | + test('input-otp should have aria-invalid attribute when input-otp is invalid', async ({ page }) => { |
| 67 | + await page.setContent( |
| 68 | + `<ion-input-otp class="ion-invalid ion-touched" helper-text="Helper text" error-text="Error text">Description</ion-input-otp>`, |
| 69 | + config |
| 70 | + ); |
| 71 | + |
| 72 | + const inputOtpGroup = page.locator('ion-input-otp [role="group"]'); |
| 73 | + |
| 74 | + await expect(inputOtpGroup).toHaveAttribute('aria-invalid'); |
| 75 | + }); |
| 76 | + test('input-otp should not have aria-invalid attribute when input-otp is valid', async ({ page }) => { |
| 77 | + await page.setContent( |
| 78 | + `<ion-input-otp helper-text="Helper text" error-text="Error text">Description</ion-input-otp>`, |
| 79 | + config |
| 80 | + ); |
| 81 | + |
| 82 | + const inputOtpGroup = page.locator('ion-input-otp [role="group"]'); |
| 83 | + |
| 84 | + await expect(inputOtpGroup).not.toHaveAttribute('aria-invalid'); |
| 85 | + }); |
| 86 | + test('input-otp should not have aria-describedby attribute when no hint or error text is present', async ({ |
| 87 | + page, |
| 88 | + }) => { |
| 89 | + await page.setContent(`<ion-input-otp>Description</ion-input-otp>`, config); |
| 90 | + |
| 91 | + const inputOtpGroup = page.locator('ion-input-otp [role="group"]'); |
| 92 | + |
| 93 | + await expect(inputOtpGroup).not.toHaveAttribute('aria-describedby'); |
| 94 | + }); |
| 95 | + }); |
| 96 | +}); |
0 commit comments