Refine the tests after Moriz suggestions

This commit is contained in:
Wolfgang Huß 2022-06-20 13:30:48 +02:00
parent a0a9eda0b4
commit f8b449e623
3 changed files with 37 additions and 28 deletions

View File

@ -5,11 +5,9 @@ import { toastSuccessSpy, toastErrorSpy } from '../../test/testSetup'
const localVue = global.localVue
const date = new Date()
const apolloMutateMock = jest.fn().mockResolvedValue({
data: {
setUserRole: date,
setUserRole: null,
},
})
@ -68,7 +66,7 @@ describe('ChangeUserRoleFormular', () => {
wrapper = Wrapper()
})
it('shows a text that you cannot change own role', () => {
it('has the text that you cannot change own role', () => {
expect(wrapper.text()).toContain('userRole.notChangeYourSelf')
})
@ -92,11 +90,11 @@ describe('ChangeUserRoleFormular', () => {
rolesToSelect = wrapper.find('select.role-select').findAll('option')
})
it('shows no text that you cannot change own role', () => {
it('has no text that you cannot change own role', () => {
expect(wrapper.text()).not.toContain('userRole.notChangeYourSelf')
})
it('shows the select label', () => {
it('has the select label', () => {
expect(wrapper.text()).toContain('userRole.selectLabel')
})
@ -109,10 +107,9 @@ describe('ChangeUserRoleFormular', () => {
})
describe('on API error', () => {
beforeEach(async () => {
beforeEach(() => {
apolloMutateMock.mockRejectedValue({ message: 'Oh no!' })
rolesToSelect.at(1).setSelected()
await wrapper.vm.$nextTick()
})
it('toasts an error message', () => {
@ -125,7 +122,7 @@ describe('ChangeUserRoleFormular', () => {
beforeEach(() => {
apolloMutateMock.mockResolvedValue({
data: {
setUserRole: date,
setUserRole: new Date(),
},
})
propsData = {
@ -173,7 +170,7 @@ describe('ChangeUserRoleFormular', () => {
expect.arrayContaining([
{
userId: 1,
isAdmin: date,
isAdmin: expect.any(Date),
},
]),
]),
@ -197,7 +194,7 @@ describe('ChangeUserRoleFormular', () => {
propsData = {
item: {
userId: 1,
isAdmin: date,
isAdmin: new Date(),
},
}
wrapper = Wrapper()

View File

@ -18,7 +18,7 @@
<template #cell(status)="row">
<div class="text-right">
<b-avatar v-if="row.item.deletedAt" class="mr-3" variant="light">
<b-avatar v-if="row.item.deletedAt" class="mr-3 test-deleted-icon" variant="light">
<b-iconstack font-scale="2">
<b-icon stacked icon="person" variant="info" scale="0.75"></b-icon>
<b-icon stacked icon="slash-circle" variant="danger"></b-icon>
@ -80,7 +80,7 @@
<transaction-link-list v-if="!row.item.deletedAt" :userId="row.item.userId" />
</b-tab>
<b-tab :title="$t('userRole.tabTitle')">
<change-user-role-formular :item="row.item" @updateDeletedAt="updateDeletedAt" />
<change-user-role-formular :item="row.item" @updateIsAdmin="updateIsAdmin" />
</b-tab>
<b-tab :title="$t('delete_user')">
<deleted-user-formular :item="row.item" @updateDeletedAt="updateDeletedAt" />
@ -128,6 +128,9 @@ export default {
updateUserData(rowItem, newCreation) {
rowItem.creation = newCreation
},
updateIsAdmin({ userId, isAdmin }) {
this.$emit('updateIsAdmin', userId, isAdmin)
},
updateDeletedAt({ userId, deletedAt }) {
this.$emit('updateDeletedAt', userId, deletedAt)
},

View File

@ -202,31 +202,40 @@ describe('UserSearch', () => {
describe('change user role', () => {
const userId = 4
it('to admin', async () => {
const now = new Date()
await wrapper
.findComponent({ name: 'SearchUserTable' })
.vm.$emit('updateIsAdmin', userId, now)
expect(wrapper.vm.searchResult.find((obj) => obj.userId === userId).isAdmin).toEqual(now)
describe('to admin', () => {
it('updates user role to admin', async () => {
await wrapper
.findComponent({ name: 'SearchUserTable' })
.vm.$emit('updateIsAdmin', userId, new Date())
expect(wrapper.vm.searchResult.find((obj) => obj.userId === userId).isAdmin).toEqual(
expect.any(Date),
)
})
})
it('to usual user', async () => {
await wrapper
.findComponent({ name: 'SearchUserTable' })
.vm.$emit('updateIsAdmin', userId, null)
expect(wrapper.vm.searchResult.find((obj) => obj.userId === userId).isAdmin).toEqual(null)
describe('to usual user', () => {
it('updates user role to usual user', async () => {
await wrapper
.findComponent({ name: 'SearchUserTable' })
.vm.$emit('updateIsAdmin', userId, null)
expect(wrapper.vm.searchResult.find((obj) => obj.userId === userId).isAdmin).toEqual(null)
})
})
})
describe('delete user', () => {
const now = new Date()
const userId = 4
beforeEach(async () => {
wrapper.findComponent({ name: 'SearchUserTable' }).vm.$emit('updateDeletedAt', userId, now)
beforeEach(() => {
wrapper
.findComponent({ name: 'SearchUserTable' })
.vm.$emit('updateDeletedAt', userId, new Date())
})
it('marks the user as deleted', () => {
expect(wrapper.vm.searchResult.find((obj) => obj.userId === userId).deletedAt).toEqual(now)
expect(wrapper.vm.searchResult.find((obj) => obj.userId === userId).deletedAt).toEqual(
expect.any(Date),
)
expect(wrapper.find('.test-deleted-icon').exists()).toBe(true)
})
it('toasts a success message', () => {