-
Notifications
You must be signed in to change notification settings - Fork 16
Handle empty IP Address field in Network Interface create flow #1854
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
Changes from all commits
4f60bb2
8220dd3
4c79975
6f7d2b7
4113ccd
6331dbb
69d0178
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
| * | ||
| * Copyright Oxide Computer Company | ||
| */ | ||
| import { test } from '@playwright/test' | ||
|
|
||
| import { expect, expectRowVisible } from './utils' | ||
|
|
||
| test('can create a NIC with a specified IP address', async ({ page }) => { | ||
| // go to an instance’s Network Interfaces page | ||
| await page.goto('/projects/mock-project/instances/db1/network-interfaces') | ||
|
|
||
| // stop the instance | ||
| await page.getByRole('button', { name: 'Instance actions' }).click() | ||
| await page.getByRole('menuitem', { name: 'Stop' }).click() | ||
|
|
||
| // open the add network interface side modal | ||
| await page.getByRole('button', { name: 'Add network interface' }).click() | ||
|
|
||
| // fill out the form | ||
| await page.getByLabel('Name').fill('nic-1') | ||
| await page.getByRole('button', { name: 'VPC' }).click() | ||
| await page.getByRole('option', { name: 'mock-vpc' }).click() | ||
| await page.getByRole('button', { name: 'Subnet' }).click() | ||
| await page.getByRole('option', { name: 'mock-subnet' }).click() | ||
| await page.getByLabel('IP Address').fill('1.2.3.4') | ||
|
|
||
| const sidebar = page.getByRole('dialog', { name: 'Add network interface' }) | ||
|
|
||
| // test that the form can be submitted and a new network interface is created | ||
| await sidebar.getByRole('button', { name: 'Add network interface' }).click() | ||
| await expect(sidebar).toBeHidden() | ||
|
|
||
| await expectRowVisible(page.getByRole('table'), { name: 'nic-1', ip: '1.2.3.4' }) | ||
| }) | ||
|
|
||
| test('can create a NIC with a blank IP address', async ({ page }) => { | ||
| // go to an instance’s Network Interfaces page | ||
| await page.goto('/projects/mock-project/instances/db1/network-interfaces') | ||
|
|
||
| // stop the instance | ||
| await page.getByRole('button', { name: 'Instance actions' }).click() | ||
| await page.getByRole('menuitem', { name: 'Stop' }).click() | ||
|
|
||
| // open the add network interface side modal | ||
| await page.getByRole('button', { name: 'Add network interface' }).click() | ||
|
|
||
| // fill out the form | ||
| await page.getByLabel('Name').fill('nic-2') | ||
| await page.getByRole('button', { name: 'VPC' }).click() | ||
| await page.getByRole('option', { name: 'mock-vpc' }).click() | ||
| await page.getByRole('button', { name: 'Subnet' }).click() | ||
| await page.getByRole('option', { name: 'mock-subnet' }).click() | ||
|
|
||
| // make sure the IP address field has a non-conforming bit of text in it | ||
| await page.getByLabel('IP Address').fill('x') | ||
|
|
||
| // try to submit it | ||
| const sidebar = page.getByRole('dialog', { name: 'Add network interface' }) | ||
| await sidebar.getByRole('button', { name: 'Add network interface' }).click() | ||
|
|
||
| // it should error out | ||
| // todo: improve error message from API | ||
| await expect(sidebar.getByText('Unknown server error')).toBeVisible() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is because we don't handle MSW errors properly in the UI. One thing we could do, it just occurred to me, is make them look more like real API errors so that the UI would handle them naturally. As in, where right now we just return the Zod error directly as JSON, we could stick it somewhere in an object that looks like
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| // make sure the IP address field has spaces in it | ||
| await page.getByLabel('IP Address').fill(' ') | ||
|
|
||
| // test that the form can be submitted and a new network interface is created | ||
| await sidebar.getByRole('button', { name: 'Add network interface' }).click() | ||
| await expect(sidebar).toBeHidden() | ||
|
|
||
| // ip address is auto-assigned | ||
| await expectRowVisible(page.getByRole('table'), { name: 'nic-2', ip: '123.45.68.8' }) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. handy row assert util |
||
| }) | ||
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.
I changed the return type from
string | undefinedto this, which effectively says it returns whatever the type of the field in question is. The explicitstring | undefinedwas fine for now, but we'd run into a type error later when we tried to use this on a field with a different type.