Merge pull request #952 from gradido/clean-up-frontend-links

refactor: Clean Up Frontend Links, Tests and Logic
This commit is contained in:
Moriz Wahl 2021-10-08 19:42:27 +02:00 committed by GitHub
commit c868ac93b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 129 additions and 58 deletions

View File

@ -131,6 +131,20 @@ describe('router', () => {
}) })
}) })
describe('register-community', () => {
it('loads the "registerCommunity" component', async () => {
const component = await routes.find((r) => r.path === '/register-community').component()
expect(component.default.name).toBe('registerCommunity')
})
})
describe('select-community', () => {
it('loads the "registerSelectCommunity" component', async () => {
const component = await routes.find((r) => r.path === '/select-community').component()
expect(component.default.name).toBe('registerSelectCommunity')
})
})
describe('reset', () => { describe('reset', () => {
it('loads the "ResetPassword" component', async () => { it('loads the "ResetPassword" component', async () => {
const component = await routes.find((r) => r.path === '/reset/:optin').component() const component = await routes.find((r) => r.path === '/reset/:optin').component()

View File

@ -36,7 +36,7 @@ const routes = [
path: '/thx/:comingFrom', path: '/thx/:comingFrom',
component: () => import('../views/Pages/thx.vue'), component: () => import('../views/Pages/thx.vue'),
beforeEnter: (to, from, next) => { beforeEnter: (to, from, next) => {
const validFrom = ['password', 'reset', 'register', 'community'] const validFrom = ['password', 'reset', 'register']
if (!validFrom.includes(from.path.split('/')[1])) { if (!validFrom.includes(from.path.split('/')[1])) {
next({ path: '/login' }) next({ path: '/login' })
} else { } else {

View File

@ -124,10 +124,11 @@
<div class="text-center"> <div class="text-center">
<div class="text-center"> <div class="text-center">
<b-button class="test-button-back" variant="outline-secondary" to="/login"> <router-link class="test-button-back" to="/login">
{{ $t('back') }} <b-button variant="outline-secondary">
</b-button> {{ $t('back') }}
</b-button>
</router-link>
<b-button <b-button
:disabled="!(namesFilled && emailFilled && form.agree && !!language)" :disabled="!(namesFilled && emailFilled && form.agree && !!language)"
type="submit" type="submit"
@ -145,13 +146,11 @@
</b-row> </b-row>
</b-container> </b-container>
<div class="text-center pt-4"> <div class="text-center pt-4">
<b-button <router-link class="test-button-another-community" to="/select-community">
class="test-button-another-community" <b-button variant="outline-secondary">
variant="outline-secondary" {{ $t('community.choose-another-community') }}
to="/select-community" </b-button>
> </router-link>
{{ $t('community.choose-another-community') }}
</b-button>
</div> </div>
</div> </div>
</template> </template>

View File

@ -1,4 +1,4 @@
import { mount } from '@vue/test-utils' import { mount, RouterLinkStub } from '@vue/test-utils'
import RegisterCommunity from './RegisterCommunity' import RegisterCommunity from './RegisterCommunity'
const localVue = global.localVue const localVue = global.localVue
@ -23,8 +23,12 @@ describe('RegisterCommunity', () => {
}, },
} }
const stubs = {
RouterLink: RouterLinkStub,
}
const Wrapper = () => { const Wrapper = () => {
return mount(RegisterCommunity, { localVue, mocks }) return mount(RegisterCommunity, { localVue, mocks, stubs })
} }
describe('mount', () => { describe('mount', () => {

View File

@ -17,24 +17,30 @@
</b-row> </b-row>
<b-row> <b-row>
<b-col class="text-center"> <b-col class="text-center">
<b-button variant="outline-secondary" to="/register"> <router-link to="/register">
{{ $t('community.continue-to-registration') }} <b-button variant="outline-secondary">
</b-button> {{ $t('community.continue-to-registration') }}
</b-button>
</router-link>
</b-col> </b-col>
</b-row> </b-row>
<hr /> <hr />
<b-row> <b-row>
<b-col class="text-center"> <b-col class="text-center">
<b-button variant="outline-secondary" to="/select-community"> <router-link to="/select-community">
{{ $t('community.choose-another-community') }} <b-button variant="outline-secondary">
</b-button> {{ $t('community.choose-another-community') }}
</b-button>
</router-link>
</b-col> </b-col>
</b-row> </b-row>
<hr /> <hr />
<b-row> <b-row>
<b-col class="text-center"> <b-col class="text-center">
<b-button variant="outline-secondary" to="/login">{{ $t('back') }}</b-button> <router-link to="/login">
<b-button variant="outline-secondary">{{ $t('back') }}</b-button>
</router-link>
</b-col> </b-col>
</b-row> </b-row>
</div> </div>
@ -44,7 +50,7 @@
</template> </template>
<script> <script>
export default { export default {
name: 'registerSelectCommunity', name: 'registerCommunity',
data() { data() {
return {} return {}
}, },

View File

@ -1,26 +1,44 @@
import { mount } from '@vue/test-utils' import { mount, RouterLinkStub } from '@vue/test-utils'
import RegisterSelectCommunity from './RegisterSelectCommunity' import RegisterSelectCommunity from './RegisterSelectCommunity'
const localVue = global.localVue const localVue = global.localVue
const spinnerHideMock = jest.fn() const spinnerHideMock = jest.fn()
const spinnerMock = jest.fn(() => { const spinnerMock = jest.fn(() => {
return { return {
hide: spinnerHideMock, hide: spinnerHideMock,
} }
}) })
const apolloQueryMock = jest.fn().mockResolvedValue({ const apolloQueryMock = jest.fn().mockResolvedValue({
data: { data: {
communities: [ communities: [
{ {
name: 'test1', id: 1,
description: 'description 1', name: 'Gradido Entwicklung',
url: 'http://test.test/vue', description: 'Die lokale Entwicklungsumgebung von Gradido.',
url: 'http://localhost/vue/',
registerUrl: 'http://localhost/vue/register-community', registerUrl: 'http://localhost/vue/register-community',
}, },
{
id: 2,
name: 'Gradido Staging',
description: 'Der Testserver der Gradido-Akademie.',
url: 'https://stage1.gradido.net/vue/',
registerUrl: 'https://stage1.gradido.net/vue/register-community',
},
{
id: 3,
name: 'Gradido-Akademie',
description: 'Freies Institut für Wirtschaftsbionik.',
url: 'https://gradido.net',
registerUrl: 'https://gdd1.gradido.com/vue/register-community',
},
], ],
}, },
}) })
const toasterMock = jest.fn() const toasterMock = jest.fn()
describe('RegisterSelectCommunity', () => { describe('RegisterSelectCommunity', () => {
@ -52,8 +70,12 @@ describe('RegisterSelectCommunity', () => {
}, },
} }
const stubs = {
RouterLink: RouterLinkStub,
}
const Wrapper = () => { const Wrapper = () => {
return mount(RegisterSelectCommunity, { localVue, mocks }) return mount(RegisterSelectCommunity, { localVue, mocks, stubs })
} }
describe('mount', () => { describe('mount', () => {
@ -65,16 +87,40 @@ describe('RegisterSelectCommunity', () => {
expect(wrapper.find('div#register-select-community').exists()).toBeTruthy() expect(wrapper.find('div#register-select-community').exists()).toBeTruthy()
}) })
it('starts with a spinner', () => {
expect(spinnerMock).toBeCalled()
})
describe('calls the apollo query', () => { describe('calls the apollo query', () => {
beforeEach(() => { describe('server returns data', () => {
apolloQueryMock.mockRejectedValue({ it('calls the API to get the data', () => {
message: 'Wrong thing', expect(apolloQueryMock).toBeCalled()
})
it('shows two other communities', () => {
expect(wrapper.findAll('div.bg-secondary')).toHaveLength(2)
})
it('hides the spinner', () => {
expect(spinnerHideMock).toBeCalled()
}) })
wrapper = Wrapper()
}) })
it('toast an error', () => { describe('server response is error', () => {
expect(toasterMock).toBeCalledWith('Wrong thing') beforeEach(() => {
apolloQueryMock.mockRejectedValue({
message: 'Wrong thing',
})
wrapper = Wrapper()
})
it('toast an error', () => {
expect(toasterMock).toBeCalledWith('Wrong thing')
})
it('hides the spinner', () => {
expect(spinnerHideMock).toBeCalled()
})
}) })
}) })
}) })

View File

@ -4,28 +4,24 @@
<div class="pb-3">{{ $t('community.current-community') }}</div> <div class="pb-3">{{ $t('community.current-community') }}</div>
<div v-if="!pending"> <div v-if="!pending">
<div v-for="community in communities" :key="community.name"> <b-card class="border-0 mb-0" bg-variant="primary">
<b-card <b>{{ $store.state.community.name }}</b>
v-if="community.name === $store.state.community.name" <br />
class="border-0 mb-0" {{ $store.state.community.description }}
bg-variant="primary" <br />
> <router-link to="/register">
<b>{{ community.name }}</b> <b-button variant="outline-secondary">
<br />
{{ $store.state.community.description }}
<br />
<b-button variant="outline-secondary" to="/register">
{{ $t('community.continue-to-registration') }} {{ $t('community.continue-to-registration') }}
</b-button> </b-button>
</b-card> </router-link>
</div> </b-card>
<hr /> <hr />
<div>{{ $t('community.other-communities') }}</div> <div>{{ $t('community.other-communities') }}</div>
<div v-for="community in communities" :key="community.id" class="pb-3"> <div v-for="community in communities" :key="community.id" class="pb-3">
<b-card v-if="community.name != $store.state.community.name" bg-variant="secondary"> <b-card bg-variant="secondary">
<b>{{ community.name }}</b> <b>{{ community.name }}</b>
<br /> <br />
{{ community.description }} {{ community.description }}
@ -44,7 +40,9 @@
</div> </div>
<div class="text-center py-lg-4"> <div class="text-center py-lg-4">
<b-button variant="outline-secondary" to="/login">{{ $t('back') }}</b-button> <router-link to="/login">
<b-button variant="outline-secondary">{{ $t('back') }}</b-button>
</router-link>
</div> </div>
</b-container> </b-container>
</div> </div>
@ -71,7 +69,9 @@ export default {
fetchPolicy: 'network-only', fetchPolicy: 'network-only',
}) })
.then((response) => { .then((response) => {
this.communities = response.data.communities this.communities = response.data.communities.filter(
(c) => c.name !== this.$store.state.community.name,
)
}) })
.catch((error) => { .catch((error) => {
this.$toasted.error(error.message) this.$toasted.error(error.message)

View File

@ -37,6 +37,7 @@ describe('UserCard_CoinAnimation', () => {
describe('mount', () => { describe('mount', () => {
beforeEach(() => { beforeEach(() => {
jest.clearAllMocks()
wrapper = Wrapper() wrapper = Wrapper()
}) })
@ -50,7 +51,7 @@ describe('UserCard_CoinAnimation', () => {
describe('enable with success', () => { describe('enable with success', () => {
beforeEach(async () => { beforeEach(async () => {
mocks.$store.state.coinanimation = false await wrapper.setData({ CoinAnimationStatus: false })
mockAPIcall.mockResolvedValue({ mockAPIcall.mockResolvedValue({
data: { data: {
updateUserInfos: { updateUserInfos: {
@ -58,7 +59,7 @@ describe('UserCard_CoinAnimation', () => {
}, },
}, },
}) })
await wrapper.find('input').trigger('change') await wrapper.find('input').setChecked()
}) })
it('calls the updateUserInfos mutation', () => { it('calls the updateUserInfos mutation', () => {
@ -81,7 +82,7 @@ describe('UserCard_CoinAnimation', () => {
describe('disable with success', () => { describe('disable with success', () => {
beforeEach(async () => { beforeEach(async () => {
mocks.$store.state.coinanimation = true await wrapper.setData({ CoinAnimationStatus: true })
mockAPIcall.mockResolvedValue({ mockAPIcall.mockResolvedValue({
data: { data: {
updateUserInfos: { updateUserInfos: {
@ -89,7 +90,7 @@ describe('UserCard_CoinAnimation', () => {
}, },
}, },
}) })
wrapper.find('input').trigger('change') await wrapper.find('input').setChecked(false)
}) })
it('calls the subscribe mutation', () => { it('calls the subscribe mutation', () => {

View File

@ -38,6 +38,7 @@ describe('UserCard_Newsletter', () => {
describe('mount', () => { describe('mount', () => {
beforeEach(() => { beforeEach(() => {
jest.clearAllMocks()
wrapper = Wrapper() wrapper = Wrapper()
}) })
@ -51,13 +52,13 @@ describe('UserCard_Newsletter', () => {
describe('unsubscribe with success', () => { describe('unsubscribe with success', () => {
beforeEach(async () => { beforeEach(async () => {
await wrapper.setData({ newsletterState: false }) await wrapper.setData({ newsletterState: true })
mockAPIcall.mockResolvedValue({ mockAPIcall.mockResolvedValue({
data: { data: {
unsubscribeNewsletter: true, unsubscribeNewsletter: true,
}, },
}) })
await wrapper.find('input').trigger('change') await wrapper.find('input').setChecked(false)
}) })
it('calls the unsubscribe mutation', () => { it('calls the unsubscribe mutation', () => {
@ -80,13 +81,13 @@ describe('UserCard_Newsletter', () => {
describe('subscribe with success', () => { describe('subscribe with success', () => {
beforeEach(async () => { beforeEach(async () => {
await wrapper.setData({ newsletterState: true }) await wrapper.setData({ newsletterState: false })
mockAPIcall.mockResolvedValue({ mockAPIcall.mockResolvedValue({
data: { data: {
subscribeNewsletter: true, subscribeNewsletter: true,
}, },
}) })
wrapper.find('input').trigger('change') await wrapper.find('input').setChecked()
}) })
it('calls the subscribe mutation', () => { it('calls the subscribe mutation', () => {
@ -104,7 +105,7 @@ describe('UserCard_Newsletter', () => {
}) })
it('toasts a success message', () => { it('toasts a success message', () => {
expect(toastSuccessMock).toBeCalledWith('settings.newsletter.newsletterFalse') expect(toastSuccessMock).toBeCalledWith('settings.newsletter.newsletterTrue')
}) })
}) })