From e4fcd3c1d568874b29873e4057c4059730bad90e Mon Sep 17 00:00:00 2001 From: minnakt Date: Tue, 13 Feb 2024 14:24:40 -0500 Subject: [PATCH] DEVPROD-808: Use basic user to test non-admin views --- .../integration/distroSettings/permissions.ts | 85 +++++-------------- cypress/integration/nav_bar.ts | 15 +--- cypress/support/commands.ts | 16 ++-- cypress/support/e2e.ts | 4 +- 4 files changed, 34 insertions(+), 86 deletions(-) diff --git a/cypress/integration/distroSettings/permissions.ts b/cypress/integration/distroSettings/permissions.ts index 0a6ac234e4..acaf7b2054 100644 --- a/cypress/integration/distroSettings/permissions.ts +++ b/cypress/integration/distroSettings/permissions.ts @@ -1,83 +1,44 @@ -describe("with various permission levels", () => { +describe("distro permissions", () => { + beforeEach(() => { + cy.logout(); + cy.login({ isAdmin: false }); + }); + it("hides the new distro button when a user cannot create distros", () => { - const userData = { - data: { - user: { - userId: "admin", - permissions: { - canCreateDistro: false, - distroPermissions: { - admin: true, - edit: true, - }, - }, - }, - }, - }; - cy.overwriteGQL("UserDistroSettingsPermissions", userData); cy.visit("/distro/rhel71-power8-large/settings/general"); cy.dataCy("new-distro-button").should("not.exist"); - cy.dataCy("delete-distro-button").should( - "not.have.attr", - "aria-disabled", - "true", - ); - cy.get("textarea").should("not.be.disabled"); }); it("disables the delete button when user lacks admin permissions", () => { - const userData = { - data: { - user: { - userId: "admin", - permissions: { - canCreateDistro: false, - distroPermissions: { - admin: false, - edit: true, - }, - }, - }, - }, - }; - cy.overwriteGQL("UserDistroSettingsPermissions", userData); cy.visit("/distro/rhel71-power8-large/settings/general"); - cy.dataCy("new-distro-button").should("not.exist"); cy.dataCy("delete-distro-button").should( "have.attr", "aria-disabled", "true", ); - cy.get("textarea").should("not.be.disabled"); }); it("disables fields when user lacks edit permissions", () => { - const userData = { - data: { - user: { - userId: "admin", - permissions: { - canCreateDistro: false, - distroPermissions: { - admin: false, - edit: false, - }, - }, - }, - }, - }; - cy.overwriteGQL("UserDistroSettingsPermissions", userData); cy.visit("/distro/rhel71-power8-large/settings/general"); - cy.dataCy("new-distro-button").should("not.exist"); - cy.dataCy("delete-distro-button").should( - "have.attr", - "aria-disabled", - "true", - ); cy.dataCy("distro-settings-page").within(() => { - cy.get("input").should("be.disabled"); + cy.get('input[type="checkbox"]').should( + "have.attr", + "aria-disabled", + "true", + ); cy.get("textarea").should("be.disabled"); - cy.get("button").should("have.attr", "aria-disabled", "true"); + }); + }); + + it("enables fields if user has edit permissions for a particular distro", () => { + cy.visit("/distro/localhost/settings/general"); + cy.dataCy("distro-settings-page").within(() => { + cy.get('input[type="checkbox"]').should( + "have.attr", + "aria-disabled", + "false", + ); + cy.get("textarea").should("not.be.disabled"); }); }); }); diff --git a/cypress/integration/nav_bar.ts b/cypress/integration/nav_bar.ts index c017528b22..c0e2239111 100644 --- a/cypress/integration/nav_bar.ts +++ b/cypress/integration/nav_bar.ts @@ -109,19 +109,8 @@ describe("Nav Bar", () => { describe("Admin settings", () => { it("Should not show Admin button to non-admins", () => { - const userData = { - data: { - user: { - userId: "admin", - displayName: "Evergreen Admin", - emailAddress: "admin@evergreen.com", - permissions: { - canEditAdminSettings: false, - }, - }, - }, - }; - cy.overwriteGQL("User", userData); + cy.logout(); + cy.login({ isAdmin: false }); cy.visit(SPRUCE_URLS.version); cy.dataCy("user-dropdown-link").click(); cy.dataCy("admin-link").should("not.exist"); diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 7fc0e052f3..c10db0f2e1 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -1,11 +1,6 @@ import { EVG_BASE_URL, GQL_URL } from "../constants"; import { hasOperationName } from "../utils/graphql-test-utils"; -const user = { - username: "admin", - password: "password", -}; - type cyGetOptions = Parameters[1]; /* closeBanner */ @@ -38,8 +33,8 @@ Cypress.Commands.add( * `enterLoginCredentials` is a custom command to enter login credentials */ Cypress.Commands.add("enterLoginCredentials", () => { - cy.get("input[name=username]").type(user.username); - cy.get("input[name=password]").type(user.password); + cy.get("input[name=username]").type("admin"); + cy.get("input[name=password]").type("password"); cy.get("button[id=login-submit]").click(); }); @@ -57,10 +52,13 @@ Cypress.Commands.add("getInputByLabel", (label: string | RegExp) => { }); /* login */ -Cypress.Commands.add("login", () => { +Cypress.Commands.add("login", ({ isAdmin = true }) => { cy.getCookie("mci-token").then((c) => { if (!c) { - cy.request("POST", `${EVG_BASE_URL}/login`, { ...user }); + cy.request("POST", `${EVG_BASE_URL}/login`, { + username: isAdmin ? "admin" : "basic", + password: "password", + }); } }); }); diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts index 27b2d69c15..bde376cad9 100644 --- a/cypress/support/e2e.ts +++ b/cypress/support/e2e.ts @@ -89,7 +89,7 @@ declare global { * Custom command to navigate to login page and login. * @example cy.login() */ - login(): void; + login({ isAdmin }: { isAdmin: boolean }): void; /** * Custom command to log out of the application. * @example cy.logout() @@ -147,7 +147,7 @@ before(() => { (() => { let mutationDispatched: boolean; beforeEach(() => { - cy.login(); + cy.login({ isAdmin: true }); cy.setCookie(bannerCookie, "true"); cy.setCookie(CY_DISABLE_COMMITS_WELCOME_MODAL, "true"); cy.setCookie(CY_DISABLE_NEW_USER_WELCOME_MODAL, "true");