From 99bf3df215a4259d7f1702309a8d71fe92e95b6b Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 23 Mar 2023 12:14:45 +0100 Subject: [PATCH] test send coins via gradido ID --- frontend/src/pages/Send.spec.js | 72 +++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/Send.spec.js b/frontend/src/pages/Send.spec.js index 0a0d5da71..3aae5a83e 100644 --- a/frontend/src/pages/Send.spec.js +++ b/frontend/src/pages/Send.spec.js @@ -10,6 +10,7 @@ const apolloMutationMock = jest.fn() apolloMutationMock.mockResolvedValue('success') const navigatorClipboardMock = jest.fn() +const routerPushMock = jest.fn() const localVue = global.localVue @@ -38,6 +39,9 @@ describe('Send', () => { $route: { query: {}, }, + $router: { + push: routerPushMock, + }, } const Wrapper = () => { @@ -85,8 +89,8 @@ describe('Send', () => { it('shows the transaction formular again', () => { expect(wrapper.findComponent({ name: 'TransactionForm' }).exists()).toBe(true) }) - // TODO:SKIPED at this point, a check must be made in the components ? - it.skip('restores the previous data in the formular', () => { + + it('restores the previous data in the formular', () => { expect(wrapper.find("input[type='email']").vm.$el.value).toBe('user@example.org') expect(wrapper.find("input[type='text']").vm.$el.value).toBe('23.45') expect(wrapper.find('textarea').vm.$el.value).toBe('Make the best of it!') @@ -107,10 +111,11 @@ describe('Send', () => { expect.objectContaining({ mutation: sendCoins, variables: { - email: 'user@example.org', + identifier: 'user@example.org', amount: 23.45, memo: 'Make the best of it!', selected: SEND_TYPES.send, + userName: '', }, }), ) @@ -162,6 +167,67 @@ describe('Send', () => { }) }) + describe('with gradidoID query', () => { + beforeEach(() => { + mocks.$route.query.gradidoID = 'gradido-ID' + wrapper = Wrapper() + }) + + it('has no email input field', () => { + expect( + wrapper.findComponent({ name: 'TransactionForm' }).find('input[type="email"]').exists(), + ).toBe(false) + }) + + describe('submit form', () => { + beforeEach(async () => { + jest.clearAllMocks() + const transactionForm = wrapper.findComponent({ name: 'TransactionForm' }) + await transactionForm.find('input[type="text"]').setValue('34.56') + await transactionForm.find('textarea').setValue('Make the best of it!') + await transactionForm.find('form').trigger('submit') + await flushPromises() + }) + + it('steps forward in the dialog', () => { + expect(wrapper.findComponent({ name: 'TransactionConfirmationSend' }).exists()).toBe(true) + }) + + describe('confirm transaction', () => { + beforeEach(async () => { + jest.clearAllMocks() + await wrapper + .findComponent({ name: 'TransactionConfirmationSend' }) + .find('button.btn-gradido') + .trigger('click') + }) + + it('calls the API', async () => { + expect(apolloMutationMock).toBeCalledWith( + expect.objectContaining({ + mutation: sendCoins, + variables: { + identifier: 'gradido-ID', + amount: 34.56, + memo: 'Make the best of it!', + selected: SEND_TYPES.send, + userName: '', + }, + }), + ) + }) + + it('resets the gradido ID query in route', () => { + expect(routerPushMock).toBeCalledWith({ + query: { + gradidoID: undefined, + }, + }) + }) + }) + }) + }) + describe('transaction form link', () => { const now = new Date().toISOString() beforeEach(async () => {