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