From 19df4547f4cc9ba9ce76cf922d8703c2ffbd3c6b Mon Sep 17 00:00:00 2001 From: gillespi314 <73313222+gillespi314@users.noreply.github.com> Date: Tue, 25 Jan 2022 11:24:26 -0600 Subject: [PATCH] Refactor e2e premium maintainer spec (#3839) --- .../integration/premium/maintainer.spec.ts | 295 ++++++++++-------- 1 file changed, 173 insertions(+), 122 deletions(-) diff --git a/cypress/integration/premium/maintainer.spec.ts b/cypress/integration/premium/maintainer.spec.ts index d8afdd632d..46379641d1 100644 --- a/cypress/integration/premium/maintainer.spec.ts +++ b/cypress/integration/premium/maintainer.spec.ts @@ -1,135 +1,186 @@ -describe( - "Premium tier - Maintainer user", - { - defaultCommandTimeout: 20000, - }, - () => { +describe("Premium tier - Maintainer user", () => { + before(() => { + Cypress.session.clearAllSavedSessions(); + cy.setup(); + cy.loginWithCySession(); + cy.seedPremium(); + cy.seedQueries(); + cy.seedPolicies("apples"); + cy.addDockerHost("apples"); + }); + after(() => { + cy.logout(); + cy.stopDockerHost(); + }); + + describe("Global maintainer", () => { beforeEach(() => { - cy.setup(); - cy.login(); - cy.seedPremium(); - cy.seedQueries(); - cy.seedPolicies("apples"); - cy.addDockerHost("apples"); - cy.logout(); + cy.loginWithCySession("mary@organization.com", "user123#"); }); + describe("Manage hosts page", () => { + it("renders elements according to role-based access controls", () => { + cy.visit("/hosts/manage"); + // Hosts table includes teams column + cy.getAttached(".data-table__table th") + .contains("Team") + .should("be.visible"); + cy.getAttached(".button-wrap") + .contains("button", /generate installer/i) + .click(); + cy.getAttached(".modal__content").contains("button", /done/i).click(); - afterEach(() => { - cy.stopDockerHost(); + cy.getAttached(".button-wrap") + .contains("button", /manage enroll secret/i) + .click(); + cy.getAttached(".enroll-secret-modal__add-secret") + .contains("button", /add secret/i) + .click(); + cy.getAttached(".secret-editor-modal__button-wrap") + .contains("button", /save/i) + .click(); + cy.getAttached(".enroll-secret-modal__button-wrap") + .contains("button", /done/i) + .click(); + }); }); - - it("Can perform the appropriate basic global maintainer actions", () => { - cy.login("mary@organization.com", "user123#"); - cy.visit("/hosts/manage"); - cy.get(".manage-hosts").should("contain", /hostname/i); // Ensures page load - - // See the "Manage" enroll secret” button. A modal appears after the user selects the button - cy.contains("button", /manage enroll secret/i).click(); - cy.contains("button", /done/i).click(); - - cy.contains("button", /generate installer/i).click(); - // TODO: Check Team Apples is in Select a team dropdown - cy.contains("button", /done/i).click(); - - // Host details page: Can see team UI - cy.get("tbody").within(() => { - // Test host text varies - cy.findByRole("button").click(); + describe("Host details page", () => { + beforeEach(() => { + cy.visit("/hosts/manage"); + cy.getAttached(".hostname__cell").first().click(); }); - - cy.wait(2000); // eslint-disable-line cypress/no-unnecessary-waiting - cy.findByText("Team").should("exist"); - cy.contains("button", /transfer/i).click(); - cy.get(".Select-control").click(); - cy.findByText(/create a team/i).should("not.exist"); - cy.get(".Select-menu").within(() => { - cy.findByText(/no team/i).should("exist"); - cy.findByText(/apples/i).should("exist"); - cy.findByText(/oranges/i).click(); + it("allows global maintainer to transfer host to an existing team", () => { + cy.getAttached(".host-details__transfer-button").click(); + cy.findByText(/create a team/i).should("not.exist"); + cy.getAttached(".Select-control").click(); + cy.getAttached(".Select-menu").within(() => { + cy.findByText(/no team/i).should("exist"); + cy.findByText(/apples/i).should("exist"); + cy.findByText(/oranges/i).click(); + }); + cy.getAttached(".transfer-action-btn").click(); + cy.findByText(/transferred to oranges/i).should("exist"); + cy.findByText(/team/i).next().contains("Oranges"); }); - cy.get(".transfer-action-btn").click(); - cy.findByText(/transferred to oranges/i).should("exist"); - cy.findByText(/team/i).next().contains("Oranges"); - cy.contains("button", /delete/i).should("exist"); - cy.contains("button", /query/i).click(); - cy.contains("button", /create custom query/i).should("exist"); - // See and select operating system - // TODO - - // Query pages: Can see teams UI for create, edit, and run query - cy.visit("/queries/manage"); - - cy.findByRole("button", { name: /create new query/i }).should("exist"); - - // TODO - Fix tests according to improved query experience - MP - // cy.findByRole("button", { name: /create new query/i }).click(); - - // cy.get(".target-select").within(() => { - // cy.findByText(/Label name, host name, IP address, etc./i).click(); - // cy.findByText(/teams/i).should("exist"); - // }); - - // cy.visit("/queries/manage"); - - // cy.findByText(/detect presence/i).click(); - - // cy.findByText(/edit & run query/i).should("exist"); - - // cy.get(".target-select").within(() => { - // cy.findByText(/Label name, host name, IP address, etc./i).click(); - // cy.findByText(/teams/i).should("exist"); - // }); - - // On the policies manage page, they should… - cy.contains("a", "Policies").click(); - // See and select the "Manage automations" button - cy.findByRole("button", { name: /manage automations/i }).click(); - cy.findByRole("button", { name: /cancel/i }).click(); - - // See and select the "Add a policy", "delete", and "edit" policy - cy.findByRole("button", { name: /add a policy/i }).click(); - cy.get(".modal__ex").within(() => { - cy.findByRole("button").click(); + it("allows global maintainer to create an operating system policy", () => { + cy.getAttached(".info-flex").within(() => { + cy.findByText(/ubuntu/i).should("exist"); + cy.getAttached(".host-details__os-policy-button").click(); + }); + cy.getAttached(".modal__content") + .findByRole("button", { name: /create new policy/i }) + .should("exist"); }); - - // No global policies seeded, switch to team apples to create, delete, edit - cy.findByText(/ask yes or no questions/i).should("exist"); - cy.findByText(/all teams/i).click(); - cy.findByText(/apples/i).click(); - - cy.get("tbody").within(() => { - cy.get("tr") - .first() - .within(() => { - cy.get(".fleet-checkbox__input").check({ force: true }); - }); + it("allows global maintainer to create a custom query", () => { + cy.getAttached(".host-details__query-button").click(); + cy.contains("button", /create custom query/i).should("exist"); + cy.getAttached(".modal__ex").click(); }); - cy.findByRole("button", { name: /delete/i }).click(); - cy.get(".remove-policies-modal").within(() => { - cy.findByRole("button", { name: /delete/i }).should("exist"); + it("allows global maintainer to delete a host", () => { + cy.getAttached(".host-details__action-button-container") + .contains("button", /delete/i) + .click(); + cy.getAttached(".host-details__modal").within(() => { + cy.findByText(/delete host/i).should("exist"); + cy.contains("button", /delete/i).should("exist"); + cy.getAttached(".modal__ex").click(); + }); + }); + }); + describe("Query pages", () => { + beforeEach(() => cy.visit("/queries/manage")); + it("allows global maintainer to select teams targets for query", () => { + cy.getAttached("tbody").within(() => { + cy.getAttached("tr") + .first() + .within(() => { + cy.getAttached(".fleet-checkbox__input").check({ force: true }); + }); + cy.findAllByText(/detect presence/i).click(); + }); + + cy.getAttached(".query-form__button-wrap").within(() => { + cy.findByRole("button", { name: /run/i }).click(); + }); + cy.contains("h3", /teams/i).should("exist"); + cy.contains(".selector-name", /apples/i).should("exist"); + }); + }); + describe("Manage policies page", () => { + beforeEach(() => cy.visit("/policies/manage")); + it("allows global maintainer to click 'Manage automations' button", () => { + cy.getAttached(".button-wrap") + .findByRole("button", { name: /manage automations/i }) + .click(); cy.findByRole("button", { name: /cancel/i }).click(); }); - cy.findByText(/filevault enabled/i).click(); - cy.getAttached(".policy-form__button-wrap--new-policy").within(() => { - cy.findByRole("button", { name: /run/i }).should("exist"); - cy.findByRole("button", { name: /save/i }).should("exist"); + it("allows global maintainer to add a new policy", () => { + cy.getAttached(".button-wrap") + .findByRole("button", { name: /add a polic/i }) + .click(); + // Add a default policy + cy.findByText(/gatekeeper enabled/i).click(); + cy.getAttached(".policy-form__button-wrap--new-policy").within(() => { + cy.findByRole("button", { name: /run/i }).should("exist"); + cy.findByRole("button", { name: /save policy/i }).click(); + }); + cy.findByRole("button", { name: /^Save$/ }).click(); + cy.findByText(/policy created/i).should("exist"); }); - // On the Packs pages (manage, new, and edit), they should… - // On the Schedule pages (manage, new, and edit), they should… - // ^^General maintainer functionality for packs page is being tested in free/maintainer.spec.ts - - // On the Profile page, they should… - // See Global in the Team section and Maintainer in the Role section - cy.visit("/profile"); - - cy.getAttached(".user-settings__additional").within(() => { - cy.findByText(/team/i) - .next() - .contains(/global/i); - cy.findByText("Role") - .next() - .contains(/maintainer/i); + it("allows global maintainer to delete a team policy", () => { + cy.visit("/policies/manage"); + cy.getAttached(".Select-control").within(() => { + cy.findByText(/all teams/i).click(); + }); + cy.getAttached(".Select-menu") + .contains(/apples/i) + .click(); + cy.getAttached("tbody").within(() => { + cy.getAttached("tr") + .first() + .within(() => { + cy.getAttached(".fleet-checkbox__input").check({ + force: true, + }); + }); + }); + cy.findByRole("button", { name: /delete/i }).click(); + cy.getAttached(".remove-policies-modal").within(() => { + cy.findByRole("button", { name: /delete/i }).should("exist"); + cy.findByRole("button", { name: /cancel/i }).click(); + }); + }); + it("allows global maintainer to edit a team policy", () => { + cy.visit("policies/manage"); + cy.findByText(/all teams/i).click(); + cy.findByText(/apples/i).click(); + cy.getAttached("tbody").within(() => { + cy.getAttached("tr") + .first() + .within(() => { + cy.getAttached(".fleet-checkbox__input").check({ + force: true, + }); + }); + }); + cy.findByText(/filevault enabled/i).click(); + cy.getAttached(".policy-form__button-wrap").within(() => { + cy.findByRole("button", { name: /run/i }).should("exist"); + cy.findByRole("button", { name: /save/i }).should("exist"); + }); }); }); - } -); + describe("User profile page", () => { + it("renders elements according to role-based access controls", () => { + cy.visit("/profile"); + cy.getAttached(".user-settings__additional").within(() => { + cy.findByText(/team/i) + .next() + .contains(/global/i); + cy.findByText("Role") + .next() + .contains(/maintainer/i); + }); + }); + }); + }); +});