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 = { 1371114febSDerick Montague 'global/getServerStatus': jest.fn(), 14602e98aaSDerick Montague 'eventLog/getEventLogData': jest.fn(), 15f833c7e3SDerick Montague 'authentication/resetStoreState': jest.fn(), 16*df8cf6acSwangqi02 'global/getSystemInfo': jest.fn(), 176859203cSDerick Montague }; 1898059c92SSukanya Pandey 196859203cSDerick Montague const store = new Vuex.Store({ actions }); 20ad2ceb6dSDerick Montague const wrapper = mount(AppHeader, { 216859203cSDerick Montague store, 226859203cSDerick Montague localVue, 2398059c92SSukanya Pandey mocks: { 24602e98aaSDerick Montague $t: (key) => key, 25602e98aaSDerick Montague }, 2698059c92SSukanya Pandey }); 2798059c92SSukanya Pandey 28ad2ceb6dSDerick Montague // Reset dispatch between tests so that multiple 29ad2ceb6dSDerick Montague // actions are not dispatched for each test 3098059c92SSukanya Pandey beforeEach(() => { 31ad2ceb6dSDerick Montague store.dispatch = jest.fn(); 3298059c92SSukanya Pandey }); 3398059c92SSukanya Pandey 34ad2ceb6dSDerick Montague it('should exist', () => { 35ad2ceb6dSDerick Montague expect(wrapper.exists()).toBe(true); 366859203cSDerick Montague }); 376859203cSDerick Montague 38ad2ceb6dSDerick Montague it('should render correctly', () => { 39ad2ceb6dSDerick Montague expect(wrapper.element).toMatchSnapshot(); 406859203cSDerick Montague }); 416859203cSDerick Montague 426859203cSDerick Montague it('refresh button click should emit refresh event', async () => { 436859203cSDerick Montague wrapper.get('#app-header-refresh').trigger('click'); 446859203cSDerick Montague await wrapper.vm.$nextTick(); 45ad2ceb6dSDerick Montague expect(wrapper.emitted('refresh')).toBeTruthy(); 466859203cSDerick Montague }); 476859203cSDerick Montague 48edb8a774SSukanya Pandey it('nav-trigger button click should emit toggle-navigation event', async () => { 496859203cSDerick Montague const rootWrapper = createWrapper(wrapper.vm.$root); 506859203cSDerick Montague wrapper.get('#app-header-trigger').trigger('click'); 516859203cSDerick Montague await wrapper.vm.$nextTick(); 52edb8a774SSukanya Pandey expect(rootWrapper.emitted('toggle-navigation')).toBeTruthy(); 536859203cSDerick Montague }); 546859203cSDerick Montague 556859203cSDerick Montague it('logout button should dispatch authentication/logout', async () => { 5658a7a03cSDerick Montague wrapper.get('[data-test-id="appHeader-link-logout"]').trigger('click'); 576859203cSDerick Montague await wrapper.vm.$nextTick(); 58ad2ceb6dSDerick Montague expect(store.dispatch).toHaveBeenCalledTimes(1); 5998059c92SSukanya Pandey }); 6098059c92SSukanya Pandey 61ad2ceb6dSDerick Montague it('change:isNavigationOpen event should set isNavigationOpen prop to false', async () => { 62ad2ceb6dSDerick Montague const rootWrapper = createWrapper(wrapper.vm.$root); 63edb8a774SSukanya Pandey rootWrapper.vm.$emit('change-is-navigation-open', false); 64ad2ceb6dSDerick Montague await rootWrapper.vm.$nextTick(); 65ad2ceb6dSDerick Montague expect(wrapper.vm.isNavigationOpen).toEqual(false); 66ad2ceb6dSDerick Montague }); 67ad2ceb6dSDerick Montague 68ad2ceb6dSDerick Montague describe('Created lifecycle hook', () => { 694dd7eabfSSukanya Pandey it('getSystemInfo should dispatch global/getSystemInfo', () => { 704dd7eabfSSukanya Pandey wrapper.vm.getSystemInfo(); 71ad2ceb6dSDerick Montague expect(store.dispatch).toHaveBeenCalledTimes(1); 7298059c92SSukanya Pandey }); 7398059c92SSukanya Pandey 746859203cSDerick Montague it('getEvents should dispatch eventLog/getEventLogData', () => { 7598059c92SSukanya Pandey wrapper.vm.getEvents(); 76ad2ceb6dSDerick Montague expect(store.dispatch).toHaveBeenCalledTimes(1); 7798059c92SSukanya Pandey }); 7898059c92SSukanya Pandey }); 7998059c92SSukanya Pandey}); 80