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

Commit

Permalink
DEVPROD-808: Use basic user to test non-admin views
Browse files Browse the repository at this point in the history
  • Loading branch information
minnakt committed Feb 13, 2024
1 parent 6c571cf commit e4fcd3c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 86 deletions.
85 changes: 23 additions & 62 deletions cypress/integration/distroSettings/permissions.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});
});
15 changes: 2 additions & 13 deletions cypress/integration/nav_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]",
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");
Expand Down
16 changes: 7 additions & 9 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -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<typeof cy.get>[1];

/* closeBanner */
Expand Down Expand Up @@ -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();
});

Expand All @@ -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",
});
}
});
});
Expand Down
4 changes: 2 additions & 2 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit e4fcd3c

Please sign in to comment.