Skip to content

Commit

Permalink
♻️ refactor: update physical cluster creation tests to remove async a…
Browse files Browse the repository at this point in the history
…nd improve logging
  • Loading branch information
futjesus committed Jan 9, 2025
1 parent 43f14c0 commit ecfb92d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 27 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/create/physical-cluster.akamai.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("Test to validate physical cluster creation on AKAMAI", () => {
physicalCluster.login(username, password);
});

it("should create a physical cluster", async () => {
it("should create a physical cluster", () => {
physicalCluster.visitClusterPage();

physicalCluster.clickOnWorkloadClusterButton();
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/create/physical-cluster.civo.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("Test to validate physical cluster creation on CIVO", () => {
physicalCluster.login(username, password);
});

it("should create a physical cluster", async () => {
it("should create a physical cluster", () => {
physicalCluster.visitClusterPage();

const cloudAccounts = physicalCluster.getClodAccounts();
Expand Down
38 changes: 21 additions & 17 deletions cypress/e2e/create/physical-cluster.do.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const cloudProvider = Cypress.env("CLOUD_PROVIDER");
const MAX_TIME_TO_WAIT = Cypress.env("MAX_TIME_TO_WAIT");
const isDigitalOcean = cloudProvider === "do";

describe("Test to validate physical cluster creation on Digital Ocean", () => {
const physicalCluster = new PhysicalCluster();
const physicalCluster = new PhysicalCluster();

describe("Test to validate physical cluster creation on Digital Ocean", () => {
beforeEach(function () {
if (!isDigitalOcean) {
cy.log("This test is only for Digital Ocean");
Expand All @@ -25,30 +25,34 @@ describe("Test to validate physical cluster creation on Digital Ocean", () => {
physicalCluster.login(username, password);
});

it("should create a physical cluster", async () => {
it("should create a physical cluster", () => {
physicalCluster.visitClusterPage();

physicalCluster.clickOnWorkloadClusterButton();

const region = physicalCluster.getRegion("digitalocean");

region.then((region) => {
physicalCluster.filloutDigitalOceanForm({
name: CLUSTER_NAME,
region: new RegExp(region, "i"),
intanceSize: new RegExp("s-1vcpu-1gb", "i"),
});
const instanceSize = physicalCluster.getInstanceSize();

physicalCluster.clickOnCreateCluster();
physicalCluster.clickOnWorkloadClusterButton();

cy.wait(2000);
instanceSize.then((instanceSize1) => {
physicalCluster.filloutDigitalOceanForm({
name: CLUSTER_NAME,
region: new RegExp(region, "i"),
intanceSize: new RegExp(instanceSize1, "i"),
});

cy.findByRole("heading", {
name: new RegExp(CLUSTER_NAME, "i"),
timeout: Number(ms(MAX_TIME_TO_WAIT)),
}).should("exist");
physicalCluster.clickOnCreateCluster();

cy.wait(2000);

cy.contains("Provisioning").should("exist");
cy.findByRole("heading", {
name: new RegExp(CLUSTER_NAME, "i"),
timeout: Number(ms(MAX_TIME_TO_WAIT)),
}).should("exist");

cy.contains("Provisioning").should("exist");
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/create/physical-cluster.vultr.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("Test to validate physical cluster creation on VULTR", () => {
physicalCluster.login(username, password);
});

it("should create a physical cluster", async () => {
it("should create a physical cluster", () => {
physicalCluster.visitClusterPage();

physicalCluster.clickOnWorkloadClusterButton();
Expand Down
6 changes: 6 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,20 @@ Cypress.Commands.add("login", (username: string, password: string) => {
cacheAcrossSpecs: true,
}
);

cy.log("Logged in");
});

Cypress.Commands.add("goApplications", () => {
cy.visit("/");
cy.findByRole("link", { name: /applications/i }).click();
cy.url().should("contain", "/applications");
cy.log("Navigated to applications");
});

Cypress.Commands.add("goClusters", () => {
cy.visit("/");
cy.findByRole("link", { name: /clusters/i }).click();
cy.url().should("contain", "/clusters");
cy.log("Navigated to clusters");
});
40 changes: 33 additions & 7 deletions cypress/utils/create-cluster/physical/Physical.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Account } from "../../../../types/accouts";

import { PhysicalClusterClass } from "./Physical.types";

export class PhysicalCluster extends PhysicalClusterClass {
export class PhysicalCluster implements PhysicalClusterClass {
login(username: string, password: string) {
cy.login(username, password);
}
Expand All @@ -22,17 +20,17 @@ export class PhysicalCluster extends PhysicalClusterClass {
clickOnWorkloadClusterButton() {
cy.log("Click on workload cluster button");

const button = cy.findByRole("button", { name: /add workload cluster/i });
cy.findByRole("button", { name: /add workload cluster/i }).click();

button.click();
cy.log("Clicked on workload cluster button");
}

clickOnCreateCluster() {
cy.log("Click on create cluster button");

const button = cy.findByRole("button", { name: /create cluster/i });
cy.findByRole("button", { name: /create cluster/i }).click();

button.click();
cy.log("Clicked on create cluster button");
}

getClodAccounts(): Cypress.Chainable {
Expand Down Expand Up @@ -70,6 +68,34 @@ export class PhysicalCluster extends PhysicalClusterClass {
return cy.get("@region");
}

getInstanceSize(): Cypress.Chainable {
cy.log("Getting instance size");

cy.get(".management-cluster").click();

cy.get("form").as("form");

cy.get("@form").should("exist");

cy.get("@form").invoke("text").as("formText");

cy.get("@formText").then((formText: any) => {
const instanceSize = (formText as string).match(
new RegExp(`Instance size(.*?)(?=Number of nodes)`, "i")
);

cy.log(`Instance size gotten: ${instanceSize}`);

cy.wrap(instanceSize.at(1)).as("instanceSize");
});

cy.findAllByRole("button").eq(0).click();

cy.log("Instance size gotten");

return cy.get("@instanceSize");
}

filloutCivoForm({ name, region, intanceSize }) {
cy.log("Filling out Civo form");

Expand Down

0 comments on commit ecfb92d

Please sign in to comment.