From 192e43888c020299f5138d261b01a6bb41d7dc1f Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 6 Feb 2023 17:54:14 +0100 Subject: [PATCH] fix unit tests, rename state to status where possible --- admin/src/pages/CreationConfirm.spec.js | 107 +++++++++++++++++------- admin/src/pages/CreationConfirm.vue | 6 +- 2 files changed, 78 insertions(+), 35 deletions(-) diff --git a/admin/src/pages/CreationConfirm.spec.js b/admin/src/pages/CreationConfirm.spec.js index f0e195627..4cb972aac 100644 --- a/admin/src/pages/CreationConfirm.spec.js +++ b/admin/src/pages/CreationConfirm.spec.js @@ -151,16 +151,6 @@ describe('CreationConfirm', () => { }) }) - describe.skip('store', () => { - it('commits resetOpenCreations to store', () => { - expect(storeCommitMock).toBeCalledWith('resetOpenCreations') - }) - - it('commits setOpenCreations to store', () => { - expect(storeCommitMock).toBeCalledWith('setOpenCreations', 2) - }) - }) - describe('actions in overlay', () => { describe('delete creation', () => { beforeEach(async () => { @@ -339,40 +329,93 @@ describe('CreationConfirm', () => { }) }) - describe('click tab "confirmed"', () => { - beforeEach(() => { + describe('filter tabs', () => { + describe('click tab "confirmed"', () => { + let refetchSpy + beforeEach(async () => { jest.clearAllMocks() - // console.log('click tab "confirmed"', wrapper.vm.statusFilter) - // console.log(wrapper.find('a[data-test="confirmed"]').html()) + refetchSpy = jest.spyOn(wrapper.vm.$apollo.queries.ListAllContributions, 'refetch') await wrapper.find('a[data-test="confirmed"]').trigger('click') - // await wrapper.setData({ tabIndex: 1 }) - await wrapper.vm.$nextTick() }) - }) - it('has statusFilter ["CONFIRMED"]', () => { - // console.log('click tab "confirmed2"', wrapper.vm.statusFilter) - // console.log(wrapper.find('[data-test="confirmed"]').html()) - expect(wrapper.vm.statusFilter).toEqual(['CONFIRMED']) - }) - it('list all Contributions confirmed', () => { - expect(wrapper.vm.$apollo.queries.ListAllContributions).toBeTruthy() - }) - describe('click tab "open"', () => { - beforeEach(() => { + it('has statusFilter set to ["CONFIRMED"]', () => { + expect( + wrapper.vm.$apollo.queries.ListAllContributions.observer.options.variables, + ).toMatchObject({ statusFilter: ['CONFIRMED'] }) + }) + + it('refetches contributions', () => { + expect(refetchSpy).toBeCalled() + }) + + describe('click tab "open"', () => { beforeEach(async () => { + jest.clearAllMocks() + refetchSpy = jest.spyOn(wrapper.vm.$apollo.queries.ListAllContributions, 'refetch') await wrapper.find('a[data-test="open"]').trigger('click') - await wrapper.vm.$nextTick() + }) + + it('has statusFilter set to ["IN_PROGRESS", "PENDING"]', () => { + expect( + wrapper.vm.$apollo.queries.ListAllContributions.observer.options.variables, + ).toMatchObject({ statusFilter: ['IN_PROGRESS', 'PENDING'] }) + }) + + it('refetches contributions', () => { + expect(refetchSpy).toBeCalled() }) }) - it('has statusFilter ["IN_PROGRESS", "PENDING"]', () => { - expect(wrapper.vm.statusFilter).toEqual(['IN_PROGRESS', 'PENDING']) + + describe('click tab "denied"', () => { + beforeEach(async () => { + jest.clearAllMocks() + refetchSpy = jest.spyOn(wrapper.vm.$apollo.queries.ListAllContributions, 'refetch') + await wrapper.find('a[data-test="denied"]').trigger('click') + }) + + it('has statusFilter set to ["DENIED"]', () => { + expect( + wrapper.vm.$apollo.queries.ListAllContributions.observer.options.variables, + ).toMatchObject({ statusFilter: ['DENIED'] }) + }) + + it('refetches contributions', () => { + expect(refetchSpy).toBeCalled() + }) }) - it('list all Contributions open', () => { - expect(wrapper.vm.$apollo.queries.ListAllContributions).toBeTruthy() + + describe('click tab "all"', () => { + beforeEach(async () => { + jest.clearAllMocks() + refetchSpy = jest.spyOn(wrapper.vm.$apollo.queries.ListAllContributions, 'refetch') + await wrapper.find('a[data-test="all"]').trigger('click') + }) + + it('has statusFilter set to ["IN_PROGRESS", "PENDING", "CONFIRMED", "DENIED", "DELETED"]', () => { + expect( + wrapper.vm.$apollo.queries.ListAllContributions.observer.options.variables, + ).toMatchObject({ + statusFilter: ['IN_PROGRESS', 'PENDING', 'CONFIRMED', 'DENIED', 'DELETED'], + }) + }) + + it('refetches contributions', () => { + expect(refetchSpy).toBeCalled() + }) }) }) }) + + describe('update status', () => { + beforeEach(async () => { + await wrapper.findComponent({ name: 'OpenCreationsTable' }).vm.$emit('update-state', 2) + }) + + it.skip('updates the status', () => { + expect(wrapper.vm.items.find((obj) => obj.id === 2).messagesCount).toBe(1) + expect(wrapper.vm.items.find((obj) => obj.id === 2).state).toBe('IN_PROGRESS') + }) + }) }) }) diff --git a/admin/src/pages/CreationConfirm.vue b/admin/src/pages/CreationConfirm.vue index b13869dd3..ff08613cf 100644 --- a/admin/src/pages/CreationConfirm.vue +++ b/admin/src/pages/CreationConfirm.vue @@ -31,7 +31,7 @@ :items="items" :fields="fields" @show-overlay="showOverlay" - @update-state="updateState" + @update-state="updateStatus" @update-contributions="$apollo.queries.AllContributions.refetch()" /> @@ -83,7 +83,7 @@ const FILTER_TAB_MAP = [ ['CONFIRMED'], ['DENIED'], ['DELETED'], - ['IN_PROGRESS', 'PENDING', 'CONFIRMED', 'DENIED'], + ['IN_PROGRESS', 'PENDING', 'CONFIRMED', 'DENIED', 'DELETED'], ] export default { @@ -168,7 +168,7 @@ export default { this.item = item this.variant = variant }, - updateState(id) { + updateStatus(id) { this.items.find((obj) => obj.id === id).messagesCount++ this.items.find((obj) => obj.id === id).state = 'IN_PROGRESS' },