mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
coverage login.spec.js
This commit is contained in:
parent
a71e864049
commit
5ffad4056b
@ -1,5 +1,5 @@
|
||||
import { config, mount } from '@vue/test-utils'
|
||||
import Vuex from 'vuex'
|
||||
import { config, mount } from '@vue/test-utils'
|
||||
import login from './login.vue'
|
||||
|
||||
const localVue = global.localVue
|
||||
@ -12,47 +12,46 @@ describe('Login.vue', () => {
|
||||
let store
|
||||
let mocks
|
||||
let wrapper
|
||||
let asyncData
|
||||
let tosVersion
|
||||
let redirect
|
||||
|
||||
|
||||
beforeEach(() => {
|
||||
mutations = {
|
||||
// 'posts/SELECT_ORDER': jest.fn(),
|
||||
}
|
||||
store = new Vuex.Store({
|
||||
getters: {
|
||||
/* 'posts/filter': () => ({}),
|
||||
'posts/orderOptions': () => () => [
|
||||
{
|
||||
key: 'store.posts.orderBy.oldest.label',
|
||||
label: 'store.posts.orderBy.oldest.label',
|
||||
icon: 'sort-amount-asc',
|
||||
value: 'createdAt_asc',
|
||||
},
|
||||
{
|
||||
key: 'store.posts.orderBy.newest.label',
|
||||
label: 'store.posts.orderBy.newest.label',
|
||||
icon: 'sort-amount-desc',
|
||||
value: 'createdAt_desc',
|
||||
},
|
||||
],
|
||||
'posts/selectedOrder': () => () => 'createdAt_desc',
|
||||
'posts/orderIcon': () => 'sort-amount-desc',
|
||||
'posts/orderBy': () => 'createdAt_desc',
|
||||
'auth/user': () => {
|
||||
return { id: 'u23' }
|
||||
}, */
|
||||
},
|
||||
mutations,
|
||||
})
|
||||
mocks = {
|
||||
$t: jest.fn(),
|
||||
$i18n: {
|
||||
locale: () => 'en',
|
||||
},
|
||||
}
|
||||
asyncData = false
|
||||
tosVersion = '0.0.0'
|
||||
redirect = jest.fn()
|
||||
})
|
||||
|
||||
describe('mount', () => {
|
||||
const Wrapper = () => {
|
||||
const Wrapper = async () => {
|
||||
store = new Vuex.Store({
|
||||
getters: {
|
||||
'auth/user': () => {
|
||||
return { termsAndConditionsAgreedVersion: tosVersion }
|
||||
},
|
||||
},
|
||||
mutations,
|
||||
})
|
||||
if (asyncData) {
|
||||
const data = login.data ? login.data() : {}
|
||||
const aData = await login.asyncData({
|
||||
store,
|
||||
redirect
|
||||
})
|
||||
login.data = function() {
|
||||
return { ...data, ...aData};
|
||||
};
|
||||
}
|
||||
return mount(login, {
|
||||
store,
|
||||
mocks,
|
||||
@ -60,12 +59,24 @@ describe('Login.vue', () => {
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = Wrapper()
|
||||
})
|
||||
|
||||
it('renders', () => {
|
||||
it('renders', async () => {
|
||||
wrapper = await Wrapper()
|
||||
expect(wrapper.findAll('.login-form')).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('renders with asyncData and wrong TOS Version', async () => {
|
||||
asyncData = true
|
||||
wrapper = await Wrapper()
|
||||
expect(redirect).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('renders with asyncData and correct TOS Version', async () => {
|
||||
asyncData = true
|
||||
tosVersion = '0.0.4'
|
||||
wrapper = await Wrapper()
|
||||
expect(redirect).toBeCalledWith('/')
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user