forked from AkkomaGang/admin-fe
Merge branch 'api/deactivated' into 'develop'
AdminAPI: change from deactivated to is_active See merge request pleroma/admin-fe!193
This commit is contained in:
commit
8a39058467
12 changed files with 164 additions and 180 deletions
|
@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
|
||||
- **Breaking**: AdminAPI changed User field `confirmation_pending` to `is_confirmed`
|
||||
- **Breaking**: AdminAPI changed User field `approval_pending` to `is_approved`
|
||||
- **Breaking**: AdminAPI changed User field `deactivated` to `is_active`
|
||||
- Hide Tag actions on Users tab if MRF TagPolicy is disabled. Add ability to enable TagPolicy from Moderation menu
|
||||
- Move `:restrict_unauthenticated` settings from Authentication tab to Instance tab
|
||||
- Replace regular inputs with textareas for setting welcome messages in the Settings section
|
||||
|
|
|
@ -43,7 +43,7 @@ export function getUserInfo(token, authHost) {
|
|||
'statuses_count': 0,
|
||||
'cover_photo': '',
|
||||
'hide_follows': false,
|
||||
'pleroma': { 'is_confirmed': true, 'deactivated': false, 'tags': ['force_nsfw'], 'is_admin': true },
|
||||
'pleroma': { 'is_confirmed': true, 'is_active': true, 'tags': ['force_nsfw'], 'is_admin': true },
|
||||
'profile_image_url_original': '',
|
||||
'created_at': 'Fri Mar 01 15:15:19 +0000 2019',
|
||||
'fields': [],
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import userChats from './chat'
|
||||
|
||||
export let users = [
|
||||
{ active: true, is_confirmed: true, is_approved: true, deactivated: false, id: '2', nickname: 'allis', local: true, external: false, roles: { admin: true, moderator: false }, tags: [], actor_type: 'Person' },
|
||||
{ active: true, is_confirmed: true, is_approved: true, deactivated: false, id: '10', nickname: 'bob', local: true, external: false, roles: { admin: false, moderator: false }, tags: ['mrf_tag:sandbox'], actor_type: 'Person' },
|
||||
{ active: true, is_confirmed: true, is_approved: false, deactivated: false, id: '567', nickname: 'ded', local: false, external: true, roles: { admin: false, moderator: false }, tags: [], actor_type: 'Person' },
|
||||
{ active: false, is_confirmed: true, is_approved: true, deactivated: true, id: 'abc', nickname: 'john', local: true, external: false, roles: { admin: false, moderator: false }, tags: ['mrf_tag:media-strip'], actor_type: 'Person' },
|
||||
{ active: true, is_confirmed: true, is_approved: false, deactivated: false, id: '100', nickname: 'sally', local: true, external: false, roles: { admin: false, moderator: false }, tags: [], actor_type: 'Service' },
|
||||
{ active: true, is_confirmed: true, is_approved: false, deactivated: false, id: '123', nickname: 'bot', local: true, external: false, roles: { admin: false, moderator: false }, tags: [], actor_type: 'Application' }
|
||||
{ is_confirmed: true, is_approved: true, is_active: true, id: '2', nickname: 'allis', local: true, external: false, roles: { admin: true, moderator: false }, tags: [], actor_type: 'Person' },
|
||||
{ is_confirmed: true, is_approved: true, is_active: true, id: '10', nickname: 'bob', local: true, external: false, roles: { admin: false, moderator: false }, tags: ['mrf_tag:sandbox'], actor_type: 'Person' },
|
||||
{ is_confirmed: true, is_approved: false, is_active: true, id: '567', nickname: 'ded', local: false, external: true, roles: { admin: false, moderator: false }, tags: [], actor_type: 'Person' },
|
||||
{ is_confirmed: true, is_approved: true, is_active: false, id: 'abc', nickname: 'john', local: true, external: false, roles: { admin: false, moderator: false }, tags: ['mrf_tag:media-strip'], actor_type: 'Person' },
|
||||
{ is_confirmed: true, is_approved: false, is_active: true, id: '100', nickname: 'sally', local: true, external: false, roles: { admin: false, moderator: false }, tags: [], actor_type: 'Service' },
|
||||
{ is_confirmed: true, is_approved: false, is_active: true, id: '123', nickname: 'bot', local: true, external: false, roles: { admin: false, moderator: false }, tags: [], actor_type: 'Application' }
|
||||
]
|
||||
|
||||
const userProfile = { avatar: 'avatar.jpg', nickname: 'allis', id: '2', tags: [], roles: { admin: true, moderator: false }, local: true, external: false }
|
||||
|
@ -17,26 +17,6 @@ const userStatuses = [
|
|||
{ account: { id: '9n1bySks25olxWrku0', nickname: 'dolin' }, content: 'what is yout favorite pizza?', id: '9jop82OBXeFPYulVjM', created_at: '2020-05-22T17:34:34.000Z', visibility: 'public' }
|
||||
]
|
||||
|
||||
const filterUsers = (str) => {
|
||||
const filters = str.split(',').filter(item => item.length > 0)
|
||||
if (filters.length === 0) {
|
||||
return users
|
||||
}
|
||||
const applyFilters = (acc, filters, users) => {
|
||||
if (filters.length === 0) {
|
||||
return acc
|
||||
}
|
||||
const filteredUsers = users.filter(user => user[filters[0]])
|
||||
const newAcc = [...filteredUsers]
|
||||
return applyFilters(newAcc, filters.slice(1), filteredUsers)
|
||||
}
|
||||
return applyFilters([], filters, users)
|
||||
}
|
||||
|
||||
const filterUsersByActorType = filters => {
|
||||
return users.filter(user => filters.includes(user.actor_type))
|
||||
}
|
||||
|
||||
export async function fetchUser(id, authHost, token) {
|
||||
return Promise.resolve({ data: userProfile })
|
||||
}
|
||||
|
@ -46,12 +26,9 @@ export async function fetchUserCredentials(nickname, authHost, token) {
|
|||
}
|
||||
|
||||
export async function fetchUsers(filters, actorTypeFilters, authHost, token, page = 1) {
|
||||
const filteredUsers = filterUsers(filters)
|
||||
const filteredByActorTypeUsers = filterUsersByActorType(actorTypeFilters)
|
||||
const response = actorTypeFilters.length === 0 ? filteredUsers : filteredByActorTypeUsers
|
||||
return Promise.resolve({ data: {
|
||||
users: response,
|
||||
count: response.length,
|
||||
users,
|
||||
count: users.length,
|
||||
page_size: 50
|
||||
}})
|
||||
}
|
||||
|
@ -69,12 +46,10 @@ export async function getPasswordResetToken(nickname, authHost, token) {
|
|||
}
|
||||
|
||||
export async function searchUsers(query, filters, actorTypeFilters, authHost, token, page = 1) {
|
||||
const filteredUsers = filterUsers(filters)
|
||||
const filteredByActorTypeUsers = filterUsersByActorType(actorTypeFilters)
|
||||
const response = actorTypeFilters.length === 0 ? filteredUsers : filteredByActorTypeUsers
|
||||
const response = users.filter(user => user.nickname === query)
|
||||
return Promise.resolve({ data: {
|
||||
users: response.filter(user => user.nickname === query),
|
||||
count: response.filter(user => user.nickname === query).length,
|
||||
users: response,
|
||||
count: response.length,
|
||||
page_size: 50
|
||||
}})
|
||||
}
|
||||
|
@ -82,7 +57,7 @@ export async function searchUsers(query, filters, actorTypeFilters, authHost, to
|
|||
export async function activateUsers(nicknames, authHost, token) {
|
||||
const response = nicknames.map(nickname => {
|
||||
const currentUser = users.find(user => user.nickname === nickname)
|
||||
return { ...currentUser, deactivated: false }
|
||||
return { ...currentUser, is_active: true }
|
||||
})
|
||||
return Promise.resolve({ data: response })
|
||||
}
|
||||
|
@ -96,7 +71,7 @@ export async function addRight(nicknames, right, authHost, token) {
|
|||
export async function deactivateUsers(nicknames, authHost, token) {
|
||||
const response = nicknames.map(nickname => {
|
||||
const currentUser = users.find(user => user.nickname === nickname)
|
||||
return { ...currentUser, deactivated: true }
|
||||
return { ...currentUser, is_active: false }
|
||||
})
|
||||
return Promise.resolve({ data: response })
|
||||
}
|
||||
|
@ -130,7 +105,7 @@ export async function untagUser(nickname, tag, authHost, token) {
|
|||
}
|
||||
|
||||
export async function createNewAccount(nickname, email, password, authHost, token) {
|
||||
const newUser = { active: true, deactivated: false, id: '15', nickname, local: true, external: false, roles: { admin: false, moderator: false }, tags: [] }
|
||||
const newUser = { active: true, is_active: true, id: '15', nickname, local: true, external: false, roles: { admin: false, moderator: false }, tags: [] }
|
||||
users = [...users, newUser]
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ const reports = {
|
|||
return
|
||||
} finally {
|
||||
const updatedReports = state.fetchedReports.map(report => {
|
||||
const updatedAccount = { ...user, deactivated: false }
|
||||
const updatedAccount = { ...user, is_active: true }
|
||||
return report.id === reportId ? { ...report, account: updatedAccount } : report
|
||||
})
|
||||
commit('SET_REPORTS', updatedReports)
|
||||
|
@ -69,7 +69,7 @@ const reports = {
|
|||
} catch (_e) {
|
||||
return
|
||||
} finally {
|
||||
const updatedReport = { ...state.singleReport, account: { ...user, deactivated: false }}
|
||||
const updatedReport = { ...state.singleReport, account: { ...user, is_active: true }}
|
||||
commit('SET_SINGLE_REPORT', updatedReport)
|
||||
}
|
||||
dispatch('SuccessMessage')
|
||||
|
@ -124,7 +124,7 @@ const reports = {
|
|||
return
|
||||
} finally {
|
||||
const updatedReports = state.fetchedReports.map(report => {
|
||||
const updatedAccount = { ...user, deactivated: true }
|
||||
const updatedAccount = { ...user, is_active: false }
|
||||
return report.id === reportId ? { ...report, account: updatedAccount } : report
|
||||
})
|
||||
commit('SET_REPORTS', updatedReports)
|
||||
|
@ -137,7 +137,7 @@ const reports = {
|
|||
} catch (_e) {
|
||||
return
|
||||
} finally {
|
||||
const updatedReport = { ...state.singleReport, account: { ...user, deactivated: true }}
|
||||
const updatedReport = { ...state.singleReport, account: { ...user, is_active: false }}
|
||||
commit('SET_SINGLE_REPORT', updatedReport)
|
||||
}
|
||||
dispatch('SuccessMessage')
|
||||
|
@ -149,7 +149,7 @@ const reports = {
|
|||
return
|
||||
} finally {
|
||||
const updatedReports = state.fetchedReports.map(report => {
|
||||
const updatedAccount = { ...user, deactivated: true }
|
||||
const updatedAccount = { ...user, is_active: false }
|
||||
return report.id === reportId ? { ...report, account: updatedAccount } : report
|
||||
})
|
||||
commit('SET_REPORTS', updatedReports)
|
||||
|
|
|
@ -88,7 +88,7 @@ const users = {
|
|||
actions: {
|
||||
async ActivateUsers({ dispatch, getters }, { users, _userId }) {
|
||||
const updatedUsers = users.map(user => {
|
||||
return { ...user, deactivated: false }
|
||||
return { ...user, is_active: true }
|
||||
})
|
||||
const nicknames = users.map(user => user.nickname)
|
||||
const callApiFn = async() => await activateUsers(nicknames, getters.authHost, getters.token)
|
||||
|
@ -168,7 +168,7 @@ const users = {
|
|||
},
|
||||
async DeactivateUsers({ dispatch, getters }, { users, _userId }) {
|
||||
const updatedUsers = users.map(user => {
|
||||
return { ...user, deactivated: true }
|
||||
return { ...user, is_active: false }
|
||||
})
|
||||
const nicknames = users.map(user => user.nickname)
|
||||
const callApiFn = async() => await deactivateUsers(nicknames, getters.authHost, getters.token)
|
||||
|
@ -200,7 +200,7 @@ const users = {
|
|||
return
|
||||
}
|
||||
const updatedUsers = users.map(user => {
|
||||
return { ...user, deactivated: true }
|
||||
return { ...user, is_active: false }
|
||||
})
|
||||
commit('SWAP_USERS', updatedUsers)
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<el-dropdown-item
|
||||
v-if="showDeactivatedButton(account)"
|
||||
@click.native="handleDeactivation(account)">
|
||||
{{ account.deactivated ? $t('users.activateAccount') : $t('users.deactivateAccount') }}
|
||||
{{ !account.is_active ? $t('users.activateAccount') : $t('users.deactivateAccount') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
v-if="showDeactivatedButton(account.id)"
|
||||
|
@ -120,11 +120,11 @@ export default {
|
|||
},
|
||||
handleDeactivation(user) {
|
||||
if (this.renderedFrom === 'showPage') {
|
||||
user.deactivated
|
||||
!user.is_active
|
||||
? this.$store.dispatch('ActivateUserFromReportShow', user)
|
||||
: this.$store.dispatch('DeactivateUserFromReportShow', user)
|
||||
} else if (this.renderedFrom === 'reportsPage') {
|
||||
user.deactivated
|
||||
!user.is_active
|
||||
? this.$store.dispatch('ActivateUserFromReports', { user, reportId: this.reportId })
|
||||
: this.$store.dispatch('DeactivateUserFromReports', { user, reportId: this.reportId })
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
v-if="showDeactivatedButton(user.id) && page !== 'statusPage'"
|
||||
:divided="showAdminAction(user)"
|
||||
@click.native="toggleActivation(user)">
|
||||
{{ user.deactivated ? $t('users.activateAccount') : $t('users.deactivateAccount') }}
|
||||
{{ !user.is_active ? $t('users.activateAccount') : $t('users.deactivateAccount') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
v-if="showDeactivatedButton(user.id) && page !== 'statusPage'"
|
||||
|
@ -261,7 +261,7 @@ export default {
|
|||
return this.$store.state.user.id !== id
|
||||
},
|
||||
toggleActivation(user) {
|
||||
user.deactivated
|
||||
!user.is_active
|
||||
? this.$store.dispatch('ActivateUsers', { users: [user], _userId: user.id })
|
||||
: this.$store.dispatch('DeactivateUsers', { users: [user], _userId: user.id })
|
||||
},
|
||||
|
|
|
@ -197,13 +197,13 @@ export default {
|
|||
applyAction(filtered, deleteRightFn)
|
||||
},
|
||||
activate: () => {
|
||||
const filtered = this.selectedUsers.filter(user => user.nickname && user.deactivated && this.$store.state.user.id !== user.id)
|
||||
const filtered = this.selectedUsers.filter(user => user.nickname && !user.is_active && this.$store.state.user.id !== user.id)
|
||||
const activateUsersFn = async(users) => await this.$store.dispatch('ActivateUsers', { users })
|
||||
|
||||
applyAction(filtered, activateUsersFn)
|
||||
},
|
||||
deactivate: () => {
|
||||
const filtered = this.selectedUsers.filter(user => user.nickname && !user.deactivated && this.$store.state.user.id !== user.id)
|
||||
const filtered = this.selectedUsers.filter(user => user.nickname && user.is_active && this.$store.state.user.id !== user.id)
|
||||
const deactivateUsersFn = async(users) => await this.$store.dispatch('DeactivateUsers', { users })
|
||||
|
||||
applyAction(filtered, deactivateUsersFn)
|
||||
|
|
|
@ -56,11 +56,11 @@
|
|||
</el-table-column>
|
||||
<el-table-column :min-width="width" :label="$t('users.status')">
|
||||
<template slot-scope="scope">
|
||||
<el-tag v-if="!scope.row.deactivated && scope.row.is_approved" type="success">
|
||||
<el-tag v-if="scope.row.is_active && scope.row.is_approved" type="success">
|
||||
<span v-if="isDesktop">{{ $t('users.active') }}</span>
|
||||
<i v-else class="el-icon-circle-check"/>
|
||||
</el-tag>
|
||||
<el-tag v-if="scope.row.deactivated && scope.row.is_approved" type="danger">
|
||||
<el-tag v-if="!scope.row.is_active && scope.row.is_approved" type="danger">
|
||||
<span v-if="isDesktop">{{ $t('users.deactivated') }}</span>
|
||||
<i v-else class="el-icon-circle-close"/>
|
||||
</el-tag>
|
||||
|
|
|
@ -90,8 +90,8 @@
|
|||
<td>{{ $t('userProfile.status') }}</td>
|
||||
<td>
|
||||
<el-tag v-if="!user.is_approved" type="info">{{ $t('userProfile.pending') }}</el-tag>
|
||||
<el-tag v-if="!user.deactivated && user.is_approved" type="success">{{ $t('userProfile.active') }}</el-tag>
|
||||
<el-tag v-if="user.deactivated" type="danger">{{ $t('userProfile.deactivated') }}</el-tag>
|
||||
<el-tag v-if="user.is_active && user.is_approved" type="success">{{ $t('userProfile.active') }}</el-tag>
|
||||
<el-tag v-if="!user.is_active" type="danger">{{ $t('userProfile.deactivated') }}</el-tag>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
@ -154,11 +154,11 @@ describe('Users actions', () => {
|
|||
await flushPromises()
|
||||
|
||||
const user = store.state.users.fetchedUsers[1]
|
||||
expect(user.deactivated).toBe(false)
|
||||
expect(user.is_active).toBe(true)
|
||||
wrapper.find(htmlElement(2, 4)).trigger('click')
|
||||
|
||||
const updatedUser = store.state.users.fetchedUsers[1]
|
||||
expect(updatedUser.deactivated).toBe(true)
|
||||
expect(updatedUser.is_active).toBe(false)
|
||||
done()
|
||||
})
|
||||
|
||||
|
@ -172,13 +172,13 @@ describe('Users actions', () => {
|
|||
}
|
||||
})
|
||||
await flushPromises()
|
||||
expect(store.state.users.fetchedUsers[1].deactivated).toBe(false)
|
||||
expect(store.state.users.fetchedUsers[1].is_active).toBe(true)
|
||||
|
||||
wrapper.find(htmlElement(2, 5)).trigger('click')
|
||||
store.dispatch('DeleteUsers', { users: [{ active: true, deactivated: false, id: '10', nickname: 'bob', local: false, external: true, roles: { admin: false, moderator: false }, tags: ['mrf_tag:sandbox'] }] })
|
||||
store.dispatch('DeleteUsers', { users: [{ active: true, is_active: true, id: '10', nickname: 'bob', local: false, external: true, roles: { admin: false, moderator: false }, tags: ['mrf_tag:sandbox'] }] })
|
||||
|
||||
await flushPromises()
|
||||
expect(store.state.users.fetchedUsers[1].deactivated).toBe(true)
|
||||
expect(store.state.users.fetchedUsers[1].is_active).toBe(false)
|
||||
done()
|
||||
})
|
||||
|
||||
|
|
|
@ -2,9 +2,12 @@ import Vuex from 'vuex'
|
|||
import { mount, createLocalVue, config } from '@vue/test-utils'
|
||||
import Element from 'element-ui'
|
||||
import Filters from '@/views/users/components/UsersFilter'
|
||||
import { storeConfig } from './store.conf'
|
||||
import { cloneDeep } from 'lodash'
|
||||
import flushPromises from 'flush-promises'
|
||||
import app from '@/store/modules/app'
|
||||
import settings from '@/store/modules/settings'
|
||||
import user from '@/store/modules/user'
|
||||
import userProfile from '@/store/modules/userProfile'
|
||||
import users from '@/store/modules/users'
|
||||
|
||||
config.mocks["$t"] = () => {}
|
||||
config.stubs.transition = false
|
||||
|
@ -20,138 +23,143 @@ jest.mock('@/api/users')
|
|||
|
||||
describe('Filters users', () => {
|
||||
let store
|
||||
let actions
|
||||
|
||||
beforeEach(async() => {
|
||||
store = new Vuex.Store(cloneDeep(storeConfig))
|
||||
actions = { ...users.actions, ToggleUsersFilter: jest.fn(), ToggleActorTypeFilter: jest.fn() }
|
||||
store = new Vuex.Store(({
|
||||
modules: {
|
||||
app,
|
||||
settings,
|
||||
user,
|
||||
userProfile,
|
||||
users: { ...users, actions }
|
||||
},
|
||||
getters: {}
|
||||
}))
|
||||
store.dispatch('FetchUsers', { page: 1 })
|
||||
await flushPromises()
|
||||
})
|
||||
|
||||
it('shows local users when "Local" filter is applied', async (done) => {
|
||||
it('enables local and active filters when component is mounted, toggles local filter on button click', async (done) => {
|
||||
const wrapper = mount(Filters, {
|
||||
store,
|
||||
localVue
|
||||
})
|
||||
expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(1, expect.anything(), ['local', 'active'], undefined)
|
||||
|
||||
const filter = wrapper.find(`li.el-select-dropdown__item:nth-child(${1})`)
|
||||
filter.trigger('click')
|
||||
|
||||
expect(actions.ToggleUsersFilter).toHaveBeenCalled()
|
||||
expect(actions.ToggleActorTypeFilter).toHaveBeenCalled()
|
||||
expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(2, expect.anything(), ['active'], undefined)
|
||||
expect(actions.ToggleActorTypeFilter).toHaveBeenCalledWith(expect.anything(), [], undefined)
|
||||
await flushPromises()
|
||||
done()
|
||||
})
|
||||
|
||||
it('applies three filters', async (done) => {
|
||||
const wrapper = mount(Filters, {
|
||||
store,
|
||||
localVue
|
||||
})
|
||||
expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(1, expect.anything(), ['local', 'active'], undefined)
|
||||
|
||||
const filter1 = wrapper.find(`.el-select-group__wrap:nth-child(${1}) li.el-select-dropdown__item:nth-child(${2})`)
|
||||
filter1.trigger('click')
|
||||
expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(2, expect.anything(), ['external', 'active'], undefined)
|
||||
expect(actions.ToggleActorTypeFilter).toHaveBeenCalledWith(expect.anything(), [], undefined)
|
||||
await flushPromises()
|
||||
|
||||
const filter2 = wrapper.find(`.el-select-group__wrap:nth-child(${2}) li.el-select-dropdown__item:nth-child(${3})`)
|
||||
filter2.trigger('click')
|
||||
expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(3, expect.anything(), ['external', 'need_approval'], undefined)
|
||||
expect(actions.ToggleActorTypeFilter).toHaveBeenCalledWith(expect.anything(), [], undefined)
|
||||
await flushPromises()
|
||||
|
||||
const filter3 = wrapper.find(`.el-select-group__wrap:nth-child(${3}) li.el-select-dropdown__item:nth-child(${1})`)
|
||||
filter3.trigger('click')
|
||||
expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(4, expect.anything(), ['external', 'need_approval'], undefined)
|
||||
expect(actions.ToggleActorTypeFilter).toHaveBeenCalledWith(expect.anything(), ['Person'], undefined)
|
||||
await flushPromises()
|
||||
done()
|
||||
})
|
||||
|
||||
it('removes all filters', async (done) => {
|
||||
const wrapper = mount(Filters, {
|
||||
store,
|
||||
localVue
|
||||
})
|
||||
expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(1, expect.anything(), ['local', 'active'], undefined)
|
||||
|
||||
const filter1 = wrapper.find(`.el-select-group__wrap:nth-child(${1}) li.el-select-dropdown__item:nth-child(${1})`)
|
||||
filter1.trigger('click')
|
||||
expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(2, expect.anything(), ['active'], undefined)
|
||||
expect(actions.ToggleActorTypeFilter).toHaveBeenCalledWith(expect.anything(), [], undefined)
|
||||
await flushPromises()
|
||||
|
||||
const filter2 = wrapper.find(`.el-select-group__wrap:nth-child(${2}) li.el-select-dropdown__item:nth-child(${1})`)
|
||||
filter2.trigger('click')
|
||||
expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(3, expect.anything(), [], undefined)
|
||||
expect(actions.ToggleActorTypeFilter).toHaveBeenCalledWith(expect.anything(), [], undefined)
|
||||
await flushPromises()
|
||||
|
||||
done()
|
||||
})
|
||||
|
||||
it('applies actor type filters', async (done) => {
|
||||
const wrapper = mount(Filters, {
|
||||
store,
|
||||
localVue
|
||||
})
|
||||
|
||||
const filter1 = wrapper.find(`.el-select-group__wrap:nth-child(${3}) li.el-select-dropdown__item:nth-child(${1})`)
|
||||
filter1.trigger('click')
|
||||
expect(actions.ToggleActorTypeFilter).toHaveBeenNthCalledWith(1, expect.anything(), ['Person'], undefined)
|
||||
await flushPromises()
|
||||
|
||||
const filter2 = wrapper.find(`.el-select-group__wrap:nth-child(${3}) li.el-select-dropdown__item:nth-child(${2})`)
|
||||
filter2.trigger('click')
|
||||
expect(actions.ToggleActorTypeFilter).toHaveBeenNthCalledWith(2, expect.anything(), ['Person', 'Service'], undefined)
|
||||
await flushPromises()
|
||||
|
||||
const filter3 = wrapper.find(`.el-select-group__wrap:nth-child(${3}) li.el-select-dropdown__item:nth-child(${3})`)
|
||||
filter3.trigger('click')
|
||||
expect(actions.ToggleActorTypeFilter).toHaveBeenNthCalledWith(3, expect.anything(), ['Person', 'Service', 'Application'], undefined)
|
||||
await flushPromises()
|
||||
|
||||
done()
|
||||
})
|
||||
|
||||
it('applies opposite filters', async (done) => {
|
||||
const wrapper = mount(Filters, {
|
||||
store,
|
||||
localVue
|
||||
})
|
||||
|
||||
expect(store.state.users.totalUsersCount).toEqual(6)
|
||||
|
||||
const filter = wrapper.find(`li.el-select-dropdown__item:nth-child(${1})`)
|
||||
filter.trigger('click')
|
||||
expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(1, expect.anything(), ['local', 'active'], undefined)
|
||||
|
||||
const filter1 = wrapper.find(`.el-select-group__wrap:nth-child(${2}) li.el-select-dropdown__item:nth-child(${2})`)
|
||||
filter1.trigger('click')
|
||||
expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(2, expect.anything(), ['local', 'deactivated'], undefined)
|
||||
await flushPromises()
|
||||
expect(store.state.users.totalUsersCount).toEqual(5)
|
||||
|
||||
done()
|
||||
})
|
||||
|
||||
it('shows users with applied filter and search query', async (done) => {
|
||||
expect(store.state.users.totalUsersCount).toEqual(6)
|
||||
|
||||
store.dispatch('ToggleUsersFilter', ['active'])
|
||||
const filter2 = wrapper.find(`.el-select-group__wrap:nth-child(${2}) li.el-select-dropdown__item:nth-child(${3})`)
|
||||
filter2.trigger('click')
|
||||
expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(3, expect.anything(), ['local', 'need_approval'], undefined)
|
||||
await flushPromises()
|
||||
store.dispatch('SearchUsers', { query: 'john', page: 1 })
|
||||
|
||||
const filter3 = wrapper.find(`.el-select-group__wrap:nth-child(${2}) li.el-select-dropdown__item:nth-child(${4})`)
|
||||
filter3.trigger('click')
|
||||
expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(4, expect.anything(), ['local', 'unconfirmed'], undefined)
|
||||
await flushPromises()
|
||||
expect(store.state.users.totalUsersCount).toEqual(0)
|
||||
|
||||
store.dispatch('SearchUsers', { query: 'allis', page: 1 })
|
||||
const filter4 = wrapper.find(`.el-select-group__wrap:nth-child(${1}) li.el-select-dropdown__item:nth-child(${2})`)
|
||||
filter4.trigger('click')
|
||||
expect(actions.ToggleUsersFilter).toHaveBeenNthCalledWith(5, expect.anything(), ['external', 'unconfirmed'], undefined)
|
||||
await flushPromises()
|
||||
expect(store.state.users.totalUsersCount).toEqual(1)
|
||||
|
||||
store.dispatch('SearchUsers', { query: '', page: 1 })
|
||||
await flushPromises()
|
||||
expect(store.state.users.totalUsersCount).toEqual(5)
|
||||
|
||||
done()
|
||||
})
|
||||
|
||||
it('applies two filters', async (done) => {
|
||||
expect(store.state.users.totalUsersCount).toEqual(6)
|
||||
|
||||
store.dispatch('ToggleUsersFilter', ['active', 'local'])
|
||||
await flushPromises()
|
||||
expect(store.state.users.totalUsersCount).toEqual(4)
|
||||
expect(store.state.users.fetchedUsers[0].nickname).toEqual('allis')
|
||||
|
||||
store.dispatch('ToggleUsersFilter', ['deactivated', 'external'])
|
||||
await flushPromises()
|
||||
expect(store.state.users.totalUsersCount).toEqual(0)
|
||||
|
||||
done()
|
||||
})
|
||||
|
||||
it('shows all users after removing filters', async (done) => {
|
||||
expect(store.state.users.totalUsersCount).toEqual(6)
|
||||
|
||||
store.dispatch('ToggleUsersFilter', ['deactivated'])
|
||||
await flushPromises()
|
||||
expect(store.state.users.totalUsersCount).toEqual(1)
|
||||
|
||||
store.dispatch('ToggleUsersFilter', [])
|
||||
await flushPromises()
|
||||
expect(store.state.users.totalUsersCount).toEqual(6)
|
||||
|
||||
done()
|
||||
})
|
||||
|
||||
it('applies actor type filter', async (done) => {
|
||||
expect(store.state.users.totalUsersCount).toEqual(6)
|
||||
|
||||
store.dispatch('ToggleActorTypeFilter', ["Person"])
|
||||
await flushPromises()
|
||||
expect(store.state.users.totalUsersCount).toEqual(4)
|
||||
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')
|
||||
|
||||
done()
|
||||
})
|
||||
|
||||
it('shows users with applied actor type filter and search query', async (done) => {
|
||||
expect(store.state.users.totalUsersCount).toEqual(6)
|
||||
|
||||
store.dispatch('ToggleActorTypeFilter', ["Person"])
|
||||
await flushPromises()
|
||||
store.dispatch('SearchUsers', { query: 'john', page: 1 })
|
||||
await flushPromises()
|
||||
expect(store.state.users.totalUsersCount).toEqual(1)
|
||||
|
||||
store.dispatch('SearchUsers', { query: 'bot', page: 1 })
|
||||
await flushPromises()
|
||||
expect(store.state.users.totalUsersCount).toEqual(0)
|
||||
|
||||
store.dispatch('SearchUsers', { query: '', page: 1 })
|
||||
await flushPromises()
|
||||
expect(store.state.users.totalUsersCount).toEqual(4)
|
||||
|
||||
done()
|
||||
})
|
||||
|
||||
it('applies two actor type filters', async (done) => {
|
||||
expect(store.state.users.totalUsersCount).toEqual(6)
|
||||
|
||||
store.dispatch('ToggleActorTypeFilter', ["Person", "Service"])
|
||||
await flushPromises()
|
||||
expect(store.state.users.totalUsersCount).toEqual(5)
|
||||
|
||||
store.dispatch('ToggleActorTypeFilter', ["Service", "Application"])
|
||||
await flushPromises()
|
||||
expect(store.state.users.totalUsersCount).toEqual(2)
|
||||
|
||||
done()
|
||||
})
|
||||
|
||||
it('shows all users after removing actor type filters', async (done) => {
|
||||
expect(store.state.users.totalUsersCount).toEqual(6)
|
||||
|
||||
store.dispatch('ToggleActorTypeFilter', ["Application"])
|
||||
await flushPromises()
|
||||
expect(store.state.users.totalUsersCount).toEqual(1)
|
||||
|
||||
store.dispatch('ToggleActorTypeFilter', [])
|
||||
await flushPromises()
|
||||
expect(store.state.users.totalUsersCount).toEqual(6)
|
||||
|
||||
done()
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue