Skip to content

Commit

Permalink
✅ chore: more configurations have been added
Browse files Browse the repository at this point in the history
  • Loading branch information
futjesus committed Dec 11, 2024
1 parent d070b72 commit 55a15af
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 147 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.env*
.git*
.nvmrc
README.md
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
CLUSTER_DOMAIN=
PASSWORD=
USERNAME=
RETRY_DELAY=
RETRY_DELAY=10000
CLOUD_PROVIDER=aws
MAX_TIME_TO_WAIT=5m
6 changes: 3 additions & 3 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { defineConfig } from "cypress";
import * as dotenv from "dotenv";

dotenv.config();
import "dotenv/config";

export default defineConfig({
e2e: {
Expand All @@ -10,6 +8,8 @@ export default defineConfig({
USERNAME: process.env.USERNAME,
PASSWORD: process.env.PASSWORD,
RETRY_DELAY: process.env.RETRY_DELAY || 10000,
CLOUD_PROVIDER: process.env.CLOUD_PROVIDER,
MAX_TIME_TO_WAIT: process.env.MAX_TIME_TO_WAIT || "1h",
},
viewportWidth: 2000,
viewportHeight: 900,
Expand Down
102 changes: 75 additions & 27 deletions cypress/e2e/physical-cluster.cy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import ms from "ms";

import { Account } from "../../types/accouts";

const CLUSTER_NAME = "test-cluster";
const isAWS = Cypress.env("CLOUD_PROVIDER") === "aws";
const MAX_TIME_TO_WAIT = Cypress.env("MAX_TIME_TO_WAIT");

// Utility function to fill out the form to create a physical cluster
const fillOutForm = () => {
cy.get("form").as("form");
cy.get("@form").should("exist");

cy.findByRole("textbox").type("test-cluster", {
cy.findByRole("textbox").type(CLUSTER_NAME, {
delay: 10,
});

Expand Down Expand Up @@ -44,42 +50,84 @@ describe("Test to validate physical cluster creation", () => {
cy.login(username, password);
});

it("should create a physical cluster", () => {
cy.visit("/");
cy.findByRole("button", { name: /add workload cluster/i }).as("button");
if (isAWS) {
it("should create a physical cluster", () => {
cy.visit("/");
cy.findByRole("button", { name: /add workload cluster/i }).as("button");

cy.request("GET", "/api/proxy?url=%2Fcloud-account").then(
({ status, body }) => {
expect(status).to.eq(200);

const { cloud_accounts: cloudAccounts } = body;
cy.wrap(cloudAccounts as Account[]).as("accounts");
}
);

cy.get("@accounts").then((accounts) => {
const cloudAccounts = accounts as unknown as Account[];
expect(cloudAccounts).to.be.an("array");
expect(cloudAccounts).to.have.length.greaterThan(0);

const defaultAccount = cloudAccounts.find(
(account) => account.name === "default"
);

expect(defaultAccount).to.exist;
});

cy.get("@button").click();

cy.request("GET", "/api/proxy?url=%2Fcloud-account").then(
({ status, body }) => {
expect(status).to.eq(200);
fillOutForm();

const { cloud_accounts: cloudAccounts } = body;
cy.wrap(cloudAccounts as Account[]).as("accounts");
}
);
cy.findByRole("button", {
name: /create cluster/i,
}).click();

cy.get("@accounts").then((accounts) => {
const cloudAccounts = accounts as unknown as Account[];
expect(cloudAccounts).to.be.an("array");
expect(cloudAccounts).to.have.length.greaterThan(0);
cy.wait(2000);

const defaultAccount = cloudAccounts.find(
(account) => account.name === "default"
cy.findByRole("heading", { name: new RegExp(CLUSTER_NAME, "i") }).should(
"exist"
);
cy.contains("Provisioning").should("exist");
});

it("should validate the cluster is provisioning", () => {
cy.visit("/");

cy.goClusterManagement();

cy.findAllByRole("button", { name: new RegExp(CLUSTER_NAME, "i") })
.eq(0)
.as("clusterProvisioningButton");

expect(defaultAccount).to.exist;
cy.get("@clusterProvisioningButton").should("exist");

cy.get("@clusterProvisioningButton").within(() => {
cy.findByText(/provisioning/i).should("exist");
});
});

cy.get("@button").click();
it("should validate the cluster is provisioned", { retries: 3 }, () => {
cy.visit("/");

fillOutForm();
cy.goClusterManagement();

cy.findByRole("button", {
name: /create cluster/i,
}).click();
cy.findAllByRole("button", { name: new RegExp(CLUSTER_NAME, "i") })
.eq(0)
.as("clusterProvisionedButton");

cy.wait(2000);
cy.get("@clusterProvisionedButton").should("exist");

cy.findByRole("heading", { name: /test-cluster/i }).should("exist");
cy.contains("Provisioning").should("exist");
});
cy.get("@clusterProvisionedButton").within(() => {
cy.findByText(/provisioned/i, {
timeout: Number(ms(MAX_TIME_TO_WAIT)),
}).should("exist");
});
});
} else {
it("Test not run because the cloud provider is not AWS", () => {
cy.log("Skipping test because the cloud provider is not AWS");
});
}
});
6 changes: 6 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ declare global {
interface Chainable<Subject = any> {
login(username: string, password: string): Chainable<void>;
goApplications(): Chainable<void>;
goClusterManagement(): Chainable<void>;
}
}
}
Expand Down Expand Up @@ -36,3 +37,8 @@ Cypress.Commands.add("goApplications", () => {
cy.visit("/");
cy.findByRole("link", { name: /applications/i }).click();
});

Cypress.Commands.add("goClusterManagement", () => {
cy.visit("/");
cy.findByRole("link", { name: /cluster management/i }).click();
});
8 changes: 4 additions & 4 deletions cypress/support/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
afterEach(function () {
// if (this.currentTest.isFailed()) {
// const retryDelay = Cypress.env("RETRY_DELAY");
// cy.wait(+retryDelay);
// }
if (this.currentTest.state === "failed") {
const retryDelay = Cypress.env("RETRY_DELAY");
cy.wait(+retryDelay);
}
});
100 changes: 0 additions & 100 deletions git-clone.sh

This file was deleted.

22 changes: 18 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"scripts": {
"deps:update": "npx npm-check-updates --interactive --format group",
"cy:open": "cypress open",
"cy:run": "cypress run"
},
"dependencies": {
"@testing-library/cypress": "^10.0.2",
"cypress": "^13.16.1",
"dotenv": "^16.4.7",
"ms": "^2.1.3",
"typescript": "^5.7.2"
},
"scripts": {
"deps:update": "npx npm-check-updates --interactive --format group",
"cy:open": "cypress open",
"cy:run": "cypress run"
"devDependencies": {
"@types/ms": "^0.7.34"
}
}
}
7 changes: 4 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "node","@testing-library/cypress"]
"types": ["cypress", "node", "@testing-library/cypress"],
"esModuleInterop": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "custom.d.ts", ".next/types/**/*.ts", "checkStatus.ts"],
"exclude": ["node_modules", "dist", "server.js", "tests", "**/*.test.*", "**/*.spec.ts", ".next"]
"include": ["**/*.ts"],
"exclude": ["node_modules", "dist"]
}

0 comments on commit 55a15af

Please sign in to comment.