Commit 19b59c33 authored by Peter Hegman's avatar Peter Hegman

Merge branch 'gitlab-ui-integration-1674-popover-close-button' into 'master'

Migrate to built-in popover's close button

See merge request gitlab-org/gitlab!78932
parents 6c499c59 690ceaff
...@@ -52,7 +52,6 @@ export default { ...@@ -52,7 +52,6 @@ export default {
return { return {
disabled: false, disabled: false,
forciblyShowing: false, forciblyShowing: false,
showCloseButton: false,
show: false, show: false,
}; };
}, },
...@@ -85,7 +84,6 @@ export default { ...@@ -85,7 +84,6 @@ export default {
if (this.startInitiallyShown) { if (this.startInitiallyShown) {
this.forciblyShowing = true; this.forciblyShowing = true;
this.showCloseButton = true;
this.show = true; this.show = true;
this.onForciblyShown(); this.onForciblyShown();
} }
...@@ -103,7 +101,6 @@ export default { ...@@ -103,7 +101,6 @@ export default {
}, },
onClose() { onClose() {
this.forciblyShowing = false; this.forciblyShowing = false;
this.show = false;
this.trackPageAction('closeBtnClick'); this.trackPageAction('closeBtnClick');
}, },
onForciblyShown() { onForciblyShown() {
...@@ -141,21 +138,13 @@ export default { ...@@ -141,21 +138,13 @@ export default {
placement="rightbottom" placement="rightbottom"
boundary="viewport" boundary="viewport"
:delay="{ hide: 400 }" :delay="{ hide: 400 }"
:show.sync="show" :show="show"
:triggers="forciblyShowing ? '' : 'hover focus'" :triggers="forciblyShowing ? '' : 'hover focus'"
:show-close-button="startInitiallyShown"
@shown="onShown" @shown="onShown"
@close-button-clicked.prevent="onClose"
> >
<template #title> <template #title>
<gl-button
v-if="showCloseButton"
category="tertiary"
class="close"
data-testid="closeBtn"
:aria-label="$options.i18n.close"
@click.prevent="onClose"
>
<span class="gl-display-inline-block" aria-hidden="true">&times;</span>
</gl-button>
{{ $options.i18n.popoverTitle }} {{ $options.i18n.popoverTitle }}
<gl-emoji class="gl-vertical-align-baseline gl-font-size-inherit gl-ml-1" data-name="wave" /> <gl-emoji class="gl-vertical-align-baseline gl-font-size-inherit gl-ml-1" data-name="wave" />
</template> </template>
......
...@@ -44,7 +44,6 @@ describe('TrialStatusPopover component', () => { ...@@ -44,7 +44,6 @@ describe('TrialStatusPopover component', () => {
planName: 'Ultimate', planName: 'Ultimate',
plansHref: 'billing/path-for/group', plansHref: 'billing/path-for/group',
purchaseHref: 'transactions/new', purchaseHref: 'transactions/new',
startInitiallyShown: undefined,
targetId: 'target-element-identifier', targetId: 'target-element-identifier',
trialEndDate: new Date('2021-02-28'), trialEndDate: new Date('2021-02-28'),
userCalloutsPath: undefined, userCalloutsPath: undefined,
...@@ -207,16 +206,24 @@ describe('TrialStatusPopover component', () => { ...@@ -207,16 +206,24 @@ describe('TrialStatusPopover component', () => {
wrapper = createComponent({ providers: { startInitiallyShown: true }, mountFn: mount }); wrapper = createComponent({ providers: { startInitiallyShown: true }, mountFn: mount });
}); });
it('is rendered', () => { it('is enabled', () => {
expect(wrapper.findByTestId('closeBtn').exists()).toBeTruthy(); expect(findGlPopover().props('showCloseButton')).toBe(true);
}); });
describe('when clicked', () => { describe('when clicked', () => {
const preventDefault = jest.fn();
beforeEach(async () => { beforeEach(async () => {
wrapper.findByTestId('closeBtn').trigger('click'); findGlPopover().vm.$emit('close-button-clicked', {
preventDefault,
});
await nextTick(); await nextTick();
}); });
it("calls `preventDefault` so user doesn't trigger the anchor tag", () => {
expect(preventDefault).toHaveBeenCalled();
});
it('closes the popover component', () => { it('closes the popover component', () => {
expect(findGlPopover().props('show')).toBeFalsy(); expect(findGlPopover().props('show')).toBeFalsy();
}); });
...@@ -226,14 +233,14 @@ describe('TrialStatusPopover component', () => { ...@@ -226,14 +233,14 @@ describe('TrialStatusPopover component', () => {
}); });
it('continues to be shown in the popover', () => { it('continues to be shown in the popover', () => {
expect(wrapper.findByTestId('closeBtn').exists()).toBeTruthy(); expect(findGlPopover().props('showCloseButton')).toBe(true);
}); });
}); });
}); });
describe('when the popover does not start off forcibly shown', () => { describe('when the popover does not start off forcibly shown', () => {
it('is not rendered', () => { it('is not rendered', () => {
expect(wrapper.findByTestId('closeBtn').exists()).toBeFalsy(); expect(findGlPopover().props('showCloseButton')).toBe(false);
}); });
}); });
}); });
......
...@@ -41,10 +41,15 @@ jest.mock('@gitlab/ui/dist/components/base/popover/popover.js', () => ({ ...@@ -41,10 +41,15 @@ jest.mock('@gitlab/ui/dist/components/base/popover/popover.js', () => ({
default: () => [], default: () => [],
}, },
...Object.fromEntries( ...Object.fromEntries(
['title', 'target', 'triggers', 'placement', 'boundary', 'container'].map((prop) => [ [
prop, 'title',
{}, 'target',
]), 'triggers',
'placement',
'boundary',
'container',
'showCloseButton',
].map((prop) => [prop, {}]),
), ),
}, },
render(h) { render(h) {
......
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