diff --git a/admin/src/components/EditCreationFormular.spec.js b/admin/src/components/EditCreationFormular.spec.js index 50704ed76..0a8ddad90 100644 --- a/admin/src/components/EditCreationFormular.spec.js +++ b/admin/src/components/EditCreationFormular.spec.js @@ -46,9 +46,12 @@ const mocks = { } const propsData = { - type: '', creation: [], - itemsMassCreation: {}, + creationUserData: { + memo: 'Test schöpfung 1', + amount: 100, + date: '2021-12-01', + }, } describe('EditCreationFormular', () => { @@ -67,7 +70,7 @@ describe('EditCreationFormular', () => { expect(wrapper.find('.component-edit-creation-formular').exists()).toBeTruthy() }) - describe('radio buttons to selcet month', () => { + describe('radio buttons to select month', () => { it('has three radio buttons', () => { expect(wrapper.findAll('input[type="radio"]').length).toBe(3) }) @@ -75,7 +78,7 @@ describe('EditCreationFormular', () => { describe('with single creation', () => { beforeEach(async () => { jest.clearAllMocks() - await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setProps({ creation: [200, 400, 600] }) await wrapper.setData({ rangeMin: 180 }) await wrapper.setData({ text: 'Test create coins' }) await wrapper.setData({ value: 90 }) @@ -113,6 +116,26 @@ describe('EditCreationFormular', () => { }), ) }) + + describe('sendForm with error', () => { + beforeEach(async () => { + jest.clearAllMocks() + apolloMutateMock.mockRejectedValue({ + message: 'Ouch!', + }) + wrapper = Wrapper() + await wrapper.setProps({ type: 'singleCreation', creation: [200, 400, 600] }) + await wrapper.setData({ text: 'Test create coins' }) + await wrapper.setData({ value: 90 }) + await wrapper.findAll('input[type="radio"]').at(0).setChecked() + await wrapper.setData({ rangeMin: 100 }) + await wrapper.find('.test-submit').trigger('click') + }) + + it('toast error message', () => { + expect(toastedErrorMock).toBeCalledWith('Ouch!') + }) + }) }) }) @@ -148,23 +171,44 @@ describe('EditCreationFormular', () => { }), ) }) + + describe('sendForm with error', () => { + beforeEach(async () => { + jest.clearAllMocks() + apolloMutateMock.mockRejectedValue({ + message: 'Ouch!', + }) + wrapper = Wrapper() + await wrapper.setProps({ creation: [200, 400, 600] }) + await wrapper.setData({ text: 'Test create coins' }) + await wrapper.setData({ value: 100 }) + await wrapper.findAll('input[type="radio"]').at(1).setChecked() + await wrapper.setData({ rangeMin: 180 }) + await wrapper.find('.test-submit').trigger('click') + }) + + it('toast error message', () => { + expect(toastedErrorMock).toBeCalledWith('Ouch!') + }) + }) }) }) describe('third radio button', () => { beforeEach(async () => { await wrapper.findAll('input[type="radio"]').at(2).setChecked() + await wrapper.setData({ rangeMin: 180 }) }) - it('sets rangeMin to 0', () => { - expect(wrapper.vm.rangeMin).toBe(0) + it('sets rangeMin to 180', () => { + expect(wrapper.vm.rangeMin).toBe(180) }) - it('sets rangeMax to 400', () => { + it('sets rangeMax to 600', () => { expect(wrapper.vm.rangeMax).toBe(600) }) - describe('sendForm', () => { + describe('sendForm with success', () => { beforeEach(async () => { await wrapper.find('.test-submit').trigger('click') }) @@ -184,6 +228,26 @@ describe('EditCreationFormular', () => { ) }) }) + + describe('sendForm with error', () => { + beforeEach(async () => { + jest.clearAllMocks() + apolloMutateMock.mockRejectedValue({ + message: 'Ouch!', + }) + wrapper = Wrapper() + await wrapper.setProps({ creation: [200, 400, 600] }) + await wrapper.setData({ text: 'Test create coins' }) + await wrapper.setData({ value: 90 }) + await wrapper.findAll('input[type="radio"]').at(2).setChecked() + await wrapper.setData({ rangeMin: 180 }) + await wrapper.find('.test-submit').trigger('click') + }) + + it('toast error message', () => { + expect(toastedErrorMock).toBeCalledWith('Ouch!') + }) + }) }) }) })