From b4e109e9f56e202021951848fc341bcd57411752 Mon Sep 17 00:00:00 2001 From: kdaud Date: Tue, 12 Nov 2024 04:33:40 +0300 Subject: [PATCH] test openmrs keycloak flows --- e2e/tests/keycloak-openmrs-flows.spec.ts | 44 +++++++++--------- e2e/tests/keycloak-superset-flows.spec.ts | 56 +++++++++++------------ e2e/utils/functions/openmrs.ts | 2 +- e2e/utils/functions/superset.ts | 4 +- package.json | 2 +- 5 files changed, 54 insertions(+), 54 deletions(-) diff --git a/e2e/tests/keycloak-openmrs-flows.spec.ts b/e2e/tests/keycloak-openmrs-flows.spec.ts index 1ed33fb..21ca2a2 100644 --- a/e2e/tests/keycloak-openmrs-flows.spec.ts +++ b/e2e/tests/keycloak-openmrs-flows.spec.ts @@ -14,6 +14,28 @@ test.beforeEach(async ({ page }) => { await expect(page.locator('div:nth-child(1)>a')).toHaveText(/home/i); }); +test('Logging out from OpenMRS logs out the user from Keycloak.', async ({ page }) => { + // setup + await keycloak.open(); + await keycloak.navigateToClients(); + await keycloak.selectOpenMRSId(); + await keycloak.selectSessions(); + await expect(page.locator('td:nth-child(1) a').nth(0)).toHaveText(/jdoe/i); + + // replay + await openmrs.logout(); + + // verify + await page.goto(`${KEYCLOAK_URL}/admin/master/console`); + await keycloak.navigateToClients(); + await keycloak.selectOpenMRSId(); + await keycloak.selectSessions(); + await expect(page.locator('h1.pf-c-title:nth-child(2)')).toHaveText(/no sessions/i); + await expect(page.locator('.pf-c-empty-state__body')).toHaveText(/there are currently no active sessions for this client/i); + await page.goto(`${O3_URL}/openmrs/spa/home/`); + await expect(page).toHaveURL(/.*login/); +}); + test('Creating an OpenMRS role creates the corresponding Keycloak role.', async ({ page }) => { // setup await page.goto(`${O3_URL}/openmrs/admin/users/role.list`); @@ -131,28 +153,6 @@ test('A (non-synced) role created from within Keycloak gets deleted in the subse await openmrs.logout(); }); -test('Logging out from OpenMRS logs out the user from Keycloak.', async ({ page }) => { - // setup - await keycloak.open(); - await keycloak.navigateToClients(); - await keycloak.selectOpenMRSId(); - await keycloak.selectSessions(); - await expect(page.locator('td:nth-child(1) a').nth(0)).toHaveText(/jdoe/i); - - // replay - await openmrs.logout(); - - // verify - await page.goto(`${KEYCLOAK_URL}/admin/master/console`); - await keycloak.navigateToClients(); - await keycloak.selectOpenMRSId(); - await keycloak.selectSessions(); - await expect(page.locator('h1.pf-c-title:nth-child(2)')).toHaveText(/no sessions/i); - await expect(page.locator('.pf-c-empty-state__body')).toHaveText(/there are currently no active sessions for this client/i); - await page.goto(`${O3_URL}/openmrs/spa/home/`); - await expect(page).toHaveURL(/.*login/); -}); - test.afterEach(async ({ page }) => { await page.close(); }); diff --git a/e2e/tests/keycloak-superset-flows.spec.ts b/e2e/tests/keycloak-superset-flows.spec.ts index 630343c..7b16da8 100644 --- a/e2e/tests/keycloak-superset-flows.spec.ts +++ b/e2e/tests/keycloak-superset-flows.spec.ts @@ -14,6 +14,34 @@ test.beforeEach(async ({ page }) => { superset = new Superset(page); }); +test('Logging out from Superset logs out the user from Keycloak.', async ({ page }) => { + // setup + await superset.open(); + await openmrs.enterLoginCredentials(); + await expect(page).toHaveURL(/.*superset/); + await expect(page.locator('#app div.header')).toHaveText(/home/i); + await keycloak.open(); + await keycloak.navigateToClients(); + await keycloak.selectSupersetId(); + await keycloak.selectSessions(); + await expect(page.locator('td:nth-child(1) a').nth(0)).toHaveText(/jdoe/i); + + // replay + await superset.logout(); + await keycloak.confirmLogout(); + await expect(page).toHaveURL(/.*login/); + + // verify + await page.goto(`${KEYCLOAK_URL}/admin/master/console`); + await keycloak.navigateToClients(); + await keycloak.selectSupersetId(); + await keycloak.selectSessions(); + await expect(page.locator('h1.pf-c-title:nth-child(2)')).toHaveText(/no sessions/i); + await expect(page.locator('.pf-c-empty-state__body')).toHaveText(/there are currently no active sessions for this client/i); + await page.goto(`${SUPERSET_URL}/superset/welcome`); + await expect(page).toHaveURL(/.*login/); +}); + test('Creating a Superset role creates the corresponding Keycloak role.', async ({ page }) => { // setup await openmrs.login(); @@ -111,34 +139,6 @@ test('A synced role deleted from within Keycloak gets recreated in the subsequen await superset.logout(); }); -test('Logging out from Superset logs out the user from Keycloak.', async ({ page }) => { - // setup - await superset.open(); - await openmrs.enterLoginCredentials(); - await expect(page).toHaveURL(/.*superset/); - await expect(page.locator('#app div.header')).toHaveText(/home/i); - await keycloak.open(); - await keycloak.navigateToClients(); - await keycloak.selectSupersetId(); - await keycloak.selectSessions(); - await expect(page.locator('td:nth-child(1) a').nth(0)).toHaveText(/jdoe/i); - - // replay - await superset.logout(); - await keycloak.confirmLogout(); - await expect(page).toHaveURL(/.*login/); - - // verify - await page.goto(`${KEYCLOAK_URL}/admin/master/console`); - await keycloak.navigateToClients(); - await keycloak.selectSupersetId(); - await keycloak.selectSessions(); - await expect(page.locator('h1.pf-c-title:nth-child(2)')).toHaveText(/no sessions/i); - await expect(page.locator('.pf-c-empty-state__body')).toHaveText(/there are currently no active sessions for this client/i); - await page.goto(`${SUPERSET_URL}/superset/welcome`); - await expect(page).toHaveURL(/.*login/); -}); - test.afterEach(async ({ page }) => { await page.close(); }); diff --git a/e2e/utils/functions/openmrs.ts b/e2e/utils/functions/openmrs.ts index ebc6d58..eca09e3 100644 --- a/e2e/utils/functions/openmrs.ts +++ b/e2e/utils/functions/openmrs.ts @@ -11,7 +11,7 @@ export var patientName = { var patientFullName = ''; export var randomOpenMRSRoleName = { - roleName : `${(Math.random() + 1).toString(36).substring(2)}` + roleName : `${Array.from({ length: 8 }, () => String.fromCharCode(Math.floor(Math.random() * 26) + 97)).join('')}` } export const delay = (mills) => { diff --git a/e2e/utils/functions/superset.ts b/e2e/utils/functions/superset.ts index b54de6a..632e7f6 100644 --- a/e2e/utils/functions/superset.ts +++ b/e2e/utils/functions/superset.ts @@ -4,8 +4,8 @@ import { delay } from './openmrs'; import { Keycloak } from './keycloak'; export var randomSupersetRoleName = { - roleName : `${(Math.random() + 1).toString(36).substring(2)}`, - updatedRoleName : `${(Math.random() + 1).toString(36).substring(2)}` + roleName : `${Array.from({ length: 8 }, () => String.fromCharCode(Math.floor(Math.random() * 26) + 97)).join('')}`, + updatedRoleName : `${Array.from({ length: 8 }, () => String.fromCharCode(Math.floor(Math.random() * 26) + 97)).join('')}` } export class Superset { diff --git a/package.json b/package.json index 7c98608..bbd32a2 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "!playwright-report/" ], "scripts": { - "ozone-pro": "npx playwright test", + "ozone-pro": "npx playwright test keycloak-openmrs", "ozone-foss": "npx playwright test odoo-openmrs erpnext-openmrs openmrs-senaite", "openmrs-distro-his": "npx playwright test odoo-openmrs openmrs-senaite" },