Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame^] | 1 | import { mount } from '@vue/test-utils'; |
| 2 | import Vue from 'vue'; |
| 3 | import AppHeader from '@/components/AppHeader'; |
| 4 | import $store from '@/store'; |
| 5 | import { BootstrapVue } from 'bootstrap-vue'; |
| 6 | |
| 7 | describe('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 | }); |