fix and improve test

This commit is contained in:
Moriz Wahl 2022-01-26 15:06:37 +01:00
parent 43d811e2fa
commit 1c833d394f
3 changed files with 29 additions and 82 deletions

View File

@ -470,7 +470,7 @@ jobs:
report_name: Coverage Admin Interface
type: lcov
result_path: ./coverage/lcov.info
min_coverage: 77
min_coverage: 78
token: ${{ github.token }}
##############################################################################

View File

@ -1,6 +1,7 @@
import { mount } from '@vue/test-utils'
import CreationConfirm from './CreationConfirm.vue'
import { deletePendingCreation } from '../graphql/deletePendingCreation'
import { confirmPendingCreation } from '../graphql/confirmPendingCreation'
const localVue = global.localVue
@ -26,7 +27,7 @@ const apolloQueryMock = jest.fn().mockResolvedValue({
lastName: 'Hotzenplotz',
email: 'raeuber@hotzenplotz.de',
amount: 1000000,
memo: 'Gut Ergatert',
memo: 'Gut Ergattert',
date: new Date(),
moderator: 0,
},
@ -73,6 +74,10 @@ describe('CreationConfirm', () => {
expect(wrapper.find('div.creation-confirm').exists()).toBeTruthy()
})
it('has two pending creations', () => {
expect(wrapper.vm.pendingCreations).toHaveLength(2)
})
describe('store', () => {
it('commits resetOpenCreations to store', () => {
expect(storeCommitMock).toBeCalledWith('resetOpenCreations')
@ -82,37 +87,9 @@ describe('CreationConfirm', () => {
})
})
describe('delete creation delete with success', () => {
describe('remove creation with success', () => {
beforeEach(async () => {
apolloQueryMock.mockResolvedValue({
data: {
getPendingCreations: [
{
id: 1,
firstName: 'Bibi',
lastName: 'Bloxberg',
email: 'bibi@bloxberg.de',
amount: 500,
memo: 'Danke für alles',
date: new Date(),
moderator: 0,
},
{
id: 2,
firstName: 'Räuber',
lastName: 'Hotzenplotz',
email: 'raeuber@hotzenplotz.de',
amount: 1000000,
memo: 'Gut Ergatert',
date: new Date(),
moderator: 0,
},
],
},
})
await wrapper
.findComponent({ name: 'UserTable' })
.vm.$emit('remove-confirm-result', { id: 1 }, 'remove')
await wrapper.findComponent({ name: 'UserTable' }).vm.$emit('remove-creation', { id: 1 })
})
it('calls the deletePendingCreation mutation', () => {
@ -131,12 +108,10 @@ describe('CreationConfirm', () => {
})
})
describe('delete creation delete with error', () => {
describe('remove creation with error', () => {
beforeEach(async () => {
apolloMutateMock.mockRejectedValue({ message: 'Ouchhh!' })
await wrapper
.findComponent({ name: 'UserTable' })
.vm.$emit('remove-confirm-result', { id: 1 }, 'remove')
await wrapper.findComponent({ name: 'UserTable' }).vm.$emit('remove-creation', { id: 1 })
})
it('toasts an error message', () => {
@ -144,43 +119,16 @@ describe('CreationConfirm', () => {
})
})
describe('confirm creation delete with success', () => {
describe('confirm creation with success', () => {
beforeEach(async () => {
apolloQueryMock.mockResolvedValue({
data: {
getPendingCreations: [
{
id: 1,
firstName: 'Bibi',
lastName: 'Bloxberg',
email: 'bibi@bloxberg.de',
amount: 500,
memo: 'Danke für alles',
date: new Date(),
moderator: 0,
},
{
id: 2,
firstName: 'Räuber',
lastName: 'Hotzenplotz',
email: 'raeuber@hotzenplotz.de',
amount: 1000000,
memo: 'Gut Ergatert',
date: new Date(),
moderator: 0,
},
],
},
})
await wrapper
.findComponent({ name: 'UserTable' })
.vm.$emit('remove-confirm-result', { id: 1 }, 'confirmed')
apolloMutateMock.mockResolvedValue({})
await wrapper.findComponent({ name: 'UserTable' }).vm.$emit('confirm-creation', { id: 2 })
})
it('calls the deletePendingCreation mutation', () => {
expect(apolloMutateMock).not.toBeCalledWith({
mutation: deletePendingCreation,
variables: { id: 1 },
it('calls the confirmPendingCreation mutation', () => {
expect(apolloMutateMock).toBeCalledWith({
mutation: confirmPendingCreation,
variables: { id: 2 },
})
})
@ -193,19 +141,18 @@ describe('CreationConfirm', () => {
})
})
describe('delete creation delete with error', () => {
describe('confirm creation with error', () => {
beforeEach(async () => {
await wrapper
.findComponent({ name: 'UserTable' })
.vm.$emit('remove-confirm-result', { id: 1 }, 'confirm')
apolloMutateMock.mockRejectedValue({ message: 'Ouchhh!' })
await wrapper.findComponent({ name: 'UserTable' }).vm.$emit('confirm-creation', { id: 2 })
})
it('toasts an error message', () => {
expect(toastedErrorMock).toBeCalledWith('creation_form.toasted_default')
expect(toastedErrorMock).toBeCalledWith('Ouchhh!')
})
})
describe('server response is error', () => {
describe('server response got get pending creations is error', () => {
beforeEach(() => {
jest.clearAllMocks()
apolloQueryMock.mockRejectedValue({

View File

@ -3,7 +3,7 @@
<user-table
class="mt-4"
type="PageCreationConfirm"
:itemsUser="confirmResult"
:itemsUser="pendingCreations"
:fieldsTable="fields"
@remove-creation="removeCreation"
@confirm-creation="confirmCreation"
@ -23,7 +23,7 @@ export default {
},
data() {
return {
confirmResult: [],
pendingCreations: [],
}
},
methods: {
@ -36,7 +36,7 @@ export default {
},
})
.then((result) => {
this.confirmResult = this.confirmResult.filter((obj) => obj.id !== item.id)
this.pendingCreations = this.pendingCreations.filter((obj) => obj.id !== item.id)
this.$store.commit('openCreationsMinus', 1)
this.$toasted.success(this.$t('creation_form.toasted_delete'))
})
@ -52,8 +52,8 @@ export default {
id: item.id,
},
})
.then(() => {
this.confirmResult = this.confirmResult.filter((obj) => obj.id !== item.id)
.then((result) => {
this.pendingCreations = this.pendingCreations.filter((obj) => obj.id !== item.id)
this.$store.commit('openCreationsMinus', 1)
this.$toasted.success(this.$t('creation_form.toasted_created'))
})
@ -69,7 +69,7 @@ export default {
})
.then((result) => {
this.$store.commit('resetOpenCreations')
this.confirmResult = result.data.getPendingCreations
this.pendingCreations = result.data.getPendingCreations
this.$store.commit('setOpenCreations', result.data.getPendingCreations.length)
})
.catch((error) => {