Skip to content

Commit

Permalink
OZ-562: Refactored component-specific user actions (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdaud authored May 10, 2024
1 parent e0f5dea commit c2e1ee2
Show file tree
Hide file tree
Showing 9 changed files with 567 additions and 604 deletions.
152 changes: 72 additions & 80 deletions e2e/tests/keycloak-openmrs-flows.spec.ts
Original file line number Diff line number Diff line change
@@ -1,191 +1,183 @@
import { test, expect } from '@playwright/test';
import { HomePage, delay, randomKeycloakRoleName } from '../utils/functions/testBase';
import { randomOpenMRSRoleName, randomSupersetRoleName } from '../utils/functions/testBase';
import { Keycloak, randomKeycloakRoleName } from '../utils/functions/keycloak';
import { OpenMRS, delay, randomOpenMRSRoleName } from '../utils/functions/openmrs';
import { Superset, randomSupersetRoleName} from '../utils/functions/superset';
import { O3_URL, KEYCLOAK_URL } from '../utils/configs/globalSetup';

let homePage: HomePage;
let openmrs: OpenMRS;
let keycloak: Keycloak;
let superset: Superset;

test.beforeEach(async ({ page }) => {
homePage = new HomePage(page);
openmrs = new OpenMRS(page);
keycloak = new Keycloak(page);
superset = new Superset(page);

await openmrs.login();
await expect(page).toHaveURL(/.*home/);
});

test('Creating an OpenMRS role creates the corresponding Keycloak role.', async ({ page }) => {
// replay
await homePage.initiateLogin();
await expect(page).toHaveURL(/.*home/);
await page.goto(`${O3_URL}/openmrs/admin/users/role.list`);
await homePage.addOpenMRSRole();
await openmrs.addRole();

// verify
await homePage.goToKeycloak();
await keycloak.open();
await expect(page).toHaveURL(/.*console/);
await homePage.goToClients();
await homePage.selectOpenMRSId()
await keycloak.goToClients();
await keycloak.selectOpenMRSId()
await expect(page.getByText(`${randomOpenMRSRoleName.roleName}`)).toBeVisible();
await expect(page.getByText('Role for e2e test').first()).toBeVisible();
await homePage.goToClientAttributes();
await keycloak.goToClientAttributes();
await expect(page.getByText('Organizational: Registration Clerk')).toBeTruthy();
await expect(page.getByText('Application: Edits Existing Encounters')).toBeTruthy();
await expect(page.getByText('Application: Uses Patient Summary')).toBeTruthy();
await expect(page.getByText('Application: Has Super User Privileges')).toBeTruthy();
await expect(page.getByText('Application: Administers System')).toBeTruthy();
await homePage.deleteOpenMRSRole();
await openmrs.deleteRole();
});

test('Updating a synced OpenMRS role updates the corresponding Keycloak role.', async ({ page }) => {
// replay
await homePage.initiateLogin();
await expect(page).toHaveURL(/.*home/);
await page.goto(`${O3_URL}/openmrs/admin/users/role.list`);
await homePage.addOpenMRSRole();
await homePage.goToKeycloak();
await openmrs.addRole();
await keycloak.open();
await expect(page).toHaveURL(/.*console/);
await homePage.goToClients();
await homePage.selectOpenMRSId();
await keycloak.goToClients();
await keycloak.selectOpenMRSId();
await expect(page.getByText(`${randomOpenMRSRoleName.roleName}`)).toBeVisible();
await expect(page.getByText('Role for e2e test').first()).toBeVisible();
await homePage.goToClientAttributes();
await keycloak.goToClientAttributes();
await expect(page.getByText('Application: Enters Vitals')).toBeTruthy();
await expect(page.getByText('Application: Edits Existing Encounters')).toBeTruthy();
await expect(page.getByText('Application: Uses Patient Summary')).toBeTruthy();
await expect(page.getByText('Organizational: Registration Clerk')).toBeTruthy();
await expect(page.getByText('Application: Records Allergies')).toBeTruthy();
await page.goto(`${O3_URL}/openmrs/admin/users/role.list`);
await homePage.updateOpenMRSRole();
await openmrs.updateRole();

// verify
await page.goto(`${KEYCLOAK_URL}/admin/master/console`);
await homePage.goToClients();
await homePage.selectOpenMRSId();
await homePage.goToClientAttributes();
await keycloak.goToClients();
await keycloak.selectOpenMRSId();
await keycloak.goToClientAttributes();
await expect(page.getByText('Updated role description')).toBeTruthy();
await page.getByTestId('attributesTab').click();
await expect(page.getByText('Application: Registers Patients')).toBeTruthy();
await expect(page.getByText('Application: Writes Clinical Notes')).toBeTruthy();
await homePage.deleteOpenMRSRole();
await openmrs.deleteRole();
});

test('Deleting a synced OpenMRS role deletes the corresponding Keycloak role.', async ({ page }) => {
// replay
await homePage.initiateLogin();
await expect(page).toHaveURL(/.*home/);
await page.goto(`${O3_URL}/openmrs/admin/users/role.list`);
await homePage.addOpenMRSRole();
await homePage.goToKeycloak();
await openmrs.addRole();
await keycloak.open();
await expect(page).toHaveURL(/.*console/);
await homePage.goToClients();
await homePage.selectOpenMRSId();
await keycloak.goToClients();
await keycloak.selectOpenMRSId();
await expect(page.getByText(`${randomOpenMRSRoleName.roleName}`)).toBeVisible();
await expect(page.getByText('Role for e2e test').first()).toBeVisible();
await homePage.goToClientAttributes();
await keycloak.goToClientAttributes();
await expect(page.getByText('Application: Enters Vitals')).toBeTruthy();
await expect(page.getByText('Application: Edits Existing Encounters')).toBeTruthy();
await expect(page.getByText('Application: Uses Patient Summary')).toBeTruthy();
await expect(page.getByText('Organizational: Registration Clerk')).toBeTruthy();
await expect(page.getByText('Application: Records Allergies')).toBeTruthy();
await homePage.deleteOpenMRSRole();
await openmrs.deleteRole();

// verify
await page.goto(`${KEYCLOAK_URL}/admin/master/console`);
await homePage.goToClients();
await homePage.selectOpenMRSId();
await keycloak.goToClients();
await keycloak.selectOpenMRSId();
const roleName = await page.locator('table tbody tr:nth-child(1) td:nth-child(1) a');
await expect(roleName).not.toHaveText(`${randomOpenMRSRoleName.roleName}`);
});

test('Creating a Superset role creates the corresponding Keycloak role.', async ({ page }) => {
// replay
await homePage.initiateLogin();
await expect(page).toHaveURL(/.*home/);
await homePage.goToSuperset();
await homePage.addSupersetRole();
await superset.open();
await superset.addRole();

// verify
await homePage.goToKeycloak();
await homePage.goToClients();
await homePage.selectSupersetId();
await keycloak.open();
await keycloak.goToClients();
await keycloak.selectSupersetId();
await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).toBeVisible();
await homePage.deleteSupersetRole();
await superset.deleteRole();
});

test('Updating a synced Superset role updates the corresponding Keycloak role.', async ({ page }) => {
// replay
await homePage.initiateLogin();
await expect(page).toHaveURL(/.*home/);
await homePage.goToSuperset();
await homePage.addSupersetRole();
await homePage.goToKeycloak();
await homePage.goToClients();
await homePage.selectSupersetId();
await superset.open();
await superset.addRole();
await keycloak.open();
await keycloak.goToClients();
await keycloak.selectSupersetId();
await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).toBeVisible();
await expect(page.getByText('')).toBeTruthy();
await homePage.updateSupersetRole();
await superset.updateRole();

// verify
await page.goto(`${KEYCLOAK_URL}/admin/master/console`);
await homePage.goToClients();
await homePage.selectSupersetId();
await keycloak.goToClients();
await keycloak.selectSupersetId();
await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).not.toBeVisible();
await expect(page.getByText(`${randomSupersetRoleName.updatedRoleName}`)).toBeVisible();
await homePage.deleteUpdatedSupersetRole();
await superset.deleteUpdatedRole();
});

test('Deleting a synced Superset role deletes the corresponding Keycloak role.', async ({ page }) => {
// replay
await homePage.initiateLogin();
await expect(page).toHaveURL(/.*home/);
await homePage.goToSuperset();
await homePage.addSupersetRole();
await homePage.goToKeycloak();
await homePage.goToClients();
await homePage.selectSupersetId();
await superset.open();
await superset.addRole();
await keycloak.open();
await keycloak.goToClients();
await keycloak.selectSupersetId();
await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).toBeVisible();
await homePage.deleteSupersetRole();
await superset.deleteRole();
await delay(30000);

// verify
await page.goto(`${KEYCLOAK_URL}/admin/master/console`);
await homePage.goToClients();
await homePage.selectSupersetId();
await keycloak.goToClients();
await keycloak.selectSupersetId();
await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).not.toBeVisible();
});

test('A synced role deleted from within Keycloak gets recreated in the subsequent polling cycle.', async ({ page }) => {
// replay
await homePage.initiateLogin();
await expect(page).toHaveURL(/.*home/);
await homePage.goToSuperset();
await homePage.addSupersetRole();
await superset.open();
await superset.addRole();

// verify
await homePage.goToKeycloak();
await homePage.goToClients();
await homePage.selectSupersetId();
await keycloak.open();
await keycloak.goToClients();
await keycloak.selectSupersetId();
await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).toBeVisible();
await homePage.deleteSyncedSupersetRoleInKeycloak();
await keycloak.deleteSyncedRole();
await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).not.toBeVisible();
await delay(30000);
await page.getByLabel('Manage').getByRole('link', { name: 'Clients' }).click();
await homePage.selectSupersetId();
await keycloak.selectSupersetId();
await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).toBeVisible();
await homePage.deleteSupersetRole();
await superset.deleteRole();
});

test('A (non-synced) role created from within Keycloak gets deleted in the subsequent polling cycle.', async ({ page }) => {
// replay
await homePage.initiateLogin();
await expect(page).toHaveURL(/.*home/);
await homePage.goToKeycloak();
await homePage.goToClients();
await homePage.selectOpenMRSId();
await homePage.createRoleInKeycloak();
await keycloak.open();
await keycloak.goToClients();
await keycloak.selectOpenMRSId();
await keycloak.createRole();

// verify
await page.getByRole('link', { name: 'Client details' }).click();
await expect(page.getByText(`${randomKeycloakRoleName.roleName}`)).toBeVisible();
await delay(30000);
await page.getByLabel('Manage').getByRole('link', { name: 'Clients' }).click();
await homePage.selectOpenMRSId();
await keycloak.selectOpenMRSId();
await expect(page.getByText(`${randomKeycloakRoleName.roleName}`)).not.toBeVisible();
});

Expand Down
Loading

0 comments on commit c2e1ee2

Please sign in to comment.