blob: ce410c8db1d3db666d704b5fb40a1873c1718d9c [file] [log] [blame]
Damian Celicoaeb19812022-11-24 02:00:53 +01001import { mount, createLocalVue, createWrapper } from '@vue/test-utils';
Sukanya Pandey98059c92020-03-26 17:10:32 +05302import AppNavigation from '@/components/AppNavigation';
3import Vue 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';
Sukanya Pandey98059c92020-03-26 17:10:32 +05306import { BootstrapVue } from 'bootstrap-vue';
7
Damian Celicoaeb19812022-11-24 02:00:53 +01008const localVue = createLocalVue();
9localVue.use(Vuex);
10
Sukanya Pandey98059c92020-03-26 17:10:32 +053011describe('AppNavigation.vue', () => {
12 let wrapper;
Damian Celicoaeb19812022-11-24 02:00:53 +010013 const router = new VueRouter();
14 const actions = {
15 'global/userPrivilege': jest.fn(),
16 };
17 const store = new Vuex.Store({ actions });
Sukanya Pandey98059c92020-03-26 17:10:32 +053018 Vue.use(BootstrapVue);
Sukanya Pandeyfba4d622020-12-29 13:31:19 +053019 Vue.use(VueRouter);
Sukanya Pandey98059c92020-03-26 17:10:32 +053020
21 wrapper = mount(AppNavigation, {
Damian Celicoaeb19812022-11-24 02:00:53 +010022 store,
Sukanya Pandeyfba4d622020-12-29 13:31:19 +053023 router,
Sukanya Pandey98059c92020-03-26 17:10:32 +053024 mocks: {
Derick Montague602e98a2020-10-21 16:20:00 -050025 $t: (key) => key,
26 },
Sukanya Pandey98059c92020-03-26 17:10:32 +053027 });
28
Derick Montaguead2ceb62020-04-24 18:11:04 -050029 it('should exist', async () => {
30 expect(wrapper.exists()).toBe(true);
Sukanya Pandey98059c92020-03-26 17:10:32 +053031 });
32
Derick Montaguead2ceb62020-04-24 18:11:04 -050033 it('should render correctly', () => {
34 expect(wrapper.element).toMatchSnapshot();
35 });
Sukanya Pandey98059c92020-03-26 17:10:32 +053036
Derick Montaguead2ceb62020-04-24 18:11:04 -050037 it('should render with nav-container open', () => {
38 wrapper.vm.isNavigationOpen = true;
39 expect(wrapper.element).toMatchSnapshot();
40 });
41
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053042 it('Nav Overlay click should emit change-is-navigation-open event', async () => {
Derick Montaguead2ceb62020-04-24 18:11:04 -050043 const rootWrapper = createWrapper(wrapper.vm.$root);
44 const navOverlay = wrapper.find('#nav-overlay');
45 navOverlay.trigger('click');
46 await wrapper.vm.$nextTick();
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053047 expect(rootWrapper.emitted('change-is-navigation-open')).toBeTruthy();
Derick Montaguead2ceb62020-04-24 18:11:04 -050048 });
49
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053050 it('toggle-navigation event should toggle isNavigation data prop value', async () => {
Derick Montaguead2ceb62020-04-24 18:11:04 -050051 const rootWrapper = createWrapper(wrapper.vm.$root);
52 wrapper.vm.isNavigationOpen = false;
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(true);
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053055 rootWrapper.vm.$emit('toggle-navigation');
Derick Montaguead2ceb62020-04-24 18:11:04 -050056 expect(wrapper.vm.isNavigationOpen).toBe(false);
Sukanya Pandey98059c92020-03-26 17:10:32 +053057 });
58});