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 2 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
31 changes: 31 additions & 0 deletions cypress/integration/dictionary/createVersion.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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, release it and copy subscription URL
Copy link
Member

Choose a reason for hiding this comment

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

I would actually break this out as three separate tests: one to create a new version. One to release it via the checkbox, and one to copy the subscription URL. That way we should also be able to check that the user can release a new version within the "Create New Version" form.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You are right @ibacher that's what @suruchee had but the last two scenarios were not passing probably because they needed a version to be created, she had a command for creating and getting a version the way the dictionary commands are but they were not working, so I told her that we first put those other two tests in the same scenario so that we see they pass, then we reach out to you about separating them.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough... The version release process actually does some backend processing, so between the request to create the version returning and the version actually being created there's a bit of a delay... not much for a small dictionary, but not no time at all either.

Probably the simplest way to do this is to force Cypress to pause immediately after submitting the new version request, e.g., by using cy.wait(500). A more complicated version of the same idea would be to have a shorter pause and at the end of each pause poll the backend until a longer period of time, e.g. 8 seconds or w/e had passed.

Copy link
Member

Choose a reason for hiding this comment

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

Here's a library to handle my "more complicated" version: https://github.com/NoriSte/cypress-wait-until. Basically looks like you can use that and wait until the backend returns that the version exists. Note that it's probably also necessary to force Cypress to reload the page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @hadijahkyampeire and @ibacher, I will update with the delay suggestion.

Given a dictionary exists
And the user is 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
When the user clicks release status switch
And the release dialog opens
And the user clicks yes button
Then the version should be released
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





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

13 changes: 11 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,
isLoggedIn,
setConceptId,
setDictionaryId,
setVersionId
} from "../../utils";

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

Expand All @@ -19,10 +26,12 @@ Given("a dictionary exists", () => {
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 => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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();
});
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
When("the user clicks the create new version button", () => {
cy.findByRole("button", { name: /Create new version/i }).click();
});
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.get("h2").contains("Create new 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
cy.get("h2").contains("Create new version")
cy.findByText("Create new version").should("be.visible")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @ibacher, but this code will cause Found multiple elements with the text error. So I tried this one. Will you please suggest another idea?

Copy link
Member

Choose a reason for hiding this comment

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

cy.findByText("Create new version", { selector: "h2" }).should("be.visible")

);

Given("the user is on the create new version dialog box", () => {
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
Given("the user is on the create new version dialog box", () => {
Given("the user clicks on the create new version dialog box", () => {

And a similar change to the feature file.

cy.visit(`/users/${getUser()}/collections/${getDictionaryId()}/`);
cy.findByRole("button", { name: /Create new version/i }).click();
cy.get("h2").contains("Create new version");
});
When("the user enters the version information", () => {
cy.findByLabelText("ID").type("1");
cy.get("#released").type("{enter}");
});
When("the user submits the form", () => {
cy.get("#versionForm").submit();
Copy link
Member

Choose a reason for hiding this comment

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

There's no #versionForm element, so just do:

cy.findByRole("button", { name: /Submit/i }).click();

});
Then("the new version should be created", () => {
cy.get("table").should("exist");
cy.get("table tbody tr").should("have.length", 1);
cy.get("table").contains("td", "1");
cy.get("table").contains("td", "No");
});
Copy link
Member

Choose a reason for hiding this comment

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

There are probably too many assertions here we don't need. E.g., what we care about is there is a row with the ID we filled in. Also, I'm not sure what the "No" here is supposed to match, but we'd probably need to check the actual checkbox if its the release status.


When("the user clicks release status switch", () => {
cy.get('[type="checkbox"]').check();
});
When("the release dialog opens", () => {
cy.get("#confirmation-dialog-title").should("exist");
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
cy.get("#confirmation-dialog-title").should("exist");
cy.get("#confirmation-dialog-title").should("be.visible");

});
When("the user clicks yes button", () => {
cy.get("button.MuiButton-textPrimary")
.eq(1)
.click();
Copy link
Member

Choose a reason for hiding this comment

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

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.visit(`/users/${getUser()}/collections/${getDictionaryId()}/${getVersionId()}`)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I see how this code checks that the subscription URL was copied? This looks like a good approach to verify that the correct text was copied.

);
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);