test Info Page

This commit is contained in:
Moriz Wahl 2022-08-17 16:21:14 +02:00
parent 35cb3176e3
commit 85e36a9cae
2 changed files with 83 additions and 30 deletions

View File

@ -1,10 +1,13 @@
import { mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import InfoStatistic from './InfoStatistic' import InfoStatistic from './InfoStatistic'
import { toastErrorSpy } from '../../test/testSetup' import { toastErrorSpy } from '../../test/testSetup'
import { listContributionLinks, communityStatistics, searchAdminUsers } from '@/graphql/queries'
const localVue = global.localVue const localVue = global.localVue
const apolloQueryMock = jest.fn().mockResolvedValue({ const apolloQueryMock = jest
.fn()
.mockResolvedValueOnce({
data: { data: {
listContributionLinks: { listContributionLinks: {
count: 2, count: 2,
@ -26,7 +29,32 @@ const apolloQueryMock = jest.fn().mockResolvedValue({
], ],
}, },
}, },
}) })
.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', () => { describe('InfoStatistic', () => {
let wrapper let wrapper
@ -54,23 +82,48 @@ describe('InfoStatistic', () => {
expect(wrapper.find('div.info-statistic').exists()).toBe(true) expect(wrapper.find('div.info-statistic').exists()).toBe(true)
}) })
it('calls listUnconfirmedContributions', () => { it('calls listContributionLinks', () => {
expect(apolloQueryMock).toBeCalled() 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', () => { describe('error apolloQueryMock', () => {
beforeEach(async () => { beforeEach(async () => {
jest.clearAllMocks()
apolloQueryMock.mockRejectedValue({ apolloQueryMock.mockRejectedValue({
message: 'uups', message: 'uups',
}) })
wrapper = Wrapper() wrapper = Wrapper()
jest.clearAllMocks()
}) })
it('toasts the error message', () => { it('toasts three error messages', () => {
expect(toastErrorSpy).toBeCalledWith( expect(toastErrorSpy).toBeCalledWith(
'listContributionLinks has no result, use default data', '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')
}) })
}) })
}) })

View File

@ -104,7 +104,7 @@ export default {
} }
}, },
methods: { methods: {
async getContributionLinks() { getContributionLinks() {
this.$apollo this.$apollo
.query({ .query({
query: listContributionLinks, query: listContributionLinks,
@ -118,7 +118,7 @@ export default {
this.toastError('listContributionLinks has no result, use default data') this.toastError('listContributionLinks has no result, use default data')
}) })
}, },
async getAdminUsers() { getAdminUsers() {
this.$apollo this.$apollo
.query({ .query({
query: searchAdminUsers, query: searchAdminUsers,
@ -132,7 +132,7 @@ export default {
this.toastError('searchAdminUsers has no result, use default data') this.toastError('searchAdminUsers has no result, use default data')
}) })
}, },
async getCommunityStatistics() { getCommunityStatistics() {
this.$apollo this.$apollo
.query({ .query({
query: communityStatistics, query: communityStatistics,
@ -149,7 +149,7 @@ export default {
result.data.communityStatistics.totalGradidoUnbookedDecayed result.data.communityStatistics.totalGradidoUnbookedDecayed
}) })
.catch(() => { .catch(() => {
this.toastError('listContributionLinks has no result, use default data') this.toastError('communityStatistics has no result, use default data')
}) })
}, },
updateTransactions(pagination) { updateTransactions(pagination) {