blob: b37c1e4c68e8cf9d8b07b159be85dbc1a415b5c6 [file] [log] [blame]
Derick Montaguead2ceb62020-04-24 18:11:04 -05001import { mount, createWrapper } from '@vue/test-utils';
Sukanya Pandey98059c92020-03-26 17:10:32 +05302import AppNavigation from '@/components/AppNavigation';
3import Vue from 'vue';
Sukanya Pandeyfba4d622020-12-29 13:31:19 +05304import VueRouter from 'vue-router';
Sukanya Pandey98059c92020-03-26 17:10:32 +05305import { BootstrapVue } from 'bootstrap-vue';
6
7describe('AppNavigation.vue', () => {
8 let wrapper;
9 Vue.use(BootstrapVue);
Sukanya Pandeyfba4d622020-12-29 13:31:19 +053010 Vue.use(VueRouter);
11 const router = new VueRouter();
Sukanya Pandey98059c92020-03-26 17:10:32 +053012
13 wrapper = mount(AppNavigation, {
Sukanya Pandeyfba4d622020-12-29 13:31:19 +053014 router,
Sukanya Pandey98059c92020-03-26 17:10:32 +053015 mocks: {
Derick Montague602e98a2020-10-21 16:20:00 -050016 $t: (key) => key,
17 },
Sukanya Pandey98059c92020-03-26 17:10:32 +053018 });
19
Derick Montaguead2ceb62020-04-24 18:11:04 -050020 it('should exist', async () => {
21 expect(wrapper.exists()).toBe(true);
Sukanya Pandey98059c92020-03-26 17:10:32 +053022 });
23
Derick Montaguead2ceb62020-04-24 18:11:04 -050024 it('should render correctly', () => {
25 expect(wrapper.element).toMatchSnapshot();
26 });
Sukanya Pandey98059c92020-03-26 17:10:32 +053027
Derick Montaguead2ceb62020-04-24 18:11:04 -050028 it('should render with nav-container open', () => {
29 wrapper.vm.isNavigationOpen = true;
30 expect(wrapper.element).toMatchSnapshot();
31 });
32
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053033 it('Nav Overlay click should emit change-is-navigation-open event', async () => {
Derick Montaguead2ceb62020-04-24 18:11:04 -050034 const rootWrapper = createWrapper(wrapper.vm.$root);
35 const navOverlay = wrapper.find('#nav-overlay');
36 navOverlay.trigger('click');
37 await wrapper.vm.$nextTick();
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053038 expect(rootWrapper.emitted('change-is-navigation-open')).toBeTruthy();
Derick Montaguead2ceb62020-04-24 18:11:04 -050039 });
40
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053041 it('toggle-navigation event should toggle isNavigation data prop value', async () => {
Derick Montaguead2ceb62020-04-24 18:11:04 -050042 const rootWrapper = createWrapper(wrapper.vm.$root);
43 wrapper.vm.isNavigationOpen = false;
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053044 rootWrapper.vm.$emit('toggle-navigation');
Derick Montaguead2ceb62020-04-24 18:11:04 -050045 expect(wrapper.vm.isNavigationOpen).toBe(true);
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053046 rootWrapper.vm.$emit('toggle-navigation');
Derick Montaguead2ceb62020-04-24 18:11:04 -050047 expect(wrapper.vm.isNavigationOpen).toBe(false);
Sukanya Pandey98059c92020-03-26 17:10:32 +053048 });
49});