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

124 lines
3.7 KiB
JavaScript
Raw Normal View History

2021-06-08 01:23:25 +05:30
import { shallowMount } from '@vue/test-utils';
2021-09-04 01:27:46 +05:30
import { merge } from 'lodash';
2021-06-08 01:23:25 +05:30
import { nextTick } from 'vue';
import FrequentItemsApp from '~/frequent_items/components/app.vue';
import { FREQUENT_ITEMS_PROJECTS } from '~/frequent_items/constants';
import eventHub from '~/frequent_items/event_hub';
import TopNavContainerView from '~/nav/components/top_nav_container_view.vue';
2021-09-04 01:27:46 +05:30
import TopNavMenuSections from '~/nav/components/top_nav_menu_sections.vue';
2021-06-08 01:23:25 +05:30
import VuexModuleProvider from '~/vue_shared/components/vuex_module_provider.vue';
import { TEST_NAV_DATA } from '../mock_data';
const DEFAULT_PROPS = {
frequentItemsDropdownType: FREQUENT_ITEMS_PROJECTS.namespace,
frequentItemsVuexModule: FREQUENT_ITEMS_PROJECTS.vuexModule,
linksPrimary: TEST_NAV_DATA.primary,
linksSecondary: TEST_NAV_DATA.secondary,
2021-09-04 01:27:46 +05:30
containerClass: 'test-frequent-items-container-class',
2021-06-08 01:23:25 +05:30
};
const TEST_OTHER_PROPS = {
namespace: 'projects',
2021-09-04 01:27:46 +05:30
currentUserName: 'test-user',
currentItem: { id: 'test' },
2021-06-08 01:23:25 +05:30
};
describe('~/nav/components/top_nav_container_view.vue', () => {
let wrapper;
2021-09-04 01:27:46 +05:30
const createComponent = (props = {}, options = {}) => {
2021-06-08 01:23:25 +05:30
wrapper = shallowMount(TopNavContainerView, {
propsData: {
...DEFAULT_PROPS,
...TEST_OTHER_PROPS,
...props,
},
2021-09-04 01:27:46 +05:30
...options,
2021-06-08 01:23:25 +05:30
});
};
2021-09-04 01:27:46 +05:30
const findMenuSections = () => wrapper.findComponent(TopNavMenuSections);
2021-06-08 01:23:25 +05:30
const findFrequentItemsApp = () => {
const parent = wrapper.findComponent(VuexModuleProvider);
return {
vuexModule: parent.props('vuexModule'),
props: parent.findComponent(FrequentItemsApp).props(),
2021-09-04 01:27:46 +05:30
attributes: parent.findComponent(FrequentItemsApp).attributes(),
2021-06-08 01:23:25 +05:30
};
};
2021-09-04 01:27:46 +05:30
const findFrequentItemsContainer = () => wrapper.find('[data-testid="frequent-items-container"]');
2021-06-08 01:23:25 +05:30
afterEach(() => {
wrapper.destroy();
});
it.each(['projects', 'groups'])(
'emits frequent items event to event hub (%s)',
async (frequentItemsDropdownType) => {
const listener = jest.fn();
eventHub.$on(`${frequentItemsDropdownType}-dropdownOpen`, listener);
createComponent({ frequentItemsDropdownType });
expect(listener).not.toHaveBeenCalled();
await nextTick();
expect(listener).toHaveBeenCalled();
},
);
describe('default', () => {
2021-09-04 01:27:46 +05:30
const EXTRA_ATTRS = { 'data-test-attribute': 'foo' };
2021-06-08 01:23:25 +05:30
beforeEach(() => {
2021-09-04 01:27:46 +05:30
createComponent({}, { attrs: EXTRA_ATTRS });
});
it('does not inherit extra attrs', () => {
expect(wrapper.attributes()).toEqual({
class: expect.any(String),
});
2021-06-08 01:23:25 +05:30
});
it('renders frequent items app', () => {
expect(findFrequentItemsApp()).toEqual({
vuexModule: DEFAULT_PROPS.frequentItemsVuexModule,
2021-09-04 01:27:46 +05:30
props: expect.objectContaining(
merge({ currentItem: { lastAccessedOn: Date.now() } }, TEST_OTHER_PROPS),
),
attributes: expect.objectContaining(EXTRA_ATTRS),
2021-06-08 01:23:25 +05:30
});
});
2021-09-04 01:27:46 +05:30
it('renders given container class', () => {
expect(findFrequentItemsContainer().classes(DEFAULT_PROPS.containerClass)).toBe(true);
2021-06-08 01:23:25 +05:30
});
2021-09-04 01:27:46 +05:30
it('renders menu sections', () => {
const sections = [
{ id: 'primary', menuItems: TEST_NAV_DATA.primary },
{ id: 'secondary', menuItems: TEST_NAV_DATA.secondary },
];
2021-06-08 01:23:25 +05:30
2021-09-04 01:27:46 +05:30
expect(findMenuSections().props()).toEqual({
sections,
withTopBorder: true,
});
2021-06-08 01:23:25 +05:30
});
});
describe('without secondary links', () => {
beforeEach(() => {
createComponent({
linksSecondary: [],
});
});
it('renders one menu item group', () => {
2021-09-04 01:27:46 +05:30
expect(findMenuSections().props('sections')).toEqual([
{ id: 'primary', menuItems: TEST_NAV_DATA.primary },
2021-06-08 01:23:25 +05:30
]);
});
});
});