summaryrefslogtreecommitdiff
path: root/tests/unit/AppHeader.spec.js
blob: 6dea960b47d3736884c0ea6131410787ce1522b1 (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
import { mount } from '@vue/test-utils';
import Vue from 'vue';
import AppHeader from '@/components/AppHeader';
import $store from '@/store';
import { BootstrapVue } from 'bootstrap-vue';

describe('AppHeader.vue', () => {
  let wrapper;
  let spy;
  Vue.use(BootstrapVue);

  wrapper = mount(AppHeader, {
    mocks: {
      $t: key => key,
      $store
    }
  });

  beforeEach(() => {
    spy = sinon.spy($store.dispatch);
  });

  describe('Component exists', () => {
    it('should check if AppHeader exists', async () => {
      expect(wrapper.exists());
    });
  });

  describe('AppHeader methods', () => {
    it('should call getHostInfo and dispatch global/getHostStatus', async () => {
      wrapper.vm.getHostInfo();
      spy('global/getHostStatus');
      expect(spy).to.have.been.calledWith('global/getHostStatus');
    });

    it('should call getEvents and dispatch eventLog/getEventLogData', async () => {
      wrapper.vm.getEvents();
      spy('eventLog/getEventLogData');
      expect(spy).to.have.been.calledWith('eventLog/getEventLogData');
    });

    it('should call refresh and emit refresh', async () => {
      spy = sinon.spy(wrapper.vm.$emit);
      wrapper.vm.refresh();
      spy('refresh');
      expect(spy).to.have.been.calledWith('refresh');
    });

    it('should call logout and dispatch authentication/logout', async () => {
      wrapper.vm.logout();
      spy('authentication/logout');
      expect(spy).to.have.been.calledWith('authentication/logout');
    });

    it('should call toggleNavigation and dispatch toggle:navigation', async () => {
      spy = sinon.spy(wrapper.vm.$root.$emit);
      wrapper.vm.toggleNavigation();
      spy('toggle:navigation');
      expect(spy).to.have.been.calledWith('toggle:navigation');
    });
  });
});