1*6859203cSDerick Montagueimport { shallowMount, createLocalVue, createWrapper } from '@vue/test-utils'; 298059c92SSukanya Pandeyimport Vue from 'vue'; 3*6859203cSDerick Montagueimport Vuex from 'vuex'; 498059c92SSukanya Pandeyimport AppHeader from '@/components/AppHeader'; 5*6859203cSDerick Montague 6*6859203cSDerick Montague// Silencing warnings about undefined Bootsrap-vue components 7*6859203cSDerick MontagueVue.config.silent = true; 8*6859203cSDerick Montagueconst localVue = createLocalVue(); 9*6859203cSDerick MontaguelocalVue.use(Vuex); 1098059c92SSukanya Pandey 1198059c92SSukanya Pandeydescribe('AppHeader.vue', () => { 12*6859203cSDerick Montague const actions = { 13*6859203cSDerick Montague 'global/getHostStatus': sinon.spy(), 14*6859203cSDerick Montague 'eventLog/getEventLogData': sinon.spy() 15*6859203cSDerick Montague }; 1698059c92SSukanya Pandey 17*6859203cSDerick Montague const store = new Vuex.Store({ actions }); 18*6859203cSDerick Montague const wrapper = shallowMount(AppHeader, { 19*6859203cSDerick Montague store, 20*6859203cSDerick Montague localVue, 2198059c92SSukanya Pandey mocks: { 22*6859203cSDerick Montague $t: key => key 2398059c92SSukanya Pandey } 2498059c92SSukanya Pandey }); 2598059c92SSukanya Pandey 26*6859203cSDerick Montague // Reset spy for each test. Otherwise mutiple actions 27*6859203cSDerick Montague // are dispatched in each test 2898059c92SSukanya Pandey beforeEach(() => { 29*6859203cSDerick Montague store.dispatch = sinon.spy(); 3098059c92SSukanya Pandey }); 3198059c92SSukanya Pandey 32*6859203cSDerick Montague describe('UI', () => { 33*6859203cSDerick Montague it('should check if AppHeader exists', () => { 34*6859203cSDerick Montague expect(wrapper.exists()).to.be.true; 35*6859203cSDerick Montague }); 36*6859203cSDerick Montague 37*6859203cSDerick Montague it('should check if the skip navigation link exists', () => { 38*6859203cSDerick Montague expect(wrapper.get('.link-skip-nav').exists()).to.be.true; 39*6859203cSDerick Montague }); 40*6859203cSDerick Montague 41*6859203cSDerick Montague it('refresh button click should emit refresh event', async () => { 42*6859203cSDerick Montague wrapper.get('#app-header-refresh').trigger('click'); 43*6859203cSDerick Montague await wrapper.vm.$nextTick(); 44*6859203cSDerick Montague expect(wrapper.emitted().refresh).to.exist; 45*6859203cSDerick Montague }); 46*6859203cSDerick Montague 47*6859203cSDerick Montague it('nav-trigger button click should emit toggle:navigation event', async () => { 48*6859203cSDerick Montague const rootWrapper = createWrapper(wrapper.vm.$root); 49*6859203cSDerick Montague wrapper.get('#app-header-trigger').trigger('click'); 50*6859203cSDerick Montague await wrapper.vm.$nextTick(); 51*6859203cSDerick Montague expect(rootWrapper.emitted()['toggle:navigation']).to.exist; 52*6859203cSDerick Montague }); 53*6859203cSDerick Montague 54*6859203cSDerick Montague it('logout button should dispatch authentication/logout', async () => { 55*6859203cSDerick Montague wrapper.get('#app-header-logout').trigger('click'); 56*6859203cSDerick Montague await wrapper.vm.$nextTick(); 57*6859203cSDerick Montague expect(store.dispatch).calledWith('authentication/logout'); 5898059c92SSukanya Pandey }); 5998059c92SSukanya Pandey }); 6098059c92SSukanya Pandey 61*6859203cSDerick Montague describe('Methods', () => { 62*6859203cSDerick Montague it('getHostInfo should dispatch global/getHostStatus', () => { 6398059c92SSukanya Pandey wrapper.vm.getHostInfo(); 64*6859203cSDerick Montague expect(store.dispatch).calledWith('global/getHostStatus'); 6598059c92SSukanya Pandey }); 6698059c92SSukanya Pandey 67*6859203cSDerick Montague it('getEvents should dispatch eventLog/getEventLogData', () => { 6898059c92SSukanya Pandey wrapper.vm.getEvents(); 69*6859203cSDerick Montague expect(store.dispatch).calledWith('eventLog/getEventLogData'); 7098059c92SSukanya Pandey }); 7198059c92SSukanya Pandey }); 7298059c92SSukanya Pandey}); 73