Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 1 | import { mount, createLocalVue, createWrapper } from '@vue/test-utils'; |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 2 | import Vue from 'vue'; |
Derick Montague | 6859203 | 2020-04-04 14:02:34 -0500 | [diff] [blame] | 3 | import Vuex from 'vuex'; |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 4 | import AppHeader from '@/components/AppHeader'; |
Derick Montague | 6859203 | 2020-04-04 14:02:34 -0500 | [diff] [blame] | 5 | |
| 6 | // Silencing warnings about undefined Bootsrap-vue components |
| 7 | Vue.config.silent = true; |
| 8 | const localVue = createLocalVue(); |
| 9 | localVue.use(Vuex); |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 10 | |
| 11 | describe('AppHeader.vue', () => { |
Derick Montague | 6859203 | 2020-04-04 14:02:34 -0500 | [diff] [blame] | 12 | const actions = { |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 13 | 'global/getHostStatus': jest.fn(), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 14 | 'eventLog/getEventLogData': jest.fn(), |
Derick Montague | f833c7e | 2020-10-27 08:21:20 -0500 | [diff] [blame] | 15 | 'authentication/resetStoreState': jest.fn(), |
Derick Montague | 6859203 | 2020-04-04 14:02:34 -0500 | [diff] [blame] | 16 | }; |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 17 | |
Derick Montague | 6859203 | 2020-04-04 14:02:34 -0500 | [diff] [blame] | 18 | const store = new Vuex.Store({ actions }); |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 19 | const wrapper = mount(AppHeader, { |
Derick Montague | 6859203 | 2020-04-04 14:02:34 -0500 | [diff] [blame] | 20 | store, |
| 21 | localVue, |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 22 | mocks: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 23 | $t: (key) => key, |
| 24 | }, |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 25 | }); |
| 26 | |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 27 | // Reset dispatch between tests so that multiple |
| 28 | // actions are not dispatched for each test |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 29 | beforeEach(() => { |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 30 | store.dispatch = jest.fn(); |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 31 | }); |
| 32 | |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 33 | it('should exist', () => { |
| 34 | expect(wrapper.exists()).toBe(true); |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 35 | }); |
| 36 | |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 37 | it('should render correctly', () => { |
| 38 | expect(wrapper.element).toMatchSnapshot(); |
| 39 | }); |
| 40 | |
| 41 | it('refresh button click should emit refresh event', async () => { |
| 42 | wrapper.get('#app-header-refresh').trigger('click'); |
| 43 | await wrapper.vm.$nextTick(); |
| 44 | expect(wrapper.emitted('refresh')).toBeTruthy(); |
| 45 | }); |
| 46 | |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame^] | 47 | it('nav-trigger button click should emit toggle-navigation event', async () => { |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 48 | const rootWrapper = createWrapper(wrapper.vm.$root); |
| 49 | wrapper.get('#app-header-trigger').trigger('click'); |
| 50 | await wrapper.vm.$nextTick(); |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame^] | 51 | expect(rootWrapper.emitted('toggle-navigation')).toBeTruthy(); |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 52 | }); |
| 53 | |
| 54 | it('logout button should dispatch authentication/logout', async () => { |
Derick Montague | 58a7a03 | 2020-09-21 12:21:48 -0500 | [diff] [blame] | 55 | wrapper.get('[data-test-id="appHeader-link-logout"]').trigger('click'); |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 56 | await wrapper.vm.$nextTick(); |
| 57 | expect(store.dispatch).toHaveBeenCalledTimes(1); |
| 58 | }); |
| 59 | |
| 60 | it('change:isNavigationOpen event should set isNavigationOpen prop to false', async () => { |
| 61 | const rootWrapper = createWrapper(wrapper.vm.$root); |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame^] | 62 | rootWrapper.vm.$emit('change-is-navigation-open', false); |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 63 | await rootWrapper.vm.$nextTick(); |
| 64 | expect(wrapper.vm.isNavigationOpen).toEqual(false); |
| 65 | }); |
| 66 | |
| 67 | describe('Created lifecycle hook', () => { |
Derick Montague | 6859203 | 2020-04-04 14:02:34 -0500 | [diff] [blame] | 68 | it('getHostInfo should dispatch global/getHostStatus', () => { |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 69 | wrapper.vm.getHostInfo(); |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 70 | expect(store.dispatch).toHaveBeenCalledTimes(1); |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 71 | }); |
| 72 | |
Derick Montague | 6859203 | 2020-04-04 14:02:34 -0500 | [diff] [blame] | 73 | it('getEvents should dispatch eventLog/getEventLogData', () => { |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 74 | wrapper.vm.getEvents(); |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 75 | expect(store.dispatch).toHaveBeenCalledTimes(1); |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 76 | }); |
| 77 | }); |
| 78 | }); |