forked from AkkomaGang/admin-fe
Add test for actor type filter
This commit is contained in:
parent
5dc68eed02
commit
697138d38b
2 changed files with 38 additions and 7 deletions
|
@ -31,6 +31,10 @@ const filterUsers = (str) => {
|
||||||
return applyFilters([], filters, users)
|
return applyFilters([], filters, users)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const filterUsersByActorType = filters => {
|
||||||
|
return users.filter(user => filters.includes(user.actor_type))
|
||||||
|
}
|
||||||
|
|
||||||
export async function fetchUser(id, authHost, token) {
|
export async function fetchUser(id, authHost, token) {
|
||||||
return Promise.resolve({ data: userProfile })
|
return Promise.resolve({ data: userProfile })
|
||||||
}
|
}
|
||||||
|
@ -39,11 +43,13 @@ export async function fetchUserCredentials(nickname, authHost, token) {
|
||||||
return Promise.resolve({ data: {}})
|
return Promise.resolve({ data: {}})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchUsers(filters, authHost, token, page = 1) {
|
export async function fetchUsers(filters, actorTypeFilters, authHost, token, page = 1) {
|
||||||
const filteredUsers = filterUsers(filters)
|
const filteredUsers = filterUsers(filters)
|
||||||
|
const filteredByActorTypeUsers = filterUsersByActorType(actorTypeFilters)
|
||||||
|
const response = actorTypeFilters.length === 0 ? filteredUsers : filteredByActorTypeUsers
|
||||||
return Promise.resolve({ data: {
|
return Promise.resolve({ data: {
|
||||||
users: filteredUsers,
|
users: response,
|
||||||
count: filteredUsers.length,
|
count: response.length,
|
||||||
page_size: 50
|
page_size: 50
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
|
@ -60,12 +66,13 @@ export async function getPasswordResetToken(nickname, authHost, token) {
|
||||||
return Promise.resolve({ data: { token: 'g05lxnBJQnL', link: 'http://url/api/pleroma/password_reset/g05lxnBJQnL' }})
|
return Promise.resolve({ data: { token: 'g05lxnBJQnL', link: 'http://url/api/pleroma/password_reset/g05lxnBJQnL' }})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function searchUsers(query, filters, authHost, token, page = 1) {
|
export async function searchUsers(query, filters, actorTypeFilters, authHost, token, page = 1) {
|
||||||
const filteredUsers = filterUsers(filters)
|
const filteredUsers = filterUsers(filters)
|
||||||
const response = filteredUsers.filter(user => user.nickname === query)
|
const filteredByActorTypeUsers = filterUsersByActorType(actorTypeFilters)
|
||||||
|
const response = actorTypeFilters.length === 0 ? filteredUsers : filteredByActorTypeUsers
|
||||||
return Promise.resolve({ data: {
|
return Promise.resolve({ data: {
|
||||||
users: response,
|
users: response.filter(user => user.nickname === query),
|
||||||
count: response.length,
|
count: response.filter(user => user.nickname === query).length,
|
||||||
page_size: 50
|
page_size: 50
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,4 +91,28 @@ describe('Filters users', () => {
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('applies actor types filters', async (done) => {
|
||||||
|
expect(store.state.users.totalUsersCount).toEqual(4)
|
||||||
|
|
||||||
|
store.dispatch('ToggleActorTypeFilter', ["Person"])
|
||||||
|
await flushPromises()
|
||||||
|
expect(store.state.users.totalUsersCount).toEqual(3)
|
||||||
|
expect(store.state.users.fetchedUsers[0].nickname).toEqual('allis')
|
||||||
|
|
||||||
|
store.dispatch('ToggleActorTypeFilter', ["Service"])
|
||||||
|
await flushPromises()
|
||||||
|
expect(store.state.users.totalUsersCount).toEqual(1)
|
||||||
|
expect(store.state.users.fetchedUsers[0].nickname).toEqual('sally')
|
||||||
|
|
||||||
|
store.dispatch('ToggleActorTypeFilter', ["Person", "Service"])
|
||||||
|
await flushPromises()
|
||||||
|
expect(store.state.users.totalUsersCount).toEqual(4)
|
||||||
|
|
||||||
|
store.dispatch('ToggleActorTypeFilter', ["Application"])
|
||||||
|
await flushPromises()
|
||||||
|
expect(store.state.users.totalUsersCount).toEqual(0)
|
||||||
|
|
||||||
|
done()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue