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

O3-2070: Create e2e test for importing using subscription #19

Merged
merged 2 commits into from Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions e2e/commands/index.ts
@@ -0,0 +1 @@
export * from './oclOperations';
20 changes: 20 additions & 0 deletions e2e/commands/oclOperations.ts
@@ -0,0 +1,20 @@
import { APIRequestContext, expect } from '@playwright/test';

export interface Subscription {
uuid: string;
url: string;
token: string;
subscribedToSnapshot?: boolean;
validationType?: 'NONE' | 'FULL';
}

export const getSavedSubscription = async (api: APIRequestContext): Promise<Subscription> => {
const subscriptionRes = await api.get('openconceptlab/subscription?v=full');
await expect(subscriptionRes.ok()).toBeTruthy();
const { results } = await subscriptionRes.json();
return results[0];
};

export const removeOclSubscription = async (api: APIRequestContext, subscription: Subscription) => {
await api.delete(`openconceptlab/subscription/${subscription.uuid}`);
};
19 changes: 19 additions & 0 deletions e2e/pages/openConceptLabPage.ts
Expand Up @@ -3,7 +3,26 @@ import { Page } from '@playwright/test';
export class OpenConceptLabPage {
constructor(readonly page: Page) {}

readonly subscriptionTab = () => this.page.getByRole('tab', { name: 'Subscription' });
readonly importTab = () => this.page.getByRole('tab', { name: 'Import', exact: true });
readonly previousImportsTab = () => this.page.getByRole('tab', { name: 'Previous Imports' });
readonly previousImportsTable = () => this.page.getByRole('table');

async goto() {
await this.page.goto('ocl');
}

async addOclSubscription() {
await this.page.getByLabel('Subscription URL').fill(process.env.E2E_OCL_SUBSCRIPTION_URL);
await this.page.getByLabel('Token').fill(process.env.E2E_OCL_TOKEN);
await this.page.getByRole('button', { name: 'Save Changes' }).click();
}

async startImport() {
await this.page.getByRole('button', { name: 'Import from Subscription' }).click();
}

async unsubscribe() {
await this.page.getByRole('button', { name: 'Unsubscribe' }).click();
}
}
39 changes: 39 additions & 0 deletions e2e/specs/openConceptLab.spec.ts
@@ -0,0 +1,39 @@
import { expect } from '@playwright/test';
import { getSavedSubscription, removeOclSubscription } from '../commands';
import { test } from '../core';
import { OpenConceptLabPage } from '../pages';

test.beforeEach(async ({ api }) => {
const savedSubscription = await getSavedSubscription(api);
if (savedSubscription) {
await removeOclSubscription(api, savedSubscription);
}
});

test('should be able to setup a subscription and import concepts', async ({ page }) => {
const openConceptLabPage = new OpenConceptLabPage(page);

// Setup the subscription
await openConceptLabPage.goto();
await openConceptLabPage.addOclSubscription();

// Start an Import
await openConceptLabPage.importTab().click();
await openConceptLabPage.startImport();

// Check results of the import
await openConceptLabPage.goto();
await openConceptLabPage.previousImportsTab().click();
await expect(openConceptLabPage.previousImportsTable()).toHaveText(/\d+ items fetched/);

// Unsubscribe
await openConceptLabPage.subscriptionTab().click();
await openConceptLabPage.unsubscribe();
});

test.afterEach(async ({ api }) => {
const savedSubscription = await getSavedSubscription(api);
if (savedSubscription) {
await removeOclSubscription(api, savedSubscription);
}
});
9 changes: 0 additions & 9 deletions e2e/specs/patientList.spec.ts

This file was deleted.

3 changes: 3 additions & 0 deletions example.env
Expand Up @@ -4,3 +4,6 @@ E2E_USER_ADMIN_USERNAME=admin
E2E_USER_ADMIN_PASSWORD=Admin123
E2E_LOGIN_DEFAULT_LOCATION_UUID=44c3efb0-2583-4c80-a79e-1f756a03c0a1
# The above location UUID is for the "Outpatient Clinic" location in the reference application
E2E_OCL_SUBSCRIPTION_URL=https://api.openconceptlab.org/orgs/openmrs/collections/DemoQueueConcepts
E2E_OCL_TOKEN=bd022mad6d3df24f5c42ewewa94b53a23edf6eee7r
# The above token is random due to the URL being related to a public collection