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