asyncData terms-and-conditions-confirm.spec.js

This commit is contained in:
Ulf Gebhardt 2021-04-26 03:57:44 +02:00
parent 8a53bda51c
commit d3d0fd053d
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD

View File

@ -1,3 +1,4 @@
import Vuex from 'vuex'
import { config, mount } from '@vue/test-utils'
import TermsAndConditionsConfirm from './terms-and-conditions-confirm.vue'
import VueMeta from 'vue-meta'
@ -10,31 +11,64 @@ config.stubs['nuxt-link'] = '<span class="nuxt-link"><slot /></span>'
describe('terms-and-conditions-confirm.vue', () => {
let wrapper
let mocks
let store
let asyncData
let tosAgree
let redirect
beforeEach(() => {
mocks = {
$t: (t) => t,
}
asyncData = false
tosAgree = false
redirect = jest.fn()
})
describe('mount', () => {
const Wrapper = () => {
const Wrapper = async () => {
store = new Vuex.Store({
getters: {
'auth/termsAndConditionsAgreed': () => tosAgree,
},
})
if (asyncData) {
const data = TermsAndConditionsConfirm.data ? TermsAndConditionsConfirm.data() : {}
const aData = await TermsAndConditionsConfirm.asyncData({
store,
redirect,
})
TermsAndConditionsConfirm.data = function () {
return { ...data, ...aData }
}
}
return mount(TermsAndConditionsConfirm, {
mocks,
localVue,
})
}
beforeEach(() => {
wrapper = Wrapper()
})
it('renders', () => {
it('renders', async () => {
wrapper = await Wrapper()
expect(wrapper.is('div')).toBe(true)
})
it('has correct <head> content', () => {
it('has correct <head> content', async () => {
wrapper = await Wrapper()
expect(wrapper.vm.$metaInfo.title).toBe('termsAndConditions.newTermsAndConditions')
})
it('renders with asyncData and did not agree to TOS', async () => {
asyncData = true
wrapper = await Wrapper()
expect(redirect).not.toHaveBeenCalled()
})
it('renders with asyncData and did agree to TOS', async () => {
asyncData = true
tosAgree = true
wrapper = await Wrapper()
expect(redirect).toBeCalledWith('/')
})
})
})