AppHeader.spec.js (6859203cebe3b6a31d23d55a3555bf36d6c73242) | AppHeader.spec.js (ad2ceb6df979cff60e05b088a17ee29dfb95a9ff) |
---|---|
1import { shallowMount, createLocalVue, createWrapper } from '@vue/test-utils'; | 1import { mount, createLocalVue, createWrapper } from '@vue/test-utils'; |
2import Vue from 'vue'; 3import Vuex from 'vuex'; 4import AppHeader from '@/components/AppHeader'; 5 6// Silencing warnings about undefined Bootsrap-vue components 7Vue.config.silent = true; 8const localVue = createLocalVue(); 9localVue.use(Vuex); 10 11describe('AppHeader.vue', () => { 12 const actions = { | 2import Vue from 'vue'; 3import Vuex from 'vuex'; 4import AppHeader from '@/components/AppHeader'; 5 6// Silencing warnings about undefined Bootsrap-vue components 7Vue.config.silent = true; 8const localVue = createLocalVue(); 9localVue.use(Vuex); 10 11describe('AppHeader.vue', () => { 12 const actions = { |
13 'global/getHostStatus': sinon.spy(), 14 'eventLog/getEventLogData': sinon.spy() | 13 'global/getHostStatus': jest.fn(), 14 'eventLog/getEventLogData': jest.fn() |
15 }; 16 17 const store = new Vuex.Store({ actions }); | 15 }; 16 17 const store = new Vuex.Store({ actions }); |
18 const wrapper = shallowMount(AppHeader, { | 18 const wrapper = mount(AppHeader, { |
19 store, 20 localVue, 21 mocks: { 22 $t: key => key 23 } 24 }); 25 | 19 store, 20 localVue, 21 mocks: { 22 $t: key => key 23 } 24 }); 25 |
26 // Reset spy for each test. Otherwise mutiple actions 27 // are dispatched in each test | 26 // Reset dispatch between tests so that multiple 27 // actions are not dispatched for each test |
28 beforeEach(() => { | 28 beforeEach(() => { |
29 store.dispatch = sinon.spy(); | 29 store.dispatch = jest.fn(); |
30 }); 31 | 30 }); 31 |
32 describe('UI', () => { 33 it('should check if AppHeader exists', () => { 34 expect(wrapper.exists()).to.be.true; 35 }); | 32 it('should exist', () => { 33 expect(wrapper.exists()).toBe(true); 34 }); |
36 | 35 |
37 it('should check if the skip navigation link exists', () => { 38 expect(wrapper.get('.link-skip-nav').exists()).to.be.true; 39 }); | 36 it('should render correctly', () => { 37 expect(wrapper.element).toMatchSnapshot(); 38 }); |
40 | 39 |
41 it('refresh button click should emit refresh event', async () => { 42 wrapper.get('#app-header-refresh').trigger('click'); 43 await wrapper.vm.$nextTick(); 44 expect(wrapper.emitted().refresh).to.exist; 45 }); | 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 }); |
46 | 45 |
47 it('nav-trigger button click should emit toggle:navigation event', async () => { 48 const rootWrapper = createWrapper(wrapper.vm.$root); 49 wrapper.get('#app-header-trigger').trigger('click'); 50 await wrapper.vm.$nextTick(); 51 expect(rootWrapper.emitted()['toggle:navigation']).to.exist; 52 }); | 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 }); |
53 | 52 |
54 it('logout button should dispatch authentication/logout', async () => { 55 wrapper.get('#app-header-logout').trigger('click'); 56 await wrapper.vm.$nextTick(); 57 expect(store.dispatch).calledWith('authentication/logout'); 58 }); | 53 it('logout button should dispatch authentication/logout', async () => { 54 wrapper.get('#app-header-logout').trigger('click'); 55 await wrapper.vm.$nextTick(); 56 expect(store.dispatch).toHaveBeenCalledTimes(1); |
59 }); 60 | 57 }); 58 |
61 describe('Methods', () => { | 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', () => { |
62 it('getHostInfo should dispatch global/getHostStatus', () => { 63 wrapper.vm.getHostInfo(); | 67 it('getHostInfo should dispatch global/getHostStatus', () => { 68 wrapper.vm.getHostInfo(); |
64 expect(store.dispatch).calledWith('global/getHostStatus'); | 69 expect(store.dispatch).toHaveBeenCalledTimes(1); |
65 }); 66 67 it('getEvents should dispatch eventLog/getEventLogData', () => { 68 wrapper.vm.getEvents(); | 70 }); 71 72 it('getEvents should dispatch eventLog/getEventLogData', () => { 73 wrapper.vm.getEvents(); |
69 expect(store.dispatch).calledWith('eventLog/getEventLogData'); | 74 expect(store.dispatch).toHaveBeenCalledTimes(1); |
70 }); 71 }); 72}); | 75 }); 76 }); 77}); |