Skip to content

Commit

Permalink
feat(e2e): implemented test to check download users link (#1827)
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksandr Andriienko <oandriie@redhat.com>
  • Loading branch information
AndrienkoAleksandr authored Nov 13, 2024
1 parent d62a347 commit 2ea0584
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions e2e-tests/playwright/e2e/plugins/rbac/rbac.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { Roles } from "../../../support/pages/rbac";
import { Common, setupBrowser } from "../../../utils/Common";
import { UIhelper } from "../../../utils/UIhelper";
import fs from "fs/promises";

test.describe
.serial("Test RBAC plugin: load permission policies and conditions from files", () => {
Expand Down Expand Up @@ -162,6 +163,42 @@ test.describe.serial("Test RBAC plugin as an admin user", () => {
await uiHelper.verifyCellsInTable(allCellsIdentifier);
});

test("Should download the user list", async () => {
await page.locator('a:has-text("Download User List")').click();
const fileContent = await downloadAndReadFile(page);
const lines = fileContent.trim().split("\n");

const header = "userEntityRef,displayName,email,lastAuthTime";
if (lines[0] !== header) {
throw new Error("Header does not match");
}

// Check that each subsequent line starts with "user:default"
const allUsersValid = lines
.slice(1)
.every((line) => line.startsWith("user:default"));
if (!allUsersValid) {
throw new Error("Not all users info are valid");
}
});

async function downloadAndReadFile(page: Page): Promise<string | undefined> {
const [download] = await Promise.all([
page.waitForEvent("download"),
page.locator('a:has-text("Download User List")').click(),
]);

const filePath = await download.path();

if (filePath) {
const fileContent = await fs.readFile(filePath, "utf-8");
return fileContent;
} else {
console.error("Download failed or path is not available");
return undefined;
}
}

test("View details of a role", async () => {
await uiHelper.clickLink("role:default/rbac_admin");

Expand Down

0 comments on commit 2ea0584

Please sign in to comment.