Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OZ-562: Refactored component-specific user actions #88

Merged
merged 11 commits into from
May 10, 2024
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 { Keycloack, 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 keycloack: Keycloack;
let superset: Superset;

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

await openmrs.initiateLogin();
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 keycloack.open();
await expect(page).toHaveURL(/.*console/);
await homePage.goToClients();
await homePage.selectOpenMRSId()
await keycloack.goToClients();
await keycloack.selectOpenMRSId()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be more something like selectOpenMRSClient() to remain in Keycloak's lingo? Or this is UI-driven and there is literally something called ID on the screen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ActuallyselectOpenMRSClient() would imply something different however, this is UI-driven with a label called client Id on the screen.

await expect(page.getByText(`${randomOpenMRSRoleName.roleName}`)).toBeVisible();
await expect(page.getByText('Role for e2e test').first()).toBeVisible();
await homePage.goToClientAttributes();
await keycloack.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 keycloack.open();
await expect(page).toHaveURL(/.*console/);
await homePage.goToClients();
await homePage.selectOpenMRSId();
await keycloack.goToClients();
await keycloack.selectOpenMRSId();
await expect(page.getByText(`${randomOpenMRSRoleName.roleName}`)).toBeVisible();
await expect(page.getByText('Role for e2e test').first()).toBeVisible();
await homePage.goToClientAttributes();
await keycloack.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 keycloack.goToClients();
await keycloack.selectOpenMRSId();
await keycloack.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 keycloack.open();
await expect(page).toHaveURL(/.*console/);
await homePage.goToClients();
await homePage.selectOpenMRSId();
await keycloack.goToClients();
await keycloack.selectOpenMRSId();
await expect(page.getByText(`${randomOpenMRSRoleName.roleName}`)).toBeVisible();
await expect(page.getByText('Role for e2e test').first()).toBeVisible();
await homePage.goToClientAttributes();
await keycloack.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 keycloack.goToClients();
await keycloack.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 keycloack.open();
await keycloack.goToClients();
await keycloack.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 keycloack.open();
await keycloack.goToClients();
await keycloack.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 keycloack.goToClients();
await keycloack.selectSupersetId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark here about "id".

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 keycloack.open();
await keycloack.goToClients();
await keycloack.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 keycloack.goToClients();
await keycloack.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 keycloack.open();
await keycloack.goToClients();
await keycloack.selectSupersetId();
await expect(page.getByText(`${randomSupersetRoleName.roleName}`)).toBeVisible();
await homePage.deleteSyncedSupersetRoleInKeycloak();
await keycloack.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 keycloack.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 keycloack.open();
await keycloack.goToClients();
await keycloack.selectOpenMRSId();
await keycloack.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 keycloack.selectOpenMRSId();
await expect(page.getByText(`${randomKeycloakRoleName.roleName}`)).not.toBeVisible();
});

Expand Down
Loading