diff --git a/packages/web-app-admin-settings/tests/unit/views/Users.spec.ts b/packages/web-app-admin-settings/tests/unit/views/Users.spec.ts
index 3dbc6716744..9fb04d68456 100644
--- a/packages/web-app-admin-settings/tests/unit/views/Users.spec.ts
+++ b/packages/web-app-admin-settings/tests/unit/views/Users.spec.ts
@@ -12,6 +12,7 @@ import {
shallowMount
} from 'web-test-helpers'
import { AxiosResponse } from 'axios'
+import { queryItemAsString } from 'web-pkg'
jest.mock('web-pkg/src/composables/appDefaults')
@@ -82,6 +83,10 @@ const getDefaultGraphMock = () => {
return graph
}
+const selectors = {
+ itemFilterGroupsStub: 'item-filter-stub[filtername="groups"]'
+}
+
describe('Users view', () => {
describe('method "createUser"', () => {
it('should hide the modal and show message on success', async () => {
@@ -325,9 +330,48 @@ describe('Users view', () => {
expect(wrapper.find('batch-actions-stub').exists()).toBeTruthy()
})
})
+
+ describe('filter', () => {
+ it('does filter users by groups when the "selectionChange"-event is triggered', async () => {
+ const graphMock = getDefaultGraphMock()
+ const { wrapper } = getMountedWrapper({ mountType: mount, graph: graphMock })
+ await wrapper.vm.loadResourcesTask.last
+ expect(graphMock.users.listUsers).toHaveBeenCalledTimes(1)
+ ;(wrapper.findComponent
(selectors.itemFilterGroupsStub).vm as any).$emit(
+ 'selectionChange',
+ [{ id: '1' }]
+ )
+ await wrapper.vm.$nextTick()
+ expect(graphMock.users.listUsers).toHaveBeenCalledTimes(2)
+ expect(graphMock.users.listUsers).toHaveBeenNthCalledWith(
+ 2,
+ 'displayName',
+ "memberOf/any(m:m/id eq '1')"
+ )
+ })
+ it('does filter initially if group ids are given via query param', async () => {
+ const groupIdsQueryParam = '1+2'
+ const graphMock = getDefaultGraphMock()
+ const { wrapper } = getMountedWrapper({
+ mountType: mount,
+ graph: graphMock,
+ queryItem: groupIdsQueryParam
+ })
+ await wrapper.vm.loadResourcesTask.last
+ expect(graphMock.users.listUsers).toHaveBeenCalledWith(
+ 'displayName',
+ "memberOf/any(m:m/id eq '1') and memberOf/any(m:m/id eq '2')"
+ )
+ })
+ })
})
-function getMountedWrapper({ mountType = shallowMount, graph = getDefaultGraphMock() } = {}) {
+function getMountedWrapper({
+ mountType = shallowMount,
+ graph = getDefaultGraphMock(),
+ queryItem = null
+} = {}) {
+ jest.mocked(queryItemAsString).mockImplementation(() => queryItem)
const mocks = {
...defaultComponentMocks()
}
@@ -351,9 +395,9 @@ function getMountedWrapper({ mountType = shallowMount, graph = getDefaultGraphMo
stubs: {
CreateUserModal: true,
AppLoadingSpinner: true,
- NoContentMessage: true,
- UsersList: true,
OcBreadcrumb: true,
+ OcTable: true,
+ ItemFilter: true,
BatchActions: true
}
}
diff --git a/packages/web-client/src/graph.ts b/packages/web-client/src/graph.ts
index 7e187a1ac46..98eec837ea6 100644
--- a/packages/web-client/src/graph.ts
+++ b/packages/web-client/src/graph.ts
@@ -50,7 +50,7 @@ export interface Graph {
changeOwnPassword: (currentPassword: string, newPassword: string) => AxiosPromise
editUser: (userId: string, user: User) => AxiosPromise
deleteUser: (userId: string) => AxiosPromise
- listUsers: (orderBy?: string) => AxiosPromise
+ listUsers: (orderBy?: string, filter?: string) => AxiosPromise
createUserAppRoleAssignment: (
userId: string,
appRoleAssignment: AppRoleAssignment
@@ -131,12 +131,12 @@ export const graph = (baseURI: string, axiosClient: AxiosInstance): Graph => {
meChangepasswordApiFactory.changeOwnPassword({ currentPassword, newPassword }),
editUser: (userId: string, user: User) => userApiFactory.updateUser(userId, user),
deleteUser: (userId: string) => userApiFactory.deleteUser(userId),
- listUsers: (orderBy?: any) =>
+ listUsers: (orderBy?: any, filter?: string) =>
usersApiFactory.listUsers(
0,
0,
'',
- '',
+ filter,
false,
new Set([orderBy]),
new Set([]),
diff --git a/packages/web-pkg/src/components/ItemFilter.vue b/packages/web-pkg/src/components/ItemFilter.vue
index cd84960a781..e93bb4c3a9b 100644
--- a/packages/web-pkg/src/components/ItemFilter.vue
+++ b/packages/web-pkg/src/components/ItemFilter.vue
@@ -1,5 +1,5 @@
-
+
+