From 24dfa3a0e7367077bcb6fa3a1c2908337f31a88e Mon Sep 17 00:00:00 2001 From: ogerly Date: Fri, 11 Mar 2022 14:59:29 +0100 Subject: [PATCH] test send.vue and ShowTransactionLinkInformations.spec.js, routes --- frontend/src/pages/Send.spec.js | 45 ++++++++++++++- frontend/src/pages/Send.vue | 57 ++++++++++--------- .../ShowTransactionLinkInformations.spec.js | 52 +++++++++++++++++ .../pages/ShowTransactionLinkInformations.vue | 28 ++++----- frontend/src/routes/router.test.js | 2 +- 5 files changed, 139 insertions(+), 45 deletions(-) diff --git a/frontend/src/pages/Send.spec.js b/frontend/src/pages/Send.spec.js index c724d965f..3f9320403 100644 --- a/frontend/src/pages/Send.spec.js +++ b/frontend/src/pages/Send.spec.js @@ -44,12 +44,14 @@ describe('Send', () => { expect(wrapper.find('div.gdd-send').exists()).toBeTruthy() }) + /* SEND */ describe('transaction form', () => { beforeEach(async () => { wrapper.findComponent({ name: 'TransactionForm' }).vm.$emit('set-transaction', { email: 'user@example.org', amount: 23.45, memo: 'Make the best of it!', + selected: 'send', }) }) it('steps forward in the dialog', () => { @@ -57,7 +59,7 @@ describe('Send', () => { }) }) - describe('confirm transaction', () => { + describe('confirm transaction if selected:send', () => { beforeEach(() => { wrapper.setData({ currentTransactionStep: 1, @@ -65,6 +67,7 @@ describe('Send', () => { email: 'user@example.org', amount: 23.45, memo: 'Make the best of it!', + selected: 'send', }, }) }) @@ -76,6 +79,7 @@ describe('Send', () => { email: 'user@example.org', amount: 23.45, memo: 'Make the best of it!', + selected: 'send', }) }) @@ -94,6 +98,7 @@ describe('Send', () => { email: 'user@example.org', amount: 23.45, memo: 'Make the best of it!', + selected: 'send', }, }), ) @@ -131,5 +136,43 @@ describe('Send', () => { }) }) }) + + /* LINK */ + describe('transaction form', () => { + beforeEach(async () => { + wrapper.findComponent({ name: 'TransactionForm' }).vm.$emit('set-transaction', { + amount: 23.45, + memo: 'Make the best of it!', + selected: 'link', + }) + }) + it('steps forward in the dialog', () => { + expect(wrapper.findComponent({ name: 'TransactionConfirmation' }).exists()).toBe(true) + }) + }) + + describe('confirm transaction if selected:link', () => { + beforeEach(() => { + wrapper.setData({ + currentTransactionStep: 1, + transactionData: { + amount: 23.45, + memo: 'Make the best of it!', + selected: 'link', + }, + }) + }) + + it('resets the transaction process when on-reset is emitted', async () => { + await wrapper.findComponent({ name: 'TransactionConfirmation' }).vm.$emit('on-reset') + expect(wrapper.findComponent({ name: 'TransactionForm' }).exists()).toBeTruthy() + expect(wrapper.vm.transactionData).toEqual({ + email: '', + amount: 23.45, + memo: 'Make the best of it!', + selected: 'link', + }) + }) + }) }) }) diff --git a/frontend/src/pages/Send.vue b/frontend/src/pages/Send.vue index 55fa013ca..4ecdbf6eb 100644 --- a/frontend/src/pages/Send.vue +++ b/frontend/src/pages/Send.vue @@ -79,32 +79,37 @@ export default { async sendTransaction() { this.loading = true this.error = false - if (this.transactionData.selected === 'send') { - this.$apollo - .mutate({ - mutation: sendCoins, - variables: this.transactionData, - }) - .then(() => { - this.error = false - this.$emit('update-balance', this.transactionData.amount) - }) - .catch((err) => { - this.errorResult = err.message - this.error = true - }) - } else if (this.transactionData.selected === 'link') { - this.$apollo - .mutate({ - mutation: createTransactionLink, - variables: { amount: this.transactionData.amount, memo: this.transactionData.memo }, - }) - .then((result) => { - alert(result) - }) - .catch((error) => { - this.toastError(error) - }) + switch (this.transactionData.selected) { + case 'send': + this.$apollo + .mutate({ + mutation: sendCoins, + variables: this.transactionData, + }) + .then(() => { + this.error = false + this.$emit('update-balance', this.transactionData.amount) + }) + .catch((err) => { + this.errorResult = err.message + this.error = true + }) + break + case 'link': + this.$apollo + .mutate({ + mutation: createTransactionLink, + variables: { amount: this.transactionData.amount, memo: this.transactionData.memo }, + }) + .then((result) => { + alert(result) + }) + .catch((error) => { + this.toastError(error) + }) + break + default: + throw new Error(`undefined transactionData.selected : ${this.transactionData.selected}`) } this.currentTransactionStep = 2 this.loading = false diff --git a/frontend/src/pages/ShowTransactionLinkInformations.spec.js b/frontend/src/pages/ShowTransactionLinkInformations.spec.js index e69de29bb..d3d9acb91 100644 --- a/frontend/src/pages/ShowTransactionLinkInformations.spec.js +++ b/frontend/src/pages/ShowTransactionLinkInformations.spec.js @@ -0,0 +1,52 @@ +import { mount } from '@vue/test-utils' +import ShowTransactionLinkInformations from './ShowTransactionLinkInformations' + +const localVue = global.localVue + +const errorHandler = jest.fn() + +localVue.config.errorHandler = errorHandler + +const queryTransactionLink = jest.fn() +queryTransactionLink.mockResolvedValue('success') + +const createMockObject = (code) => { + return { + localVue, + mocks: { + $t: jest.fn((t) => t), + $i18n: { + locale: () => 'en', + }, + $store: { + // commit: stateCommitMock, + }, + $apollo: { + query: queryTransactionLink, + }, + $route: { + params: { + code, + }, + }, + }, + } +} + +describe('ShowTransactionLinkInformations', () => { + let wrapper + + const Wrapper = (functionN) => { + return mount(ShowTransactionLinkInformations, functionN) + } + + describe('mount', () => { + beforeEach(() => { + wrapper = Wrapper(createMockObject()) + }) + + it('renders the component', () => { + expect(wrapper.find('div.show-transaction-link-informations').exists()).toBeTruthy() + }) + }) +}) diff --git a/frontend/src/pages/ShowTransactionLinkInformations.vue b/frontend/src/pages/ShowTransactionLinkInformations.vue index 385a8c921..050657d95 100644 --- a/frontend/src/pages/ShowTransactionLinkInformations.vue +++ b/frontend/src/pages/ShowTransactionLinkInformations.vue @@ -1,12 +1,11 @@