Skip to content

Commit

Permalink
test openmrs keycloak flows
Browse files Browse the repository at this point in the history
  • Loading branch information
kdaud committed Nov 12, 2024
1 parent f999545 commit b4e109e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 54 deletions.
44 changes: 22 additions & 22 deletions e2e/tests/keycloak-openmrs-flows.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down Expand Up @@ -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();
});
56 changes: 28 additions & 28 deletions e2e/tests/keycloak-superset-flows.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
});
2 changes: 1 addition & 1 deletion e2e/utils/functions/openmrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions e2e/utils/functions/superset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit b4e109e

Please sign in to comment.