Filter dedicated client scopes when searching (#28433)

Closes #28431

Signed-off-by: Jon Koops <jonkoops@gmail.com>
This commit is contained in:
Jon Koops 2024-04-04 13:28:09 +02:00 committed by GitHub
parent 71eacdc1c5
commit 7cbe609571
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 22 additions and 18 deletions

View file

@ -102,7 +102,7 @@ describe("Clients test", () => {
commonPage commonPage
.tableUtils() .tableUtils()
.checkRowItemExists(clientScopeName + 0) .checkRowItemExists(clientScopeName + 0)
.checkRowItemsEqualTo(2); .checkRowItemsEqualTo(1);
}); });
it("Should search non-existent client scope by name", () => { it("Should search non-existent client scope by name", () => {
@ -187,7 +187,7 @@ describe("Clients test", () => {
commonPage.modalUtils().confirmModal(); commonPage.modalUtils().confirmModal();
commonPage.masthead().checkNotificationMessage(msgScopeMappingRemoved); commonPage.masthead().checkNotificationMessage(msgScopeMappingRemoved);
commonPage.tableToolbarUtils().searchItem(itemName, false); commonPage.tableToolbarUtils().searchItem(itemName, false);
commonPage.tableUtils().checkRowItemExists(itemName, false); listingPage.assertNoResults();
}); });
it("Should remove multiple client scopes from search bar", () => { it("Should remove multiple client scopes from search bar", () => {

View file

@ -151,7 +151,7 @@ describe("Realm roles test", () => {
it("Should search non-existent associated role by name", () => { it("Should search non-existent associated role by name", () => {
const itemName = "non-existent-associated-role"; const itemName = "non-existent-associated-role";
listingPage.searchItem(itemName, false); listingPage.searchItem(itemName, false);
cy.findByTestId(listingPage.emptyState).should("exist"); listingPage.assertNoResults();
}); });
it("Should hide inherited roles test", () => { it("Should hide inherited roles test", () => {

View file

@ -264,7 +264,7 @@ describe("User Fed LDAP mapper tests", () => {
providersPage.clickExistingCard(ldapName); providersPage.clickExistingCard(ldapName);
providersPage.goToMappers(); providersPage.goToMappers();
listingPage.searchItem(nonexistingSearchTerm, false); listingPage.searchItem(nonexistingSearchTerm, false);
cy.findByTestId(listingPage.emptyState).should("exist"); listingPage.assertNoResults();
}); });
// *** test cleanup *** // *** test cleanup ***

View file

@ -127,7 +127,7 @@ describe("User creation", () => {
it("Search non-existing user test", () => { it("Search non-existing user test", () => {
listingPage.searchItem("user_DNE"); listingPage.searchItem("user_DNE");
cy.findByTestId(listingPage.emptyState).should("exist"); listingPage.assertNoResults();
}); });
it("User details test", () => { it("User details test", () => {

View file

@ -34,7 +34,7 @@ export default class ListingPage extends CommonElements {
#itemsRows = "table:visible"; #itemsRows = "table:visible";
#deleteUserButton = "delete-user-btn"; #deleteUserButton = "delete-user-btn";
#emptyListImg = '[role="tabpanel"]:not([hidden]) [data-testid="empty-state"]'; #emptyListImg = '[role="tabpanel"]:not([hidden]) [data-testid="empty-state"]';
public emptyState = "empty-state"; #emptyState = "empty-state";
#itemRowDrpDwn = ".pf-c-dropdown__toggle"; #itemRowDrpDwn = ".pf-c-dropdown__toggle";
#itemRowSelect = ".pf-c-select__toggle:nth-child(1)"; #itemRowSelect = ".pf-c-select__toggle:nth-child(1)";
#itemRowSelectItem = ".pf-c-select__menu-item"; #itemRowSelectItem = ".pf-c-select__menu-item";
@ -401,6 +401,10 @@ export default class ListingPage extends CommonElements {
return this; return this;
} }
assertNoResults() {
cy.findByTestId(this.#emptyState).should("exist");
}
assertDefaultResource() { assertDefaultResource() {
this.assertResource("Default Resource"); this.assertResource("Default Resource");
return this; return this;

View file

@ -5,14 +5,12 @@ export default class TablePage extends CommonElements {
#tableRowItemChckBx: string; #tableRowItemChckBx: string;
#tableHeaderRowItem: string; #tableHeaderRowItem: string;
#tableInModal: boolean; #tableInModal: boolean;
static tableSelector = "table[aria-label]"; static tableSelector = ".pf-c-table";
constructor(parentElement?: string) { constructor(parentElement?: string) {
super(parentElement ?? TablePage.tableSelector + ":visible"); super(parentElement ?? TablePage.tableSelector + ":visible");
this.#tableRowItem = this.#tableRowItem = this.parentSelector + "tbody tr";
this.parentSelector + "tbody tr[data-ouia-component-type]"; this.#tableHeaderRowItem = this.parentSelector + "thead tr";
this.#tableHeaderRowItem =
this.parentSelector + "thead tr[data-ouia-component-type]";
this.#tableRowItemChckBx = ".pf-c-table__check"; this.#tableRowItemChckBx = ".pf-c-table__check";
this.#tableInModal = false; this.#tableInModal = false;
} }

View file

@ -165,21 +165,19 @@ export const ClientScopes = ({
return row; return row;
}); });
const rows = [...optional, ...defaultScopes]; let rows = [...optional, ...defaultScopes];
const names = rows.map((row) => row.name); const names = rows.map((row) => row.name);
setRest( setRest(
clientScopes clientScopes
.filter((scope) => !names.includes(scope.name)) .filter((scope) => !names.includes(scope.name))
.filter((scope) => scope.protocol === protocol), .filter((scope) => scope.protocol === protocol),
); );
const filter = rows = localeSort(rows, mapByKey("name"));
searchType === "name" ? nameFilter(search) : typeFilter(searchTypeType);
const firstNum = Number(first);
const page = localeSort(rows.filter(filter), mapByKey("name"));
if (isViewer) { if (isViewer) {
page.unshift({ rows.unshift({
id: DEDICATED_ROW, id: DEDICATED_ROW,
name: t("dedicatedScopeName", { clientName }), name: t("dedicatedScopeName", { clientName }),
type: AllClientScopes.none, type: AllClientScopes.none,
@ -187,7 +185,11 @@ export const ClientScopes = ({
}); });
} }
return page.slice(firstNum, firstNum + Number(max)); const filter =
searchType === "name" ? nameFilter(search) : typeFilter(searchTypeType);
const firstNum = Number(first);
return rows.filter(filter).slice(firstNum, firstNum + Number(max));
}; };
const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({ const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({