From e21e238a68c835c590465ff9dcbff0f5397f2d5e Mon Sep 17 00:00:00 2001 From: minnakt Date: Tue, 13 Feb 2024 16:28:19 -0500 Subject: [PATCH] Update command --- .../integration/distroSettings/permissions.ts | 11 ++++++++++- cypress/integration/nav_bar.ts | 16 ++++++++-------- cypress/support/commands.ts | 4 ++-- cypress/support/e2e.ts | 5 +++-- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/cypress/integration/distroSettings/permissions.ts b/cypress/integration/distroSettings/permissions.ts index acaf7b2054..6313c11cd2 100644 --- a/cypress/integration/distroSettings/permissions.ts +++ b/cypress/integration/distroSettings/permissions.ts @@ -1,15 +1,22 @@ describe("distro permissions", () => { beforeEach(() => { cy.logout(); - cy.login({ isAdmin: false }); }); it("hides the new distro button when a user cannot create distros", () => { + cy.login({ username: "privileged" }); 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", () => { + cy.login({ username: "regular" }); cy.visit("/distro/rhel71-power8-large/settings/general"); cy.dataCy("delete-distro-button").should( "have.attr", @@ -19,6 +26,7 @@ describe("distro permissions", () => { }); it("disables fields when user lacks edit permissions", () => { + cy.login({ username: "regular" }); cy.visit("/distro/rhel71-power8-large/settings/general"); cy.dataCy("distro-settings-page").within(() => { cy.get('input[type="checkbox"]').should( @@ -31,6 +39,7 @@ describe("distro permissions", () => { }); it("enables fields if user has edit permissions for a particular distro", () => { + cy.login({ username: "regular" }); cy.visit("/distro/localhost/settings/general"); cy.dataCy("distro-settings-page").within(() => { cy.get('input[type="checkbox"]').should( diff --git a/cypress/integration/nav_bar.ts b/cypress/integration/nav_bar.ts index c0e2239111..5834132daf 100644 --- a/cypress/integration/nav_bar.ts +++ b/cypress/integration/nav_bar.ts @@ -108,14 +108,6 @@ describe("Nav Bar", () => { }); describe("Admin settings", () => { - it("Should not show Admin button to non-admins", () => { - cy.logout(); - cy.login({ isAdmin: false }); - cy.visit(SPRUCE_URLS.version); - cy.dataCy("user-dropdown-link").click(); - cy.dataCy("admin-link").should("not.exist"); - }); - it("Should show Admin button to admins", () => { cy.visit(SPRUCE_URLS.version); cy.dataCy("user-dropdown-link").click(); @@ -123,5 +115,13 @@ describe("Nav Bar", () => { .should("be.visible") .should("have.attr", "href", LEGACY_URLS.admin); }); + + it("Should not show Admin button to non-admins", () => { + cy.logout(); + cy.login({ username: "regular" }); + 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 c10db0f2e1..70cfafeaeb 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -52,11 +52,11 @@ Cypress.Commands.add("getInputByLabel", (label: string | RegExp) => { }); /* login */ -Cypress.Commands.add("login", ({ isAdmin = true }) => { +Cypress.Commands.add("login", ({ username = "admin" }) => { cy.getCookie("mci-token").then((c) => { if (!c) { cy.request("POST", `${EVG_BASE_URL}/login`, { - username: isAdmin ? "admin" : "basic", + username, password: "password", }); } diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts index bde376cad9..fb86213906 100644 --- a/cypress/support/e2e.ts +++ b/cypress/support/e2e.ts @@ -87,9 +87,10 @@ declare global { selectLGOption(label: string, option: string | RegExp): void; /** * Custom command to navigate to login page and login. + * @param username The username of the account to log in to. * @example cy.login() */ - login({ isAdmin }: { isAdmin: boolean }): void; + login({ username }: { username: string }): void; /** * Custom command to log out of the application. * @example cy.logout() @@ -147,7 +148,7 @@ before(() => { (() => { let mutationDispatched: boolean; beforeEach(() => { - cy.login({ isAdmin: true }); + cy.login({ username: "admin" }); cy.setCookie(bannerCookie, "true"); cy.setCookie(CY_DISABLE_COMMITS_WELCOME_MODAL, "true"); cy.setCookie(CY_DISABLE_NEW_USER_WELCOME_MODAL, "true");