blob: 6dea960b47d3736884c0ea6131410787ce1522b1 [file] [log] [blame]
Sukanya Pandey98059c92020-03-26 17:10:32 +05301import { mount } from '@vue/test-utils';
2import Vue from 'vue';
3import AppHeader from '@/components/AppHeader';
4import $store from '@/store';
5import { BootstrapVue } from 'bootstrap-vue';
6
7describe('AppHeader.vue', () => {
8 let wrapper;
9 let spy;
10 Vue.use(BootstrapVue);
11
12 wrapper = mount(AppHeader, {
13 mocks: {
14 $t: key => key,
15 $store
16 }
17 });
18
19 beforeEach(() => {
20 spy = sinon.spy($store.dispatch);
21 });
22
23 describe('Component exists', () => {
24 it('should check if AppHeader exists', async () => {
25 expect(wrapper.exists());
26 });
27 });
28
29 describe('AppHeader methods', () => {
30 it('should call getHostInfo and dispatch global/getHostStatus', async () => {
31 wrapper.vm.getHostInfo();
32 spy('global/getHostStatus');
33 expect(spy).to.have.been.calledWith('global/getHostStatus');
34 });
35
36 it('should call getEvents and dispatch eventLog/getEventLogData', async () => {
37 wrapper.vm.getEvents();
38 spy('eventLog/getEventLogData');
39 expect(spy).to.have.been.calledWith('eventLog/getEventLogData');
40 });
41
42 it('should call refresh and emit refresh', async () => {
43 spy = sinon.spy(wrapper.vm.$emit);
44 wrapper.vm.refresh();
45 spy('refresh');
46 expect(spy).to.have.been.calledWith('refresh');
47 });
48
49 it('should call logout and dispatch authentication/logout', async () => {
50 wrapper.vm.logout();
51 spy('authentication/logout');
52 expect(spy).to.have.been.calledWith('authentication/logout');
53 });
54
55 it('should call toggleNavigation and dispatch toggle:navigation', async () => {
56 spy = sinon.spy(wrapper.vm.$root.$emit);
57 wrapper.vm.toggleNavigation();
58 spy('toggle:navigation');
59 expect(spy).to.have.been.calledWith('toggle:navigation');
60 });
61 });
62});