diff --git a/admin/src/components/ContributionMessages/ContributionMessagesFormular.spec.js b/admin/src/components/ContributionMessages/ContributionMessagesFormular.spec.js index a81009c09..b7f01f8b8 100644 --- a/admin/src/components/ContributionMessages/ContributionMessagesFormular.spec.js +++ b/admin/src/components/ContributionMessages/ContributionMessagesFormular.spec.js @@ -1,6 +1,7 @@ import { mount } from '@vue/test-utils' import ContributionMessagesFormular from './ContributionMessagesFormular' import { toastErrorSpy, toastSuccessSpy } from '../../../test/testSetup' +import { adminCreateContributionMessage } from '@/graphql/adminCreateContributionMessage' const localVue = global.localVue @@ -34,6 +35,7 @@ describe('ContributionMessagesFormular', () => { describe('mount', () => { beforeEach(() => { wrapper = Wrapper() + jest.clearAllMocks() }) it('has a DIV .contribution-messages-formular', () => { @@ -73,13 +75,65 @@ describe('ContributionMessagesFormular', () => { ) }) - it('emitted "update-state" with data', async () => { - expect(wrapper.emitted('update-state')).toEqual( + it('emitted "update-status" with data', async () => { + expect(wrapper.emitted('update-status')).toEqual( expect.arrayContaining([expect.arrayContaining([42])]), ) }) }) + describe('send DIALOG contribution message with success', () => { + beforeEach(async () => { + await wrapper.setData({ + form: { + text: 'text form message', + }, + }) + await wrapper.find('button[data-test="submit-dialog"]').trigger('click') + }) + + it('moderatorMesage has `DIALOG`', () => { + expect(apolloMutateMock).toBeCalledWith({ + mutation: adminCreateContributionMessage, + variables: { + contributionId: 42, + message: 'text form message', + messageType: 'DIALOG', + }, + }) + }) + + it('toasts an success message', () => { + expect(toastSuccessSpy).toBeCalledWith('message.request') + }) + }) + + describe('send MODERATOR contribution message with success', () => { + beforeEach(async () => { + await wrapper.setData({ + form: { + text: 'text form message', + }, + }) + await wrapper.find('button[data-test="submit-moderator"]').trigger('click') + }) + + it('moderatorMesage has `MODERATOR`', () => { + expect(apolloMutateMock).toBeCalledWith({ + mutation: adminCreateContributionMessage, + variables: { + contributionId: 42, + message: 'text form message', + messageType: 'MODERATOR', + }, + }) + }) + + it('toasts an success message', () => { + expect(toastSuccessSpy).toBeCalledWith('message.request') + }) + }) + describe('send contribution message with error', () => { beforeEach(async () => { apolloMutateMock.mockRejectedValue({ message: 'OUCH!' }) @@ -91,21 +145,5 @@ describe('ContributionMessagesFormular', () => { expect(toastErrorSpy).toBeCalledWith('OUCH!') }) }) - - describe('send contribution message with success', () => { - beforeEach(async () => { - wrapper.setData({ - form: { - text: 'text form message', - }, - }) - wrapper = Wrapper() - await wrapper.find('form').trigger('submit') - }) - - it('toasts an success message', () => { - expect(toastSuccessSpy).toBeCalledWith('message.request') - }) - }) }) }) diff --git a/admin/src/components/ContributionMessages/ContributionMessagesFormular.vue b/admin/src/components/ContributionMessages/ContributionMessagesFormular.vue index 3a5d6e0b8..1286104a4 100644 --- a/admin/src/components/ContributionMessages/ContributionMessagesFormular.vue +++ b/admin/src/components/ContributionMessages/ContributionMessagesFormular.vue @@ -1,7 +1,7 @@