Update tests for applying actions on multiple users

This commit is contained in:
Angelina Filippova 2019-05-14 23:07:47 +03:00
parent 90553ba75c
commit 11255be51f
2 changed files with 222 additions and 37 deletions

View file

@ -7,7 +7,7 @@
{{ $t('users.grantAdmin') }}
</el-dropdown-item>
<el-dropdown-item
@click.native="revokeRightToMultipleUsers('admin')">
@click.native="revokeRightFromMultipleUsers('admin')">
{{ $t('users.revokeAdmin') }}
</el-dropdown-item>
<el-dropdown-item
@ -15,7 +15,7 @@
{{ $t('users.grantModerator') }}
</el-dropdown-item>
<el-dropdown-item
@click.native="revokeRightToMultipleUsers('moderator')">
@click.native="revokeRightFromMultipleUsers('moderator')">
{{ $t('users.revokeModerator') }}
</el-dropdown-item>
<el-dropdown-item
@ -149,7 +149,7 @@ export default {
grantRight(right)
)
},
revokeRightToMultipleUsers(right) {
revokeRightFromMultipleUsers(right) {
const { revokeRight } = this.mappers()
this.confirmMessage(
`Are you sure you want to revoke ${right} rights from all selected users?`,

View file

@ -22,10 +22,9 @@ describe('Apply users actions to multiple users', () => {
store = new Vuex.Store(cloneDeep(storeConfig))
store.dispatch('FetchUsers', { page: 1 })
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, {
store,
localVue,
@ -43,13 +42,26 @@ describe('Apply users actions to multiple users', () => {
expect(wrapper.vm.grantRightToMultipleUsers).toHaveBeenCalled()
expect(wrapper.vm.grantRightToMultipleUsers).toHaveBeenCalledWith('admin')
wrapper.find(`.el-dropdown-menu__item:nth-child(3)`).trigger('click')
expect(wrapper.vm.grantRightToMultipleUsers).toHaveBeenCalled()
expect(wrapper.vm.grantRightToMultipleUsers).toHaveBeenCalledWith('moderator')
const grantRight = wrapper.vm.mappers().grantRight
const user1 = store.state.users.fetchedUsers[0]
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()
})
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, {
store,
localVue,
@ -60,20 +72,86 @@ describe('Apply users actions to multiple users', () => {
})
await flushPromises()
const revokeRightToMultipleUsersStub = jest.fn()
wrapper.setMethods({ revokeRightToMultipleUsers: revokeRightToMultipleUsersStub })
const grantRightToMultipleUsersStub = jest.fn()
wrapper.setMethods({ grantRightToMultipleUsers: grantRightToMultipleUsersStub })
wrapper.find(`.el-dropdown-menu__item:nth-child(2)`).trigger('click')
expect(wrapper.vm.revokeRightToMultipleUsers).toHaveBeenCalled()
expect(wrapper.vm.revokeRightToMultipleUsers).toHaveBeenCalledWith('admin')
wrapper.find(`.el-dropdown-menu__item:nth-child(3)`).trigger('click')
expect(wrapper.vm.grantRightToMultipleUsers).toHaveBeenCalled()
expect(wrapper.vm.grantRightToMultipleUsers).toHaveBeenCalledWith('moderator')
wrapper.find(`.el-dropdown-menu__item:nth-child(4)`).trigger('click')
expect(wrapper.vm.revokeRightToMultipleUsers).toHaveBeenCalled()
expect(wrapper.vm.revokeRightToMultipleUsers).toHaveBeenCalledWith('moderator')
const grantRight = wrapper.vm.mappers().grantRight
const user1 = store.state.users.fetchedUsers[0]
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()
})
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, {
store,
localVue,
@ -86,23 +164,90 @@ describe('Apply users actions to multiple users', () => {
const activateMultipleUsersStub = jest.fn()
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')
expect(wrapper.vm.activateMultipleUsers).toHaveBeenCalled()
wrapper.find(`.el-dropdown-menu__item:nth-child(6)`).trigger('click')
expect(wrapper.vm.deactivateMultipleUsers).toHaveBeenCalled()
const activate = wrapper.vm.mappers().activate
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')
expect(wrapper.vm.deleteMultipleUsers).toHaveBeenCalled()
const updatedUser = store.state.users.fetchedUsers[2]
expect(updatedUser.deactivated).toBe(false)
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, {
store,
localVue,
@ -115,32 +260,72 @@ describe('Apply users actions to multiple users', () => {
const addTagForMultipleUsersStub = jest.fn()
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')
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalled()
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')
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalled()
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')
expect(wrapper.vm.addTagForMultipleUsers).toHaveBeenCalled()
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')
expect(wrapper.vm.removeTagFromMultipleUsers).toHaveBeenCalled()
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()
})
})