Merge pull request #2087 from gradido/add-confirm-dialog-on-delete-contribution

fix: Add Confirm Dialog on Delete Contribution
This commit is contained in:
Moriz Wahl 2022-07-26 12:23:04 +02:00 committed by GitHub
commit 082475511d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 26 deletions

View File

@ -35,6 +35,7 @@
"creation_form": { "creation_form": {
"creation_failed": "Ausstehende Schöpfung für {email} konnte nicht erzeugt werden.", "creation_failed": "Ausstehende Schöpfung für {email} konnte nicht erzeugt werden.",
"creation_for": "Aktives Grundeinkommen für", "creation_for": "Aktives Grundeinkommen für",
"deleteNow": "Möchtest du diesen Beitrag zur Gemeinschaft wirklich löschen?",
"enter_text": "Text eintragen", "enter_text": "Text eintragen",
"form": "Schöpfungsformular", "form": "Schöpfungsformular",
"min_characters": "Mindestens 10 Zeichen eingeben", "min_characters": "Mindestens 10 Zeichen eingeben",

View File

@ -35,6 +35,7 @@
"creation_form": { "creation_form": {
"creation_failed": "Could not create pending creation for {email}", "creation_failed": "Could not create pending creation for {email}",
"creation_for": "Active Basic Income for", "creation_for": "Active Basic Income for",
"deleteNow": "Do you really want to delete this contribution to the community?",
"enter_text": "Enter text", "enter_text": "Enter text",
"form": "Creation form", "form": "Creation form",
"min_characters": "Enter at least 10 characters", "min_characters": "Enter at least 10 characters",

View File

@ -80,10 +80,19 @@ describe('CreationConfirm', () => {
}) })
describe('remove creation with success', () => { describe('remove creation with success', () => {
let spy
describe('admin confirms deletion', () => {
beforeEach(async () => { beforeEach(async () => {
spy = jest.spyOn(wrapper.vm.$bvModal, 'msgBoxConfirm')
spy.mockImplementation(() => Promise.resolve('some value'))
await wrapper.findAll('tr').at(1).findAll('button').at(0).trigger('click') await wrapper.findAll('tr').at(1).findAll('button').at(0).trigger('click')
}) })
it('opens a modal', () => {
expect(spy).toBeCalled()
})
it('calls the adminDeleteContribution mutation', () => { it('calls the adminDeleteContribution mutation', () => {
expect(apolloMutateMock).toBeCalledWith({ expect(apolloMutateMock).toBeCalledWith({
mutation: adminDeleteContribution, mutation: adminDeleteContribution,
@ -100,8 +109,25 @@ describe('CreationConfirm', () => {
}) })
}) })
describe('remove creation with error', () => { describe('admin cancels deletion', () => {
beforeEach(async () => { beforeEach(async () => {
spy = jest.spyOn(wrapper.vm.$bvModal, 'msgBoxConfirm')
spy.mockImplementation(() => Promise.resolve(false))
await wrapper.findAll('tr').at(1).findAll('button').at(0).trigger('click')
})
it('does not call the adminDeleteContribution mutation', () => {
expect(apolloMutateMock).not.toBeCalled()
})
})
})
describe('remove creation with error', () => {
let spy
beforeEach(async () => {
spy = jest.spyOn(wrapper.vm.$bvModal, 'msgBoxConfirm')
spy.mockImplementation(() => Promise.resolve('some value'))
apolloMutateMock.mockRejectedValue({ message: 'Ouchhh!' }) apolloMutateMock.mockRejectedValue({ message: 'Ouchhh!' })
await wrapper.findAll('tr').at(1).findAll('button').at(0).trigger('click') await wrapper.findAll('tr').at(1).findAll('button').at(0).trigger('click')
}) })

View File

@ -34,7 +34,9 @@ export default {
}, },
methods: { methods: {
removeCreation(item) { removeCreation(item) {
this.$apollo this.$bvModal.msgBoxConfirm(this.$t('creation_form.deleteNow')).then(async (value) => {
if (value)
await this.$apollo
.mutate({ .mutate({
mutation: adminDeleteContribution, mutation: adminDeleteContribution,
variables: { variables: {
@ -48,6 +50,7 @@ export default {
.catch((error) => { .catch((error) => {
this.toastError(error.message) this.toastError(error.message)
}) })
})
}, },
confirmCreation() { confirmCreation() {
this.$apollo this.$apollo