rename query file and query, update specs

This commit is contained in:
Moriz Wahl 2023-02-28 18:28:52 +01:00
parent 457cea4619
commit a811b2bf2d
5 changed files with 70 additions and 38 deletions

View File

@ -1,6 +1,6 @@
import gql from 'graphql-tag' import gql from 'graphql-tag'
export const listAllContributions = gql` export const adminListAllContributions = gql`
query ( query (
$currentPage: Int = 1 $currentPage: Int = 1
$pageSize: Int = 25 $pageSize: Int = 25

View File

@ -2,7 +2,7 @@ import { mount } from '@vue/test-utils'
import CreationConfirm from './CreationConfirm' import CreationConfirm from './CreationConfirm'
import { adminDeleteContribution } from '../graphql/adminDeleteContribution' import { adminDeleteContribution } from '../graphql/adminDeleteContribution'
import { denyContribution } from '../graphql/denyContribution' import { denyContribution } from '../graphql/denyContribution'
import { listAllContributions } from '../graphql/listAllContributions' import { adminListAllContributions } from '../graphql/adminListAllContributions'
import { confirmContribution } from '../graphql/confirmContribution' import { confirmContribution } from '../graphql/confirmContribution'
import { toastErrorSpy, toastSuccessSpy } from '../../test/testSetup' import { toastErrorSpy, toastSuccessSpy } from '../../test/testSetup'
import VueApollo from 'vue-apollo' import VueApollo from 'vue-apollo'
@ -38,7 +38,7 @@ const mocks = {
const defaultData = () => { const defaultData = () => {
return { return {
listAllContributions: { adminListAllContributions: {
contributionCount: 2, contributionCount: 2,
contributionList: [ contributionList: [
{ {
@ -97,7 +97,7 @@ describe('CreationConfirm', () => {
const confirmContributionMock = jest.fn() const confirmContributionMock = jest.fn()
mockClient.setRequestHandler( mockClient.setRequestHandler(
listAllContributions, adminListAllContributions,
jest jest
.fn() .fn()
.mockRejectedValueOnce({ message: 'Ouch!' }) .mockRejectedValueOnce({ message: 'Ouch!' })
@ -331,67 +331,93 @@ describe('CreationConfirm', () => {
describe('filter tabs', () => { describe('filter tabs', () => {
describe('click tab "confirmed"', () => { describe('click tab "confirmed"', () => {
let refetchSpy let requestIdCounter
beforeEach(async () => { beforeEach(async () => {
jest.clearAllMocks() requestIdCounter = wrapper.vm.$apollo.queries.ListAllContributions.observer.queryId
refetchSpy = jest.spyOn(wrapper.vm.$apollo.queries.ListAllContributions, 'refetch')
await wrapper.find('a[data-test="confirmed"]').trigger('click') 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"]', () => { it('has statusFilter set to ["CONFIRMED"]', () => {
expect( expect(
wrapper.vm.$apollo.queries.ListAllContributions.observer.options.variables, wrapper.vm.$apollo.queries.ListAllContributions.observer.options.variables,
).toMatchObject({ statusFilter: ['CONFIRMED'] }) ).toMatchObject({ statusFilter: ['CONFIRMED'] })
}) })
it('refetches contributions', () => {
expect(refetchSpy).toBeCalled()
})
describe('click tab "open"', () => { describe('click tab "open"', () => {
beforeEach(async () => { beforeEach(async () => {
jest.clearAllMocks() requestIdCounter = wrapper.vm.$apollo.queries.ListAllContributions.observer.queryId
refetchSpy = jest.spyOn(wrapper.vm.$apollo.queries.ListAllContributions, 'refetch')
await wrapper.find('a[data-test="open"]').trigger('click') 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"]', () => { it('has statusFilter set to ["IN_PROGRESS", "PENDING"]', () => {
expect( expect(
wrapper.vm.$apollo.queries.ListAllContributions.observer.options.variables, wrapper.vm.$apollo.queries.ListAllContributions.observer.options.variables,
).toMatchObject({ statusFilter: ['IN_PROGRESS', 'PENDING'] }) ).toMatchObject({ statusFilter: ['IN_PROGRESS', 'PENDING'] })
}) })
it('refetches contributions', () => {
expect(refetchSpy).toBeCalled()
})
}) })
describe('click tab "denied"', () => { describe('click tab "denied"', () => {
beforeEach(async () => { beforeEach(async () => {
jest.clearAllMocks() requestIdCounter = wrapper.vm.$apollo.queries.ListAllContributions.observer.queryId
refetchSpy = jest.spyOn(wrapper.vm.$apollo.queries.ListAllContributions, 'refetch')
await wrapper.find('a[data-test="denied"]').trigger('click') 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"]', () => { it('has statusFilter set to ["DENIED"]', () => {
expect( expect(
wrapper.vm.$apollo.queries.ListAllContributions.observer.options.variables, wrapper.vm.$apollo.queries.ListAllContributions.observer.options.variables,
).toMatchObject({ statusFilter: ['DENIED'] }) ).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', () => { 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"', () => { describe('click tab "all"', () => {
beforeEach(async () => { beforeEach(async () => {
jest.clearAllMocks() requestIdCounter = wrapper.vm.$apollo.queries.ListAllContributions.observer.queryId
refetchSpy = jest.spyOn(wrapper.vm.$apollo.queries.ListAllContributions, 'refetch')
await wrapper.find('a[data-test="all"]').trigger('click') 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"]', () => { it('has statusFilter set to ["IN_PROGRESS", "PENDING", "CONFIRMED", "DENIED", "DELETED"]', () => {
expect( expect(
wrapper.vm.$apollo.queries.ListAllContributions.observer.options.variables, wrapper.vm.$apollo.queries.ListAllContributions.observer.options.variables,
@ -399,10 +425,6 @@ describe('CreationConfirm', () => {
statusFilter: ['IN_PROGRESS', 'PENDING', 'CONFIRMED', 'DENIED', 'DELETED'], 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) 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).messagesCount).toBe(1)
expect(wrapper.vm.items.find((obj) => obj.id === 2).state).toBe('IN_PROGRESS') 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')
})
})
}) })
}) })

View File

@ -73,7 +73,7 @@
<script> <script>
import Overlay from '../components/Overlay' import Overlay from '../components/Overlay'
import OpenCreationsTable from '../components/Tables/OpenCreationsTable' import OpenCreationsTable from '../components/Tables/OpenCreationsTable'
import { listAllContributions } from '../graphql/listAllContributions' import { adminListAllContributions } from '../graphql/adminListAllContributions'
import { adminDeleteContribution } from '../graphql/adminDeleteContribution' import { adminDeleteContribution } from '../graphql/adminDeleteContribution'
import { confirmContribution } from '../graphql/confirmContribution' import { confirmContribution } from '../graphql/confirmContribution'
import { denyContribution } from '../graphql/denyContribution' import { denyContribution } from '../graphql/denyContribution'
@ -384,7 +384,7 @@ export default {
apollo: { apollo: {
ListAllContributions: { ListAllContributions: {
query() { query() {
return listAllContributions return adminListAllContributions
}, },
variables() { variables() {
return { return {

View File

@ -1,6 +1,6 @@
import { mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import Overview from './Overview' import Overview from './Overview'
import { listAllContributions } from '../graphql/listAllContributions' import { adminListAllContributions } from '../graphql/adminListAllContributions'
import VueApollo from 'vue-apollo' import VueApollo from 'vue-apollo'
import { createMockClient } from 'mock-apollo-client' import { createMockClient } from 'mock-apollo-client'
import { toastErrorSpy } from '../../test/testSetup' import { toastErrorSpy } from '../../test/testSetup'
@ -30,7 +30,7 @@ const mocks = {
const defaultData = () => { const defaultData = () => {
return { return {
listAllContributions: { adminListAllContributions: {
contributionCount: 2, contributionCount: 2,
contributionList: [ contributionList: [
{ {
@ -84,11 +84,11 @@ const defaultData = () => {
describe('Overview', () => { describe('Overview', () => {
let wrapper let wrapper
const listAllContributionsMock = jest.fn() const adminListAllContributionsMock = jest.fn()
mockClient.setRequestHandler( mockClient.setRequestHandler(
listAllContributions, adminListAllContributions,
listAllContributionsMock adminListAllContributionsMock
.mockRejectedValueOnce({ message: 'Ouch!' }) .mockRejectedValueOnce({ message: 'Ouch!' })
.mockResolvedValue({ data: defaultData() }), .mockResolvedValue({ data: defaultData() }),
) )
@ -109,8 +109,8 @@ describe('Overview', () => {
}) })
}) })
it('calls the listAllContributions query', () => { it('calls the adminListAllContributions query', () => {
expect(listAllContributionsMock).toBeCalledWith({ expect(adminListAllContributionsMock).toBeCalledWith({
currentPage: 1, currentPage: 1,
order: 'DESC', order: 'DESC',
pageSize: 25, pageSize: 25,

View File

@ -31,7 +31,7 @@
</div> </div>
</template> </template>
<script> <script>
import { listAllContributions } from '../graphql/listAllContributions' import { adminListAllContributions } from '../graphql/adminListAllContributions'
export default { export default {
name: 'overview', name: 'overview',
@ -43,7 +43,7 @@ export default {
apollo: { apollo: {
AllContributions: { AllContributions: {
query() { query() {
return listAllContributions return adminListAllContributions
}, },
variables() { variables() {
// may be at some point we need a pagination here // may be at some point we need a pagination here