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(), 14ad2ceb6dSDerick Montague 'eventLog/getEventLogData': jest.fn() 156859203cSDerick Montague }; 1698059c92SSukanya Pandey 176859203cSDerick Montague const store = new Vuex.Store({ actions }); 18ad2ceb6dSDerick Montague const wrapper = mount(AppHeader, { 196859203cSDerick Montague store, 206859203cSDerick Montague localVue, 2198059c92SSukanya Pandey mocks: { 226859203cSDerick Montague $t: key => key 2398059c92SSukanya Pandey } 2498059c92SSukanya Pandey }); 2598059c92SSukanya Pandey 26ad2ceb6dSDerick Montague // Reset dispatch between tests so that multiple 27ad2ceb6dSDerick Montague // actions are not dispatched for each test 2898059c92SSukanya Pandey beforeEach(() => { 29ad2ceb6dSDerick Montague store.dispatch = jest.fn(); 3098059c92SSukanya Pandey }); 3198059c92SSukanya Pandey 32ad2ceb6dSDerick Montague it('should exist', () => { 33ad2ceb6dSDerick Montague expect(wrapper.exists()).toBe(true); 346859203cSDerick Montague }); 356859203cSDerick Montague 36ad2ceb6dSDerick Montague it('should render correctly', () => { 37ad2ceb6dSDerick Montague expect(wrapper.element).toMatchSnapshot(); 386859203cSDerick Montague }); 396859203cSDerick Montague 406859203cSDerick Montague it('refresh button click should emit refresh event', async () => { 416859203cSDerick Montague wrapper.get('#app-header-refresh').trigger('click'); 426859203cSDerick Montague await wrapper.vm.$nextTick(); 43ad2ceb6dSDerick Montague expect(wrapper.emitted('refresh')).toBeTruthy(); 446859203cSDerick Montague }); 456859203cSDerick Montague 466859203cSDerick Montague it('nav-trigger button click should emit toggle:navigation event', async () => { 476859203cSDerick Montague const rootWrapper = createWrapper(wrapper.vm.$root); 486859203cSDerick Montague wrapper.get('#app-header-trigger').trigger('click'); 496859203cSDerick Montague await wrapper.vm.$nextTick(); 50ad2ceb6dSDerick Montague expect(rootWrapper.emitted('toggle:navigation')).toBeTruthy(); 516859203cSDerick Montague }); 526859203cSDerick Montague 536859203cSDerick Montague it('logout button should dispatch authentication/logout', async () => { 54*58a7a03cSDerick Montague wrapper.get('[data-test-id="appHeader-link-logout"]').trigger('click'); 556859203cSDerick Montague await wrapper.vm.$nextTick(); 56ad2ceb6dSDerick Montague expect(store.dispatch).toHaveBeenCalledTimes(1); 5798059c92SSukanya Pandey }); 5898059c92SSukanya Pandey 59ad2ceb6dSDerick Montague it('change:isNavigationOpen event should set isNavigationOpen prop to false', async () => { 60ad2ceb6dSDerick Montague const rootWrapper = createWrapper(wrapper.vm.$root); 61ad2ceb6dSDerick Montague rootWrapper.vm.$emit('change:isNavigationOpen', false); 62ad2ceb6dSDerick Montague await rootWrapper.vm.$nextTick(); 63ad2ceb6dSDerick Montague expect(wrapper.vm.isNavigationOpen).toEqual(false); 64ad2ceb6dSDerick Montague }); 65ad2ceb6dSDerick Montague 66ad2ceb6dSDerick Montague describe('Created lifecycle hook', () => { 676859203cSDerick Montague it('getHostInfo should dispatch global/getHostStatus', () => { 6898059c92SSukanya Pandey wrapper.vm.getHostInfo(); 69ad2ceb6dSDerick Montague expect(store.dispatch).toHaveBeenCalledTimes(1); 7098059c92SSukanya Pandey }); 7198059c92SSukanya Pandey 726859203cSDerick Montague it('getEvents should dispatch eventLog/getEventLogData', () => { 7398059c92SSukanya Pandey wrapper.vm.getEvents(); 74ad2ceb6dSDerick Montague expect(store.dispatch).toHaveBeenCalledTimes(1); 7598059c92SSukanya Pandey }); 7698059c92SSukanya Pandey }); 7798059c92SSukanya Pandey}); 78