Skip to content

Commit

Permalink
OCLOMRS-1026: Add automated tests to View Organisation Sources and Co…
Browse files Browse the repository at this point in the history
…llections (#741)
  • Loading branch information
hadijahkyampeire committed Sep 22, 2021
1 parent 2840ebc commit da18b22
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 2 deletions.
30 changes: 30 additions & 0 deletions cypress/integration/organisation/details.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Feature: Organisation details Page
Background:
Given the user is logged in

@organisation
Scenario: The user should see all details of the organisation
Given an organization exists
And the user is on the organisation details page
Then the organisation name should be displayed
And the organisation sources should be displayed
And the organisation members should be displayed
And the organisation dictionaries should be displayed

@organisation
Scenario: The user should see organisation sources
Given an organization exists
And a source exists in the organisation
When the user is on the organisation details page
Then the user should see the organisation source
When the user clicks on the source
Then the user should be on the org source page

@organisation
Scenario: The user should see organisation dictionary
Given an organization exists
And a dictionary exists in the organisation
When the user is on the organisation details page
Then the user should see the organisation dictionary
When the user clicks on the dictionary
Then the user should be on the org dictionary page
44 changes: 43 additions & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ Cypress.Commands.add(
id: source,
custom_validation_schema: "OpenMRS",
short_code: source,
name: `${source}`,
name: "Test Org Source",
description: "",
public_access: public_access ? "View" : "None",
source_type: "Dictionary"
Expand All @@ -352,6 +352,48 @@ Cypress.Commands.add(
}
);

Cypress.Commands.add(
"createOrgDictionary",
(
dictionary: string = `TOC-${nanoid()}`,
organisation: string = "CIEL",
public_access: boolean = false
) => {
getAuthToken().then(authToken =>
cy
.request({
method: "GET",
headers: {
Authorization: authToken
},
url: `${apiUrl}/orgs/${organisation}/collections/${dictionary}/`,
failOnStatusCode: false
})
.then(response => {
if (response.status !== 200) {
cy.request({
method: "POST",
headers: {
Authorization: authToken
},
url: `${apiUrl}/orgs/${organisation}/collections/`,
body: {
id: dictionary,
custom_validation_schema: "OpenMRS",
short_code: dictionary,
name: "Test Org Dictionary",
description: "",
public_access: public_access ? "View" : "None",
source_type: "Dictionary"
}
});
}
})
);
return cy.wrap(dictionary);
}
);

Cypress.Commands.add(
"deleteSource",
(
Expand Down
5 changes: 5 additions & 0 deletions cypress/support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ declare namespace Cypress {
organisation?: string,
public_access?: boolean
): Chainable<Subject>;
createOrgDictionary(
dictionary?: string,
organisation?: string,
public_access?: boolean
): Chainable<Subject>;
deleteSource(
source: string,
username?: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
When
} from "cypress-cucumber-preprocessor/steps";
import { customAlphabet } from "nanoid";
import { getOrganisationId, isLoggedIn } from "../../../utils";
import { isLoggedIn } from "../../../utils";

let organisationID = "";
const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz", 4);
Expand Down
59 changes: 59 additions & 0 deletions cypress/support/step_definitions/organisation/details/details.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Given, Then, When } from "cypress-cucumber-preprocessor/steps";
import { getOrganisationId } from "../../../utils";

Given("an organization exists", () => {
cy.createOrganisation(getOrganisationId());
});

Given("a source exists in the organisation", () => {
cy.createOrgSource(undefined, getOrganisationId());
});

Given("a dictionary exists in the organisation", () => {
cy.createOrgDictionary(undefined, getOrganisationId());
});

Given("the user is on the organisation details page", () =>
cy.visit(`/orgs/${getOrganisationId()}/`)
);

Then("the organisation name should be displayed", () => {
cy.findByText("Details").should("be.visible");
cy.findByText("Test Organisation", { selector: "span" }).should("be.visible");
});

Then("the organisation sources should be displayed", () => {
cy.findByText("Sources", { selector: "legend" }).should("be.visible");
});

Then("the organisation members should be displayed", () => {
cy.findByText("Members", { selector: "legend" }).should("be.visible");
});

Then("the organisation dictionaries should be displayed", () => {
cy.findByText("Dictionaries", { selector: "legend" }).should("be.visible");
});

Then("the user should see the organisation source", () => {
cy.contains("li", "Test Org Source");
});

When("the user clicks on the source", () =>
cy.contains("li", "Test Org Source").get("li > a").click()
);

Then("the user should be on the org source page", () =>
cy.url().should("contain",`/orgs/${getOrganisationId()}/sources/`)
);

Then("the user should see the organisation dictionary", () => {
cy.contains("li", "Test Org Dictionary");
});

When("the user clicks on the dictionary", () =>
cy.contains("li", "Test Org Dictionary").get("li > a").click()
);

Then("the user should be on the org dictionary page", () =>
cy.url().should("contain",`/orgs/${getOrganisationId()}/collections/`)
);

0 comments on commit da18b22

Please sign in to comment.