From 2bec8f3f9058a8266d988a952e502ae276b71e96 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 22 Dec 2021 09:16:15 +0100 Subject: [PATCH] Test the CreationTransactionListFormular. --- .../CreationTransactionListFormular.spec.js | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 admin/src/components/CreationTransactionListFormular.spec.js diff --git a/admin/src/components/CreationTransactionListFormular.spec.js b/admin/src/components/CreationTransactionListFormular.spec.js new file mode 100644 index 000000000..80b337268 --- /dev/null +++ b/admin/src/components/CreationTransactionListFormular.spec.js @@ -0,0 +1,115 @@ +import { mount } from '@vue/test-utils' +import CreationTransactionListFormular from './CreationTransactionListFormular.vue' + +const localVue = global.localVue + +const apolloQueryMock = jest.fn().mockResolvedValue({ + data: { + transactionList: { + transactions: [ + { + type: 'created', + balance: 100, + decayStart: 0, + decayEnd: 0, + decayDuration: 0, + memo: 'Testing', + transactionId: 1, + name: 'Bibi', + email: 'bibi@bloxberg.de', + date: new Date(), + decay: { + balance: 0.01, + decayStart: 0, + decayEnd: 0, + decayDuration: 0, + decayStartBlock: 0, + }, + }, + { + type: 'created', + balance: 200, + decayStart: 0, + decayEnd: 0, + decayDuration: 0, + memo: 'Testing 2', + transactionId: 2, + name: 'Bibi', + email: 'bibi@bloxberg.de', + date: new Date(), + decay: { + balance: 0.01, + decayStart: 0, + decayEnd: 0, + decayDuration: 0, + decayStartBlock: 0, + }, + }, + ], + }, + }, +}) + +const toastedErrorMock = jest.fn() + +const mocks = { + $apollo: { + query: apolloQueryMock, + }, + $toasted: { + global: { + error: toastedErrorMock, + }, + }, +} + +const propsData = { + userId: 1, +} + +describe('CreationTransactionListFormular', () => { + let wrapper + + const Wrapper = () => { + return mount(CreationTransactionListFormular, { localVue, mocks, propsData }) + } + + describe('mount', () => { + beforeEach(() => { + wrapper = Wrapper() + }) + + it('sends query to Apollo when created', () => { + expect(apolloQueryMock).toBeCalledWith( + expect.objectContaining({ + variables: { + currentPage: 1, + pageSize: 25, + order: 'DESC', + onlyCreations: true, + userId: 1, + }, + }), + ) + }) + + it('has two values for the transaction', () => { + expect(wrapper.find('tbody').findAll('tr').length).toBe(2) + }) + + describe('query transaction with error', () => { + beforeEach(() => { + apolloQueryMock.mockRejectedValue({ message: 'OUCH!' }) + wrapper = Wrapper() + }) + + it('calls the API', () => { + expect(apolloQueryMock).toBeCalled() + }) + + it('toast error', () => { + expect(toastedErrorMock).toBeCalledWith('OUCH!') + }) + }) + }) +})