From 324568876fe8b6d05795626a9fa30137781d617e Mon Sep 17 00:00:00 2001 From: Oleksandr Andriienko Date: Sun, 27 Oct 2024 23:43:47 +0200 Subject: [PATCH] feat(e2e): implemented test to check download users link Signed-off-by: Oleksandr Andriienko --- .../playwright/e2e/plugins/rbac/rbac.spec.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/e2e-tests/playwright/e2e/plugins/rbac/rbac.spec.ts b/e2e-tests/playwright/e2e/plugins/rbac/rbac.spec.ts index 1222fa205a..087ee06bf3 100644 --- a/e2e-tests/playwright/e2e/plugins/rbac/rbac.spec.ts +++ b/e2e-tests/playwright/e2e/plugins/rbac/rbac.spec.ts @@ -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", () => { @@ -150,6 +151,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 { + 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");