Fix tests for updated user actions

This commit is contained in:
Angelina Filippova 2019-10-18 13:57:48 +02:00
parent 6975f43527
commit fa2410d614
3 changed files with 21 additions and 39 deletions

View file

@ -52,7 +52,6 @@ export async function activateUsers(nicknames, authHost, token) {
}
export async function addRight(nicknames, right, authHost, token) {
console.log(nicknames)
return Promise.resolve({ data:
{ [`is_${right}`]: true }
})
@ -72,9 +71,9 @@ export async function deleteRight(nickname, right, authHost, token) {
})
}
export async function deleteUser(nickname, authHost, token) {
export async function deleteUsers(nicknames, authHost, token) {
return Promise.resolve({ data:
nickname
nicknames
})
}

View file

@ -75,7 +75,7 @@ describe('Users actions', () => {
store = new Vuex.Store(cloneDeep(storeConfig))
})
it('grants admin and moderator rights to a local user', async (done) => {
it('grants admin right to a local user', async (done) => {
const wrapper = mount(Users, {
store,
localVue,
@ -87,14 +87,28 @@ describe('Users actions', () => {
const user = store.state.users.fetchedUsers[2]
expect(user.roles.admin).toBe(false)
expect(user.roles.moderator).toBe(false)
wrapper.find(htmlElement(3, 1)).trigger('click')
await flushPromises()
wrapper.find(htmlElement(3, 2)).trigger('click')
await flushPromises()
const updatedUser = store.state.users.fetchedUsers[2]
expect(updatedUser.roles.admin).toBe(true)
done()
})
it('grants moderator right to a local user', async (done) => {
const wrapper = mount(Users, {
store,
localVue,
sync: false,
stubs: ['router-link']
})
await flushPromises()
const user = store.state.users.fetchedUsers[2]
expect(user.roles.admin).toBe(false)
expect(user.roles.moderator).toBe(false)
wrapper.find(htmlElement(3, 2)).trigger('click')
const updatedUser = store.state.users.fetchedUsers[2]
expect(updatedUser.roles.moderator).toBe(true)
done()
})
@ -126,9 +140,7 @@ describe('Users actions', () => {
const user = store.state.users.fetchedUsers[1]
expect(user.deactivated).toBe(false)
wrapper.find(htmlElement(2, 1)).trigger('click')
await flushPromises()
const updatedUser = store.state.users.fetchedUsers[1]
expect(updatedUser.deactivated).toBe(true)
@ -166,9 +178,7 @@ describe('Users actions', () => {
expect(user2.tags.length).toBe(1)
wrapper.find(htmlElement(1, 5)).trigger('click')
await flushPromises()
wrapper.find(htmlElement(2, 5)).trigger('click')
await flushPromises()
const updatedUser1 = store.state.users.fetchedUsers[0]
const updatedUser2 = store.state.users.fetchedUsers[1]
@ -188,33 +198,13 @@ describe('Users actions', () => {
const user = store.state.users.fetchedUsers[1]
expect(user.tags.length).toBe(1)
wrapper.find(htmlElement(2, 6)).trigger('click')
await flushPromises()
const updatedUser = store.state.users.fetchedUsers[1]
expect(updatedUser.tags.length).toBe(0)
done()
})
it('shows check icon when tag is added', async (done) => {
const wrapper = mount(Users, {
store,
localVue,
sync: false,
stubs: ['router-link']
})
await flushPromises()
expect(wrapper.find(`${htmlElement(1, 5)} i`).exists()).toBe(false)
wrapper.find(htmlElement(1, 5)).trigger('click')
await flushPromises()
expect(wrapper.find(`${htmlElement(1, 5)} i`).exists()).toBe(true)
done()
})
it('does not change user index in array when tag is added', async (done) => {
const wrapper = mount(Users, {
store,

View file

@ -51,7 +51,6 @@ describe('Apply users actions to multiple users', () => {
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]
@ -88,7 +87,6 @@ describe('Apply users actions to multiple users', () => {
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]
@ -123,7 +121,6 @@ describe('Apply users actions to multiple users', () => {
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]
@ -173,7 +170,6 @@ describe('Apply users actions to multiple users', () => {
const user = store.state.users.fetchedUsers[2]
expect(user.deactivated).toBe(true)
activate()
await flushPromises()
const updatedUser = store.state.users.fetchedUsers[2]
expect(updatedUser.deactivated).toBe(false)
@ -203,7 +199,6 @@ describe('Apply users actions to multiple users', () => {
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]
@ -270,7 +265,6 @@ describe('Apply users actions to multiple users', () => {
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]
@ -311,7 +305,6 @@ describe('Apply users actions to multiple users', () => {
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]