Skip to content

Commit

Permalink
Change the default role mapping filter to clients
Browse files Browse the repository at this point in the history
Client roles are more common that realm roles, so we should start the
user off looking at a more useful set of options.

Signed-off-by: James Hewitt <james.hewitt@uk.ibm.com>
  • Loading branch information
Jamstah committed May 9, 2024
1 parent 2055cf6 commit 163ff52
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 19 deletions.
16 changes: 14 additions & 2 deletions js/apps/admin-ui/cypress/e2e/client_scopes_test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,14 @@ describe("Client Scopes test", () => {

it("Assign and unassign role", () => {
const role = "admin";
const roleType = "roles";
listingPage.searchItem(scopeName, false).goToItemDetails(scopeName);
scopeTab.goToScopeTab().assignRole().selectRow(role).assign();
scopeTab
.goToScopeTab()
.assignRole()
.changeRoleTypeFilter(roleType)
.selectRow(role)
.assign();
masthead.checkNotificationMessage("Role mapping updated");
scopeTab.checkRoles([role]);
scopeTab.hideInheritedRoles().selectRow(role).unAssign();
Expand Down Expand Up @@ -446,6 +452,7 @@ describe("Client Scopes test", () => {
const predefinedMapper = "Allowed Web Origins";
const scopeTab = new RoleMappingTab("client-scope");
const role = "admin";
const roleType = "roles";

listingPage.goToCreateItem();
createClientScopePage.fillClientScopeData(scopeName).save();
Expand Down Expand Up @@ -475,7 +482,12 @@ describe("Client Scopes test", () => {
cy.checkA11y();
cy.findByTestId("cancel").click();

scopeTab.goToScopeTab().assignRole().selectRow(role).assign();
scopeTab
.goToScopeTab()
.assignRole()
.changeRoleTypeFilter(roleType)
.selectRow(role)
.assign();
cy.checkA11y();
});
});
Expand Down
3 changes: 3 additions & 0 deletions js/apps/admin-ui/cypress/e2e/clients_test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ describe("Clients test", () => {
const serviceAccountTab = new RoleMappingTab("user");
const serviceAccountName = "service-account-client";
const createRealmRoleName = `create-realm-${uuid()}`;
const createRealmRoleType = `roles`;

before(async () => {
await adminClient.inRealm(realmName, () =>
Expand Down Expand Up @@ -1008,6 +1009,7 @@ describe("Clients test", () => {
serviceAccountTab
.goToServiceAccountTab()
.assignRole(false)
.changeRoleTypeFilter(createRealmRoleType)
.selectRow(createRealmRoleName, true)
.assign();
commonPage.masthead().checkNotificationMessage("Role mapping updated");
Expand All @@ -1029,6 +1031,7 @@ describe("Clients test", () => {
commonPage.sidebar().waitForPageLoad();

serviceAccountTab
.changeRoleTypeFilter("roles")
.selectRow("offline_access", true)
.selectRow(createRealmRoleName, true)
.assign();
Expand Down
6 changes: 4 additions & 2 deletions js/apps/admin-ui/cypress/e2e/group_test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,10 @@ describe("Group test", () => {

it("Assign roles from empty state", () => {
roleMappingTab.assignRole();
groupDetailPage.createRoleMapping();
roleMappingTab.assign();
roleMappingTab
.changeRoleTypeFilter("roles")
.selectRow("default-roles-")
.assign();
});

it("Show and search roles", () => {
Expand Down
3 changes: 2 additions & 1 deletion js/apps/admin-ui/cypress/e2e/realm_user_registration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ describe("Realm settings - User registration tab", () => {

it("Add admin role", () => {
const role = "admin";
const roleType = "roles";
userRegistration.addRole();
sidebarPage.waitForPageLoad();
userRegistration.selectRow(role).assign();
userRegistration.changeRoleTypeFilter(roleType).selectRow(role).assign();
masthead.checkNotificationMessage("Associated roles have been added");
listingPage.searchItem(role, false).itemExist(role);

Expand Down
3 changes: 2 additions & 1 deletion js/apps/admin-ui/cypress/e2e/users_test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ describe("User creation", () => {
describe("Accessibility tests for users", () => {
const a11yUser = "a11y-user";
const role = "admin";
const roleType = "roles";
const roleMappingTab = new RoleMappingTab("");

beforeEach(() => {
Expand Down Expand Up @@ -552,7 +553,7 @@ describe("User creation", () => {
roleMappingTab.goToRoleMappingTab();
cy.findByTestId("assignRole").click();
cy.checkA11y();
roleMappingTab.selectRow(role).assign();
roleMappingTab.changeRoleTypeFilter(roleType).selectRow(role).assign();
});

it("Check a11y violations on user groups tab", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default class RoleMappingTab {
#assignedRolesTable = "assigned-roles";
#namesColumn = 'td[data-label="Name"]:visible';
#roleMappingTab = "role-mapping-tab";
#filterTypeDropdown = "filter-type-dropdown";

constructor(type: string) {
this.#type = type;
Expand Down Expand Up @@ -60,6 +61,16 @@ export default class RoleMappingTab {
return this;
}

changeRoleTypeFilter(filter: string) {
// Invert the filter because the testid of the DropdownItem is the current filter
const option = filter == "roles" ? "clients" : "roles";

cy.findByTestId(this.#filterTypeDropdown).click();
cy.findByTestId(option).click();

return this;
}

selectRow(name: string, modal = false) {
cy.get(modal ? ".pf-v5-c-modal-box " : "" + this.#namesColumn)
.contains(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ export default class GroupDetailPage extends GroupPage {
return this;
}

createRoleMapping() {
listingPage.clickItemCheckbox("default-roles-");
}

checkDefaultRole() {
listingPage.itemExist("default-roles");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class AssociatedRolesPage {
#addAssociatedRolesModalButton = "assign";
#compositeRoleBadge = "composite-role-badge";
#filterTypeDropdown = "filter-type-dropdown";
#filterTypeDropdownItem = "roles";
#filterTypeDropdownItem = "clients";
#usersPage = "users-page";
#removeRolesButton = "unAssignRole";
#addRoleTable = '[aria-label="Roles"] td[data-label="Name"]';
Expand All @@ -15,6 +15,10 @@ export default class AssociatedRolesPage {

cy.findByTestId(this.#addRolesDropdownItem).click();

cy.findByTestId(this.#filterTypeDropdown).click();

cy.findByTestId(this.#filterTypeDropdownItem).click();

cy.get(this.#addRoleTable)
.contains(roleName)
.parent()
Expand All @@ -36,7 +40,7 @@ export default class AssociatedRolesPage {
addAssociatedRoleFromSearchBar(roleName: string, isClientRole?: boolean) {
cy.findByTestId(this.#addRoleToolbarButton).click({ force: true });

if (isClientRole) {
if (!isClientRole) {
cy.findByTestId(this.#filterTypeDropdown).click();
cy.findByTestId(this.#filterTypeDropdownItem).click();
}
Expand All @@ -59,10 +63,6 @@ export default class AssociatedRolesPage {
addAssociatedClientRole(roleName: string) {
cy.findByTestId(this.#addRoleToolbarButton).click();

cy.findByTestId(this.#filterTypeDropdown).click();

cy.findByTestId(this.#filterTypeDropdownItem).click();

cy.findByTestId(".pf-v5-c-spinner__tail-ball").should("not.exist");

cy.get(this.#addRoleTable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default class UserRegistration {
#addDefaultGroupBtn = "no-default-groups-empty-action";
#namesColumn = 'tbody td[data-label="Name"]:visible';
#addBtn = "assign";
#filterTypeDropdown = "filter-type-dropdown";

goToTab() {
cy.findByTestId(this.#userRegistrationTab).click({ force: true });
Expand All @@ -26,6 +27,16 @@ export default class UserRegistration {
return this;
}

changeRoleTypeFilter(filter: string) {
// Invert the filter because the testid is the current selection
const option = filter == "roles" ? "clients" : "roles";

cy.findByTestId(this.#filterTypeDropdown).click();
cy.findByTestId(option).click();

return this;
}

selectRow(name: string) {
cy.get(this.#namesColumn)
.contains(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ export const AddRoleMappingModal = ({

const [searchToggle, setSearchToggle] = useState(false);

const [filterType, setFilterType] = useState<FilterType>(
canViewRealmRoles ? "roles" : "clients",
);
const [filterType, setFilterType] = useState<FilterType>("clients");
const [selectedRows, setSelectedRows] = useState<Row[]>([]);
const [key, setKey] = useState(0);
const refresh = () => setKey(key + 1);
Expand Down

0 comments on commit 163ff52

Please sign in to comment.