From 4451cb9f72a5d6ede9b1eb5429ac6ccba61d6a23 Mon Sep 17 00:00:00 2001 From: suruchee Date: Mon, 26 Jul 2021 20:56:49 +0545 Subject: [PATCH 1/3] OCLOMRS-970:Automated test for creating a version, releasing it and copy subscriptionURL --- .../dictionary/createVersion.feature | 31 ++++++++++ .../support/step_definitions/common/common.ts | 13 ++++- .../dictionary/createVersion/createVersion.ts | 57 +++++++++++++++++++ cypress/support/utils.ts | 9 ++- 4 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 cypress/integration/dictionary/createVersion.feature create mode 100644 cypress/support/step_definitions/dictionary/createVersion/createVersion.ts diff --git a/cypress/integration/dictionary/createVersion.feature b/cypress/integration/dictionary/createVersion.feature new file mode 100644 index 000000000..8313a39b6 --- /dev/null +++ b/cypress/integration/dictionary/createVersion.feature @@ -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 + 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 + + + + + diff --git a/cypress/support/step_definitions/common/common.ts b/cypress/support/step_definitions/common/common.ts index 4308a3e89..a6638b99f 100644 --- a/cypress/support/step_definitions/common/common.ts +++ b/cypress/support/step_definitions/common/common.ts @@ -2,7 +2,14 @@ /// 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); @@ -19,10 +26,12 @@ Given("a dictionary exists", () => { Before({ tags: "@dictionary" }, () => { setDictionaryId(`TD-${nanoid()}`); }); - Before({ tags: "@concept" }, () => { setConceptId(`CT-${nanoid()}`); }); +Before({ tags: "@version" }, () => { + setVersionId(`Ver-${nanoid()}`); +}); After({ tags: "@dictionary" }, () => { isLoggedIn().then(loggedIn => { diff --git a/cypress/support/step_definitions/dictionary/createVersion/createVersion.ts b/cypress/support/step_definitions/dictionary/createVersion/createVersion.ts new file mode 100644 index 000000000..da784ccaa --- /dev/null +++ b/cypress/support/step_definitions/dictionary/createVersion/createVersion.ts @@ -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(); +}); +Then("the user should be on the create new version dialog box", () => + cy.get("h2").contains("Create new version") +); + +Given("the user is on the create new version dialog box", () => { + 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(); +}); +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"); +}); + +When("the user clicks release status switch", () => { + cy.get('[type="checkbox"]').check(); +}); +When("the release dialog opens", () => { + cy.get("#confirmation-dialog-title").should("exist"); +}); +When("the user clicks yes button", () => { + cy.get("button.MuiButton-textPrimary") + .eq(1) + .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()}`) +); diff --git a/cypress/support/utils.ts b/cypress/support/utils.ts index 8865065fa..bdae598e3 100644 --- a/cypress/support/utils.ts +++ b/cypress/support/utils.ts @@ -21,8 +21,13 @@ export const getAuthToken = () => .its("token") .then(token => `Token ${token}`); export const getDictionaryId = () => Cypress.env("dictionaryId"); -export const setDictionaryId = (dictionaryId: string) => Cypress.env("dictionaryId", 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 getVersionId = () => Cypress.env("versionId"); +export const setVersionId = (versionId: string) => + Cypress.env("versionId", versionId); export const getUser = () => Cypress.env("USERNAME") || "ocladmin"; export const getPassword = () => Cypress.env("PASSWORD") || "Root123"; From 5c73ffb3ee5a318b484947bde9e93a91e51ac77a Mon Sep 17 00:00:00 2001 From: suruchee Date: Tue, 27 Jul 2021 15:41:45 +0545 Subject: [PATCH 2/3] updated with suggestions and update for checking the subscription url should be copied --- .../dictionary/createVersion.feature | 9 +-- .../support/step_definitions/common/common.ts | 1 + .../dictionary/createVersion/createVersion.ts | 57 ++++++++++--------- 3 files changed, 32 insertions(+), 35 deletions(-) diff --git a/cypress/integration/dictionary/createVersion.feature b/cypress/integration/dictionary/createVersion.feature index 8313a39b6..f4ad3c9d2 100644 --- a/cypress/integration/dictionary/createVersion.feature +++ b/cypress/integration/dictionary/createVersion.feature @@ -13,7 +13,7 @@ Feature: Creating a dictionary version Releasing it and copy subscription URL @version Scenario: The user should be able to create a new version, release it and copy subscription URL Given a dictionary exists - And the user is on the create new version dialog box + 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 @@ -23,9 +23,4 @@ Feature: Creating a dictionary version Releasing it and copy subscription URL 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 - - - - - + Then the subscription url should be copied \ No newline at end of file diff --git a/cypress/support/step_definitions/common/common.ts b/cypress/support/step_definitions/common/common.ts index a6638b99f..faed212d1 100644 --- a/cypress/support/step_definitions/common/common.ts +++ b/cypress/support/step_definitions/common/common.ts @@ -29,6 +29,7 @@ Before({ tags: "@dictionary" }, () => { Before({ tags: "@concept" }, () => { setConceptId(`CT-${nanoid()}`); }); + Before({ tags: "@version" }, () => { setVersionId(`Ver-${nanoid()}`); }); diff --git a/cypress/support/step_definitions/dictionary/createVersion/createVersion.ts b/cypress/support/step_definitions/dictionary/createVersion/createVersion.ts index da784ccaa..7516eac05 100644 --- a/cypress/support/step_definitions/dictionary/createVersion/createVersion.ts +++ b/cypress/support/step_definitions/dictionary/createVersion/createVersion.ts @@ -1,18 +1,18 @@ import { Given, Then, When } from "cypress-cucumber-preprocessor/steps"; -import {getDictionaryId, getUser, getVersionId} from "../../../utils"; +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(); -}); +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") ); -Given("the user is on the create new version dialog box", () => { +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.get("h2").contains("Create new version"); @@ -21,37 +21,38 @@ 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(); -}); +When("the user submits the form", () => + 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"); + cy.get('[type="checkbox"]').should("not.be.checked"); }); -When("the user clicks release status switch", () => { - cy.get('[type="checkbox"]').check(); -}); -When("the release dialog opens", () => { - cy.get("#confirmation-dialog-title").should("exist"); -}); -When("the user clicks yes button", () => { - cy.get("button.MuiButton-textPrimary") - .eq(1) - .click(); -}); +When("the user clicks release status switch", () => + 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 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()}`) -); +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()}` + ); + }); + }); +}); From 974d5ecdd5e9dfb0df7115301b37f13f1c96ace9 Mon Sep 17 00:00:00 2001 From: suruchee Date: Tue, 3 Aug 2021 22:54:55 +0545 Subject: [PATCH 3/3] separating into three different test: creating version, releasing it and copy dictionary --- .../dictionary/createVersion.feature | 20 +++- cypress/support/commands.ts | 95 ++++++++++++++++++- cypress/support/index.d.ts | 16 ++++ .../support/step_definitions/common/common.ts | 16 +++- .../dictionary/createVersion/createVersion.ts | 17 ++-- package-lock.json | 13 +++ package.json | 1 + 7 files changed, 168 insertions(+), 10 deletions(-) diff --git a/cypress/integration/dictionary/createVersion.feature b/cypress/integration/dictionary/createVersion.feature index f4ad3c9d2..a8279d0ac 100644 --- a/cypress/integration/dictionary/createVersion.feature +++ b/cypress/integration/dictionary/createVersion.feature @@ -1,4 +1,4 @@ -Feature: Creating a dictionary version Releasing it and copy subscription URL +Feature: Creating a dictionary version, releasing it and copy subscription URL Background: Given the user is logged in @@ -11,16 +11,32 @@ Feature: Creating a dictionary version Releasing it and copy subscription URL @dictionary @version - Scenario: The user should be able to create a new version, release it and copy subscription URL + 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 \ No newline at end of file diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index a63260b1a..91bff6b87 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -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"; @@ -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); + } +); \ No newline at end of file diff --git a/cypress/support/index.d.ts b/cypress/support/index.d.ts index 4278e27a8..fd30f55a5 100644 --- a/cypress/support/index.d.ts +++ b/cypress/support/index.d.ts @@ -37,5 +37,21 @@ declare namespace Cypress { organisation: string, username?: string ): Chainable; + createVersion( + version?: string, + dictionary?: string, + username?: string, + ): Chainable; + getVersion( + version?: string, + dictionary?: string, + username?: string, + shouldFail?:boolean + ): Chainable; + updateVersion( + version?: string, + dictionary?: string, + username?: string + ): Chainable; } } diff --git a/cypress/support/step_definitions/common/common.ts b/cypress/support/step_definitions/common/common.ts index faed212d1..d5aaf1740 100644 --- a/cypress/support/step_definitions/common/common.ts +++ b/cypress/support/step_definitions/common/common.ts @@ -4,7 +4,7 @@ import { After, Before, Given } from "cypress-cucumber-preprocessor/steps"; import { customAlphabet } from "nanoid"; import { getDictionaryId, - getUser, + getUser, getVersionId, isLoggedIn, setConceptId, setDictionaryId, @@ -23,6 +23,20 @@ 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()}`); }); diff --git a/cypress/support/step_definitions/dictionary/createVersion/createVersion.ts b/cypress/support/step_definitions/dictionary/createVersion/createVersion.ts index 7516eac05..dcf270bc1 100644 --- a/cypress/support/step_definitions/dictionary/createVersion/createVersion.ts +++ b/cypress/support/step_definitions/dictionary/createVersion/createVersion.ts @@ -1,3 +1,4 @@ +import 'cypress-wait-until'; import { Given, Then, When } from "cypress-cucumber-preprocessor/steps"; import { getDictionaryId, getUser, getVersionId } from "../../../utils"; @@ -9,28 +10,32 @@ 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") + 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.get("h2").contains("Create new version"); + 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() +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.get('[type="checkbox"]').check() +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") diff --git a/package-lock.json b/package-lock.json index 013949c13..8eb3c061c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -62,6 +62,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", @@ -7818,6 +7819,12 @@ "node": ">=0.10.0" } }, + "node_modules/cypress-wait-until": { + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/cypress-wait-until/-/cypress-wait-until-1.7.1.tgz", + "integrity": "sha512-8DL5IsBTbAxBjfYgCzdbohPq/bY+IKc63fxtso1C8RWhLnQkZbVESyaclNr76jyxfId6uyzX8+Xnt0ZwaXNtkA==", + "dev": true + }, "node_modules/cypress/node_modules/@types/node": { "version": "14.17.3", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.3.tgz", @@ -31904,6 +31911,12 @@ } } }, + "cypress-wait-until": { + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/cypress-wait-until/-/cypress-wait-until-1.7.1.tgz", + "integrity": "sha512-8DL5IsBTbAxBjfYgCzdbohPq/bY+IKc63fxtso1C8RWhLnQkZbVESyaclNr76jyxfId6uyzX8+Xnt0ZwaXNtkA==", + "dev": true + }, "d": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz", diff --git a/package.json b/package.json index 74a9670ef..e8621a3b3 100644 --- a/package.json +++ b/package.json @@ -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",