2023-06-20 00:43:36 +05:30
|
|
|
import { nextTick } from 'vue';
|
2023-07-09 08:55:56 +05:30
|
|
|
import {
|
|
|
|
GlDisclosureDropdown,
|
|
|
|
GlTooltip,
|
|
|
|
GlDisclosureDropdownGroup,
|
|
|
|
GlDisclosureDropdownItem,
|
|
|
|
} from '@gitlab/ui';
|
2023-04-23 21:23:45 +05:30
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
2023-07-09 08:55:56 +05:30
|
|
|
import { stubComponent } from 'helpers/stub_component';
|
|
|
|
import InviteMembersTrigger from '~/invite_members/components/invite_members_trigger.vue';
|
2023-04-23 21:23:45 +05:30
|
|
|
import { __ } from '~/locale';
|
|
|
|
import CreateMenu from '~/super_sidebar/components/create_menu.vue';
|
|
|
|
import { createNewMenuGroups } from '../mock_data';
|
|
|
|
|
|
|
|
describe('CreateMenu component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const findGlDisclosureDropdown = () => wrapper.findComponent(GlDisclosureDropdown);
|
2023-07-09 08:55:56 +05:30
|
|
|
const findGlDisclosureDropdownGroups = () => wrapper.findAllComponents(GlDisclosureDropdownGroup);
|
|
|
|
const findGlDisclosureDropdownItems = () => wrapper.findAllComponents(GlDisclosureDropdownItem);
|
|
|
|
const findInviteMembersTrigger = () => wrapper.findComponent(InviteMembersTrigger);
|
2023-04-23 21:23:45 +05:30
|
|
|
const findGlTooltip = () => wrapper.findComponent(GlTooltip);
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
const closeAndFocusMock = jest.fn();
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
const createWrapper = () => {
|
|
|
|
wrapper = shallowMountExtended(CreateMenu, {
|
|
|
|
propsData: {
|
|
|
|
groups: createNewMenuGroups,
|
|
|
|
},
|
2023-07-09 08:55:56 +05:30
|
|
|
stubs: {
|
|
|
|
InviteMembersTrigger,
|
|
|
|
GlDisclosureDropdown: stubComponent(GlDisclosureDropdown, {
|
|
|
|
methods: { closeAndFocus: closeAndFocusMock },
|
|
|
|
}),
|
|
|
|
},
|
2023-04-23 21:23:45 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('default', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createWrapper();
|
|
|
|
});
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
it('passes popper options to the dropdown', () => {
|
|
|
|
createWrapper();
|
|
|
|
|
|
|
|
expect(findGlDisclosureDropdown().props('popperOptions')).toEqual({
|
|
|
|
modifiers: [{ name: 'offset', options: { offset: [-147, 4] } }],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
it("sets the toggle's label", () => {
|
|
|
|
expect(findGlDisclosureDropdown().props('toggleText')).toBe(__('Create new...'));
|
|
|
|
});
|
2023-07-09 08:55:56 +05:30
|
|
|
it('has correct amount of dropdown groups', () => {
|
|
|
|
const items = findGlDisclosureDropdownGroups();
|
|
|
|
|
|
|
|
expect(items.exists()).toBe(true);
|
|
|
|
expect(items).toHaveLength(createNewMenuGroups.length);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has correct amount of dropdown items', () => {
|
|
|
|
const items = findGlDisclosureDropdownItems();
|
|
|
|
const numberOfMenuItems = createNewMenuGroups
|
|
|
|
.map((group) => group.items.length)
|
|
|
|
.reduce((a, b) => a + b);
|
2023-04-23 21:23:45 +05:30
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
expect(items.exists()).toBe(true);
|
|
|
|
expect(items).toHaveLength(numberOfMenuItems);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the invite member trigger', () => {
|
|
|
|
expect(findInviteMembersTrigger().exists()).toBe(true);
|
2023-04-23 21:23:45 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it("sets the toggle ID and tooltip's target", () => {
|
|
|
|
expect(findGlDisclosureDropdown().props('toggleId')).toBe(wrapper.vm.$options.toggleId);
|
|
|
|
expect(findGlTooltip().props('target')).toBe(`#${wrapper.vm.$options.toggleId}`);
|
|
|
|
});
|
2023-06-20 00:43:36 +05:30
|
|
|
|
|
|
|
it('hides the tooltip when the dropdown is opened', async () => {
|
|
|
|
findGlDisclosureDropdown().vm.$emit('shown');
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(findGlTooltip().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows the tooltip when the dropdown is closed', async () => {
|
|
|
|
findGlDisclosureDropdown().vm.$emit('shown');
|
|
|
|
findGlDisclosureDropdown().vm.$emit('hidden');
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
expect(findGlTooltip().exists()).toBe(true);
|
|
|
|
});
|
2023-07-09 08:55:56 +05:30
|
|
|
|
|
|
|
it('closes the dropdown when invite members modal is opened', () => {
|
|
|
|
findInviteMembersTrigger().vm.$emit('modal-opened');
|
|
|
|
expect(closeAndFocusMock).toHaveBeenCalled();
|
|
|
|
});
|
2023-04-23 21:23:45 +05:30
|
|
|
});
|
|
|
|
});
|