Update tests for applying actions on multiple users
This commit is contained in:
parent
90553ba75c
commit
11255be51f
2 changed files with 222 additions and 37 deletions
|
@ -7,7 +7,7 @@
|
||||||
{{ $t('users.grantAdmin') }}
|
{{ $t('users.grantAdmin') }}
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
<el-dropdown-item
|
<el-dropdown-item
|
||||||
@click.native="revokeRightToMultipleUsers('admin')">
|
@click.native="revokeRightFromMultipleUsers('admin')">
|
||||||
{{ $t('users.revokeAdmin') }}
|
{{ $t('users.revokeAdmin') }}
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
<el-dropdown-item
|
<el-dropdown-item
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
{{ $t('users.grantModerator') }}
|
{{ $t('users.grantModerator') }}
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
<el-dropdown-item
|
<el-dropdown-item
|
||||||
@click.native="revokeRightToMultipleUsers('moderator')">
|
@click.native="revokeRightFromMultipleUsers('moderator')">
|
||||||
{{ $t('users.revokeModerator') }}
|
{{ $t('users.revokeModerator') }}
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
<el-dropdown-item
|
<el-dropdown-item
|
||||||
|
@ -149,7 +149,7 @@ export default {
|
||||||
grantRight(right)
|
grantRight(right)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
revokeRightToMultipleUsers(right) {
|
revokeRightFromMultipleUsers(right) {
|
||||||
const { revokeRight } = this.mappers()
|
const { revokeRight } = this.mappers()
|
||||||
this.confirmMessage(
|
this.confirmMessage(
|
||||||
`Are you sure you want to revoke ${right} rights from all selected users?`,
|
`Are you sure you want to revoke ${right} rights from all selected users?`,
|
||||||
|
|
|
@ -22,10 +22,9 @@ describe('Apply users actions to multiple users', () => {
|
||||||
store = new Vuex.Store(cloneDeep(storeConfig))
|
store = new Vuex.Store(cloneDeep(storeConfig))
|
||||||
store.dispatch('FetchUsers', { page: 1 })
|
store.dispatch('FetchUsers', { page: 1 })
|
||||||
await flushPromises()
|
await flushPromises()
|
||||||
global.confirm = () => true
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls function that grants admin and moderator rights to multiple users', async (done) => {
|
it('grants admin rights to multiple users', async (done) => {
|
||||||
const wrapper = mount(DropdownMenu, {
|
const wrapper = mount(DropdownMenu, {
|
||||||
store,
|
store,
|
||||||
localVue,
|
localVue,
|
||||||
|
@ -43,13 +42,26 @@ describe('Apply users actions to multiple users', () => {
|
||||||
expect(wrapper.vm.grantRightToMultipleUsers).toHaveBeenCalled()
|
expect(wrapper.vm.grantRightToMultipleUsers).toHaveBeenCalled()
|
||||||
expect(wrapper.vm.grantRightToMultipleUsers).toHaveBeenCalledWith('admin')
|
expect(wrapper.vm.grantRightToMultipleUsers).toHaveBeenCalledWith('admin')
|
||||||
|
|
||||||
wrapper.find(`.el-dropdown-menu__item:nth-child(3)`).trigger('click')
|
const grantRight = wrapper.vm.mappers().grantRight
|
||||||
expect(wrapper.vm.grantRightToMultipleUsers).toHaveBeenCalled()
|
const user1 = store.state.users.fetchedUsers[0]
|
||||||
expect(wrapper.vm.grantRightToMultipleUsers).toHaveBeenCalledWith('moderator')
|
const user2 = store.state.users.fetchedUsers[1]
|
||||||
|
const user3 = store.state.users.fetchedUsers[2]
|
||||||
|
expect(user1.roles.admin).toBe(true)
|
||||||
|
expect(user2.roles.admin).toBe(false)
|
||||||
|
expect(user3.roles.admin).toBe(false)
|
||||||
|
grantRight('admin')()
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
const updatedUser1 = store.state.users.fetchedUsers[0]
|
||||||
|
const updatedUser2 = store.state.users.fetchedUsers[1]
|
||||||
|
const updatedUser3 = store.state.users.fetchedUsers[2]
|
||||||
|
expect(updatedUser1.roles.admin).toBe(true)
|
||||||
|
expect(updatedUser2.roles.admin).toBe(false)
|
||||||
|
expect(updatedUser3.roles.admin).toBe(true)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls function that revokes admin and moderator rights to multiple users', async (done) => {
|
it('grants moderator rights to multiple users', async (done) => {
|
||||||
const wrapper = mount(DropdownMenu, {
|
const wrapper = mount(DropdownMenu, {
|
||||||
store,
|
store,
|
||||||
localVue,
|
localVue,
|
||||||
|
@ -60,20 +72,86 @@ describe('Apply users actions to multiple users', () => {
|
||||||
})
|
})
|
||||||
await flushPromises()
|
await flushPromises()
|
||||||
|
|
||||||
const revokeRightToMultipleUsersStub = jest.fn()
|
const grantRightToMultipleUsersStub = jest.fn()
|
||||||
wrapper.setMethods({ revokeRightToMultipleUsers: revokeRightToMultipleUsersStub })
|
wrapper.setMethods({ grantRightToMultipleUsers: grantRightToMultipleUsersStub })
|
||||||
|
|
||||||
wrapper.find(`.el-dropdown-menu__item:nth-child(2)`).trigger('click')
|
wrapper.find(`.el-dropdown-menu__item:nth-child(3)`).trigger('click')
|
||||||
expect(wrapper.vm.revokeRightToMultipleUsers).toHaveBeenCalled()
|
expect(wrapper.vm.grantRightToMultipleUsers).toHaveBeenCalled()
|
||||||
expect(wrapper.vm.revokeRightToMultipleUsers).toHaveBeenCalledWith('admin')
|
expect(wrapper.vm.grantRightToMultipleUsers).toHaveBeenCalledWith('moderator')
|
||||||
|
|
||||||
wrapper.find(`.el-dropdown-menu__item:nth-child(4)`).trigger('click')
|
const grantRight = wrapper.vm.mappers().grantRight
|
||||||
expect(wrapper.vm.revokeRightToMultipleUsers).toHaveBeenCalled()
|
const user1 = store.state.users.fetchedUsers[0]
|
||||||
expect(wrapper.vm.revokeRightToMultipleUsers).toHaveBeenCalledWith('moderator')
|
const user2 = store.state.users.fetchedUsers[1]
|
||||||
|
const user3 = store.state.users.fetchedUsers[2]
|
||||||
|
expect(user1.roles.moderator).toBe(false)
|
||||||
|
expect(user2.roles.moderator).toBe(false)
|
||||||
|
expect(user3.roles.moderator).toBe(false)
|
||||||
|
grantRight('moderator')()
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
const updatedUser1 = store.state.users.fetchedUsers[0]
|
||||||
|
const updatedUser2 = store.state.users.fetchedUsers[1]
|
||||||
|
const updatedUser3 = store.state.users.fetchedUsers[2]
|
||||||
|
expect(updatedUser1.roles.moderator).toBe(true)
|
||||||
|
expect(updatedUser2.roles.moderator).toBe(false)
|
||||||
|
expect(updatedUser3.roles.moderator).toBe(true)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls function that activates, deactivates and deletes multiple accounts', async (done) => {
|
it('revokes admin rights from multiple users', async (done) => {
|
||||||
|
const wrapper = mount(DropdownMenu, {
|
||||||
|
store,
|
||||||
|
localVue,
|
||||||
|
sync: false,
|
||||||
|
propsData: {
|
||||||
|
selectedUsers: users
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
const revokeRightFromMultipleUsersStub = jest.fn()
|
||||||
|
wrapper.setMethods({ revokeRightFromMultipleUsers: revokeRightFromMultipleUsersStub })
|
||||||
|
|
||||||
|
wrapper.find(`.el-dropdown-menu__item:nth-child(2)`).trigger('click')
|
||||||
|
expect(wrapper.vm.revokeRightFromMultipleUsers).toHaveBeenCalled()
|
||||||
|
expect(wrapper.vm.revokeRightFromMultipleUsers).toHaveBeenCalledWith('admin')
|
||||||
|
|
||||||
|
const revokeRight = wrapper.vm.mappers().revokeRight
|
||||||
|
const user1 = store.state.users.fetchedUsers[0]
|
||||||
|
const user2 = store.state.users.fetchedUsers[2]
|
||||||
|
expect(user1.roles.admin).toBe(true)
|
||||||
|
expect(user2.roles.admin).toBe(false)
|
||||||
|
revokeRight('admin')()
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
const updatedUser1 = store.state.users.fetchedUsers[0]
|
||||||
|
const updatedUser2 = store.state.users.fetchedUsers[2]
|
||||||
|
expect(updatedUser1.roles.admin).toBe(false)
|
||||||
|
expect(updatedUser2.roles.admin).toBe(false)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('calls a function that revokes moderator rights from multiple users', async (done) => {
|
||||||
|
const wrapper = mount(DropdownMenu, {
|
||||||
|
store,
|
||||||
|
localVue,
|
||||||
|
sync: false,
|
||||||
|
propsData: {
|
||||||
|
selectedUsers: users
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
const revokeRightFromMultipleUsersStub = jest.fn()
|
||||||
|
wrapper.setMethods({ revokeRightFromMultipleUsers: revokeRightFromMultipleUsersStub })
|
||||||
|
|
||||||
|
wrapper.find(`.el-dropdown-menu__item:nth-child(4)`).trigger('click')
|
||||||
|
expect(wrapper.vm.revokeRightFromMultipleUsers).toHaveBeenCalled()
|
||||||
|
expect(wrapper.vm.revokeRightFromMultipleUsers).toHaveBeenCalledWith('moderator')
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('activates multiple accounts', async (done) => {
|
||||||
const wrapper = mount(DropdownMenu, {
|
const wrapper = mount(DropdownMenu, {
|
||||||
store,
|
store,
|
||||||
localVue,
|
localVue,
|
||||||
|
@ -86,23 +164,90 @@ describe('Apply users actions to multiple users', () => {
|
||||||
|
|
||||||
const activateMultipleUsersStub = jest.fn()
|
const activateMultipleUsersStub = jest.fn()
|
||||||
wrapper.setMethods({ activateMultipleUsers: activateMultipleUsersStub })
|
wrapper.setMethods({ activateMultipleUsers: activateMultipleUsersStub })
|
||||||
const deactivateMultipleUsersStub = jest.fn()
|
|
||||||
wrapper.setMethods({ deactivateMultipleUsers: deactivateMultipleUsersStub })
|
|
||||||
const deleteMultipleUsersStub = jest.fn()
|
|
||||||
wrapper.setMethods({ deleteMultipleUsers: deleteMultipleUsersStub })
|
|
||||||
|
|
||||||
wrapper.find(`.el-dropdown-menu__item:nth-child(5)`).trigger('click')
|
wrapper.find(`.el-dropdown-menu__item:nth-child(5)`).trigger('click')
|
||||||
expect(wrapper.vm.activateMultipleUsers).toHaveBeenCalled()
|
expect(wrapper.vm.activateMultipleUsers).toHaveBeenCalled()
|
||||||
|
|
||||||
wrapper.find(`.el-dropdown-menu__item:nth-child(6)`).trigger('click')
|
const activate = wrapper.vm.mappers().activate
|
||||||
expect(wrapper.vm.deactivateMultipleUsers).toHaveBeenCalled()
|
const user = store.state.users.fetchedUsers[2]
|
||||||
|
expect(user.deactivated).toBe(true)
|
||||||
|
activate()
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
wrapper.find(`.el-dropdown-menu__item:nth-child(7)`).trigger('click')
|
const updatedUser = store.state.users.fetchedUsers[2]
|
||||||
expect(wrapper.vm.deleteMultipleUsers).toHaveBeenCalled()
|
expect(updatedUser.deactivated).toBe(false)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls function that applies and removes tags from multiple accounts', async (done) => {
|
it('deactivates multiple accounts', async (done) => {
|
||||||
|
const wrapper = mount(DropdownMenu, {
|
||||||
|
store,
|
||||||
|
localVue,
|
||||||
|
sync: false,
|
||||||
|
propsData: {
|
||||||
|
selectedUsers: users
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
const deactivateMultipleUsersStub = jest.fn()
|
||||||
|
wrapper.setMethods({ deactivateMultipleUsers: deactivateMultipleUsersStub })
|
||||||
|
|
||||||
|
wrapper.find(`.el-dropdown-menu__item:nth-child(6)`).trigger('click')
|
||||||
|
expect(wrapper.vm.deactivateMultipleUsers).toHaveBeenCalled()
|
||||||
|
|
||||||
|
const deactivate = wrapper.vm.mappers().deactivate
|
||||||
|
const user1 = store.state.users.fetchedUsers[0]
|
||||||
|
const user2 = store.state.users.fetchedUsers[1]
|
||||||
|
expect(user1.deactivated).toBe(false)
|
||||||
|
expect(user2.deactivated).toBe(false)
|
||||||
|
deactivate()
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
const updatedUser1 = store.state.users.fetchedUsers[0]
|
||||||
|
const updatedUser2 = store.state.users.fetchedUsers[1]
|
||||||
|
expect(updatedUser1.deactivated).toBe(true)
|
||||||
|
expect(updatedUser2.deactivated).toBe(true)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('deletes multiple accounts', async (done) => {
|
||||||
|
const wrapper = mount(DropdownMenu, {
|
||||||
|
store,
|
||||||
|
localVue,
|
||||||
|
sync: false,
|
||||||
|
propsData: {
|
||||||
|
selectedUsers: users
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
const deleteMultipleUsersStub = jest.fn()
|
||||||
|
wrapper.setMethods({ deleteMultipleUsers: deleteMultipleUsersStub })
|
||||||
|
|
||||||
|
wrapper.find(`.el-dropdown-menu__item:nth-child(7)`).trigger('click')
|
||||||
|
expect(wrapper.vm.deleteMultipleUsers).toHaveBeenCalled()
|
||||||
|
|
||||||
|
const remove = wrapper.vm.mappers().remove
|
||||||
|
const user1 = store.state.users.fetchedUsers[0]
|
||||||
|
const user2 = store.state.users.fetchedUsers[1]
|
||||||
|
const user3 = store.state.users.fetchedUsers[2]
|
||||||
|
expect(user1.deactivated).toBe(false)
|
||||||
|
expect(user2.deactivated).toBe(false)
|
||||||
|
expect(user3.deactivated).toBe(true)
|
||||||
|
remove()
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
const updatedUser1 = store.state.users.fetchedUsers[0]
|
||||||
|
const updatedUser2 = store.state.users.fetchedUsers[1]
|
||||||
|
const updatedUser3 = store.state.users.fetchedUsers[2]
|
||||||
|
expect(updatedUser1.deactivated).toBe(true)
|
||||||
|
expect(updatedUser2.deactivated).toBe(true)
|
||||||
|
expect(updatedUser3.deactivated).toBe(true)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('applies tags for multiple accounts', async (done) => {
|
||||||
const wrapper = mount(DropdownMenu, {
|
const wrapper = mount(DropdownMenu, {
|
||||||
store,
|
store,
|
||||||
localVue,
|
localVue,
|
||||||
|
@ -115,32 +260,72 @@ describe('Apply users actions to multiple users', () => {
|
||||||
|
|
||||||
const addTagForMultipleUsersStub = jest.fn()
|
const addTagForMultipleUsersStub = jest.fn()
|
||||||
wrapper.setMethods({ addTagForMultipleUsers: addTagForMultipleUsersStub })
|
wrapper.setMethods({ addTagForMultipleUsers: addTagForMultipleUsersStub })
|
||||||
const removeTagFromMultipleUsersStub = jest.fn()
|
|
||||||
wrapper.setMethods({ removeTagFromMultipleUsers: removeTagFromMultipleUsersStub })
|
|
||||||
|
|
||||||
wrapper.find(`.el-dropdown-menu__item:nth-child(8) button:nth-child(1)`).trigger('click')
|
wrapper.find(`.el-dropdown-menu__item:nth-child(8) button:nth-child(1)`).trigger('click')
|
||||||
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalled()
|
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalled()
|
||||||
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalledWith('force_nsfw')
|
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalledWith('force_nsfw')
|
||||||
|
|
||||||
wrapper.find(`.el-dropdown-menu__item:nth-child(9) button:nth-child(2)`).trigger('click')
|
|
||||||
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalled()
|
|
||||||
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalledWith('strip_media')
|
|
||||||
|
|
||||||
wrapper.find(`.el-dropdown-menu__item:nth-child(10) button:nth-child(1)`).trigger('click')
|
wrapper.find(`.el-dropdown-menu__item:nth-child(10) button:nth-child(1)`).trigger('click')
|
||||||
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalled()
|
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalled()
|
||||||
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalledWith('force_unlisted')
|
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalledWith('force_unlisted')
|
||||||
|
|
||||||
wrapper.find(`.el-dropdown-menu__item:nth-child(11) button:nth-child(2)`).trigger('click')
|
|
||||||
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalled()
|
|
||||||
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalledWith('sandbox')
|
|
||||||
|
|
||||||
wrapper.find(`.el-dropdown-menu__item:nth-child(12) button:nth-child(1)`).trigger('click')
|
wrapper.find(`.el-dropdown-menu__item:nth-child(12) button:nth-child(1)`).trigger('click')
|
||||||
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalled()
|
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalled()
|
||||||
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalledWith('disable_remote_subscription')
|
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalledWith('disable_remote_subscription')
|
||||||
|
|
||||||
|
const addTag = wrapper.vm.mappers().addTag
|
||||||
|
const user1 = store.state.users.fetchedUsers[0]
|
||||||
|
const user2 = store.state.users.fetchedUsers[1]
|
||||||
|
expect(user1.tags.length).toBe(0)
|
||||||
|
expect(user2.tags.length).toBe(1)
|
||||||
|
addTag('strip_media')()
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
const updatedUser1 = store.state.users.fetchedUsers[0]
|
||||||
|
const updatedUser2 = store.state.users.fetchedUsers[1]
|
||||||
|
expect(updatedUser1.tags.length).toBe(1)
|
||||||
|
expect(updatedUser2.tags.length).toBe(2)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('removes tags from multiple accounts', async (done) => {
|
||||||
|
const wrapper = mount(DropdownMenu, {
|
||||||
|
store,
|
||||||
|
localVue,
|
||||||
|
sync: false,
|
||||||
|
propsData: {
|
||||||
|
selectedUsers: users
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
const removeTagFromMultipleUsersStub = jest.fn()
|
||||||
|
wrapper.setMethods({ removeTagFromMultipleUsers: removeTagFromMultipleUsersStub })
|
||||||
|
|
||||||
|
wrapper.find(`.el-dropdown-menu__item:nth-child(9) button:nth-child(2)`).trigger('click')
|
||||||
|
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalled()
|
||||||
|
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalledWith('strip_media')
|
||||||
|
|
||||||
|
wrapper.find(`.el-dropdown-menu__item:nth-child(11) button:nth-child(2)`).trigger('click')
|
||||||
|
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalled()
|
||||||
|
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalledWith('sandbox')
|
||||||
|
|
||||||
wrapper.find(`.el-dropdown-menu__item:nth-child(13) button:nth-child(2)`).trigger('click')
|
wrapper.find(`.el-dropdown-menu__item:nth-child(13) button:nth-child(2)`).trigger('click')
|
||||||
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalled()
|
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalled()
|
||||||
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalledWith('disable_any_subscription')
|
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalledWith('disable_any_subscription')
|
||||||
|
|
||||||
|
const removeTag = wrapper.vm.mappers().removeTag
|
||||||
|
const user1 = store.state.users.fetchedUsers[1]
|
||||||
|
const user2 = store.state.users.fetchedUsers[2]
|
||||||
|
expect(user1.tags.length).toBe(1)
|
||||||
|
expect(user2.tags.length).toBe(1)
|
||||||
|
removeTag('strip_media')()
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
|
const updatedUser1 = store.state.users.fetchedUsers[1]
|
||||||
|
const updatedUser2 = store.state.users.fetchedUsers[2]
|
||||||
|
expect(updatedUser1.tags.length).toBe(1)
|
||||||
|
expect(updatedUser2.tags.length).toBe(0)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue