From 2fe1c8a5de66cc495cbd448d11b241ccb5a20d1b Mon Sep 17 00:00:00 2001 From: NandanAnantharamu <67676905+NandanAnantharamu@users.noreply.github.com> Date: Fri, 2 Oct 2020 14:30:33 +0530 Subject: [PATCH] Feature/share app test (#843) * Add ShareApp test * Sharing app tests and public access --- .../OrganisationTests/ShareAppTests_spec.js | 128 ++++++++++++++++++ app/client/cypress/locators/HomePage.json | 6 +- .../cypress/locators/publishWidgetspage.json | 7 +- app/client/cypress/support/commands.js | 43 ++++++ 4 files changed, 180 insertions(+), 4 deletions(-) create mode 100644 app/client/cypress/integration/Smoke_TestSuite/OrganisationTests/ShareAppTests_spec.js diff --git a/app/client/cypress/integration/Smoke_TestSuite/OrganisationTests/ShareAppTests_spec.js b/app/client/cypress/integration/Smoke_TestSuite/OrganisationTests/ShareAppTests_spec.js new file mode 100644 index 0000000000..4046207d8e --- /dev/null +++ b/app/client/cypress/integration/Smoke_TestSuite/OrganisationTests/ShareAppTests_spec.js @@ -0,0 +1,128 @@ +/// + +const homePage = require("../../../locators/HomePage.json"); +const publish = require("../../../locators/publishWidgetspage.json"); + +describe("Create new org and share with a user", function() { + let orgid; + let appid; + let currentUrl; + + it("create org and then share with a user from Application share option within application", function() { + cy.NavigateToHome(); + cy.generateUUID().then(uid => { + orgid = uid; + appid = uid; + localStorage.setItem("OrgName", orgid); + cy.createOrg(orgid); + cy.CreateAppForOrg(orgid, appid); + cy.wait("@getPagesForApp").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + cy.get("h2").contains("Drag and drop a widget here"); + cy.get(homePage.shareApp).click(); + cy.shareApp(Cypress.env("TESTUSERNAME1"), homePage.viewerRole); + }); + cy.LogOut(); + }); + + it("login as invited user and then validate viewer privilage", function() { + cy.LogintoApp(Cypress.env("TESTUSERNAME1"), Cypress.env("TESTPASSWORD1")); + cy.get(homePage.searchInput).type(appid); + cy.wait(2000); + cy.get(homePage.appsContainer).contains(orgid); + cy.xpath(homePage.ShareBtn).should("not.exist"); + cy.get(homePage.applicationCard).trigger("mouseover"); + cy.get(homePage.appEditIcon).should("not.exist"); + cy.launchApp(appid); + cy.LogOut(); + }); + + it("Enable public access to Application", function() { + cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD")); + cy.visit("/applications"); + cy.wait("@applications").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + cy.SearchApp(appid); + cy.wait("@getPagesForApp").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + cy.get("h2").contains("Drag and drop a widget here"); + cy.get(homePage.shareApp).click(); + cy.enablePublicAccess(); + cy.PublishtheApp(); + currentUrl = cy.url(); + cy.url().then(url => { + currentUrl = url; + cy.log(currentUrl); + }); + cy.get(publish.backToEditor).click(); + cy.LogOut(); + }); + + it("login as uninvited user and then validate public access of Application", function() { + cy.LogintoApp(Cypress.env("TESTUSERNAME2"), Cypress.env("TESTPASSWORD2")); + cy.visit(currentUrl); + cy.wait("@getPagesForApp").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + cy.get(publish.pageInfo) + .invoke("text") + .then(text => { + const someText = text; + expect(someText).to.equal("This page seems to be blank"); + }); + cy.LogOut(); + }); + it("login as Owner and disable public access", function() { + cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD")); + cy.visit("/applications"); + cy.wait("@applications").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + cy.SearchApp(appid); + cy.wait("@getPagesForApp").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + cy.get("h2").contains("Drag and drop a widget here"); + cy.get(homePage.shareApp).click(); + cy.enablePublicAccess(); + cy.LogOut(); + }); + + it("login as uninvited user and then validate public access disable feature", function() { + cy.LogintoApp(Cypress.env("TESTUSERNAME2"), Cypress.env("TESTPASSWORD2")); + cy.visit(currentUrl); + cy.wait("@getPagesForApp").should( + "have.nested.property", + "response.body.responseMeta.status", + 404, + ); + cy.LogOut(); + }); + + it("login as owner and delete App ", function() { + cy.LoginFromAPI(Cypress.env("USERNAME"), Cypress.env("PASSWORD")); + cy.visit("/applications"); + cy.wait("@applications").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + cy.SearchApp(appid); + cy.get("#loading").should("not.exist"); + }); +}); diff --git a/app/client/cypress/locators/HomePage.json b/app/client/cypress/locators/HomePage.json index 67231dedb2..a6f5c9ec5f 100644 --- a/app/client/cypress/locators/HomePage.json +++ b/app/client/cypress/locators/HomePage.json @@ -42,5 +42,9 @@ "orgSectionBtn": ".t--org-section .bp3-button", "shareOrg": ") a:contains('Share')", "orgSection": "a:contains(", - "createAppFrOrg": ") .t--create-app-popup" + "createAppFrOrg": ") .t--create-app-popup", + "shareApp": ".t--application-share-btn", + "enablePublicAccess": ".bp3-control-indicator", + "closeBtn": ".bp3-dialog-close-button" + } \ No newline at end of file diff --git a/app/client/cypress/locators/publishWidgetspage.json b/app/client/cypress/locators/publishWidgetspage.json index 2383588e7e..1474aa3dd1 100644 --- a/app/client/cypress/locators/publishWidgetspage.json +++ b/app/client/cypress/locators/publishWidgetspage.json @@ -19,8 +19,8 @@ "tableLength": ".t--widget-tablewidget .tbody", "mapSearch": ".t--widget-mapwidget input", "pickMyLocation": ".t--widget-mapwidget div[title='Pick My Location']", - "rectChart":".t--widget-chartwidget g rect", - "chartLab":".t--widget-chartwidget g:nth-child(5) text", + "rectChart": ".t--widget-chartwidget g rect", + "chartLab": ".t--widget-chartwidget g:nth-child(5) text", "searchInput": "input", "downloadBtn": ".t--table-download-btn", "filterBtn": ".t--table-filter-toggle-btn", @@ -34,5 +34,6 @@ "compactOpt": ".t--table-compact-mode-option", "visibilityMode": ".t--table-column-visibility-toggle-btn", "visibilityOpt": ".option-title", - "containerWidget": ".t--widget-containerwidget" + "containerWidget": ".t--widget-containerwidget", + "pageInfo": ".bp3-heading" } \ No newline at end of file diff --git a/app/client/cypress/support/commands.js b/app/client/cypress/support/commands.js index 8d44458704..0fc05ab64c 100644 --- a/app/client/cypress/support/commands.js +++ b/app/client/cypress/support/commands.js @@ -88,6 +88,48 @@ Cypress.Commands.add("inviteUserForOrg", (orgName, email, role) => { .click(); }); +Cypress.Commands.add("shareApp", (email, role) => { + cy.xpath(homePage.email) + .click({ force: true }) + .type(email); + cy.xpath(homePage.selectRole).click({ force: true }); + cy.xpath(role).click({ force: true }); + cy.xpath(homePage.inviteBtn).click({ force: true }); + cy.wait("@postInvite").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + cy.contains(email); + cy.get(homePage.closeBtn).click(); +}); + +Cypress.Commands.add("shareAndPublic", (email, role) => { + cy.xpath(homePage.email) + .click({ force: true }) + .type(email); + cy.xpath(homePage.selectRole).click({ force: true }); + cy.xpath(role).click({ force: true }); + cy.xpath(homePage.inviteBtn).click({ force: true }); + cy.wait("@postInvite").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + cy.contains(email); + cy.enablePublicAccess(); +}); + +Cypress.Commands.add("enablePublicAccess", () => { + cy.get(homePage.enablePublicAccess).click(); + cy.wait("@changeAccess").should( + "have.nested.property", + "response.body.responseMeta.status", + 200, + ); + cy.get(homePage.closeBtn).click(); +}); + Cypress.Commands.add("deleteUserFromOrg", (orgName, email) => { cy.get(homePage.orgList.concat(orgName).concat(")")) .scrollIntoView() @@ -1585,6 +1627,7 @@ Cypress.Commands.add("startServerAndRoutes", () => { cy.route("GET", "/api/v1/users/me").as("getUser"); cy.route("POST", "/api/v1/pages").as("createPage"); cy.route("POST", "/api/v1/pages/clone/*").as("clonePage"); + cy.route("PUT", "/api/v1/applications/*/changeAccess").as("changeAccess"); }); Cypress.Commands.add("alertValidate", text => {