fix unit tests, rename state to status where possible

This commit is contained in:
Moriz Wahl 2023-02-06 17:54:14 +01:00
parent 0f12c33e1c
commit 192e43888c
2 changed files with 78 additions and 35 deletions

View File

@ -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('actions in overlay', () => {
describe('delete creation', () => { describe('delete creation', () => {
beforeEach(async () => { beforeEach(async () => {
@ -339,39 +329,92 @@ describe('CreationConfirm', () => {
}) })
}) })
describe('filter tabs', () => {
describe('click tab "confirmed"', () => { describe('click tab "confirmed"', () => {
beforeEach(() => { let refetchSpy
beforeEach(async () => { beforeEach(async () => {
jest.clearAllMocks() jest.clearAllMocks()
// console.log('click tab "confirmed"', wrapper.vm.statusFilter) refetchSpy = jest.spyOn(wrapper.vm.$apollo.queries.ListAllContributions, 'refetch')
// console.log(wrapper.find('a[data-test="confirmed"]').html())
await wrapper.find('a[data-test="confirmed"]').trigger('click') await wrapper.find('a[data-test="confirmed"]').trigger('click')
// await wrapper.setData({ tabIndex: 1 })
await wrapper.vm.$nextTick()
}) })
it('has statusFilter set to ["CONFIRMED"]', () => {
expect(
wrapper.vm.$apollo.queries.ListAllContributions.observer.options.variables,
).toMatchObject({ statusFilter: ['CONFIRMED'] })
}) })
it('has statusFilter ["CONFIRMED"]', () => {
// console.log('click tab "confirmed2"', wrapper.vm.statusFilter) it('refetches contributions', () => {
// console.log(wrapper.find('[data-test="confirmed"]').html()) expect(refetchSpy).toBeCalled()
expect(wrapper.vm.statusFilter).toEqual(['CONFIRMED'])
})
it('list all Contributions confirmed', () => {
expect(wrapper.vm.$apollo.queries.ListAllContributions).toBeTruthy()
}) })
describe('click tab "open"', () => { describe('click tab "open"', () => {
beforeEach(() => {
beforeEach(async () => { beforeEach(async () => {
jest.clearAllMocks()
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')
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('list all Contributions open', () => {
expect(wrapper.vm.$apollo.queries.ListAllContributions).toBeTruthy() it('has statusFilter set to ["DENIED"]', () => {
expect(
wrapper.vm.$apollo.queries.ListAllContributions.observer.options.variables,
).toMatchObject({ statusFilter: ['DENIED'] })
}) })
it('refetches contributions', () => {
expect(refetchSpy).toBeCalled()
})
})
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')
}) })
}) })
}) })

View File

@ -31,7 +31,7 @@
:items="items" :items="items"
:fields="fields" :fields="fields"
@show-overlay="showOverlay" @show-overlay="showOverlay"
@update-state="updateState" @update-state="updateStatus"
@update-contributions="$apollo.queries.AllContributions.refetch()" @update-contributions="$apollo.queries.AllContributions.refetch()"
/> />
@ -83,7 +83,7 @@ const FILTER_TAB_MAP = [
['CONFIRMED'], ['CONFIRMED'],
['DENIED'], ['DENIED'],
['DELETED'], ['DELETED'],
['IN_PROGRESS', 'PENDING', 'CONFIRMED', 'DENIED'], ['IN_PROGRESS', 'PENDING', 'CONFIRMED', 'DENIED', 'DELETED'],
] ]
export default { export default {
@ -168,7 +168,7 @@ export default {
this.item = item this.item = item
this.variant = variant this.variant = variant
}, },
updateState(id) { updateStatus(id) {
this.items.find((obj) => obj.id === id).messagesCount++ this.items.find((obj) => obj.id === id).messagesCount++
this.items.find((obj) => obj.id === id).state = 'IN_PROGRESS' this.items.find((obj) => obj.id === id).state = 'IN_PROGRESS'
}, },