blob: 52e45437df89039ef736737147e4787cbe1c37c0 [file] [log] [blame]
Derick Montague68592032020-04-04 14:02:34 -05001import { shallowMount, createLocalVue, createWrapper } from '@vue/test-utils';
Sukanya Pandey98059c92020-03-26 17:10:32 +05302import Vue from 'vue';
Derick Montague68592032020-04-04 14:02:34 -05003import Vuex from 'vuex';
Sukanya Pandey98059c92020-03-26 17:10:32 +05304import AppHeader from '@/components/AppHeader';
Derick Montague68592032020-04-04 14:02:34 -05005
6// Silencing warnings about undefined Bootsrap-vue components
7Vue.config.silent = true;
8const localVue = createLocalVue();
9localVue.use(Vuex);
Sukanya Pandey98059c92020-03-26 17:10:32 +053010
11describe('AppHeader.vue', () => {
Derick Montague68592032020-04-04 14:02:34 -050012 const actions = {
13 'global/getHostStatus': sinon.spy(),
14 'eventLog/getEventLogData': sinon.spy()
15 };
Sukanya Pandey98059c92020-03-26 17:10:32 +053016
Derick Montague68592032020-04-04 14:02:34 -050017 const store = new Vuex.Store({ actions });
18 const wrapper = shallowMount(AppHeader, {
19 store,
20 localVue,
Sukanya Pandey98059c92020-03-26 17:10:32 +053021 mocks: {
Derick Montague68592032020-04-04 14:02:34 -050022 $t: key => key
Sukanya Pandey98059c92020-03-26 17:10:32 +053023 }
24 });
25
Derick Montague68592032020-04-04 14:02:34 -050026 // Reset spy for each test. Otherwise mutiple actions
27 // are dispatched in each test
Sukanya Pandey98059c92020-03-26 17:10:32 +053028 beforeEach(() => {
Derick Montague68592032020-04-04 14:02:34 -050029 store.dispatch = sinon.spy();
Sukanya Pandey98059c92020-03-26 17:10:32 +053030 });
31
Derick Montague68592032020-04-04 14:02:34 -050032 describe('UI', () => {
33 it('should check if AppHeader exists', () => {
34 expect(wrapper.exists()).to.be.true;
35 });
36
37 it('should check if the skip navigation link exists', () => {
38 expect(wrapper.get('.link-skip-nav').exists()).to.be.true;
39 });
40
41 it('refresh button click should emit refresh event', async () => {
42 wrapper.get('#app-header-refresh').trigger('click');
43 await wrapper.vm.$nextTick();
44 expect(wrapper.emitted().refresh).to.exist;
45 });
46
47 it('nav-trigger button click should emit toggle:navigation event', async () => {
48 const rootWrapper = createWrapper(wrapper.vm.$root);
49 wrapper.get('#app-header-trigger').trigger('click');
50 await wrapper.vm.$nextTick();
51 expect(rootWrapper.emitted()['toggle:navigation']).to.exist;
52 });
53
54 it('logout button should dispatch authentication/logout', async () => {
55 wrapper.get('#app-header-logout').trigger('click');
56 await wrapper.vm.$nextTick();
57 expect(store.dispatch).calledWith('authentication/logout');
Sukanya Pandey98059c92020-03-26 17:10:32 +053058 });
59 });
60
Derick Montague68592032020-04-04 14:02:34 -050061 describe('Methods', () => {
62 it('getHostInfo should dispatch global/getHostStatus', () => {
Sukanya Pandey98059c92020-03-26 17:10:32 +053063 wrapper.vm.getHostInfo();
Derick Montague68592032020-04-04 14:02:34 -050064 expect(store.dispatch).calledWith('global/getHostStatus');
Sukanya Pandey98059c92020-03-26 17:10:32 +053065 });
66
Derick Montague68592032020-04-04 14:02:34 -050067 it('getEvents should dispatch eventLog/getEventLogData', () => {
Sukanya Pandey98059c92020-03-26 17:10:32 +053068 wrapper.vm.getEvents();
Derick Montague68592032020-04-04 14:02:34 -050069 expect(store.dispatch).calledWith('eventLog/getEventLogData');
Sukanya Pandey98059c92020-03-26 17:10:32 +053070 });
71 });
72});