Skip to content

Commit

Permalink
fix(networks) enhance tests and fix a bug handling booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
edlerd committed Sep 1, 2023
1 parent 643c2b7 commit bab5ee4
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/util/networkEdit.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { LxdNetwork } from "types/network";

const toBool = (value: string | undefined): boolean | undefined =>
value !== undefined ? Boolean(value) : undefined;
const toBool = (value: string | undefined): boolean | undefined => {
if (value === undefined) {
return undefined;
}
return value === "true";
};

export const getNetworkEditValues = (network: LxdNetwork) => {
return {
Expand Down
8 changes: 6 additions & 2 deletions tests/helpers/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,20 @@ export const setSchedule = async (page: Page, value: string) => {
await page.getByPlaceholder("Enter cron expression").last().fill(value);
};

export const clickCheckbox = async (page: Page, name: string) => {
await page.getByRole("gridcell", { name }).first().getByText(name).click();
};

export const activateOverride = async (page: Page, field: string) => {
if (
!(await page
.getByRole("row", { name: field })
.getByRole("button", { name: "Clear" })
.getByRole("button", { name: "Clear override" })
.isVisible())
) {
await page
.getByRole("row", { name: field })
.getByRole("button", { name: "Override" })
.getByRole("button", { name: "Create override" })
.click();
}
};
Expand Down
5 changes: 4 additions & 1 deletion tests/helpers/instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export const createInstance = async (
type = "container"
) => {
await page.goto("/ui/");
await page.getByRole("link", { name: "Instances" }).first().click();
await page
.getByRole("link", { name: "Instances", exact: true })
.first()
.click();
await page.getByRole("button", { name: "Create instance" }).click();
await page.getByLabel("Instance name").click();
await page.getByLabel("Instance name").fill(instance);
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const randomNetworkName = (): string => {

export const createNetwork = async (page: Page, network: string) => {
await page.goto("/ui/");
await page.getByRole("link", { name: "Networks" }).click();
await page.getByRole("link", { name: "Networks", exact: true }).click();
await page.getByRole("button", { name: "Create network" }).click();
await page.getByRole("heading", { name: "Create a network" }).click();
await page.getByLabel("Name").click();
Expand All @@ -29,7 +29,7 @@ export const deleteNetwork = async (page: Page, network: string) => {

export const visitNetwork = async (page: Page, network: string) => {
await page.goto("/ui/");
await page.getByRole("link", { name: "Networks" }).click();
await page.getByRole("link", { name: "Networks", exact: true }).click();
await page.getByRole("link", { name: network }).first().click();
};

Expand Down
62 changes: 62 additions & 0 deletions tests/networks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import {
saveNetwork,
visitNetwork,
} from "./helpers/network";
import {
activateOverride,
assertReadMode,
clickCheckbox,
} from "./helpers/configuration";

test("network create and remove", async ({ page }) => {
const network = randomNetworkName();
Expand All @@ -20,10 +25,67 @@ test("network edit basic details", async ({ page }) => {

await editNetwork(page, network);
await page.getByPlaceholder("Enter description").fill("A-new-description");
await clickCheckbox(page, "IPv4 NAT");
await clickCheckbox(page, "IPv6 NAT");

await page.getByRole("button", { name: "Advanced" }).click();
await page.getByText("Bridge", { exact: true }).click();
await activateOverride(page, "MTU Bridge MTU");
await page.getByLabel("MTU").fill("1300");
await activateOverride(page, "Bridge Driver");
await page
.getByRole("combobox", { name: "Bridge Driver" })
.selectOption("native");

await page.getByText("DNS").click();
await activateOverride(page, "DNS domain Domain");
await page.getByLabel("DNS domain").fill("abc");
await activateOverride(page, "DNS mode");
await page.getByRole("combobox", { name: "DNS mode" }).selectOption("none");
await activateOverride(page, "DNS search");
await page.getByLabel("DNS search").fill("abc");

await page.getByText("IPv4").click();
await activateOverride(page, "IPv4 DHCP true");
await clickCheckbox(page, "IPv4 DHCP");
await activateOverride(page, "IPv4 DHCP expiry");
await page.getByLabel("IPv4 DHCP expiry").fill("2h");

await page.getByText("IPv6").click();
await activateOverride(page, "IPv6 DHCP true");
await clickCheckbox(page, "IPv6 DHCP");
await activateOverride(page, "IPv6 DHCP expiry");
await page.getByLabel("IPv6 DHCP expiry").fill("3h");
await activateOverride(page, "IPv6 DHCP stateful");
await clickCheckbox(page, "IPv6 DHCP stateful");

await saveNetwork(page);

await visitNetwork(page, network);
await page.getByRole("cell", { name: "A-new-description" }).click();

await page.getByTestId("tab-link-Configuration").click();
await assertReadMode(page, "Ipv4 NAT", "false");
await assertReadMode(page, "Ipv6 NAT", "false");

await page.getByRole("button", { name: "Advanced", exact: true }).click();
await page.getByText("Bridge", { exact: true }).click();
await assertReadMode(page, "MTU Bridge MTU", "1300");
await assertReadMode(page, "Bridge Driver", "native");

await page.getByText("DNS", { exact: true }).click();
await assertReadMode(page, "DNS domain Domain", "abc");
await assertReadMode(page, "DNS mode", "none");
await assertReadMode(page, "DNS search", "abc");

await page.getByText("IPv4", { exact: true }).click();
await assertReadMode(page, "IPv4 DHCP", "true");
await assertReadMode(page, "IPv4 DHCP expiry", "2h");

await page.getByText("IPv6", { exact: true }).click();
await assertReadMode(page, "IPv6 DHCP true", "true");
await assertReadMode(page, "IPv6 DHCP expiry", "3h");
await assertReadMode(page, "IPv6 DHCP stateful", "true");

await deleteNetwork(page, network);
});

0 comments on commit bab5ee4

Please sign in to comment.