1import { shallowMount, createLocalVue, createWrapper } from '@vue/test-utils'; 2import Vue from 'vue'; 3import Vuex from 'vuex'; 4import AppHeader from '@/components/AppHeader'; 5 6// Silencing warnings about undefined Bootsrap-vue components 7Vue.config.silent = true; 8const localVue = createLocalVue(); 9localVue.use(Vuex); 10 11describe('AppHeader.vue', () => { 12 const actions = { 13 'global/getHostStatus': sinon.spy(), 14 'eventLog/getEventLogData': sinon.spy() 15 }; 16 17 const store = new Vuex.Store({ actions }); 18 const wrapper = shallowMount(AppHeader, { 19 store, 20 localVue, 21 mocks: { 22 $t: key => key 23 } 24 }); 25 26 // Reset spy for each test. Otherwise mutiple actions 27 // are dispatched in each test 28 beforeEach(() => { 29 store.dispatch = sinon.spy(); 30 }); 31 32 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'); 58 }); 59 }); 60 61 describe('Methods', () => { 62 it('getHostInfo should dispatch global/getHostStatus', () => { 63 wrapper.vm.getHostInfo(); 64 expect(store.dispatch).calledWith('global/getHostStatus'); 65 }); 66 67 it('getEvents should dispatch eventLog/getEventLogData', () => { 68 wrapper.vm.getEvents(); 69 expect(store.dispatch).calledWith('eventLog/getEventLogData'); 70 }); 71 }); 72}); 73