mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
fix unit tests
This commit is contained in:
parent
9910e2e201
commit
625b4cb3d0
@ -1,5 +1,5 @@
|
|||||||
import { mount } from '@vue/test-utils'
|
import { mount } from '@vue/test-utils'
|
||||||
import ContributionInfo from './ContributionInfo'
|
import CommunityTemplate from './CommunityTemplate'
|
||||||
|
|
||||||
const localVue = global.localVue
|
const localVue = global.localVue
|
||||||
|
|
||||||
@ -10,15 +10,17 @@ const mocks = {
|
|||||||
$t: jest.fn((t) => t),
|
$t: jest.fn((t) => t),
|
||||||
$d: jest.fn((d) => d),
|
$d: jest.fn((d) => d),
|
||||||
$route: {
|
$route: {
|
||||||
hash: '',
|
params: {
|
||||||
|
tab: 'contribute',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('ContributionInfo', () => {
|
describe('CommunityTemplate', () => {
|
||||||
let wrapper
|
let wrapper
|
||||||
|
|
||||||
const Wrapper = () => {
|
const Wrapper = () => {
|
||||||
return mount(ContributionInfo, { localVue, mocks })
|
return mount(CommunityTemplate, { localVue, mocks })
|
||||||
}
|
}
|
||||||
describe('mount', () => {
|
describe('mount', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@ -29,9 +31,9 @@ describe('ContributionInfo', () => {
|
|||||||
expect(wrapper.findComponent({ name: 'ContributionInfo' }).exists()).toBe(true)
|
expect(wrapper.findComponent({ name: 'ContributionInfo' }).exists()).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('mounted with hash #my', () => {
|
describe('mounted with parameter contributions', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mocks.$route.hash = '#my'
|
mocks.$route.params.tab = 'contributions'
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has a header related to "my contribitions"', () => {
|
it('has a header related to "my contribitions"', () => {
|
||||||
@ -59,9 +61,9 @@ describe('ContributionInfo', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('mounted with hash #all', () => {
|
describe('mounted with parameter community', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mocks.$route.hash = '#all'
|
mocks.$route.params.tab = 'community'
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has a header related to "the community"', () => {
|
it('has a header related to "the community"', () => {
|
||||||
@ -89,9 +91,9 @@ describe('ContributionInfo', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('mounted with hash #edit', () => {
|
describe('mounted with parameter contribute', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mocks.$route.hash = '#edit'
|
mocks.$route.params.tab = 'contribute'
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has a header related to "the community"', () => {
|
it('has a header related to "the community"', () => {
|
||||||
@ -215,7 +215,9 @@ describe('Community', () => {
|
|||||||
push: routerPushMock,
|
push: routerPushMock,
|
||||||
},
|
},
|
||||||
$route: {
|
$route: {
|
||||||
hash: '#edit',
|
params: {
|
||||||
|
tab: 'contribute',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,7 +262,11 @@ describe('Community', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('check for correct tabIndex if state is "IN_PROGRESS" or not', () => {
|
it('check for correct tabIndex if state is "IN_PROGRESS" or not', () => {
|
||||||
expect(routerPushMock).toBeCalledWith({ path: '/community#my' })
|
expect(routerPushMock).toBeCalledWith({ params: { tab: 'contributions' } })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('sets tab index to 1', () => {
|
||||||
|
expect(wrapper.vm.tabIndex).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('toasts an info', () => {
|
it('toasts an info', () => {
|
||||||
@ -268,16 +274,6 @@ describe('Community', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('API calls after creation', () => {
|
|
||||||
it('has a DIV .community-page', () => {
|
|
||||||
expect(wrapper.find('div.community-page').exists()).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('emits update transactions', () => {
|
|
||||||
expect(wrapper.emitted('update-transactions')).toEqual([[0]])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('save contrubtion', () => {
|
describe('save contrubtion', () => {
|
||||||
describe('with error', () => {
|
describe('with error', () => {
|
||||||
const now = new Date().toISOString()
|
const now = new Date().toISOString()
|
||||||
@ -491,6 +487,10 @@ describe('Community', () => {
|
|||||||
it('sets tab index back to 0', () => {
|
it('sets tab index back to 0', () => {
|
||||||
expect(wrapper.vm.tabIndex).toBe(0)
|
expect(wrapper.vm.tabIndex).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('pushes contribute parameter to router', () => {
|
||||||
|
expect(routerPushMock).toBeCalledWith({ params: { tab: 'contribute' } })
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('update list all contributions', () => {
|
describe('update list all contributions', () => {
|
||||||
|
|||||||
@ -161,7 +161,7 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
'$route.params.tab'(tab) {
|
'$route.params.tab'() {
|
||||||
this.updateTabIndex()
|
this.updateTabIndex()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -282,6 +282,7 @@ export default {
|
|||||||
this.form.amount = item.amount
|
this.form.amount = item.amount
|
||||||
this.form.hours = item.amount / 20
|
this.form.hours = item.amount / 20
|
||||||
this.updateAmount = item.amount
|
this.updateAmount = item.amount
|
||||||
|
this.tabIndex = 0
|
||||||
this.$router.push({ params: { tab: 'contribute' } })
|
this.$router.push({ params: { tab: 'contribute' } })
|
||||||
},
|
},
|
||||||
updateTransactions(pagination) {
|
updateTransactions(pagination) {
|
||||||
|
|||||||
@ -49,8 +49,8 @@ describe('router', () => {
|
|||||||
expect(routes.find((r) => r.path === '/').redirect()).toEqual({ path: '/login' })
|
expect(routes.find((r) => r.path === '/').redirect()).toEqual({ path: '/login' })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has sixteen routes defined', () => {
|
it('has 19 routes defined', () => {
|
||||||
expect(routes).toHaveLength(18)
|
expect(routes).toHaveLength(19)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('overview', () => {
|
describe('overview', () => {
|
||||||
@ -75,7 +75,19 @@ describe('router', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('community', () => {
|
describe('community without tab parameter', () => {
|
||||||
|
it('requires authorization', () => {
|
||||||
|
expect(routes.find((r) => r.path === '/community').meta.requiresAuth).toBeTruthy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('redirects to contribute tab', async () => {
|
||||||
|
expect(routes.find((r) => r.path === '/community').redirect()).toEqual({
|
||||||
|
path: '/community/contribute',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('community with tab parameter', () => {
|
||||||
it('requires authorization', () => {
|
it('requires authorization', () => {
|
||||||
expect(routes.find((r) => r.path === '/community').meta.requiresAuth).toBeTruthy()
|
expect(routes.find((r) => r.path === '/community').meta.requiresAuth).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user