debian-mirror-gitlab/spec/frontend/vue_shared/components/help_popover_spec.js

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

126 lines
3 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { GlButton, GlPopover } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import HelpPopover from '~/vue_shared/components/help_popover.vue';
describe('HelpPopover', () => {
let wrapper;
const title = 'popover <strong>title</strong>';
const content = 'popover <b>content</b>';
2022-08-27 11:52:29 +05:30
const findQuestionButton = () => wrapper.findComponent(GlButton);
const findPopover = () => wrapper.findComponent(GlPopover);
2022-04-04 11:22:00 +05:30
const createComponent = ({ props, ...opts } = {}) => {
2021-03-11 19:13:27 +05:30
wrapper = mount(HelpPopover, {
propsData: {
options: {
title,
content,
},
2022-04-04 11:22:00 +05:30
...props,
2021-03-11 19:13:27 +05:30
},
2022-04-04 11:22:00 +05:30
...opts,
2021-03-11 19:13:27 +05:30
});
};
afterEach(() => {
wrapper.destroy();
});
2022-04-04 11:22:00 +05:30
describe('with title and content', () => {
beforeEach(() => {
createComponent();
2021-03-11 19:13:27 +05:30
});
2022-04-04 11:22:00 +05:30
it('renders a link button with an icon question', () => {
expect(findQuestionButton().props()).toMatchObject({
2022-06-21 17:19:12 +05:30
icon: 'question-o',
2022-04-04 11:22:00 +05:30
variant: 'link',
});
});
2021-03-11 19:13:27 +05:30
2022-04-04 11:22:00 +05:30
it('renders popover that uses the question button as target', () => {
expect(findPopover().props().target()).toBe(findQuestionButton().vm.$el);
});
2021-03-11 19:13:27 +05:30
2022-04-04 11:22:00 +05:30
it('shows title and content', () => {
expect(findPopover().html()).toContain(title);
expect(findPopover().html()).toContain(content);
});
it('allows rendering title with HTML tags', () => {
expect(findPopover().find('strong').exists()).toBe(true);
});
it('allows rendering content with HTML tags', () => {
expect(findPopover().find('b').exists()).toBe(true);
});
2021-03-11 19:13:27 +05:30
});
2021-04-29 21:17:54 +05:30
describe('without title', () => {
2022-04-04 11:22:00 +05:30
beforeEach(() => {
createComponent({
props: {
options: {
title: null,
content,
},
},
});
});
it('does not show title', () => {
expect(findPopover().html()).not.toContain(title);
});
2021-04-29 21:17:54 +05:30
2022-04-04 11:22:00 +05:30
it('shows content', () => {
expect(findPopover().html()).toContain(content);
2021-04-29 21:17:54 +05:30
});
});
2022-04-04 11:22:00 +05:30
describe('with other options', () => {
2021-03-11 19:13:27 +05:30
const placement = 'bottom';
2022-04-04 11:22:00 +05:30
beforeEach(() => {
createComponent({
props: {
options: {
placement,
},
},
});
});
it('options bind to the popover', () => {
expect(findPopover().props().placement).toBe(placement);
});
});
describe('with custom slots', () => {
const titleSlot = '<h1>title</h1>';
const defaultSlot = '<strong>content</strong>';
2021-03-11 19:13:27 +05:30
2022-04-04 11:22:00 +05:30
beforeEach(() => {
createComponent({
slots: {
title: titleSlot,
default: defaultSlot,
},
});
});
it('shows title slot', () => {
expect(findPopover().html()).toContain(titleSlot);
});
it('shows default content slot', () => {
expect(findPopover().html()).toContain(defaultSlot);
});
it('overrides title and content from options', () => {
expect(findPopover().html()).not.toContain(title);
expect(findPopover().html()).toContain(content);
});
2021-03-11 19:13:27 +05:30
});
});