diff --git a/frontend/src/pages/InfoStatistic.spec.js b/frontend/src/pages/InfoStatistic.spec.js index ade3a0340..6adcf77d4 100644 --- a/frontend/src/pages/InfoStatistic.spec.js +++ b/frontend/src/pages/InfoStatistic.spec.js @@ -1,32 +1,60 @@ import { mount } from '@vue/test-utils' import InfoStatistic from './InfoStatistic' import { toastErrorSpy } from '../../test/testSetup' +import { listContributionLinks, communityStatistics, searchAdminUsers } from '@/graphql/queries' const localVue = global.localVue -const apolloQueryMock = jest.fn().mockResolvedValue({ - data: { - listContributionLinks: { - count: 2, - links: [ - { - id: 1, - amount: 200, - name: 'Dokumenta 2017', - memo: 'Vielen Dank für deinen Besuch bei der Dokumenta 2017', - cycle: 'ONCE', - }, - { - id: 2, - amount: 200, - name: 'Dokumenta 2022', - memo: 'Vielen Dank für deinen Besuch bei der Dokumenta 2022', - cycle: 'ONCE', - }, - ], +const apolloQueryMock = jest + .fn() + .mockResolvedValueOnce({ + data: { + listContributionLinks: { + count: 2, + links: [ + { + id: 1, + amount: 200, + name: 'Dokumenta 2017', + memo: 'Vielen Dank für deinen Besuch bei der Dokumenta 2017', + cycle: 'ONCE', + }, + { + id: 2, + amount: 200, + name: 'Dokumenta 2022', + memo: 'Vielen Dank für deinen Besuch bei der Dokumenta 2022', + cycle: 'ONCE', + }, + ], + }, }, - }, -}) + }) + .mockResolvedValueOnce({ + data: { + searchAdminUsers: { + userCount: 2, + userList: [ + { firstName: 'Peter', lastName: 'Lustig' }, + { firstName: 'Super', lastName: 'Admin' }, + ], + }, + }, + }) + .mockResolvedValueOnce({ + data: { + communityStatistics: { + totalUsers: 3113, + activeUsers: 1057, + deletedUsers: 35, + totalGradidoCreated: '4083774.05000000000000000000', + totalGradidoDecayed: '-1062639.13634129622923372197', + totalGradidoAvailable: '2513565.869444365732411569', + totalGradidoUnbookedDecayed: '-500474.6738366222166261272', + }, + }, + }) + .mockResolvedValue('default') describe('InfoStatistic', () => { let wrapper @@ -54,23 +82,48 @@ describe('InfoStatistic', () => { expect(wrapper.find('div.info-statistic').exists()).toBe(true) }) - it('calls listUnconfirmedContributions', () => { - expect(apolloQueryMock).toBeCalled() + it('calls listContributionLinks', () => { + expect(apolloQueryMock).toBeCalledWith( + expect.objectContaining({ + query: listContributionLinks, + fetchPolicy: 'network-only', + }), + ) + }) + + it('calls searchAdminUsers', () => { + expect(apolloQueryMock).toBeCalledWith( + expect.objectContaining({ + query: searchAdminUsers, + fetchPolicy: 'network-only', + }), + ) + }) + + it('calls getCommunityStatistics', () => { + expect(apolloQueryMock).toBeCalledWith( + expect.objectContaining({ + query: communityStatistics, + fetchPolicy: 'network-only', + }), + ) }) describe('error apolloQueryMock', () => { beforeEach(async () => { + jest.clearAllMocks() apolloQueryMock.mockRejectedValue({ message: 'uups', }) wrapper = Wrapper() - jest.clearAllMocks() }) - it('toasts the error message', () => { + it('toasts three error messages', () => { expect(toastErrorSpy).toBeCalledWith( 'listContributionLinks has no result, use default data', ) + expect(toastErrorSpy).toBeCalledWith('searchAdminUsers has no result, use default data') + expect(toastErrorSpy).toBeCalledWith('communityStatistics has no result, use default data') }) }) }) diff --git a/frontend/src/pages/InfoStatistic.vue b/frontend/src/pages/InfoStatistic.vue index 227f2536a..06a847c3a 100644 --- a/frontend/src/pages/InfoStatistic.vue +++ b/frontend/src/pages/InfoStatistic.vue @@ -104,7 +104,7 @@ export default { } }, methods: { - async getContributionLinks() { + getContributionLinks() { this.$apollo .query({ query: listContributionLinks, @@ -118,7 +118,7 @@ export default { this.toastError('listContributionLinks has no result, use default data') }) }, - async getAdminUsers() { + getAdminUsers() { this.$apollo .query({ query: searchAdminUsers, @@ -132,7 +132,7 @@ export default { this.toastError('searchAdminUsers has no result, use default data') }) }, - async getCommunityStatistics() { + getCommunityStatistics() { this.$apollo .query({ query: communityStatistics, @@ -149,7 +149,7 @@ export default { result.data.communityStatistics.totalGradidoUnbookedDecayed }) .catch(() => { - this.toastError('listContributionLinks has no result, use default data') + this.toastError('communityStatistics has no result, use default data') }) }, updateTransactions(pagination) {