summaryrefslogtreecommitdiff
path: root/tests/unit/AppHeader.spec.js
blob: 52e45437df89039ef736737147e4787cbe1c37c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { shallowMount, createLocalVue, createWrapper } from '@vue/test-utils';
import Vue from 'vue';
import Vuex from 'vuex';
import AppHeader from '@/components/AppHeader';

// Silencing warnings about undefined Bootsrap-vue components
Vue.config.silent = true;
const localVue = createLocalVue();
localVue.use(Vuex);

describe('AppHeader.vue', () => {
  const actions = {
    'global/getHostStatus': sinon.spy(),
    'eventLog/getEventLogData': sinon.spy()
  };

  const store = new Vuex.Store({ actions });
  const wrapper = shallowMount(AppHeader, {
    store,
    localVue,
    mocks: {
      $t: key => key
    }
  });

  // Reset spy for each test. Otherwise mutiple actions
  // are dispatched in each test
  beforeEach(() => {
    store.dispatch = sinon.spy();
  });

  describe('UI', () => {
    it('should check if AppHeader exists', () => {
      expect(wrapper.exists()).to.be.true;
    });

    it('should check if the skip navigation link exists', () => {
      expect(wrapper.get('.link-skip-nav').exists()).to.be.true;
    });

    it('refresh button click should emit refresh event', async () => {
      wrapper.get('#app-header-refresh').trigger('click');
      await wrapper.vm.$nextTick();
      expect(wrapper.emitted().refresh).to.exist;
    });

    it('nav-trigger button click should emit toggle:navigation event', async () => {
      const rootWrapper = createWrapper(wrapper.vm.$root);
      wrapper.get('#app-header-trigger').trigger('click');
      await wrapper.vm.$nextTick();
      expect(rootWrapper.emitted()['toggle:navigation']).to.exist;
    });

    it('logout button should dispatch authentication/logout', async () => {
      wrapper.get('#app-header-logout').trigger('click');
      await wrapper.vm.$nextTick();
      expect(store.dispatch).calledWith('authentication/logout');
    });
  });

  describe('Methods', () => {
    it('getHostInfo should dispatch global/getHostStatus', () => {
      wrapper.vm.getHostInfo();
      expect(store.dispatch).calledWith('global/getHostStatus');
    });

    it('getEvents should dispatch eventLog/getEventLogData', () => {
      wrapper.vm.getEvents();
      expect(store.dispatch).calledWith('eventLog/getEventLogData');
    });
  });
});