|
| 1 | +/* |
| 2 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 | + * file, you can obtain one at https://mozilla.org/MPL/2.0/. |
| 5 | + * |
| 6 | + * Copyright Oxide Computer Company |
| 7 | + */ |
| 8 | +import { test } from '@playwright/test' |
| 9 | + |
| 10 | +import { expect, expectRowVisible } from './utils' |
| 11 | + |
| 12 | +test('can create a NIC with a specified IP address', async ({ page }) => { |
| 13 | + // go to an instance’s Network Interfaces page |
| 14 | + await page.goto('/projects/mock-project/instances/db1/network-interfaces') |
| 15 | + |
| 16 | + // stop the instance |
| 17 | + await page.getByRole('button', { name: 'Instance actions' }).click() |
| 18 | + await page.getByRole('menuitem', { name: 'Stop' }).click() |
| 19 | + |
| 20 | + // open the add network interface side modal |
| 21 | + await page.getByRole('button', { name: 'Add network interface' }).click() |
| 22 | + |
| 23 | + // fill out the form |
| 24 | + await page.getByLabel('Name').fill('nic-1') |
| 25 | + await page.getByRole('button', { name: 'VPC' }).click() |
| 26 | + await page.getByRole('option', { name: 'mock-vpc' }).click() |
| 27 | + await page.getByRole('button', { name: 'Subnet' }).click() |
| 28 | + await page.getByRole('option', { name: 'mock-subnet' }).click() |
| 29 | + await page.getByLabel('IP Address').fill('1.2.3.4') |
| 30 | + |
| 31 | + const sidebar = page.getByRole('dialog', { name: 'Add network interface' }) |
| 32 | + |
| 33 | + // test that the form can be submitted and a new network interface is created |
| 34 | + await sidebar.getByRole('button', { name: 'Add network interface' }).click() |
| 35 | + await expect(sidebar).toBeHidden() |
| 36 | + |
| 37 | + await expectRowVisible(page.getByRole('table'), { name: 'nic-1', ip: '1.2.3.4' }) |
| 38 | +}) |
| 39 | + |
| 40 | +test('can create a NIC with a blank IP address', async ({ page }) => { |
| 41 | + // go to an instance’s Network Interfaces page |
| 42 | + await page.goto('/projects/mock-project/instances/db1/network-interfaces') |
| 43 | + |
| 44 | + // stop the instance |
| 45 | + await page.getByRole('button', { name: 'Instance actions' }).click() |
| 46 | + await page.getByRole('menuitem', { name: 'Stop' }).click() |
| 47 | + |
| 48 | + // open the add network interface side modal |
| 49 | + await page.getByRole('button', { name: 'Add network interface' }).click() |
| 50 | + |
| 51 | + // fill out the form |
| 52 | + await page.getByLabel('Name').fill('nic-2') |
| 53 | + await page.getByRole('button', { name: 'VPC' }).click() |
| 54 | + await page.getByRole('option', { name: 'mock-vpc' }).click() |
| 55 | + await page.getByRole('button', { name: 'Subnet' }).click() |
| 56 | + await page.getByRole('option', { name: 'mock-subnet' }).click() |
| 57 | + |
| 58 | + // make sure the IP address field has a non-conforming bit of text in it |
| 59 | + await page.getByLabel('IP Address').fill('x') |
| 60 | + |
| 61 | + // try to submit it |
| 62 | + const sidebar = page.getByRole('dialog', { name: 'Add network interface' }) |
| 63 | + await sidebar.getByRole('button', { name: 'Add network interface' }).click() |
| 64 | + |
| 65 | + // it should error out |
| 66 | + // todo: improve error message from API |
| 67 | + await expect(sidebar.getByText('Unknown server error')).toBeVisible() |
| 68 | + |
| 69 | + // make sure the IP address field has spaces in it |
| 70 | + await page.getByLabel('IP Address').fill(' ') |
| 71 | + |
| 72 | + // test that the form can be submitted and a new network interface is created |
| 73 | + await sidebar.getByRole('button', { name: 'Add network interface' }).click() |
| 74 | + await expect(sidebar).toBeHidden() |
| 75 | + |
| 76 | + // ip address is auto-assigned |
| 77 | + await expectRowVisible(page.getByRole('table'), { name: 'nic-2', ip: '123.45.68.8' }) |
| 78 | +}) |
0 commit comments