Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the default role mapping filter to clients #29405

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -178,7 +178,7 @@
listingPage
.searchItem(clientScopeName, false)
.clickRowSelectItem(itemName, $assignedType);
cy.wait(2000);

Check warning on line 181 in js/apps/admin-ui/cypress/e2e/client_scopes_test.spec.ts

View workflow job for this annotation

GitHub Actions / Admin UI

Do not wait for arbitrary time periods
listingPage.searchItem(itemName, false).itemExist($assignedType);
});
});
Expand Down Expand Up @@ -342,8 +342,14 @@

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 @@
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 @@
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 @@ -219,7 +219,7 @@
cy.intercept(`/admin/realms/${realmName}/client-scopes`).as("load");
commonPage.tableToolbarUtils().clickSearchButton();
cy.wait("@load");
cy.wait(1000);

Check warning on line 222 in js/apps/admin-ui/cypress/e2e/clients_test.spec.ts

View workflow job for this annotation

GitHub Actions / Admin UI

Do not wait for arbitrary time periods
commonPage.tableToolbarUtils().checkActionItemIsEnabled("Remove", false);
commonPage.tableToolbarUtils().searchItem(clientScopeName, false);
commonPage
Expand All @@ -229,7 +229,7 @@
cy.intercept(`/admin/realms/${realmName}/client-scopes`).as("load");
commonPage.tableToolbarUtils().clickSearchButton();
cy.wait("@load");
cy.wait(1000);

Check warning on line 232 in js/apps/admin-ui/cypress/e2e/clients_test.spec.ts

View workflow job for this annotation

GitHub Actions / Admin UI

Do not wait for arbitrary time periods
commonPage.tableToolbarUtils().clickActionItem("Remove");
commonPage.masthead().checkNotificationMessage(msgScopeMappingRemoved);
commonPage.tableToolbarUtils().searchItem(clientScopeName, false);
Expand Down Expand Up @@ -574,7 +574,7 @@
{ action: "drag-drop" },
);

cy.wait(1000);

Check warning on line 577 in js/apps/admin-ui/cypress/e2e/clients_test.spec.ts

View workflow job for this annotation

GitHub Actions / Admin UI

Do not wait for arbitrary time periods
//cy.findByTestId("realm-file").contains('"clientId": "identical"')
cy.findByTestId("clientId").click();
cy.findByText("Save").click();
Expand Down Expand Up @@ -932,6 +932,7 @@
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 @@
serviceAccountTab
.goToServiceAccountTab()
.assignRole(false)
.changeRoleTypeFilter(createRealmRoleType)
.selectRow(createRealmRoleName, true)
.assign();
commonPage.masthead().checkNotificationMessage("Role mapping updated");
Expand All @@ -1029,6 +1031,7 @@
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 @@ -263,7 +263,7 @@
});

// https://github.com/keycloak/keycloak-admin-ui/issues/2726
it.skip("Fail to create group with duplicated name", () => {

Check warning on line 266 in js/apps/admin-ui/cypress/e2e/group_test.spec.ts

View workflow job for this annotation

GitHub Actions / Admin UI

Unexpected skipped mocha test
childGroupsTab
.createGroup(predefinedGroups[2], false)
.assertNotificationCouldNotCreateGroupWithDuplicatedName(
Expand Down Expand Up @@ -466,8 +466,10 @@

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
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