-
Notifications
You must be signed in to change notification settings - Fork 62
Add inline input validation to create forms and wizards #775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Anton-Fil
wants to merge
2
commits into
Kuadrant:main
Choose a base branch
from
Anton-Fil:inline-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| import { test, expect, Page } from '@playwright/test'; | ||
| import { dismissConsoleTour } from './helpers'; | ||
|
|
||
| async function gotoPage(page: Page, path: string): Promise<void> { | ||
| await page.goto(path); | ||
| await page.waitForLoadState('domcontentloaded'); | ||
| await dismissConsoleTour(page); | ||
| } | ||
|
|
||
| test.describe('Inline validation', () => { | ||
| test('HTTPRoute name field shows validation errors', { tag: '@nightly' }, async ({ page }) => { | ||
| const namespace = 'default'; | ||
| const path = `/k8s/ns/${namespace}/gateway.networking.k8s.io~v1~HTTPRoute/~new`; | ||
|
|
||
| await gotoPage(page, path); | ||
|
|
||
| // Wait for form to be visible | ||
| await expect(page.locator('#httproute-name')).toBeVisible({ timeout: 15_000 }); | ||
|
|
||
| // Test 1: Empty field after blur should show "required" error | ||
| await page.locator('#httproute-name').focus(); | ||
| await page.locator('#httproute-name').blur(); | ||
|
|
||
| // Should show error message | ||
| await expect( | ||
| page.locator('text=This field is required').or(page.locator('[variant="error"]')), | ||
| ).toBeVisible({ timeout: 5_000 }); | ||
|
|
||
| // Test 2: Invalid uppercase characters | ||
| await page.locator('#httproute-name').fill('INVALID-ROUTE'); | ||
| await page.locator('#httproute-name').blur(); | ||
|
|
||
| // Should show validation error | ||
| await expect( | ||
| page.locator( | ||
| 'text=Name must consist of lowercase alphanumeric characters, "-", or ".", and must start and end with an alphanumeric character', | ||
| ), | ||
| ).toBeVisible({ timeout: 5_000 }); | ||
|
|
||
| // Input should have error state (red border via ValidatedOptions.error) | ||
| const input = page.locator('#httproute-name'); | ||
| const ariaInvalid = await input.getAttribute('aria-invalid'); | ||
| expect(ariaInvalid).toBe('true'); | ||
|
|
||
| // Test 3: Invalid special characters (underscore) | ||
| await page.locator('#httproute-name').fill('invalid_route'); | ||
| await page.locator('#httproute-name').blur(); | ||
|
|
||
| await expect( | ||
| page.locator( | ||
| 'text=Name must consist of lowercase alphanumeric characters, "-", or ".", and must start and end with an alphanumeric character', | ||
| ), | ||
| ).toBeVisible({ timeout: 5_000 }); | ||
|
|
||
| // Test 4: Valid input clears error | ||
| await page.locator('#httproute-name').fill('valid-route-123'); | ||
| await page.locator('#httproute-name').blur(); | ||
|
|
||
| // Error should disappear | ||
| await expect( | ||
| page.locator( | ||
| 'text=Name must consist of lowercase alphanumeric characters, "-", or ".", and must start and end with an alphanumeric character', | ||
| ), | ||
| ).not.toBeVisible({ timeout: 5_000 }); | ||
|
|
||
| // Helper text should be shown instead | ||
| await expect(page.locator('text=Unique name of the HTTPRoute')).toBeVisible({ | ||
| timeout: 5_000, | ||
| }); | ||
|
|
||
| // Input should not have error state | ||
| const ariaInvalidAfter = await input.getAttribute('aria-invalid'); | ||
| expect(ariaInvalidAfter).not.toBe('true'); | ||
| }); | ||
|
|
||
| test('Gateway listener port shows validation errors', { tag: '@nightly' }, async ({ page }) => { | ||
| const namespace = 'default'; | ||
| const path = `/k8s/ns/${namespace}/gateway.networking.k8s.io~v1~Gateway/~new`; | ||
|
|
||
| await gotoPage(page, path); | ||
|
|
||
| // Wait for form to be visible | ||
| await expect(page.locator('#gateway-name')).toBeVisible({ timeout: 15_000 }); | ||
|
|
||
| // Fill gateway name to proceed | ||
| await page.locator('#gateway-name').fill('test-gateway'); | ||
|
|
||
| // Click "Add listener" button | ||
| await page.getByRole('button', { name: /Add listener/i }).click(); | ||
|
|
||
| // Wait for listener wizard to open | ||
| await expect(page.locator('#listener-name')).toBeVisible({ timeout: 10_000 }); | ||
|
|
||
| // Fill listener name | ||
| await page.locator('#listener-name').fill('http'); | ||
|
|
||
| // Test port validation - invalid port (0) | ||
| await page.locator('#listener-port').fill('0'); | ||
| await page.locator('#listener-port').blur(); | ||
|
|
||
| // Should show validation error | ||
| await expect(page.locator('text=Port must be between 1 and 65535')).toBeVisible({ | ||
| timeout: 5_000, | ||
| }); | ||
|
|
||
| // Test port validation - port > 65535 | ||
| await page.locator('#listener-port').fill('70000'); | ||
| await page.locator('#listener-port').blur(); | ||
|
|
||
| await expect(page.locator('text=Port must be between 1 and 65535')).toBeVisible({ | ||
| timeout: 5_000, | ||
| }); | ||
|
|
||
| // Test valid port | ||
| await page.locator('#listener-port').fill('8080'); | ||
| await page.locator('#listener-port').blur(); | ||
|
|
||
| // Error should disappear | ||
| await expect(page.locator('text=Port must be between 1 and 65535')).not.toBeVisible({ | ||
| timeout: 5_000, | ||
| }); | ||
| }); | ||
|
|
||
| test('DNS Policy name shows validation errors', { tag: '@nightly' }, async ({ page }) => { | ||
| const namespace = 'default'; | ||
| const path = `/k8s/ns/${namespace}/kuadrant.io~v1~DNSPolicy/~new`; | ||
|
|
||
| await gotoPage(page, path); | ||
|
|
||
| // Wait for form to be visible | ||
| await expect(page.locator('#policy-name')).toBeVisible({ timeout: 15_000 }); | ||
|
|
||
| // Test uppercase in policy name | ||
| await page.locator('#policy-name').fill('DNS-POLICY-TEST'); | ||
| await page.locator('#policy-name').blur(); | ||
|
|
||
| // Should show validation error | ||
| await expect( | ||
| page.locator( | ||
| 'text=Name must consist of lowercase alphanumeric characters, "-", or ".", and must start and end with an alphanumeric character', | ||
| ), | ||
| ).toBeVisible({ timeout: 5_000 }); | ||
|
|
||
| // Test valid name | ||
| await page.locator('#policy-name').fill('dns-policy-test'); | ||
| await page.locator('#policy-name').blur(); | ||
|
|
||
| // Error should disappear | ||
| await expect( | ||
| page.locator( | ||
| 'text=Name must consist of lowercase alphanumeric characters, "-", or ".", and must start and end with an alphanumeric character', | ||
| ), | ||
| ).not.toBeVisible({ timeout: 5_000 }); | ||
|
|
||
| // Helper text should be visible | ||
| await expect(page.locator('text=Unique name of the DNS Policy')).toBeVisible({ | ||
| timeout: 5_000, | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Scope the required-error assertion to the HTTPRoute name field.
[variant="error"]can match an unrelated validation error on the page. The assertion can pass when#httproute-namedoes not show the required error. Assert the required text directly, or locate the error message within the name field’s form group.🤖 Prompt for AI Agents