blob: f9a653955e4922c77baee38807cbf9e3b13df9db [file] [log] [blame]
Derick Montaguead2ceb62020-04-24 18:11:04 -05001import { mount, createLocalVue, createWrapper } from '@vue/test-utils';
Sukanya Pandey98059c92020-03-26 17:10:32 +05302import Vue from 'vue';
Derick Montague68592032020-04-04 14:02:34 -05003import Vuex from 'vuex';
Sukanya Pandey98059c92020-03-26 17:10:32 +05304import AppHeader from '@/components/AppHeader';
Derick Montague68592032020-04-04 14:02:34 -05005
6// Silencing warnings about undefined Bootsrap-vue components
7Vue.config.silent = true;
8const localVue = createLocalVue();
9localVue.use(Vuex);
Sukanya Pandey98059c92020-03-26 17:10:32 +053010
11describe('AppHeader.vue', () => {
Derick Montague68592032020-04-04 14:02:34 -050012 const actions = {
Derick Montaguead2ceb62020-04-24 18:11:04 -050013 'global/getHostStatus': jest.fn(),
Derick Montague602e98a2020-10-21 16:20:00 -050014 'eventLog/getEventLogData': jest.fn(),
Derick Montague68592032020-04-04 14:02:34 -050015 };
Sukanya Pandey98059c92020-03-26 17:10:32 +053016
Derick Montague68592032020-04-04 14:02:34 -050017 const store = new Vuex.Store({ actions });
Derick Montaguead2ceb62020-04-24 18:11:04 -050018 const wrapper = mount(AppHeader, {
Derick Montague68592032020-04-04 14:02:34 -050019 store,
20 localVue,
Sukanya Pandey98059c92020-03-26 17:10:32 +053021 mocks: {
Derick Montague602e98a2020-10-21 16:20:00 -050022 $t: (key) => key,
23 },
Sukanya Pandey98059c92020-03-26 17:10:32 +053024 });
25
Derick Montaguead2ceb62020-04-24 18:11:04 -050026 // Reset dispatch between tests so that multiple
27 // actions are not dispatched for each test
Sukanya Pandey98059c92020-03-26 17:10:32 +053028 beforeEach(() => {
Derick Montaguead2ceb62020-04-24 18:11:04 -050029 store.dispatch = jest.fn();
Sukanya Pandey98059c92020-03-26 17:10:32 +053030 });
31
Derick Montaguead2ceb62020-04-24 18:11:04 -050032 it('should exist', () => {
33 expect(wrapper.exists()).toBe(true);
Sukanya Pandey98059c92020-03-26 17:10:32 +053034 });
35
Derick Montaguead2ceb62020-04-24 18:11:04 -050036 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 Montague58a7a032020-09-21 12:21:48 -050054 wrapper.get('[data-test-id="appHeader-link-logout"]').trigger('click');
Derick Montaguead2ceb62020-04-24 18:11:04 -050055 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 Montague68592032020-04-04 14:02:34 -050067 it('getHostInfo should dispatch global/getHostStatus', () => {
Sukanya Pandey98059c92020-03-26 17:10:32 +053068 wrapper.vm.getHostInfo();
Derick Montaguead2ceb62020-04-24 18:11:04 -050069 expect(store.dispatch).toHaveBeenCalledTimes(1);
Sukanya Pandey98059c92020-03-26 17:10:32 +053070 });
71
Derick Montague68592032020-04-04 14:02:34 -050072 it('getEvents should dispatch eventLog/getEventLogData', () => {
Sukanya Pandey98059c92020-03-26 17:10:32 +053073 wrapper.vm.getEvents();
Derick Montaguead2ceb62020-04-24 18:11:04 -050074 expect(store.dispatch).toHaveBeenCalledTimes(1);
Sukanya Pandey98059c92020-03-26 17:10:32 +053075 });
76 });
77});