Skip to content

Commit

Permalink
chore(e2e): rhidp-5094 - [Test automation] restore skipped e2e tests …
Browse files Browse the repository at this point in the history
…nov2024 (#2058)

* test

* lint fixes
  • Loading branch information
gustavolira authored Dec 10, 2024
1 parent ab08160 commit ed0ef2e
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 44 deletions.
3 changes: 3 additions & 0 deletions .ibm/pipelines/value_files/values_showcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ global:
- package: '@pataknight/[email protected]'
disabled: false
integrity: sha512-srTnFDYn3Ett6z33bX4nL2NQY8wqux8TkpgBQNsE8S73nMfsor/wAdmVgHL+xW7pxQ09DT4YTdaG3GkH+cyyNQ==
- package: '@backstage-community/[email protected]'
disabled: false
integrity: sha512-agmfwxHkZPy0zaXzjMKY9Us9l7J2og+z7p2lDWQBmlJ1KZRo6OBQdnlG1mTEryfEEl/bx5Ko+f1PhFj2/BmiIQ==

# -- Upstream Backstage [chart configuration](https://github.com/backstage/charts/blob/main/charts/backstage/values.yaml)
upstream:
Expand Down
19 changes: 12 additions & 7 deletions dynamic-plugins/_utils/src/wrappers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ function parseYamlFile<T>(filePath: string): T {
function validateDynamicPluginsConfig(
config: DynamicPluginsConfig,
wrapperDirNames: string[],
externalDynamicPlugin?: DynamicPluginConfig,
externalDynamicPlugins?: DynamicPluginConfig[],
): void {
const dynamicPluginsPackageNames = config.plugins.reduce(
(packageNames, plugin) => {
if (externalDynamicPlugin?.package !== plugin.package) {
const isExternalPlugin = externalDynamicPlugins?.some((externalDynamicPlugin) => externalDynamicPlugin.package === plugin.package)
if (!isExternalPlugin) {
// We want the third index ['.', 'dynamic-plugins', 'dist', 'backstage-plugin-scaffolder-backend-module-github-dynamic']
packageNames.push(plugin.package.split("/")[3]);
}
Expand Down Expand Up @@ -188,8 +189,8 @@ describe("Dynamic Plugin Wrappers", () => {
);

it.each(frontendPackageJsonFiles)(
"$name should have scalprum config in the `package.json`",
({ name, scalprum }) => {
"should have scalprum config in the `package.json`",
({ scalprum }) => {
expect(scalprum).toBeTruthy();
},
);
Expand Down Expand Up @@ -240,16 +241,20 @@ describe("Dynamic Plugin Wrappers", () => {
IBM_VALUES_SHOWCASE_CONFIG_FILE,
);

const externalDynamicPluginConfig: DynamicPluginConfig = {
const externalDynamicPluginsConfig: DynamicPluginConfig[] = [{
package: "@pataknight/[email protected]",
disabled: false,
};
},
{
package: "@backstage-community/[email protected]"
}
];

it("should have a corresponding package", () => {
validateDynamicPluginsConfig(
config.global.dynamic,
wrapperDirNames,
externalDynamicPluginConfig,
externalDynamicPluginsConfig,
);
});
});
Expand Down
27 changes: 13 additions & 14 deletions e2e-tests/playwright/e2e/catalog-scaffolded-from-link.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,23 @@ test.describe.serial("Link Scaffolded Templates to Catalog Items", () => {
await uiHelper.clickLink("Open in catalog");
});

test.fixme(
"Verify Scaffolded link in components Dependencies and scaffoldedFrom relation in entity Raw Yaml ",
async () => {
await common.clickOnGHloginPopup();
await uiHelper.clickTab("Dependencies");
await uiHelper.verifyText(
`ownerOf / ownedByscaffoldedFromcomponent:${reactAppDetails.componentName}group:${reactAppDetails.owner}Create React App Template`,
);
await catalogImport.inspectEntityAndVerifyYaml(
`- type: scaffoldedFrom\n targetRef: template:default/create-react-app-template-with-timestamp-entityref\n target:\n kind: template\n namespace: default\n name: create-react-app-template-with-timestamp-entityref`,
);
},
);
//FIXME
test.skip("Verify Scaffolded link in components Dependencies and scaffoldedFrom relation in entity Raw Yaml ", async () => {
await common.clickOnGHloginPopup();
await uiHelper.clickTab("Dependencies");
await uiHelper.verifyText(
`ownerOf / ownedByscaffoldedFromcomponent:${reactAppDetails.componentName}group:${reactAppDetails.owner}Create React App Template`,
);
await catalogImport.inspectEntityAndVerifyYaml(
`- type: scaffoldedFrom\n targetRef: template:default/create-react-app-template-with-timestamp-entityref\n target:\n kind: template\n namespace: default\n name: create-react-app-template-with-timestamp-entityref`,
);
});

test("Verify Registered Template and scaffolderOf relation in entity Raw Yaml", async () => {
await uiHelper.openSidebar("Catalog");
await uiHelper.selectMuiBox("Kind", "Template");
await uiHelper.searchInputPlaceholder("Create React App Template");

await uiHelper.searchInputPlaceholder("Create React App Template\n");
await uiHelper.verifyRowInTableByUniqueText("Create React App Template", [
"website",
]);
Expand Down
4 changes: 3 additions & 1 deletion e2e-tests/playwright/e2e/catalog-timestamp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ test.describe("Test timestamp column on Catalog", () => {
await catalogImport.registerExistingComponent(component);
await uiHelper.openSidebar("Catalog");
await uiHelper.selectMuiBox("Kind", "Component");
await uiHelper.searchInputPlaceholder("timestamp-test");
await uiHelper.clickByDataTestId("user-picker-all");
await uiHelper.searchInputPlaceholder("timestamp-test-created");
await uiHelper.verifyText("timestamp-test-created");
await uiHelper.verifyColumnHeading(["Created At"], true);
await uiHelper.verifyRowInTableByUniqueText("timestamp-test-created", [
/^\d{1,2}\/\d{1,2}\/\d{1,4}, \d:\d{1,2}:\d{1,2} (AM|PM)$/g,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test.describe("Change app-config at e2e test runtime", () => {

const kubeUtils = new KubeClient();
const dynamicTitle = generateDynamicTitle();

const uiHelper = new UIhelper(page);
try {
LOGGER.info(`Updating ConfigMap '${configMapName}' with new title.`);
await kubeUtils.updateConfigMapTitle(
Expand All @@ -31,6 +31,9 @@ test.describe("Change app-config at e2e test runtime", () => {
const common = new Common(page);
await common.loginAsGuest();
await new UIhelper(page).openSidebar("Home");
await uiHelper.verifyHeading("Welcome back!");
await uiHelper.verifyText("Quick Access");
await expect(page.locator("#search-bar-text-field")).toBeVisible();
LOGGER.info("Verifying new title in the UI...");
expect(await page.title()).toContain(dynamicTitle);
LOGGER.info("Title successfully verified in the UI.");
Expand Down
13 changes: 11 additions & 2 deletions e2e-tests/playwright/e2e/github-happy-path.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { TEMPLATES } from "../support/testData/templates";

let page: Page;

// TODO: replace skip with serial
test.describe.skip("GitHub Happy path", () => {
test.describe.serial("GitHub Happy path", () => {
let common: Common;
let uiHelper: UIhelper;
let catalogImport: CatalogImport;
Expand Down Expand Up @@ -89,6 +88,16 @@ test.describe.skip("GitHub Happy path", () => {
await uiHelper.selectMuiBox("Kind", "Component");
await uiHelper.clickByDataTestId("user-picker-all");
await uiHelper.clickLink("Backstage Showcase");

const expectedPath = "/catalog/default/component/backstage-showcase";
// Wait for the expected path in the URL
await page.waitForURL(`**${expectedPath}`, {
waitUntil: "domcontentloaded", // Wait until the DOM is loaded
timeout: 10000,
});
// Optionally, verify that the current URL contains the expected path
await expect(page.url()).toContain(expectedPath);

await common.clickOnGHloginPopup();
await uiHelper.verifyLink("Janus Website", { exact: false });
await backstageShowcase.verifyPRStatisticsRendered();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test.describe.serial("GitHub integration with Org data fetching", () => {
await uiHelper.openSidebar("Catalog");
await uiHelper.selectMuiBox("Kind", "Group");

await uiHelper.searchInputPlaceholder("m");
await uiHelper.searchInputPlaceholder("maintainers");
await uiHelper.verifyRowsInTable(["maintainers"]);

await uiHelper.searchInputPlaceholder("r");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,20 @@ test.describe("dynamic-plugins-info UI tests", () => {
expect(await row.locator("td").nth(3).innerText()).toBe("Yes"); // preinstalled
});

// TODO: Add plugin-todo-list plugin in ci process to enable this test
// TODO: Enable this test once the behavior for loading this plugin is fixed.
// TODO: In RHDH 1.5, this plugin incorrectly appears as disabled despite being properly imported and explicitly enabled.
test.skip("it should have a plugin-todo-list plugin which is Enabled but not Preinstalled", async ({
page,
}) => {
await page
.getByPlaceholder("Filter")
.pressSequentially("plugin-todo-list\n", { delay: 300 });
const row = await page.locator(
UI_HELPER_ELEMENTS.rowByText("@internal/plugin-todo-list"),
.pressSequentially("plugin-todo\n", { delay: 300 });

// Verify the Enabled and Preinstalled column values for the specific row
await uiHelper.verifyPluginRow(
"@backstage-community/plugin-todo", // Text to locate the row (Name column)
"Yes", // Expected value in the Enabled column
"No", // Expected value in the Preinstalled column
);
expect(await row.locator("td").nth(2).innerText()).toBe("Yes"); // enabled
expect(await row.locator("td").nth(3).innerText()).toBe("No"); // not preinstalled
});
});
2 changes: 1 addition & 1 deletion e2e-tests/playwright/e2e/plugins/http-request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test.describe("Testing scaffolder-backend-module-http-request to invoke an exter

await uiHelper.openSidebar("Catalog");
await uiHelper.selectMuiBox("Kind", "Template");
await uiHelper.searchInputPlaceholder("Test");
await uiHelper.searchInputPlaceholder("Test HTTP Request");
await uiHelper.clickLink("Test HTTP Request");
await uiHelper.verifyHeading("Test HTTP Request");
await uiHelper.clickLink("Launch Template");
Expand Down
13 changes: 12 additions & 1 deletion e2e-tests/playwright/e2e/plugins/ocm.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page, test } from "@playwright/test";
import { expect, Page, test } from "@playwright/test";
import { Common, setupBrowser } from "../../utils/common";
import { UIhelper } from "../../utils/ui-helper";
import { Clusters } from "../../support/pages/clusters";
Expand Down Expand Up @@ -32,6 +32,17 @@ test.describe.serial("Test OCM plugin", () => {
});
test("Navigate to Clusters and Verify OCM Clusters", async () => {
await uiHelper.openSidebar("Clusters");
const expectedPath = "/ocm";

// Wait for the expected path in the URL
await page.waitForURL(`**${expectedPath}`, {
waitUntil: "domcontentloaded", // Wait until the DOM is loaded
timeout: 10000, // Set timeout to 10 seconds
});

expect(page.url()).toContain(expectedPath);

await uiHelper.verifyHeading("Your Managed Clusters");
await uiHelper.verifyRowInTableByUniqueText(clusterDetails.clusterName, [
clusterDetails.status,
clusterDetails.platform,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ test.describe("Test Customized Quick Access and tech-radar plugin", () => {
await homePage.verifyQuickAccess("SECURITY TOOLS", "Keycloak", true);
});

test("Verify tech-radar", async ({ page }) => {
// TODO: Investigate why Tech Radar is showing "Process" instead of "Storage".
test.skip("Verify tech-radar", async ({ page }) => {
const uiHelper = new UIhelper(page);
const techRadar = new TechRadar(page);

Expand All @@ -30,6 +31,6 @@ test.describe("Test Customized Quick Access and tech-radar plugin", () => {
await techRadar.verifyRadarDetails("Languages", "JavaScript");
await techRadar.verifyRadarDetails("Storage", "AWS S3");
await techRadar.verifyRadarDetails("Frameworks", "React");
await techRadar.verifyRadarDetails("Infrastructure", "ArgoCD");
await techRadar.verifyRadarDetails("Infrastructure", "GitHub Actions");
});
});
17 changes: 11 additions & 6 deletions e2e-tests/playwright/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,17 @@ export class Common {
}

async clickOnGHloginPopup() {
await this.uiHelper.clickButton("Log in");
await this.checkAndReauthorizeGithubApp();
await this.page.waitForSelector(this.uiHelper.getButtonSelector("Log in"), {
state: "hidden",
timeout: 100000,
});
const isLoginRequiredVisible =
await this.uiHelper.isTextVisible("Login Required");
if (isLoginRequiredVisible) {
await this.uiHelper.clickButton("Log in");
await this.checkAndReauthorizeGithubApp();
await this.uiHelper.waitForLoginBtnDisappear();
} else {
console.log(
'"Log in" button is not visible. Skipping login popup actions.',
);
}
}

getGitHub2FAOTP(userid: string): string {
Expand Down
51 changes: 49 additions & 2 deletions e2e-tests/playwright/utils/ui-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,22 @@ export class UIhelper {
await this.page.getByLabel(label).fill(text);
}

/**
* Fills the search input with the provided text and waits for at least one
* search result containing the text to become visible.
*
* @param searchText - The text to be entered into the search input field.
*/
async searchInputPlaceholder(searchText: string) {
await this.page.fill('input[placeholder="Search"]', searchText);
// Wait for the search input to be visible
const searchInput = this.page.locator('input[placeholder="Search"]');
await expect(searchInput).toBeVisible();

await searchInput.fill(searchText);

// Wait for at least one search result to become visible
const resultLocator = this.page.locator(`text=${searchText}`);
await expect(resultLocator.first()).toBeVisible();
}

async filterInputPlaceholder(searchText: string) {
Expand Down Expand Up @@ -98,7 +112,6 @@ export class UIhelper {
if (options?.notVisible) {
await expect(linkLocator).not.toBeVisible();
} else {
await linkLocator.scrollIntoViewIfNeeded();
await expect(linkLocator).toBeVisible();
}
}
Expand Down Expand Up @@ -277,6 +290,16 @@ export class UIhelper {
return `${UI_HELPER_ELEMENTS.MuiButtonLabel}:has-text("${label}")`;
}

getLoginBtnSelector(): string {
return 'MuiListItem-root li.MuiListItem-root button.MuiButton-root:has(span.MuiButton-label:text("Log in"))';
}

async waitForLoginBtnDisappear() {
await this.page.waitForSelector(await this.getLoginBtnSelector(), {
state: "detached",
});
}

async verifyButtonURL(label: string | RegExp, url: string | RegExp) {
const buttonUrl = await this.page
.getByRole("button", { name: label })
Expand Down Expand Up @@ -494,4 +517,28 @@ export class UIhelper {
await deleteButton.waitFor({ state: "attached" });
await deleteButton.click();
}

/**
* Verifies the values of the Enabled and Preinstalled columns for a specific row.
*
* @param text - Text to locate the specific row (based on the Name column).
* @param expectedEnabled - Expected value for the Enabled column ("Yes" or "No").
* @param expectedPreinstalled - Expected value for the Preinstalled column ("Yes" or "No").
*/
async verifyPluginRow(
text: string,
expectedEnabled: string,
expectedPreinstalled: string,
) {
// Locate the row based on the text in the Name column
const rowSelector = `tr:has(td:text-is("${text}"))`;
const row = this.page.locator(rowSelector);

// Locate the "Enabled" (3rd column) and "Preinstalled" (4th column) cells by their index
const enabledColumn = row.locator("td").nth(2); // Index 2 for "Enabled"
const preinstalledColumn = row.locator("td").nth(3); // Index 3 for "Preinstalled"

await expect(enabledColumn).toHaveText(expectedEnabled);
await expect(preinstalledColumn).toHaveText(expectedPreinstalled);
}
}

0 comments on commit ed0ef2e

Please sign in to comment.