Change the removeConfirmResult so we switch over the event possibilities instead of an if else logic.

This commit is contained in:
elweyn 2021-12-17 09:05:24 +01:00
parent fedd1d626d
commit 238352bf24
2 changed files with 27 additions and 23 deletions

View File

@ -194,14 +194,13 @@ describe('CreationConfirm', () => {
describe('delete creation delete with error', () => {
beforeEach(async () => {
apolloMutateMock.mockRejectedValue({ message: 'Ouchhh!' })
await wrapper
.findComponent({ name: 'UserTable' })
.vm.$emit('remove-confirm-result', { id: 1 }, 'confirm')
})
it('toasts an error message', () => {
expect(toastedErrorMock).not.toBeCalledWith('Ouchhh!')
expect(toastedErrorMock).toBeCalledWith('Case confirm is not supported')
})
})

View File

@ -53,27 +53,32 @@ export default {
removeConfirmResult(e, event) {
let index = 0
const findArr = this.confirmResult.find((arr) => arr.id === e.id)
if (event === 'remove') {
this.$apollo
.mutate({
mutation: deletePendingCreation,
variables: {
id: findArr.id,
},
})
.then((result) => {
index = this.confirmResult.indexOf(findArr)
this.confirmResult.splice(index, 1)
this.$store.commit('openCreationsMinus', 1)
this.$toasted.success('Pending Creation has been deleted')
})
.catch((error) => {
this.$toasted.error(error.message)
})
} else {
this.confirmResult.splice(index, 1)
this.$store.commit('openCreationsMinus', 1)
this.$toasted.success('Pending Creation has been deleted')
switch (event) {
case 'remove':
this.$apollo
.mutate({
mutation: deletePendingCreation,
variables: {
id: findArr.id,
},
})
.then((result) => {
index = this.confirmResult.indexOf(findArr)
this.confirmResult.splice(index, 1)
this.$store.commit('openCreationsMinus', 1)
this.$toasted.success('Pending Creation has been deleted')
})
.catch((error) => {
this.$toasted.error(error.message)
})
break
case 'confirmed':
this.confirmResult.splice(index, 1)
this.$store.commit('openCreationsMinus', 1)
this.$toasted.success('Pending Creation has been deleted')
break
default:
this.$toasted.error('Case ' + event + ' is not supported')
}
},
getPendingCreations() {