blob: ca8a95714643b8b6a61a28cea9e94bb4b5b90ee5 [file] [log] [blame]
Ed Tanous7d6b44c2024-03-23 14:56:34 -07001import { mount, createWrapper } from '@vue/test-utils';
Sukanya Pandey98059c92020-03-26 17:10:32 +05302import AppNavigation from '@/components/AppNavigation';
Ed Tanous7d6b44c2024-03-23 14:56:34 -07003import { createApp } from 'vue';
Damian Celicoaeb19812022-11-24 02:00:53 +01004import Vuex from 'vuex';
Sukanya Pandeyfba4d622020-12-29 13:31:19 +05305import VueRouter from 'vue-router';
Ed Tanous7d6b44c2024-03-23 14:56:34 -07006//import { BootstrapVue } from 'bootstrap-vue';
Damian Celicoaeb19812022-11-24 02:00:53 +01007
Sukanya Pandey98059c92020-03-26 17:10:32 +05308describe('AppNavigation.vue', () => {
9 let wrapper;
Damian Celicoaeb19812022-11-24 02:00:53 +010010 const router = new VueRouter();
11 const actions = {
12 'global/userPrivilege': jest.fn(),
13 };
14 const store = new Vuex.Store({ actions });
Ed Tanous7d6b44c2024-03-23 14:56:34 -070015 const app = createApp();
16 //app.use(BootstrapVue);
17 app.use(VueRouter);
Sukanya Pandey98059c92020-03-26 17:10:32 +053018
19 wrapper = mount(AppNavigation, {
Damian Celicoaeb19812022-11-24 02:00:53 +010020 store,
Sukanya Pandeyfba4d622020-12-29 13:31:19 +053021 router,
Sukanya Pandey98059c92020-03-26 17:10:32 +053022 mocks: {
Derick Montague602e98a2020-10-21 16:20:00 -050023 $t: (key) => key,
24 },
Sukanya Pandey98059c92020-03-26 17:10:32 +053025 });
26
Derick Montaguead2ceb62020-04-24 18:11:04 -050027 it('should exist', async () => {
28 expect(wrapper.exists()).toBe(true);
Sukanya Pandey98059c92020-03-26 17:10:32 +053029 });
30
Derick Montaguead2ceb62020-04-24 18:11:04 -050031 it('should render correctly', () => {
32 expect(wrapper.element).toMatchSnapshot();
33 });
Sukanya Pandey98059c92020-03-26 17:10:32 +053034
Derick Montaguead2ceb62020-04-24 18:11:04 -050035 it('should render with nav-container open', () => {
36 wrapper.vm.isNavigationOpen = true;
37 expect(wrapper.element).toMatchSnapshot();
38 });
39
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053040 it('Nav Overlay click should emit change-is-navigation-open event', async () => {
Derick Montaguead2ceb62020-04-24 18:11:04 -050041 const rootWrapper = createWrapper(wrapper.vm.$root);
42 const navOverlay = wrapper.find('#nav-overlay');
43 navOverlay.trigger('click');
44 await wrapper.vm.$nextTick();
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053045 expect(rootWrapper.emitted('change-is-navigation-open')).toBeTruthy();
Derick Montaguead2ceb62020-04-24 18:11:04 -050046 });
47
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053048 it('toggle-navigation event should toggle isNavigation data prop value', async () => {
Derick Montaguead2ceb62020-04-24 18:11:04 -050049 const rootWrapper = createWrapper(wrapper.vm.$root);
50 wrapper.vm.isNavigationOpen = false;
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053051 rootWrapper.vm.$emit('toggle-navigation');
Derick Montaguead2ceb62020-04-24 18:11:04 -050052 expect(wrapper.vm.isNavigationOpen).toBe(true);
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053053 rootWrapper.vm.$emit('toggle-navigation');
Derick Montaguead2ceb62020-04-24 18:11:04 -050054 expect(wrapper.vm.isNavigationOpen).toBe(false);
Sukanya Pandey98059c92020-03-26 17:10:32 +053055 });
56});