From a811b2bf2d282684064db4145e875e170d4d4173 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 28 Feb 2023 18:28:52 +0100 Subject: [PATCH] rename query file and query, update specs --- ...utions.js => adminListAllContributions.js} | 2 +- admin/src/pages/CreationConfirm.spec.js | 84 +++++++++++++------ admin/src/pages/CreationConfirm.vue | 4 +- admin/src/pages/Overview.spec.js | 14 ++-- admin/src/pages/Overview.vue | 4 +- 5 files changed, 70 insertions(+), 38 deletions(-) rename admin/src/graphql/{listAllContributions.js => adminListAllContributions.js} (93%) diff --git a/admin/src/graphql/listAllContributions.js b/admin/src/graphql/adminListAllContributions.js similarity index 93% rename from admin/src/graphql/listAllContributions.js rename to admin/src/graphql/adminListAllContributions.js index 319433fc2..cd47cd1d4 100644 --- a/admin/src/graphql/listAllContributions.js +++ b/admin/src/graphql/adminListAllContributions.js @@ -1,6 +1,6 @@ import gql from 'graphql-tag' -export const listAllContributions = gql` +export const adminListAllContributions = gql` query ( $currentPage: Int = 1 $pageSize: Int = 25 diff --git a/admin/src/pages/CreationConfirm.spec.js b/admin/src/pages/CreationConfirm.spec.js index 710f2b26f..5632db0bd 100644 --- a/admin/src/pages/CreationConfirm.spec.js +++ b/admin/src/pages/CreationConfirm.spec.js @@ -2,7 +2,7 @@ import { mount } from '@vue/test-utils' import CreationConfirm from './CreationConfirm' import { adminDeleteContribution } from '../graphql/adminDeleteContribution' import { denyContribution } from '../graphql/denyContribution' -import { listAllContributions } from '../graphql/listAllContributions' +import { adminListAllContributions } from '../graphql/adminListAllContributions' import { confirmContribution } from '../graphql/confirmContribution' import { toastErrorSpy, toastSuccessSpy } from '../../test/testSetup' import VueApollo from 'vue-apollo' @@ -38,7 +38,7 @@ const mocks = { const defaultData = () => { return { - listAllContributions: { + adminListAllContributions: { contributionCount: 2, contributionList: [ { @@ -97,7 +97,7 @@ describe('CreationConfirm', () => { const confirmContributionMock = jest.fn() mockClient.setRequestHandler( - listAllContributions, + adminListAllContributions, jest .fn() .mockRejectedValueOnce({ message: 'Ouch!' }) @@ -331,67 +331,93 @@ describe('CreationConfirm', () => { describe('filter tabs', () => { describe('click tab "confirmed"', () => { - let refetchSpy + let requestIdCounter beforeEach(async () => { - jest.clearAllMocks() - refetchSpy = jest.spyOn(wrapper.vm.$apollo.queries.ListAllContributions, 'refetch') + requestIdCounter = wrapper.vm.$apollo.queries.ListAllContributions.observer.queryId await wrapper.find('a[data-test="confirmed"]').trigger('click') }) + it('refetches contributions', () => { + expect(wrapper.vm.$apollo.queries.ListAllContributions.observer.queryId).toBe( + `${Number(requestIdCounter) + 1}`, + ) + }) + 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') + requestIdCounter = wrapper.vm.$apollo.queries.ListAllContributions.observer.queryId await wrapper.find('a[data-test="open"]').trigger('click') }) + it('refetches contributions', () => { + expect(wrapper.vm.$apollo.queries.ListAllContributions.observer.queryId).toBe( + `${Number(requestIdCounter) + 1}`, + ) + }) + 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() - }) }) describe('click tab "denied"', () => { beforeEach(async () => { - jest.clearAllMocks() - refetchSpy = jest.spyOn(wrapper.vm.$apollo.queries.ListAllContributions, 'refetch') + requestIdCounter = wrapper.vm.$apollo.queries.ListAllContributions.observer.queryId await wrapper.find('a[data-test="denied"]').trigger('click') }) + it('refetches contributions', () => { + expect(wrapper.vm.$apollo.queries.ListAllContributions.observer.queryId).toBe( + `${Number(requestIdCounter) + 1}`, + ) + }) + it('has statusFilter set to ["DENIED"]', () => { expect( wrapper.vm.$apollo.queries.ListAllContributions.observer.options.variables, ).toMatchObject({ statusFilter: ['DENIED'] }) }) + }) + + describe('click tab "deleted"', () => { + beforeEach(async () => { + requestIdCounter = wrapper.vm.$apollo.queries.ListAllContributions.observer.queryId + await wrapper.find('a[data-test="deleted"]').trigger('click') + }) it('refetches contributions', () => { - expect(refetchSpy).toBeCalled() + expect(wrapper.vm.$apollo.queries.ListAllContributions.observer.queryId).toBe( + `${Number(requestIdCounter) + 1}`, + ) + }) + + it('has statusFilter set to ["DELETED"]', () => { + expect( + wrapper.vm.$apollo.queries.ListAllContributions.observer.options.variables, + ).toMatchObject({ statusFilter: ['DELETED'] }) }) }) describe('click tab "all"', () => { beforeEach(async () => { - jest.clearAllMocks() - refetchSpy = jest.spyOn(wrapper.vm.$apollo.queries.ListAllContributions, 'refetch') + requestIdCounter = wrapper.vm.$apollo.queries.ListAllContributions.observer.queryId await wrapper.find('a[data-test="all"]').trigger('click') }) + it('refetches contributions', () => { + expect(wrapper.vm.$apollo.queries.ListAllContributions.observer.queryId).toBe( + `${Number(requestIdCounter) + 1}`, + ) + }) it('has statusFilter set to ["IN_PROGRESS", "PENDING", "CONFIRMED", "DENIED", "DELETED"]', () => { expect( wrapper.vm.$apollo.queries.ListAllContributions.observer.options.variables, @@ -399,10 +425,6 @@ describe('CreationConfirm', () => { statusFilter: ['IN_PROGRESS', 'PENDING', 'CONFIRMED', 'DENIED', 'DELETED'], }) }) - - it('refetches contributions', () => { - expect(refetchSpy).toBeCalled() - }) }) }) }) @@ -412,10 +434,20 @@ describe('CreationConfirm', () => { await wrapper.findComponent({ name: 'OpenCreationsTable' }).vm.$emit('update-state', 2) }) - it.skip('updates the status', () => { + it('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') }) }) + + describe('unknown variant', () => { + beforeEach(async () => { + await wrapper.setData({ variant: 'unknown' }) + }) + + it('has overlay icon "info"', () => { + expect(wrapper.vm.overlayIcon).toBe('info') + }) + }) }) }) diff --git a/admin/src/pages/CreationConfirm.vue b/admin/src/pages/CreationConfirm.vue index 3d63aa735..c0b829e30 100644 --- a/admin/src/pages/CreationConfirm.vue +++ b/admin/src/pages/CreationConfirm.vue @@ -73,7 +73,7 @@