do not emit events. Trigger the events by interactions instead

This commit is contained in:
Moriz Wahl 2022-03-31 21:23:30 +02:00
parent 23d14a79f7
commit c6dcd29f67

View File

@ -4,6 +4,7 @@ import { toastErrorSpy, toastSuccessSpy } from '@test/testSetup'
import { TRANSACTION_STEPS } from '@/components/GddSend.vue' import { TRANSACTION_STEPS } from '@/components/GddSend.vue'
import { sendCoins, createTransactionLink } from '@/graphql/mutations.js' import { sendCoins, createTransactionLink } from '@/graphql/mutations.js'
import DashboardLayout from '@/layouts/DashboardLayout_gdd.vue' import DashboardLayout from '@/layouts/DashboardLayout_gdd.vue'
import flushPromises from 'flush-promises'
const apolloMutationMock = jest.fn() const apolloMutationMock = jest.fn()
apolloMutationMock.mockResolvedValue('success') apolloMutationMock.mockResolvedValue('success')
@ -57,12 +58,13 @@ describe('Send', () => {
describe('fill transaction form for send coins', () => { describe('fill transaction form for send coins', () => {
beforeEach(async () => { beforeEach(async () => {
wrapper.findComponent({ name: 'TransactionForm' }).vm.$emit('set-transaction', { const transactionForm = wrapper.findComponent({ name: 'TransactionForm' })
email: 'user@example.org', await transactionForm.findAll('input[type="radio"]').at(0).setChecked()
amount: 23.45, await transactionForm.find('input[type="email"]').setValue('user@example.org')
memo: 'Make the best of it!', await transactionForm.find('input[type="text"]').setValue('23.45')
selected: SEND_TYPES.send, await transactionForm.find('textarea').setValue('Make the best of it!')
}) await transactionForm.find('form').trigger('submit')
await flushPromises()
}) })
it('steps forward in the dialog', () => { it('steps forward in the dialog', () => {
@ -74,7 +76,8 @@ describe('Send', () => {
beforeEach(async () => { beforeEach(async () => {
await wrapper await wrapper
.findComponent({ name: 'TransactionConfirmationSend' }) .findComponent({ name: 'TransactionConfirmationSend' })
.vm.$emit('on-reset') .find('button.btn-secondary')
.trigger('click')
}) })
it('shows the transaction formular again', () => { it('shows the transaction formular again', () => {
@ -98,7 +101,8 @@ describe('Send', () => {
jest.clearAllMocks() jest.clearAllMocks()
await wrapper await wrapper
.findComponent({ name: 'TransactionConfirmationSend' }) .findComponent({ name: 'TransactionConfirmationSend' })
.vm.$emit('send-transaction') .find('button.btn-success')
.trigger('click')
}) })
it('calls the API when send-transaction is emitted', async () => { it('calls the API when send-transaction is emitted', async () => {
@ -131,7 +135,8 @@ describe('Send', () => {
apolloMutationMock.mockRejectedValue({ message: 'recipient not known' }) apolloMutationMock.mockRejectedValue({ message: 'recipient not known' })
await wrapper await wrapper
.findComponent({ name: 'TransactionConfirmationSend' }) .findComponent({ name: 'TransactionConfirmationSend' })
.vm.$emit('send-transaction') .find('button.btn-success')
.trigger('click')
}) })
it('has a component TransactionResultSendError', () => { it('has a component TransactionResultSendError', () => {
@ -155,18 +160,17 @@ describe('Send', () => {
}) })
}) })
/* LINK */
describe('transaction form link', () => { describe('transaction form link', () => {
beforeEach(async () => { beforeEach(async () => {
apolloMutationMock.mockResolvedValue({ apolloMutationMock.mockResolvedValue({
data: { createTransactionLink: { code: '0123456789' } }, data: { createTransactionLink: { code: '0123456789' } },
}) })
await wrapper.findComponent({ name: 'TransactionForm' }).vm.$emit('set-transaction', { const transactionForm = wrapper.findComponent({ name: 'TransactionForm' })
amount: 56.78, await transactionForm.findAll('input[type="radio"]').at(1).setChecked()
memo: 'Make the best of the link!', await transactionForm.find('input[type="text"]').setValue('56.78')
selected: SEND_TYPES.link, await transactionForm.find('textarea').setValue('Make the best of the link!')
}) await transactionForm.find('form').trigger('submit')
await flushPromises()
}) })
it('steps forward in the dialog', () => { it('steps forward in the dialog', () => {
@ -178,7 +182,8 @@ describe('Send', () => {
jest.clearAllMocks() jest.clearAllMocks()
await wrapper await wrapper
.findComponent({ name: 'TransactionConfirmationLink' }) .findComponent({ name: 'TransactionConfirmationLink' })
.vm.$emit('send-transaction') .find('button.btn-success')
.trigger('click')
}) })
it('calls the API when send-transaction is emitted', async () => { it('calls the API when send-transaction is emitted', async () => {
@ -254,10 +259,13 @@ describe('Send', () => {
}) })
}) })
describe('send apollo if transaction link with error', () => { describe('apollo call returns error', () => {
beforeEach(() => { beforeEach(async () => {
apolloMutationMock.mockRejectedValue({ message: 'OUCH!' }) apolloMutationMock.mockRejectedValue({ message: 'OUCH!' })
wrapper.find('button.btn-success').trigger('click') await wrapper
.findComponent({ name: 'TransactionConfirmationLink' })
.find('button.btn-success')
.trigger('click')
}) })
it('toasts an error message', () => { it('toasts an error message', () => {