diff --git a/frontend/src/components/Template/RightSide/ContributionInfo.spec.js b/frontend/src/layouts/templates/CommunityTemplate.spec.js similarity index 85% rename from frontend/src/components/Template/RightSide/ContributionInfo.spec.js rename to frontend/src/layouts/templates/CommunityTemplate.spec.js index f4547e42d..cd4b598ef 100644 --- a/frontend/src/components/Template/RightSide/ContributionInfo.spec.js +++ b/frontend/src/layouts/templates/CommunityTemplate.spec.js @@ -1,5 +1,5 @@ import { mount } from '@vue/test-utils' -import ContributionInfo from './ContributionInfo' +import CommunityTemplate from './CommunityTemplate' const localVue = global.localVue @@ -10,15 +10,17 @@ const mocks = { $t: jest.fn((t) => t), $d: jest.fn((d) => d), $route: { - hash: '', + params: { + tab: 'contribute', + }, }, } -describe('ContributionInfo', () => { +describe('CommunityTemplate', () => { let wrapper const Wrapper = () => { - return mount(ContributionInfo, { localVue, mocks }) + return mount(CommunityTemplate, { localVue, mocks }) } describe('mount', () => { beforeEach(() => { @@ -29,9 +31,9 @@ describe('ContributionInfo', () => { expect(wrapper.findComponent({ name: 'ContributionInfo' }).exists()).toBe(true) }) - describe('mounted with hash #my', () => { + describe('mounted with parameter contributions', () => { beforeEach(() => { - mocks.$route.hash = '#my' + mocks.$route.params.tab = 'contributions' }) 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(() => { - mocks.$route.hash = '#all' + mocks.$route.params.tab = '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(() => { - mocks.$route.hash = '#edit' + mocks.$route.params.tab = 'contribute' }) it('has a header related to "the community"', () => { diff --git a/frontend/src/pages/Community.spec.js b/frontend/src/pages/Community.spec.js index b4d1677df..28d742fe9 100644 --- a/frontend/src/pages/Community.spec.js +++ b/frontend/src/pages/Community.spec.js @@ -215,7 +215,9 @@ describe('Community', () => { push: routerPushMock, }, $route: { - hash: '#edit', + params: { + tab: 'contribute', + }, }, } @@ -260,7 +262,11 @@ describe('Community', () => { }) 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', () => { @@ -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('with error', () => { const now = new Date().toISOString() @@ -491,6 +487,10 @@ describe('Community', () => { it('sets tab index back to 0', () => { expect(wrapper.vm.tabIndex).toBe(0) }) + + it('pushes contribute parameter to router', () => { + expect(routerPushMock).toBeCalledWith({ params: { tab: 'contribute' } }) + }) }) describe('update list all contributions', () => { diff --git a/frontend/src/pages/Community.vue b/frontend/src/pages/Community.vue index cadf49ffe..af626f400 100644 --- a/frontend/src/pages/Community.vue +++ b/frontend/src/pages/Community.vue @@ -161,7 +161,7 @@ export default { }, }, watch: { - '$route.params.tab'(tab) { + '$route.params.tab'() { this.updateTabIndex() }, }, @@ -282,6 +282,7 @@ export default { this.form.amount = item.amount this.form.hours = item.amount / 20 this.updateAmount = item.amount + this.tabIndex = 0 this.$router.push({ params: { tab: 'contribute' } }) }, updateTransactions(pagination) { diff --git a/frontend/src/routes/router.test.js b/frontend/src/routes/router.test.js index dff97d160..ed5d274c3 100644 --- a/frontend/src/routes/router.test.js +++ b/frontend/src/routes/router.test.js @@ -49,8 +49,8 @@ describe('router', () => { expect(routes.find((r) => r.path === '/').redirect()).toEqual({ path: '/login' }) }) - it('has sixteen routes defined', () => { - expect(routes).toHaveLength(18) + it('has 19 routes defined', () => { + expect(routes).toHaveLength(19) }) 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', () => { expect(routes.find((r) => r.path === '/community').meta.requiresAuth).toBeTruthy() })