Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Update command
Browse files Browse the repository at this point in the history
  • Loading branch information
minnakt committed Feb 13, 2024
1 parent e4fcd3c commit e21e238
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
11 changes: 10 additions & 1 deletion cypress/integration/distroSettings/permissions.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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(
Expand All @@ -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(
Expand Down
16 changes: 8 additions & 8 deletions cypress/integration/nav_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,20 @@ 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();
cy.dataCy("admin-link")
.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");
});
});
});
4 changes: 2 additions & 2 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
}
Expand Down
5 changes: 3 additions & 2 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit e21e238

Please sign in to comment.