Skip to content
Snippets Groups Projects
Commit 688a77d1 authored by Dominik Seeger's avatar Dominik Seeger Committed by robinwilliam.hundt
Browse files

added tests for AutoLogout component

parent f15d6b21
Branches
Tags
1 merge request!128Merge improve testing
......@@ -3,6 +3,8 @@ import { mount, createLocalVue } from '@vue/test-utils'
import AutoLogout from '@/components/AutoLogout.vue'
import sinon from 'sinon'
import { Authentication } from '@/store/modules/authentication'
import { SET_LAST_INTERACTION } from '@/store/mutations'
import { lastInteraction } from '@/store/plugins/lastInteractionPlugin'
import chai from 'chai'
chai.should()
......@@ -28,7 +30,7 @@ describe('Auto Logout Unit Tests', () => {
beforeEach(() => {
store = new Vuex.Store({
state: {}
plugins: [lastInteraction]
})
})
......@@ -43,7 +45,7 @@ describe('Auto Logout Unit Tests', () => {
})
it('should be visible when logoutDialog is set to true', () => {
let store = new Vuex.Store({})
let wrapper = mount(AutoLogout, { localVue, store })
let wrapper = mount(AutoLogout, { localVue: localVue, store })
wrapper.vm.$data.logoutDialog = true
wrapper.html().should.contain('<div class="v-dialog v-dialog--active v-dialog--persistent" style="max-width: 30%;">')
})
......@@ -51,8 +53,16 @@ describe('Auto Logout Unit Tests', () => {
let spy = sinon.spy()
sinon.replace(Authentication, 'refreshJWT', spy)
let store = new Vuex.Store({})
let wrapper = mount(AutoLogout, { localVue, store })
let wrapper = mount(AutoLogout, { localVue: localVue, store })
wrapper.find('#continue-btn').trigger('click')
spy.called.should.equal(true)
})
it('should automatically update jwt when it is older than 20% of its lifetime', () => {
// replace lastTokenRefreshTry and jwtTimeDelta from the store to emulate wanted behaviour
let wrapper = mount(AutoLogout, { localVue: localVue, store })
let spy = sinon.spy()
sinon.replaceGetter(Authentication.state, 'jwtTimeDelta', () => 10 * 1e3)
sinon.replaceGetter(Authentication.state, 'lastTokenRefreshTry', () => Date.now() - 2.1 * 1e3)
sinon.replace(Authentication, 'refreshJWT', spy)
})
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment