Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 1 | import { mount, 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'; |
Sukanya Pandey | fba4d62 | 2020-12-29 13:31:19 +0530 | [diff] [blame] | 4 | import VueRouter from 'vue-router'; |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 5 | import { BootstrapVue } from 'bootstrap-vue'; |
| 6 | |
| 7 | describe('AppNavigation.vue', () => { |
| 8 | let wrapper; |
| 9 | Vue.use(BootstrapVue); |
Sukanya Pandey | fba4d62 | 2020-12-29 13:31:19 +0530 | [diff] [blame] | 10 | Vue.use(VueRouter); |
| 11 | const router = new VueRouter(); |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 12 | |
| 13 | wrapper = mount(AppNavigation, { |
Sukanya Pandey | fba4d62 | 2020-12-29 13:31:19 +0530 | [diff] [blame] | 14 | router, |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 15 | mocks: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 16 | $t: (key) => key, |
| 17 | }, |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 18 | }); |
| 19 | |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 20 | it('should exist', async () => { |
| 21 | expect(wrapper.exists()).toBe(true); |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 22 | }); |
| 23 | |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 24 | it('should render correctly', () => { |
| 25 | expect(wrapper.element).toMatchSnapshot(); |
| 26 | }); |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 27 | |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 28 | it('should render with nav-container open', () => { |
| 29 | wrapper.vm.isNavigationOpen = true; |
| 30 | expect(wrapper.element).toMatchSnapshot(); |
| 31 | }); |
| 32 | |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 33 | it('Nav Overlay click should emit change-is-navigation-open event', async () => { |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 34 | const rootWrapper = createWrapper(wrapper.vm.$root); |
| 35 | const navOverlay = wrapper.find('#nav-overlay'); |
| 36 | navOverlay.trigger('click'); |
| 37 | await wrapper.vm.$nextTick(); |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 38 | expect(rootWrapper.emitted('change-is-navigation-open')).toBeTruthy(); |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 39 | }); |
| 40 | |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 41 | it('toggle-navigation event should toggle isNavigation data prop value', async () => { |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 42 | const rootWrapper = createWrapper(wrapper.vm.$root); |
| 43 | wrapper.vm.isNavigationOpen = false; |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 44 | rootWrapper.vm.$emit('toggle-navigation'); |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 45 | expect(wrapper.vm.isNavigationOpen).toBe(true); |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 46 | rootWrapper.vm.$emit('toggle-navigation'); |
Derick Montague | ad2ceb6 | 2020-04-24 18:11:04 -0500 | [diff] [blame] | 47 | expect(wrapper.vm.isNavigationOpen).toBe(false); |
Sukanya Pandey | 98059c9 | 2020-03-26 17:10:32 +0530 | [diff] [blame] | 48 | }); |
| 49 | }); |