From c54a0580399642f85372fe462d0690e228e6197c Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 9 Aug 2021 21:50:36 +0200 Subject: [PATCH] complete testing for dashboard layout --- .../views/Layout/DashboardLayout_gdd.spec.js | 90 +++++++++++++++---- .../src/views/Layout/DashboardLayout_gdd.vue | 1 + 2 files changed, 76 insertions(+), 15 deletions(-) diff --git a/frontend/src/views/Layout/DashboardLayout_gdd.spec.js b/frontend/src/views/Layout/DashboardLayout_gdd.spec.js index 4f47785dc..6e19b28a2 100644 --- a/frontend/src/views/Layout/DashboardLayout_gdd.spec.js +++ b/frontend/src/views/Layout/DashboardLayout_gdd.spec.js @@ -6,16 +6,10 @@ jest.useFakeTimers() const localVue = global.localVue -const transitionStub = () => ({ - render(h) { - return this.$options._renderChildren - }, -}) - const storeDispatchMock = jest.fn() const storeCommitMock = jest.fn() const routerPushMock = jest.fn() -const logoutQueryMock = jest.fn().mockResolvedValue({ +const apolloMock = jest.fn().mockResolvedValue({ data: { logout: 'success', }, @@ -39,7 +33,7 @@ describe('DashboardLayoutGdd', () => { push: routerPushMock, }, $apollo: { - query: logoutQueryMock, + query: apolloMock, }, $store: { state: { @@ -53,8 +47,7 @@ describe('DashboardLayoutGdd', () => { const stubs = { RouterLink: RouterLinkStub, - FadeTransition: transitionStub(), - RouterView: transitionStub(), + RouterView: true, } const Wrapper = () => { @@ -136,7 +129,7 @@ describe('DashboardLayoutGdd', () => { }) it('calls the API', async () => { - expect(logoutQueryMock).toBeCalledWith( + expect(apolloMock).toBeCalledWith( expect.objectContaining({ variables: { sessionId: 1 }, }), @@ -154,11 +147,78 @@ describe('DashboardLayoutGdd', () => { describe('update balance', () => { it('updates the amount correctelly', async () => { - await wrapper.setData({ balance: 0 }) - console.log(wrapper.html()) - await wrapper.findComponent({ name: 'RouterView' }).vm.$emit('update-balance', 5) + await wrapper.findComponent({ ref: 'router-view' }).vm.$emit('update-balance', 5) await flushPromises() - expect(wrapper.vm.balance).toBe(5) + expect(wrapper.vm.balance).toBe(-5) + }) + }) + + describe('update transactions', () => { + beforeEach(async () => { + apolloMock.mockResolvedValue({ + data: { + transactionList: { + gdtSum: 100, + count: 4, + balance: 1450, + decay: 1250, + transactions: ['transaction', 'transaction', 'transaction', 'transaction'], + }, + }, + }) + await wrapper + .findComponent({ ref: 'router-view' }) + .vm.$emit('update-transactions', { firstPage: 2, items: 5 }) + await flushPromises() + }) + + it('calls the API', () => { + expect(apolloMock).toBeCalledWith( + expect.objectContaining({ + variables: { + sessionId: 1, + firstPage: 2, + items: 5, + }, + }), + ) + }) + + it('updates balance', () => { + expect(wrapper.vm.balance).toBe(1250) + }) + + it('updates transactions', () => { + expect(wrapper.vm.transactions).toEqual([ + 'transaction', + 'transaction', + 'transaction', + 'transaction', + ]) + }) + + it('updates GDT balance', () => { + expect(wrapper.vm.GdtBalance).toBe(100) + }) + + it('updates transaction count', () => { + expect(wrapper.vm.transactionCount).toBe(4) + }) + }) + + describe('update transactions returns error', () => { + beforeEach(async () => { + apolloMock.mockRejectedValue({ + message: 'error', + }) + await wrapper + .findComponent({ ref: 'router-view' }) + .vm.$emit('update-transactions', { firstPage: 2, items: 5 }) + await flushPromises() + }) + + it('sets pending to true', () => { + expect(wrapper.vm.pending).toBeTruthy() }) }) }) diff --git a/frontend/src/views/Layout/DashboardLayout_gdd.vue b/frontend/src/views/Layout/DashboardLayout_gdd.vue index 8884cd47f..dc4b60991 100755 --- a/frontend/src/views/Layout/DashboardLayout_gdd.vue +++ b/frontend/src/views/Layout/DashboardLayout_gdd.vue @@ -51,6 +51,7 @@