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

Added first tests for AutoLogout component

parent 263c8c53
No related branches found
No related tags found
No related merge requests found
......@@ -15,10 +15,12 @@
</v-card-text>
<v-card-actions>
<v-btn flat color="grey lighten-0"
id="logout-btn"
@click="logout"
>Logout now</v-btn>
<v-spacer/>
<v-btn flat color="blue darken-2"
id="continue-btn"
@click="continueWork"
>Continue</v-btn>
</v-card-actions>
......
import Vuex from 'vuex'
import { mount, createLocalVue } from '@vue/test-utils'
import AutoLogout from '../../src/components/AutoLogout.vue'
import AutoLogout from '@/components/AutoLogout.vue'
import sinon from 'sinon'
import { Authentication } from '@/store/modules/authentication'
import chai from 'chai'
chai.should()
const localVue = createLocalVue();
localVue.use(Vuex);
let localVue = createLocalVue()
localVue.use(Vuex)
describe('Auto Logout Unit Tests', () => {
let store: any = null
let consoleTemp = {
warn: console.warn,
error: console.error,
}
before(function() {
console.warn = function() {}
console.error = function() {}
})
after(function() {
console.warn = consoleTemp.warn
console.error = consoleTemp.error
})
beforeEach(() => {
store = new Vuex.Store({
state: {}
})
})
afterEach(() => {
sinon.restore()
})
it('should be hidden by default', () => {
let store = new Vuex.Store({})
let wrapper = mount(AutoLogout, { localVue, store })
let wrapper = mount(AutoLogout, { localVue: localVue, store })
wrapper.vm.$data.logoutDialog.should.equal(false)
wrapper.html().should.contain('<div class="v-dialog v-dialog--persistent" style="max-width: 30%; display: none;">')
})
it('should be visible when logoutDialog is set to true', () => {
let store = new Vuex.Store({})
let wrapper = mount(AutoLogout, { 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%;">')
})
it('should get a refresh token from the server when user clicks button', () => {
let spy = sinon.spy()
sinon.replace(Authentication, 'refreshJWT', spy)
let store = new Vuex.Store({})
let wrapper = mount(AutoLogout, { localVue, store })
// @ts-ignore
wrapper.vm.continueWork()
wrapper.find('#continue-btn').trigger('click')
spy.called.should.equal(true)
})
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment