Skip to content

Commit 76b1d1c

Browse files
authored
chore(e2e): introduce kubernetes actions namespace test (#2150)
* chore(e2e): introduce kubernetes actions namespace test Signed-off-by: Dominika Zemanovicova <[email protected]> * Simplify test Signed-off-by: Dominika Zemanovicova <[email protected]> * Update for changes Signed-off-by: Dominika Zemanovicova <[email protected]> * Use KubeClient Signed-off-by: Dominika Zemanovicova <[email protected]> * Add kubernetes actions to configs Signed-off-by: Dominika Zemanovicova <[email protected]> * Revert unwanted change Signed-off-by: Dominika Zemanovicova <[email protected]> * Handle namespaces more safely Signed-off-by: Dominika Zemanovicova <[email protected]> * Add ScrollIntoView Signed-off-by: Dominika Zemanovicova <[email protected]> * Test template exists Signed-off-by: Dominika Zemanovicova <[email protected]> * Revert "Test template exists" This reverts commit 4d07fb4. * Move template Signed-off-by: Dominika Zemanovicova <[email protected]> * Remove unnecessary visible check Signed-off-by: Dominika Zemanovicova <[email protected]> * Reapply "Test template exists" This reverts commit e885222. * Fix TLS verification Signed-off-by: Dominika Zemanovicova <[email protected]> * Wait for action finish Signed-off-by: Dominika Zemanovicova <[email protected]> * Delete template registration Signed-off-by: Dominika Zemanovicova <[email protected]> --------- Signed-off-by: Dominika Zemanovicova <[email protected]>
1 parent beb54c6 commit 76b1d1c

File tree

8 files changed

+84
-3
lines changed

8 files changed

+84
-3
lines changed

.ibm/pipelines/resources/config_map/app-config-rhdh.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ catalog:
110110
target: https://github.com/redhat-developer/rhdh/blob/main/catalog-entities/all.yaml
111111
- type: url
112112
target: https://github.com/redhat-developer/red-hat-developer-hub-software-templates/blob/main/templates.yaml
113+
- type: url
114+
target: https://github.com/backstage/community-plugins/blob/main/workspaces/scaffolder-backend-module-kubernetes/plugins/kubernetes-actions/examples/templates/01-kubernetes-template.yaml
113115
- type: url
114116
target: https://github.com/janus-qe/acr-catalog/blob/main/catalog-info.yaml
115117
- type: url

.ibm/pipelines/value_files/sanity-check-plugins.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ global:
7171
disabled: false
7272
- package: ./dynamic-plugins/dist/roadiehq-scaffolder-backend-module-utils-dynamic
7373
disabled: false
74+
- package: ./dynamic-plugins/dist/backstage-community-plugin-scaffolder-backend-module-kubernetes-dynamic
75+
disabled: false
7476
- package: ./dynamic-plugins/dist/backstage-community-plugin-scaffolder-backend-module-quay-dynamic
7577
disabled: false
7678
- package: ./dynamic-plugins/dist/backstage-community-plugin-scaffolder-backend-module-regex-dynamic

.ibm/pipelines/value_files/values_showcase.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ global:
101101
disabled: false
102102
- package: ./dynamic-plugins/dist/backstage-community-plugin-acr
103103
disabled: false
104+
- package: ./dynamic-plugins/dist/backstage-community-plugin-scaffolder-backend-module-kubernetes-dynamic
105+
disabled: false
104106
- package: ./dynamic-plugins/dist/roadiehq-scaffolder-backend-module-http-request-dynamic
105107
disabled: false
106108
- package: ./dynamic-plugins/dist/backstage-community-plugin-catalog-backend-module-scaffolder-relation-processor-dynamic

e2e-tests/playwright/e2e/github-happy-path.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ test.describe.skip("GitHub Happy path", () => {
8080
await uiHelper.verifyHeading("Templates");
8181

8282
for (const template of TEMPLATES) {
83-
await uiHelper.waitForH4Title(template);
83+
await uiHelper.waitForTitle(template, 4);
8484
await uiHelper.verifyHeading(template);
8585
}
8686
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Page, test } from "@playwright/test";
2+
import { Common, setupBrowser } from "../../../utils/common";
3+
import { UIhelper } from "../../../utils/ui-helper";
4+
import { KubeClient } from "../../../utils/kube-client";
5+
import { UI_HELPER_ELEMENTS } from "../../../support/pageObjects/global-obj";
6+
7+
test.describe("Test Kubernetes Actions plugin", () => {
8+
let common: Common;
9+
let uiHelper: UIhelper;
10+
let page: Page;
11+
let kubeClient: KubeClient;
12+
let namespace: string;
13+
14+
test.beforeAll(async ({ browser }, testInfo) => {
15+
page = (await setupBrowser(browser, testInfo)).page;
16+
common = new Common(page);
17+
uiHelper = new UIhelper(page);
18+
kubeClient = new KubeClient();
19+
20+
await common.loginAsGuest();
21+
await uiHelper.openSidebar("Create...");
22+
});
23+
24+
test("Creates kubernetes namespace", async () => {
25+
namespace = `test-kubernetes-actions-${Date.now()}`;
26+
await uiHelper.verifyHeading("Software Templates");
27+
await uiHelper.clickBtnInCard("Create a kubernetes namespace", "Choose");
28+
await uiHelper.waitForTitle("Create a kubernetes namespace", 2);
29+
30+
await uiHelper.fillTextInputByLabel("Namespace name", namespace);
31+
await uiHelper.fillTextInputByLabel("Url", process.env.K8S_CLUSTER_URL);
32+
await uiHelper.fillTextInputByLabel("Token", process.env.K8S_CLUSTER_TOKEN);
33+
await uiHelper.checkCheckbox("Skip TLS verification");
34+
await uiHelper.clickButton("Review");
35+
await uiHelper.clickButton("Create");
36+
await page.waitForSelector(
37+
`${UI_HELPER_ELEMENTS.MuiTypography}:has-text("second")`,
38+
);
39+
await kubeClient.getNamespaceByName(namespace);
40+
});
41+
42+
test.afterEach(async () => {
43+
await kubeClient.deleteNamespaceAndWait(namespace);
44+
});
45+
});

e2e-tests/playwright/support/pageObjects/global-obj.ts

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export const UI_HELPER_ELEMENTS = {
1616
MuiButtonTextPrimary: ".MuiButton-textPrimary",
1717
MuiCard: (cardHeading) =>
1818
`//div[contains(@class,'MuiCardHeader-root') and descendant::*[text()='${cardHeading}']]/..`,
19+
MuiCardRoot: (cardText: string) =>
20+
`//div[contains(@class,'MuiCard-root')][descendant::text()[contains(., '${cardText}')]]`,
1921
MuiTable: "table.MuiTable-root",
2022
MuiCardHeader: 'div[class*="MuiCardHeader-root"]',
2123
MuiInputBase: 'div[class*="MuiInputBase-root"]',

e2e-tests/playwright/utils/kube-client.ts

+10
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ export class KubeClient {
5757
}
5858
}
5959

60+
async getNamespaceByName(name: string): Promise<k8s.V1Namespace | null> {
61+
try {
62+
LOGGER.debug(`Getting namespace ${name}.`);
63+
return (await this.coreV1Api.readNamespace(name)).body;
64+
} catch (e) {
65+
LOGGER.error(`Error getting namespace ${name}: ${e.body?.message}`);
66+
throw e;
67+
}
68+
}
69+
6070
async scaleDeployment(
6171
deploymentName: string,
6272
namespace: string,

e2e-tests/playwright/utils/ui-helper.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ export class UIhelper {
3939
await this.page.keyboard.press("Tab");
4040
}
4141

42+
async checkCheckbox(text: string) {
43+
const locator = this.page.getByRole("checkbox", {
44+
name: text,
45+
});
46+
await locator.check();
47+
}
48+
4249
async clickButton(
4350
label: string | RegExp,
4451
options: { exact?: boolean; force?: boolean } = {
@@ -298,8 +305,8 @@ export class UIhelper {
298305
await expect(headingLocator).toBeVisible();
299306
}
300307

301-
async waitForH4Title(text: string) {
302-
await this.page.waitForSelector(`h4:has-text("${text}")`, {
308+
async waitForTitle(text: string, level: number = 1) {
309+
await this.page.waitForSelector(`h${level}:has-text("${text}")`, {
303310
timeout: 10000,
304311
});
305312
}
@@ -423,6 +430,17 @@ export class UIhelper {
423430
await expect(link).toBeVisible();
424431
}
425432

433+
async clickBtnInCard(cardText: string, btnText: string, exact = true) {
434+
const cardLocator = this.page
435+
.locator(UI_HELPER_ELEMENTS.MuiCardRoot(cardText))
436+
.first();
437+
await cardLocator.scrollIntoViewIfNeeded();
438+
await cardLocator
439+
.getByRole("button", { name: btnText, exact: exact })
440+
.first()
441+
.click();
442+
}
443+
426444
async verifyTextinCard(
427445
cardHeading: string,
428446
text: string | RegExp,

0 commit comments

Comments
 (0)