8000 Reset group tree pagination when search changes by FayezBast · Pull Request #55559 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
8000
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions js/apps/admin-ui/src/groups/components/GroupTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,12 @@ export const GroupTree = ({
}}
inputGroupName="searchForGroups"
inputGroupPlaceholder={t("searchForGroups")}
inputGroupOnEnter={setSearch}
inputGroupOnEnter={(value) => {
if (value !== search) {
setFirst(0);
setSearch(value);
}
}}
toolbarItem={
<InputGroup className="pf-v5-u-pt-sm">
<InputGroupItem>
Expand All @@ -391,7 +396,12 @@ export const GroupTree = ({
data-testid="exact-search"
name="exact"
isChecked={exact}
value) => setExact(value)}
value) => {
if (search) {
setFirst(0);
}
setExact(value);
}}
className="pf-v5-u-mr-xs"
/>
</InputGroupItem>
Expand Down
57 changes: 57 additions & 0 deletions js/apps/admin-ui/test/groups/list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,60 @@ test.describe.serial("Search group under current group", () => {
await assertAxeViolations(page);
});
});

test("Restarts group tree pagination when the search changes", async ({
page,
}) => {
const groupName = "paginated-group";
const groups = [
{ name: groupName },
...Array.from({ length: 20 }, (_, index) => ({
name: `${groupName}-${index}`,
})),
];
await using testBed = await createTestBed({ groups });
await login(page);
await goToRealm(page, testBed.realm);
await goToGroups(page);

const tree = page.getByRole("tree");
const firstGroup = tree.getByText(groupName, { exact: true });
const searchGroup = page.getByTestId("searchForGroups");
const search = searchGroup.getByPlaceholder("Search group");
const toolbar = page
.getByTestId("table-toolbar")
.filter({ has: searchGroup });
const nextPage = toolbar.getByLabel("Go to next page");
const previousPage = toolbar.getByLabel("Go to previous page");

await expect(firstGroup).toBeVisible();
await nextPage.click();
await expect(firstGroup).toBeHidden();

await search.fill(`${groupName}-19`);
await search.press("Enter");
await expect(
tree.getByText(`${groupName}-19`, { exact: true }),
).toBeVisible();

await search.fill(groupName);
await search.press("Enter");
await expect(firstGroup).toBeVisible();
await nextPage.click();
await expect(firstGroup).toBeHidden();

await search.press("Enter");
await expect(previousPage).toBeEnabled();

await searchGroup.getByRole("button", { name: "Reset", exact: true }).click();
await expect(firstGroup).toBeVisible();

await search.fill(groupName);
await search.press("Enter");
await nextPage.click();
await expect(firstGroup).toBeHidden();

await toolbar.getByTestId("exact-search").check();
await expect(firstGroup).toBeVisible();
await expect(tree.getByRole("treeitem")).toHaveCount(1);
});
0