Damian Celico | aeb1981 | 2022-11-24 02:00:53 +0100 | [diff] [blame] | 1 | import { mount, createLocalVue, createWrapper } from '@vue/test-utils'; |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 2 | import AppNavigation from '@/components/AppNavigation'; |
| 3 | import Vue from 'vue'; |
Damian Celico | aeb1981 | 2022-11-24 02:00:53 +0100 | [diff] [blame] | 4 | import Vuex from 'vuex'; |
Sukanya Pandey | fba4d62 | 2020-12-29 13:31:19 +0530 | [diff] [blame] | 5 | import VueRouter from 'vue-router'; |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 6 | import { BootstrapVue } from 'bootstrap-vue'; |
| 7 | |
Damian Celico | aeb1981 | 2022-11-24 02:00:53 +0100 | [diff] [blame] | 8 | const localVue = createLocalVue(); |
| 9 | localVue.use(Vuex); |
| 10 | |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 11 | describe('AppNavigation.vue', () => { |
| 12 | let wrapper; |
Damian Celico | aeb1981 | 2022-11-24 02:00:53 +0100 | [diff] [blame] | 13 | const router = new VueRouter(); |
| 14 | const actions = { |
| 15 | 'global/userPrivilege': jest.fn(), |
| 16 | }; |
| 17 | const store = new Vuex.Store({ actions }); |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 18 | Vue.use(BootstrapVue); |
Sukanya Pandey | fba4d62 | 2020-12-29 13:31:19 +0530 | [diff] [blame] | 19 | Vue.use(VueRouter); |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 20 | |
| 21 | wrapper = mount(AppNavigation, { |
Damian Celico | aeb1981 | 2022-11-24 02:00:53 +0100 | [diff] [blame] | 22 | store, |
Sukanya Pandey | fba4d62 | 2020-12-29 13:31:19 +0530 | [diff] [blame] | 23 | router, |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 24 | mocks: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 25 | $t: (key) => key, |
| 26 | }, |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 27 | }); |
| 28 | |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 29 | it('should exist', async () => { |
| 30 | expect(wrapper.exists()).toBe(true); |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 31 | }); |
| 32 | |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 33 | it('should render correctly', () => { |
| 34 | expect(wrapper.element).toMatchSnapshot(); |
| 35 | }); |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 36 | |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 37 | it('should render with nav-container open', () => { |
| 38 | wrapper.vm.isNavigationOpen = true; |
| 39 | expect(wrapper.element).toMatchSnapshot(); |
| 40 | }); |
| 41 | |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 42 | it('Nav Overlay click should emit change-is-navigation-open event', async () => { |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 43 | const rootWrapper = createWrapper(wrapper.vm.$root); |
| 44 | const navOverlay = wrapper.find('#nav-overlay'); |
| 45 | navOverlay.trigger('click'); |
| 46 | await wrapper.vm.$nextTick(); |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 47 | expect(rootWrapper.emitted('change-is-navigation-open')).toBeTruthy(); |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 48 | }); |
| 49 | |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 50 | it('toggle-navigation event should toggle isNavigation data prop value', async () => { |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 51 | const rootWrapper = createWrapper(wrapper.vm.$root); |
| 52 | wrapper.vm.isNavigationOpen = false; |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 53 | rootWrapper.vm.$emit('toggle-navigation'); |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 54 | expect(wrapper.vm.isNavigationOpen).toBe(true); |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 55 | rootWrapper.vm.$emit('toggle-navigation'); |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 56 | expect(wrapper.vm.isNavigationOpen).toBe(false); |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 57 | }); |
| 58 | }); |