1ad2ceb6dSDerick Montagueimport { mount, createLocalVue, createWrapper } from '@vue/test-utils'; 298059c92SSukanya Pandeyimport Vue from 'vue'; 36859203cSDerick Montagueimport Vuex from 'vuex'; 498059c92SSukanya Pandeyimport AppHeader from '@/components/AppHeader'; 56859203cSDerick Montague 66859203cSDerick Montague// Silencing warnings about undefined Bootsrap-vue components 76859203cSDerick MontagueVue.config.silent = true; 86859203cSDerick Montagueconst localVue = createLocalVue(); 96859203cSDerick MontaguelocalVue.use(Vuex); 1098059c92SSukanya Pandey 1198059c92SSukanya Pandeydescribe('AppHeader.vue', () => { 126859203cSDerick Montague const actions = { 13ad2ceb6dSDerick Montague 'global/getHostStatus': jest.fn(), 14602e98aaSDerick Montague 'eventLog/getEventLogData': jest.fn(), 15f833c7e3SDerick Montague 'authentication/resetStoreState': jest.fn(), 166859203cSDerick Montague }; 1798059c92SSukanya Pandey 186859203cSDerick Montague const store = new Vuex.Store({ actions }); 19ad2ceb6dSDerick Montague const wrapper = mount(AppHeader, { 206859203cSDerick Montague store, 216859203cSDerick Montague localVue, 2298059c92SSukanya Pandey mocks: { 23602e98aaSDerick Montague $t: (key) => key, 24602e98aaSDerick Montague }, 2598059c92SSukanya Pandey }); 2698059c92SSukanya Pandey 27ad2ceb6dSDerick Montague // Reset dispatch between tests so that multiple 28ad2ceb6dSDerick Montague // actions are not dispatched for each test 2998059c92SSukanya Pandey beforeEach(() => { 30ad2ceb6dSDerick Montague store.dispatch = jest.fn(); 3198059c92SSukanya Pandey }); 3298059c92SSukanya Pandey 33ad2ceb6dSDerick Montague it('should exist', () => { 34ad2ceb6dSDerick Montague expect(wrapper.exists()).toBe(true); 356859203cSDerick Montague }); 366859203cSDerick Montague 37ad2ceb6dSDerick Montague it('should render correctly', () => { 38ad2ceb6dSDerick Montague expect(wrapper.element).toMatchSnapshot(); 396859203cSDerick Montague }); 406859203cSDerick Montague 416859203cSDerick Montague it('refresh button click should emit refresh event', async () => { 426859203cSDerick Montague wrapper.get('#app-header-refresh').trigger('click'); 436859203cSDerick Montague await wrapper.vm.$nextTick(); 44ad2ceb6dSDerick Montague expect(wrapper.emitted('refresh')).toBeTruthy(); 456859203cSDerick Montague }); 466859203cSDerick Montague 47*edb8a774SSukanya Pandey it('nav-trigger button click should emit toggle-navigation event', async () => { 486859203cSDerick Montague const rootWrapper = createWrapper(wrapper.vm.$root); 496859203cSDerick Montague wrapper.get('#app-header-trigger').trigger('click'); 506859203cSDerick Montague await wrapper.vm.$nextTick(); 51*edb8a774SSukanya Pandey expect(rootWrapper.emitted('toggle-navigation')).toBeTruthy(); 526859203cSDerick Montague }); 536859203cSDerick Montague 546859203cSDerick Montague it('logout button should dispatch authentication/logout', async () => { 5558a7a03cSDerick Montague wrapper.get('[data-test-id="appHeader-link-logout"]').trigger('click'); 566859203cSDerick Montague await wrapper.vm.$nextTick(); 57ad2ceb6dSDerick Montague expect(store.dispatch).toHaveBeenCalledTimes(1); 5898059c92SSukanya Pandey }); 5998059c92SSukanya Pandey 60ad2ceb6dSDerick Montague it('change:isNavigationOpen event should set isNavigationOpen prop to false', async () => { 61ad2ceb6dSDerick Montague const rootWrapper = createWrapper(wrapper.vm.$root); 62*edb8a774SSukanya Pandey rootWrapper.vm.$emit('change-is-navigation-open', false); 63ad2ceb6dSDerick Montague await rootWrapper.vm.$nextTick(); 64ad2ceb6dSDerick Montague expect(wrapper.vm.isNavigationOpen).toEqual(false); 65ad2ceb6dSDerick Montague }); 66ad2ceb6dSDerick Montague 67ad2ceb6dSDerick Montague describe('Created lifecycle hook', () => { 686859203cSDerick Montague it('getHostInfo should dispatch global/getHostStatus', () => { 6998059c92SSukanya Pandey wrapper.vm.getHostInfo(); 70ad2ceb6dSDerick Montague expect(store.dispatch).toHaveBeenCalledTimes(1); 7198059c92SSukanya Pandey }); 7298059c92SSukanya Pandey 736859203cSDerick Montague it('getEvents should dispatch eventLog/getEventLogData', () => { 7498059c92SSukanya Pandey wrapper.vm.getEvents(); 75ad2ceb6dSDerick Montague expect(store.dispatch).toHaveBeenCalledTimes(1); 7698059c92SSukanya Pandey }); 7798059c92SSukanya Pandey }); 7898059c92SSukanya Pandey}); 79