1*7d6b44cbSEd Tanousimport { mount, createWrapper } from '@vue/test-utils'; 2*7d6b44cbSEd Tanousimport { createStore } from 'vuex'; 398059c92SSukanya Pandeyimport AppHeader from '@/components/AppHeader'; 46859203cSDerick Montague 598059c92SSukanya Pandeydescribe('AppHeader.vue', () => { 66859203cSDerick Montague const actions = { 771114febSDerick Montague 'global/getServerStatus': jest.fn(), 8602e98aaSDerick Montague 'eventLog/getEventLogData': jest.fn(), 9f833c7e3SDerick Montague 'authentication/resetStoreState': jest.fn(), 10df8cf6acSwangqi02 'global/getSystemInfo': jest.fn(), 116859203cSDerick Montague }; 1298059c92SSukanya Pandey 13665235c6SEd Tanous // VueX requires that all modules be present, even if they aren't used 14665235c6SEd Tanous // in the test, so invent a Fake auth module and install it. 15665235c6SEd Tanous const modules = { 16665235c6SEd Tanous authentication: { 17665235c6SEd Tanous namespaced: true, 18665235c6SEd Tanous }, 19665235c6SEd Tanous }; 20665235c6SEd Tanous 21*7d6b44cbSEd Tanous const store = createStore({ actions, modules }); 22ad2ceb6dSDerick Montague const wrapper = mount(AppHeader, { 236859203cSDerick Montague store, 2498059c92SSukanya Pandey mocks: { 25602e98aaSDerick Montague $t: (key) => key, 26602e98aaSDerick Montague }, 2798059c92SSukanya Pandey }); 2898059c92SSukanya Pandey 29ad2ceb6dSDerick Montague // Reset dispatch between tests so that multiple 30ad2ceb6dSDerick Montague // actions are not dispatched for each test 3198059c92SSukanya Pandey beforeEach(() => { 32ad2ceb6dSDerick Montague store.dispatch = jest.fn(); 3398059c92SSukanya Pandey }); 3498059c92SSukanya Pandey 35ad2ceb6dSDerick Montague it('should exist', () => { 36ad2ceb6dSDerick Montague expect(wrapper.exists()).toBe(true); 376859203cSDerick Montague }); 386859203cSDerick Montague 39ad2ceb6dSDerick Montague it('should render correctly', () => { 40ad2ceb6dSDerick Montague expect(wrapper.element).toMatchSnapshot(); 416859203cSDerick Montague }); 426859203cSDerick Montague 436859203cSDerick Montague it('refresh button click should emit refresh event', async () => { 446859203cSDerick Montague wrapper.get('#app-header-refresh').trigger('click'); 456859203cSDerick Montague await wrapper.vm.$nextTick(); 46ad2ceb6dSDerick Montague expect(wrapper.emitted('refresh')).toBeTruthy(); 476859203cSDerick Montague }); 486859203cSDerick Montague 49edb8a774SSukanya Pandey it('nav-trigger button click should emit toggle-navigation event', async () => { 506859203cSDerick Montague const rootWrapper = createWrapper(wrapper.vm.$root); 516859203cSDerick Montague wrapper.get('#app-header-trigger').trigger('click'); 526859203cSDerick Montague await wrapper.vm.$nextTick(); 53edb8a774SSukanya Pandey expect(rootWrapper.emitted('toggle-navigation')).toBeTruthy(); 546859203cSDerick Montague }); 556859203cSDerick Montague 566859203cSDerick Montague it('logout button should dispatch authentication/logout', async () => { 5758a7a03cSDerick Montague wrapper.get('[data-test-id="appHeader-link-logout"]').trigger('click'); 586859203cSDerick Montague await wrapper.vm.$nextTick(); 59ad2ceb6dSDerick Montague expect(store.dispatch).toHaveBeenCalledTimes(1); 6098059c92SSukanya Pandey }); 6198059c92SSukanya Pandey 62ad2ceb6dSDerick Montague it('change:isNavigationOpen event should set isNavigationOpen prop to false', async () => { 63ad2ceb6dSDerick Montague const rootWrapper = createWrapper(wrapper.vm.$root); 64edb8a774SSukanya Pandey rootWrapper.vm.$emit('change-is-navigation-open', false); 65ad2ceb6dSDerick Montague await rootWrapper.vm.$nextTick(); 66ad2ceb6dSDerick Montague expect(wrapper.vm.isNavigationOpen).toEqual(false); 67ad2ceb6dSDerick Montague }); 68ad2ceb6dSDerick Montague 69ad2ceb6dSDerick Montague describe('Created lifecycle hook', () => { 704dd7eabfSSukanya Pandey it('getSystemInfo should dispatch global/getSystemInfo', () => { 714dd7eabfSSukanya Pandey wrapper.vm.getSystemInfo(); 72ad2ceb6dSDerick Montague expect(store.dispatch).toHaveBeenCalledTimes(1); 7398059c92SSukanya Pandey }); 7498059c92SSukanya Pandey 756859203cSDerick Montague it('getEvents should dispatch eventLog/getEventLogData', () => { 7698059c92SSukanya Pandey wrapper.vm.getEvents(); 77ad2ceb6dSDerick Montague expect(store.dispatch).toHaveBeenCalledTimes(1); 7898059c92SSukanya Pandey }); 7998059c92SSukanya Pandey }); 8098059c92SSukanya Pandey}); 81