mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
complete testing for dashboard layout
This commit is contained in:
parent
242ec1989d
commit
c54a058039
@ -6,16 +6,10 @@ jest.useFakeTimers()
|
|||||||
|
|
||||||
const localVue = global.localVue
|
const localVue = global.localVue
|
||||||
|
|
||||||
const transitionStub = () => ({
|
|
||||||
render(h) {
|
|
||||||
return this.$options._renderChildren
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const storeDispatchMock = jest.fn()
|
const storeDispatchMock = jest.fn()
|
||||||
const storeCommitMock = jest.fn()
|
const storeCommitMock = jest.fn()
|
||||||
const routerPushMock = jest.fn()
|
const routerPushMock = jest.fn()
|
||||||
const logoutQueryMock = jest.fn().mockResolvedValue({
|
const apolloMock = jest.fn().mockResolvedValue({
|
||||||
data: {
|
data: {
|
||||||
logout: 'success',
|
logout: 'success',
|
||||||
},
|
},
|
||||||
@ -39,7 +33,7 @@ describe('DashboardLayoutGdd', () => {
|
|||||||
push: routerPushMock,
|
push: routerPushMock,
|
||||||
},
|
},
|
||||||
$apollo: {
|
$apollo: {
|
||||||
query: logoutQueryMock,
|
query: apolloMock,
|
||||||
},
|
},
|
||||||
$store: {
|
$store: {
|
||||||
state: {
|
state: {
|
||||||
@ -53,8 +47,7 @@ describe('DashboardLayoutGdd', () => {
|
|||||||
|
|
||||||
const stubs = {
|
const stubs = {
|
||||||
RouterLink: RouterLinkStub,
|
RouterLink: RouterLinkStub,
|
||||||
FadeTransition: transitionStub(),
|
RouterView: true,
|
||||||
RouterView: transitionStub(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Wrapper = () => {
|
const Wrapper = () => {
|
||||||
@ -136,7 +129,7 @@ describe('DashboardLayoutGdd', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('calls the API', async () => {
|
it('calls the API', async () => {
|
||||||
expect(logoutQueryMock).toBeCalledWith(
|
expect(apolloMock).toBeCalledWith(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
variables: { sessionId: 1 },
|
variables: { sessionId: 1 },
|
||||||
}),
|
}),
|
||||||
@ -154,11 +147,78 @@ describe('DashboardLayoutGdd', () => {
|
|||||||
|
|
||||||
describe('update balance', () => {
|
describe('update balance', () => {
|
||||||
it('updates the amount correctelly', async () => {
|
it('updates the amount correctelly', async () => {
|
||||||
await wrapper.setData({ balance: 0 })
|
await wrapper.findComponent({ ref: 'router-view' }).vm.$emit('update-balance', 5)
|
||||||
console.log(wrapper.html())
|
|
||||||
await wrapper.findComponent({ name: 'RouterView' }).vm.$emit('update-balance', 5)
|
|
||||||
await flushPromises()
|
await flushPromises()
|
||||||
expect(wrapper.vm.balance).toBe(5)
|
expect(wrapper.vm.balance).toBe(-5)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('update transactions', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
apolloMock.mockResolvedValue({
|
||||||
|
data: {
|
||||||
|
transactionList: {
|
||||||
|
gdtSum: 100,
|
||||||
|
count: 4,
|
||||||
|
balance: 1450,
|
||||||
|
decay: 1250,
|
||||||
|
transactions: ['transaction', 'transaction', 'transaction', 'transaction'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
await wrapper
|
||||||
|
.findComponent({ ref: 'router-view' })
|
||||||
|
.vm.$emit('update-transactions', { firstPage: 2, items: 5 })
|
||||||
|
await flushPromises()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('calls the API', () => {
|
||||||
|
expect(apolloMock).toBeCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
variables: {
|
||||||
|
sessionId: 1,
|
||||||
|
firstPage: 2,
|
||||||
|
items: 5,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('updates balance', () => {
|
||||||
|
expect(wrapper.vm.balance).toBe(1250)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('updates transactions', () => {
|
||||||
|
expect(wrapper.vm.transactions).toEqual([
|
||||||
|
'transaction',
|
||||||
|
'transaction',
|
||||||
|
'transaction',
|
||||||
|
'transaction',
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('updates GDT balance', () => {
|
||||||
|
expect(wrapper.vm.GdtBalance).toBe(100)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('updates transaction count', () => {
|
||||||
|
expect(wrapper.vm.transactionCount).toBe(4)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('update transactions returns error', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
apolloMock.mockRejectedValue({
|
||||||
|
message: 'error',
|
||||||
|
})
|
||||||
|
await wrapper
|
||||||
|
.findComponent({ ref: 'router-view' })
|
||||||
|
.vm.$emit('update-transactions', { firstPage: 2, items: 5 })
|
||||||
|
await flushPromises()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('sets pending to true', () => {
|
||||||
|
expect(wrapper.vm.pending).toBeTruthy()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -51,6 +51,7 @@
|
|||||||
<fade-transition :duration="200" origin="center top" mode="out-in">
|
<fade-transition :duration="200" origin="center top" mode="out-in">
|
||||||
<!-- your content here -->
|
<!-- your content here -->
|
||||||
<router-view
|
<router-view
|
||||||
|
ref="router-view"
|
||||||
:balance="balance"
|
:balance="balance"
|
||||||
:gdt-balance="GdtBalance"
|
:gdt-balance="GdtBalance"
|
||||||
:transactions="transactions"
|
:transactions="transactions"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user