Commit eb0b2c47 authored by David O'Regan's avatar David O'Regan

Merge branch 'mrincon-add-slots-to-help-popover' into 'master'

Pass custom slots from HelpPopover to GlPopover

See merge request gitlab-org/gitlab!79319
parents adbada71 87d190eb
...@@ -33,6 +33,9 @@ export default { ...@@ -33,6 +33,9 @@ export default {
<template #default> <template #default>
<div v-safe-html="options.content"></div> <div v-safe-html="options.content"></div>
</template> </template>
<template v-for="slot in Object.keys($slots)" #[slot]>
<slot :name="slot"></slot>
</template>
</gl-popover> </gl-popover>
</span> </span>
</template> </template>
...@@ -9,26 +9,29 @@ describe('HelpPopover', () => { ...@@ -9,26 +9,29 @@ describe('HelpPopover', () => {
const findQuestionButton = () => wrapper.find(GlButton); const findQuestionButton = () => wrapper.find(GlButton);
const findPopover = () => wrapper.find(GlPopover); const findPopover = () => wrapper.find(GlPopover);
const buildWrapper = (options = {}) => {
const createComponent = ({ props, ...opts } = {}) => {
wrapper = mount(HelpPopover, { wrapper = mount(HelpPopover, {
propsData: { propsData: {
options: { options: {
title, title,
content, content,
...options,
}, },
...props,
}, },
...opts,
}); });
}; };
beforeEach(() => {
buildWrapper();
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
describe('with title and content', () => {
beforeEach(() => {
createComponent();
});
it('renders a link button with an icon question', () => { it('renders a link button with an icon question', () => {
expect(findQuestionButton().props()).toMatchObject({ expect(findQuestionButton().props()).toMatchObject({
icon: 'question', icon: 'question',
...@@ -40,6 +43,11 @@ describe('HelpPopover', () => { ...@@ -40,6 +43,11 @@ describe('HelpPopover', () => {
expect(findPopover().props().target()).toBe(findQuestionButton().vm.$el); expect(findPopover().props().target()).toBe(findQuestionButton().vm.$el);
}); });
it('shows title and content', () => {
expect(findPopover().html()).toContain(title);
expect(findPopover().html()).toContain(content);
});
it('allows rendering title with HTML tags', () => { it('allows rendering title with HTML tags', () => {
expect(findPopover().find('strong').exists()).toBe(true); expect(findPopover().find('strong').exists()).toBe(true);
}); });
...@@ -47,21 +55,71 @@ describe('HelpPopover', () => { ...@@ -47,21 +55,71 @@ describe('HelpPopover', () => {
it('allows rendering content with HTML tags', () => { it('allows rendering content with HTML tags', () => {
expect(findPopover().find('b').exists()).toBe(true); expect(findPopover().find('b').exists()).toBe(true);
}); });
});
describe('without title', () => { describe('without title', () => {
it('does not render title', () => { beforeEach(() => {
buildWrapper({ title: null }); createComponent({
props: {
options: {
title: null,
content,
},
},
});
});
expect(findPopover().find('span').exists()).toBe(false); it('does not show title', () => {
expect(findPopover().html()).not.toContain(title);
});
it('shows content', () => {
expect(findPopover().html()).toContain(content);
}); });
}); });
it('binds other popover options to the popover instance', () => { describe('with other options', () => {
const placement = 'bottom'; const placement = 'bottom';
wrapper.destroy(); beforeEach(() => {
buildWrapper({ placement }); createComponent({
props: {
options: {
placement,
},
},
});
});
it('options bind to the popover', () => {
expect(findPopover().props().placement).toBe(placement); expect(findPopover().props().placement).toBe(placement);
}); });
});
describe('with custom slots', () => {
const titleSlot = '<h1>title</h1>';
const defaultSlot = '<strong>content</strong>';
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);
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment