debian-mirror-gitlab/spec/frontend/nav/components/top_nav_app_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
2 KiB
JavaScript
Raw Normal View History

2021-09-04 01:27:46 +05:30
import { GlNavItemDropdown } from '@gitlab/ui';
2022-11-25 23:54:43 +05:30
import { mount, shallowMount } from '@vue/test-utils';
import { mockTracking } from 'helpers/tracking_helper';
2021-06-08 01:23:25 +05:30
import TopNavApp from '~/nav/components/top_nav_app.vue';
import TopNavDropdownMenu from '~/nav/components/top_nav_dropdown_menu.vue';
import { TEST_NAV_DATA } from '../mock_data';
describe('~/nav/components/top_nav_app.vue', () => {
let wrapper;
2021-09-04 01:27:46 +05:30
const createComponent = () => {
2022-11-25 23:54:43 +05:30
wrapper = mount(TopNavApp, {
propsData: {
navData: TEST_NAV_DATA,
},
});
};
const createComponentShallow = () => {
2021-09-04 01:27:46 +05:30
wrapper = shallowMount(TopNavApp, {
2021-06-08 01:23:25 +05:30
propsData: {
navData: TEST_NAV_DATA,
},
});
};
const findNavItemDropdown = () => wrapper.findComponent(GlNavItemDropdown);
2022-11-25 23:54:43 +05:30
const findNavItemDropdowToggle = () => findNavItemDropdown().find('.js-top-nav-dropdown-toggle');
2021-06-08 01:23:25 +05:30
const findMenu = () => wrapper.findComponent(TopNavDropdownMenu);
afterEach(() => {
wrapper.destroy();
});
describe('default', () => {
beforeEach(() => {
2022-11-25 23:54:43 +05:30
createComponentShallow();
2021-06-08 01:23:25 +05:30
});
it('renders nav item dropdown', () => {
expect(findNavItemDropdown().attributes('href')).toBeUndefined();
expect(findNavItemDropdown().attributes()).toMatchObject({
2022-10-11 01:57:18 +05:30
icon: '',
text: '',
2021-06-08 01:23:25 +05:30
'no-flip': '',
2022-10-11 01:57:18 +05:30
'no-caret': '',
2021-06-08 01:23:25 +05:30
});
});
it('renders top nav dropdown menu', () => {
expect(findMenu().props()).toStrictEqual({
primary: TEST_NAV_DATA.primary,
secondary: TEST_NAV_DATA.secondary,
views: TEST_NAV_DATA.views,
});
});
});
2022-11-25 23:54:43 +05:30
describe('tracking', () => {
it('emits a tracking event when the toggle is clicked', () => {
const trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn);
createComponent();
findNavItemDropdowToggle().trigger('click');
expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_nav', {
label: 'hamburger_menu',
property: 'top_navigation',
});
});
});
2021-06-08 01:23:25 +05:30
});