diff --git a/app/components/form/fields/DescriptionField.tsx b/app/components/form/fields/DescriptionField.tsx index 51b2b4ed36..3d45d962ac 100644 --- a/app/components/form/fields/DescriptionField.tsx +++ b/app/components/form/fields/DescriptionField.tsx @@ -16,7 +16,18 @@ export function DescriptionField< TFieldValues extends FieldValues, TName extends FieldPath, >(props: Omit, 'validate'>) { - return + return ( + { + const trimmedDescription = event.target.value.trim() + event.target.value = trimmedDescription + props.control._formValues.description = trimmedDescription + }} + {...props} + /> + ) } // TODO Update JSON schema to match this, add fuzz testing between this and name pattern diff --git a/test/e2e/floating-ip-create.e2e.ts b/test/e2e/floating-ip-create.e2e.ts index dfe5af2091..b76d65e4e5 100644 --- a/test/e2e/floating-ip-create.e2e.ts +++ b/test/e2e/floating-ip-create.e2e.ts @@ -24,9 +24,8 @@ test('can create a floating IP', async ({ page }) => { const floatingIpName = 'my-floating-ip' await page.fill('input[name=name]', floatingIpName) - await page - .getByRole('textbox', { name: 'Description' }) - .fill('A description for this Floating IP') + const description = page.getByRole('textbox', { name: 'Description' }) + await description.fill('A description for this Floating IP') const poolListbox = page.getByRole('button', { name: 'IP pool' }) @@ -51,6 +50,20 @@ test('can create a floating IP', async ({ page }) => { description: 'A description for this Floating IP', 'IP pool': 'ip-pool-1', }) + + // Make sure that descriptions with only whitespace get trimmed + await page.locator('text="New Floating IP"').click() + await page.fill('input[name=name]', 'no-description') + await description.fill(' ') + await description.blur() + await expect(description).toContainText('') + await page.getByRole('button', { name: 'Create floating IP' }).click() + + await expectRowVisible(page.getByRole('table'), { + name: 'no-description', + description: '—', + 'IP pool': 'ip-pool-1', + }) }) test('can detach and attach a floating IP', async ({ page }) => {