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

OCLOMRS-970:Automated test for creating a version, releasing it and copy subscriptionURL #724

Merged
merged 4 commits into from
Aug 3, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions cypress/integration/dictionary/createVersion.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Feature: Creating a dictionary version, releasing it and copy subscription URL
Background:
Given the user is logged in

@dictionary
Scenario: The user should be able to click the button to create a new version
Given a dictionary exists
And the user is on the dictionary page
When the user clicks the create new version button
Then the user should be on the create new version dialog box

@dictionary
@version
Scenario: The user should be able to create a new version
Given a dictionary exists
And the user clicks on the create new version dialog box
When the user enters the version information
And the user submits the form
Then the new version should be created

@dictionary
@version
Scenario: The user should be able to release a version
Given a dictionary exists
And a version exists
And the user is on the dictionary page
When the user clicks release status switch
And the release dialog opens
And the user clicks yes button
Then the version should be released

@dictionary
@version
@released
Scenario: The user should be able to copy subscription URL
Given a dictionary exists
And a version exists
And a version is released
And the user is on the dictionary page
When the user clicks the more actions button
And the user selects the "Copy Subscription URL" menu list item
Then the subscription url should be copied
95 changes: 94 additions & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
LOGOUT_ACTION
} from "../../src/apps/authentication/redux/actionTypes";
import { nanoid } from "nanoid";
import { getStore, getAuthToken, getUser, getPassword } from "./utils";
import {getStore, getAuthToken, getUser, getPassword, getDictionaryId, getVersionId} from "./utils";

const apiUrl: string = Cypress.env("API_URL") || "http://localhost:8000";

Expand Down Expand Up @@ -314,3 +314,96 @@ Cypress.Commands.add("getOrganisation", (organisation: string) => {
.its("body");
});
});
Cypress.Commands.add(
"createVersion",
(
version: string = `Ver-${nanoid()}`,
dictionary: string = `TD-${nanoid()}`,
username: string = getUser(),
) => {
getAuthToken().then(authToken =>
cy.request({
method: "GET",
headers: {
Authorization: authToken
},
url: `${apiUrl}/users/${username}/collections/${dictionary}/versions/${version}`,
failOnStatusCode: false
}).then(response => {
if (response.status !== 200) {
cy.request({
method: "POST",
headers: {
Authorization: authToken
},
url: `${apiUrl}/users/${username}/collections/${dictionary}/versions/`,
body: {
id: version,
released: false,
description: ""
}
});
}
})
);
return cy.wrap(version);
}
);

Cypress.Commands.add(
"getVersion",
(
version: string ,
dictionary: string = getDictionaryId(),
username: string = getUser(),
shouldFail: boolean = true
) => {
return getAuthToken().then(authToken => {
return cy
.request({
method: "GET",
headers: {
Authorization: authToken
},
url: `${apiUrl}/users/${username}/collections/${dictionary}/versions/${version}`,
failOnStatusCode: shouldFail
})
.its("body");
});
}
);
Cypress.Commands.add(
"updateVersion",
(
version: string = getVersionId(),
dictionary: string = getDictionaryId(),
username: string = getUser()
) => {
getAuthToken().then(authToken =>
cy.request({
method: "GET",
headers: {
Authorization: authToken
},
url: `${apiUrl}/users/${username}/collections/${dictionary}/versions/${version}`,
failOnStatusCode: false
}).then(response => {
if (response.status !== 200) {
cy.request({
method: "PUT",
headers: {
Authorization: authToken
},
url: `${apiUrl}/users/${username}/collections/${dictionary}/${version}/`,
body: {
id: version,
released: true,
description: ""
}
});
}
})
);
return cy.wrap(version);
}
);
16 changes: 16 additions & 0 deletions cypress/support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,21 @@ declare namespace Cypress {
organisation: string,
username?: string
): Chainable<Subject>;
createVersion(
version?: string,
dictionary?: string,
username?: string,
): Chainable<Subject>;
getVersion(
version?: string,
dictionary?: string,
username?: string,
shouldFail?:boolean
): Chainable<Subject>;
updateVersion(
version?: string,
dictionary?: string,
username?: string
): Chainable<Subject>;
}
}
28 changes: 26 additions & 2 deletions cypress/support/step_definitions/common/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
/// <reference types="../../" />
import { After, Before, Given } from "cypress-cucumber-preprocessor/steps";
import { customAlphabet } from "nanoid";
import { getDictionaryId, getUser, isLoggedIn, setConceptId, setDictionaryId } from "../../utils";
import {
getDictionaryId,
getUser, getVersionId,
isLoggedIn,
setConceptId,
setDictionaryId,
setVersionId
} from "../../utils";

const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz", 4);

Expand All @@ -16,14 +23,31 @@ Given("a dictionary exists", () => {
);
});

Given("a version exists", () => {
const versionId = getVersionId();
const dictionaryId = getDictionaryId();
const user = getUser();
cy.createVersion(versionId, dictionaryId, user);
});

Given("a version is released", () => {
const versionId = getVersionId();
const dictionaryId = getDictionaryId();
const user = getUser();
cy.updateVersion(versionId, dictionaryId, user);
});

Before({ tags: "@dictionary" }, () => {
setDictionaryId(`TD-${nanoid()}`);
});

Before({ tags: "@concept" }, () => {
setConceptId(`CT-${nanoid()}`);
});

Before({ tags: "@version" }, () => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Before({ tags: "@version" }, () => {
Before({ tags: "@version" }, () => {

setVersionId(`Ver-${nanoid()}`);
});

After({ tags: "@dictionary" }, () => {
isLoggedIn().then(loggedIn => {
if (loggedIn) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'cypress-wait-until';
import { Given, Then, When } from "cypress-cucumber-preprocessor/steps";
import { getDictionaryId, getUser, getVersionId } from "../../../utils";

Given("the user is on the dictionary page", () => {
cy.visit(`/users/${getUser()}/collections/${getDictionaryId()}/`);
cy.findByText("Versions").should("be.visible");
});
When("the user clicks the create new version button", () =>
cy.findByRole("button", { name: /Create new version/i }).click()
);
Then("the user should be on the create new version dialog box", () =>
cy.findByText("Create new version", { selector: "h2" }).should("be.visible")
);

Given("the user clicks on the create new version dialog box", () => {
cy.visit(`/users/${getUser()}/collections/${getDictionaryId()}/`);
cy.findByRole("button", { name: /Create new version/i }).click();
cy.findByText("Create new version", { selector: "h2" }).should("be.visible")
});
When("the user enters the version information", () => {
cy.findByLabelText("ID").type("1");
cy.get("#released").type("{enter}");
});
When("the user submits the form", () =>{
cy.findByRole("button", { name: /Submit/i }).click();
}
);
Then("the new version should be created", () => {
cy.get("table").contains("td", "1");
cy.get('[type="checkbox"]').should("not.be.checked");
});

When("the user clicks release status switch", () =>{
cy.reload(true);
cy.waitUntil(() => cy.getVersion(getVersionId(), getDictionaryId(), getUser(), false), { timeout: 10000 });
cy.get('[type="checkbox"]').check();
}
);
When("the release dialog opens", () =>
cy.get("#confirmation-dialog-title").should("be.visible")
);
When("the user clicks yes button", () => cy.findByText(/Yes/i).click());
Then("the version should be released", () =>
cy.get('[type="checkbox"]').should("be.checked")
);

When("the user clicks the more actions button", () =>
cy.findByTitle("More actions").click()
);
When(/the user selects the "(.+)" menu list item/, menuItem =>
cy.findByText(menuItem).click()
);
Then("the subscription url should be copied", () => {
cy.window().then(win => {
win.navigator.clipboard.readText().then(text => {
assert.equal(
text,
`/users/${getUser()}/collections/${getDictionaryId()}/${getVersionId()}`
);
});
});
});
6 changes: 5 additions & 1 deletion cypress/support/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export const getDictionaryId = () => Cypress.env("dictionaryId");
export const setDictionaryId = (dictionaryId: string) =>
Cypress.env("dictionaryId", dictionaryId);
export const getConceptId = () => Cypress.env("conceptId");
export const setConceptId = (conceptId: string) => Cypress.env("conceptId", conceptId);
export const setConceptId = (conceptId: string) =>
Cypress.env("conceptId", conceptId);
export const getOrganisationId = () => Cypress.env("organisationId");
export const setOrganisationId = (organisationId: string) =>
Cypress.env("organisationId", organisationId);
export const getVersionId = () => Cypress.env("versionId");
export const setVersionId = (versionId: string) =>
Cypress.env("versionId", versionId);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Cypress.env("versionId", versionId);
Cypress.env("versionId", versionId);

13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"@types/node": "^12.7.12",
"cypress": "^7.5.0",
"cypress-cucumber-preprocessor": "^4.1.2",
"cypress-wait-until": "^1.7.1",
"eslint-plugin-cypress": "^2.11.2",
"husky": "^6.0.0",
"jest-junit": "^12.0.0",
Expand Down