github.com/minio/console@v1.4.1/web-app/tests/permissions-1/groups.ts (about) 1 // This file is part of MinIO Console Server 2 // Copyright (c) 2022 MinIO, Inc. 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Affero General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 import * as roles from "../utils/roles"; 18 import * as elements from "../utils/elements"; 19 import * as constants from "../utils/constants"; 20 import * as functions from "../utils/functions"; 21 import { Selector } from "testcafe"; 22 import { groupsElement, identityElement } from "../utils/elements-menu"; 23 import { IAM_PAGES } from "../../src/common/SecureComponent/permissions"; 24 25 const groupsListItemFor = (modifier: string) => { 26 return Selector(".ReactVirtualized__Table__rowColumn").withText( 27 `${constants.TEST_GROUP_NAME}-${modifier}`, 28 ); 29 }; 30 31 const appBaseUrl = "http://localhost:9090"; 32 let groupsPageUrl = `${appBaseUrl}${IAM_PAGES.GROUPS}`; 33 let groupsAddPageUrl = `${appBaseUrl}${IAM_PAGES.GROUPS_ADD}`; 34 const createGroup = async (t: TestController, modifier: string) => { 35 await t 36 .useRole(roles.groups) 37 .navigateTo(groupsAddPageUrl) 38 .typeText( 39 elements.groupNameInput, 40 `${constants.TEST_GROUP_NAME}-${modifier}`, 41 ) 42 .typeText(elements.filterUserInput, constants.TEST_USER_NAME) 43 .click(elements.groupUserCheckbox) 44 .click(elements.saveButton); 45 }; 46 47 fixture("For user with Groups permissions") 48 .page(appBaseUrl) 49 .beforeEach(async (t) => { 50 await t.useRole(roles.groups); 51 }); 52 53 test("Create Group button exists", async (t) => { 54 const createGroupButtonExists = elements.createGroupButton.exists; 55 await t 56 .navigateTo(groupsPageUrl) 57 .expect(createGroupButtonExists) 58 .ok() 59 .wait(2000); 60 }); 61 62 test("Groups sidebar item exists", async (t) => { 63 await t 64 .expect(identityElement.exists) 65 .ok() 66 .click(identityElement) 67 .expect(groupsElement.exists) 68 .ok() 69 .wait(2000); 70 }); 71 72 test("Create Group button is clickable", async (t) => { 73 await t 74 .navigateTo(groupsPageUrl) 75 .click(elements.createGroupButton) 76 .expect(true) 77 .ok() 78 .wait(2000); 79 }); 80 81 test("Group Name input exists in the Create Group page", async (t) => { 82 await t 83 .navigateTo(groupsPageUrl) 84 .click(elements.createGroupButton) 85 .expect(elements.groupNameInput.exists) 86 .ok() 87 .wait(2000); 88 }); 89 90 test("Users table exists in the Create Groups page", async (t) => { 91 const createGroupUserTableExists = elements.table.exists; 92 await t 93 .navigateTo(groupsPageUrl) 94 .click(elements.createGroupButton) 95 .expect(createGroupUserTableExists) 96 .ok() 97 .wait(2000); 98 }); 99 100 test.before(async (t) => { 101 // A user must be created as we need to choose a user from the dropdown 102 await functions.createUser(t); 103 })("Create Group page can be submitted after inputs are entered", async (t) => { 104 // We need to log back in after we use the admin account to create bucket, 105 // using the specific role we use in this module 106 await t 107 .useRole(roles.groups) 108 .navigateTo(groupsAddPageUrl) 109 .typeText(elements.groupNameInput, constants.TEST_GROUP_NAME) 110 .typeText(elements.filterUserInput, constants.TEST_USER_NAME) 111 .click(elements.groupUserCheckbox) 112 .click(elements.saveButton) 113 .wait(2000); 114 }); 115 116 test.before(async (t) => { 117 // A user must be created as we need to choose a user from the dropdown 118 await functions.createUser(t); 119 await createGroup(t, "groups-table"); 120 })("Groups table exists", async (t) => { 121 await t 122 .navigateTo(groupsPageUrl) 123 .expect(elements.table.exists) 124 .ok() 125 .wait(2000); 126 }); 127 128 test.before(async (t) => { 129 // A user must be created as we need to choose a user from the dropdown 130 await functions.createUser(t); 131 await createGroup(t, "disable-enable"); 132 })("Created Group can be disabled and enabled back", async (t) => { 133 await t 134 .navigateTo(groupsPageUrl) 135 .click(groupsListItemFor("disable-enable")) 136 .click(elements.switchInput) 137 .expect(elements.groupStatusText.innerText) 138 .eql("Disabled") 139 .click(elements.switchInput) 140 .expect(elements.groupStatusText.innerText) 141 .eql("Enabled"); 142 });