Commit d318043a authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Merge branch 'add-dismissable-by-group-per-user-to-invite-banner' into 'master'

Add cookie to dismiss button on invite group banner

See merge request gitlab-org/gitlab!38362
parents ab0560cd a659e955
<script> <script>
import { GlBanner } from '@gitlab/ui'; import { GlBanner } from '@gitlab/ui';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { parseBoolean, setCookie, getCookie } from '~/lib/utils/common_utils';
export default { export default {
components: { components: {
GlBanner, GlBanner,
}, },
inject: ['svgPath', 'inviteMembersPath'], inject: ['svgPath', 'inviteMembersPath', 'isDismissedKey'],
data() { data() {
return { return {
visible: true, isDismissed: parseBoolean(getCookie(this.isDismissedKey)),
}; };
}, },
methods: { methods: {
handleClose() { handleClose() {
this.visible = false; setCookie(this.isDismissedKey, true);
this.isDismissed = true;
}, },
}, },
i18n: { i18n: {
...@@ -29,7 +31,7 @@ export default { ...@@ -29,7 +31,7 @@ export default {
<template> <template>
<gl-banner <gl-banner
v-if="visible" v-if="!isDismissed"
ref="banner" ref="banner"
:title="$options.i18n.title" :title="$options.i18n.title"
:button-text="$options.i18n.button_text" :button-text="$options.i18n.button_text"
......
...@@ -8,13 +8,14 @@ export default function initInviteMembersBanner() { ...@@ -8,13 +8,14 @@ export default function initInviteMembersBanner() {
return false; return false;
} }
const { svgPath, inviteMembersPath } = el.dataset; const { svgPath, inviteMembersPath, isDismissedKey } = el.dataset;
return new Vue({ return new Vue({
el, el,
provide: { provide: {
svgPath, svgPath,
inviteMembersPath, inviteMembersPath,
isDismissedKey,
}, },
render: createElement => createElement(InviteMembersBanner), render: createElement => createElement(InviteMembersBanner),
}); });
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
= content_for :group_invite_members_banner do = content_for :group_invite_members_banner do
.container-fluid.container-limited{ class: "gl-pb-2! gl-pt-6! #{@content_class}" } .container-fluid.container-limited{ class: "gl-pb-2! gl-pt-6! #{@content_class}" }
.js-group-invite-members-banner{ data: { svg_path: image_path('illustrations/merge_requests.svg'), .js-group-invite-members-banner{ data: { svg_path: image_path('illustrations/merge_requests.svg'),
is_dismissed_key: "invite_#{@group.id}_#{current_user.id}",
invite_members_path: group_group_members_path(@group) } } invite_members_path: group_group_members_path(@group) } }
= content_for :meta_tags do = content_for :meta_tags do
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlBanner } from '@gitlab/ui'; import { GlBanner } from '@gitlab/ui';
import InviteMembersBanner from '~/groups/components/invite_members_banner.vue'; import InviteMembersBanner from '~/groups/components/invite_members_banner.vue';
import { setCookie, parseBoolean } from '~/lib/utils/common_utils';
const expectedTitle = 'Collaborate with your team'; jest.mock('~/lib/utils/common_utils');
const expectedBody =
const isDismissedKey = 'invite_99_1';
const title = 'Collaborate with your team';
const body =
"We noticed that you haven't invited anyone to this group. Invite your colleagues so you can discuss issues, collaborate on merge requests, and share your knowledge"; "We noticed that you haven't invited anyone to this group. Invite your colleagues so you can discuss issues, collaborate on merge requests, and share your knowledge";
const expectedSvgPath = '/illustrations/background'; const svgPath = '/illustrations/background';
const expectedInviteMembersPath = 'groups/members'; const inviteMembersPath = 'groups/members';
const expectedButtonText = 'Invite your colleagues'; const buttonText = 'Invite your colleagues';
const createComponent = (stubs = {}) => { const createComponent = (stubs = {}) => {
return shallowMount(InviteMembersBanner, { return shallowMount(InviteMembersBanner, {
provide: { provide: {
svgPath: expectedSvgPath, svgPath,
inviteMembersPath: expectedInviteMembersPath, inviteMembersPath,
isDismissedKey,
}, },
stubs, stubs,
}); });
...@@ -37,23 +42,23 @@ describe('InviteMembersBanner', () => { ...@@ -37,23 +42,23 @@ describe('InviteMembersBanner', () => {
}); });
it('uses the svgPath for the banner svgpath', () => { it('uses the svgPath for the banner svgpath', () => {
expect(findBanner().attributes('svgpath')).toBe(expectedSvgPath); expect(findBanner().attributes('svgpath')).toBe(svgPath);
}); });
it('uses the title from options for title', () => { it('uses the title from options for title', () => {
expect(findBanner().attributes('title')).toBe(expectedTitle); expect(findBanner().attributes('title')).toBe(title);
}); });
it('includes the body text from options', () => { it('includes the body text from options', () => {
expect(findBanner().html()).toContain(expectedBody); expect(findBanner().html()).toContain(body);
}); });
it('uses the button_text text from options for buttontext', () => { it('uses the button_text text from options for buttontext', () => {
expect(findBanner().attributes('buttontext')).toBe(expectedButtonText); expect(findBanner().attributes('buttontext')).toBe(buttonText);
}); });
it('uses the href from inviteMembersPath for buttonlink', () => { it('uses the href from inviteMembersPath for buttonlink', () => {
expect(findBanner().attributes('buttonlink')).toBe(expectedInviteMembersPath); expect(findBanner().attributes('buttonlink')).toBe(inviteMembersPath);
}); });
}); });
...@@ -61,16 +66,35 @@ describe('InviteMembersBanner', () => { ...@@ -61,16 +66,35 @@ describe('InviteMembersBanner', () => {
const findButton = () => { const findButton = () => {
return wrapper.find('button'); return wrapper.find('button');
}; };
const stubs = {
GlBanner,
};
it('sets visible to false', () => { beforeEach(() => {
wrapper = createComponent(stubs); wrapper = createComponent({ GlBanner });
findButton().trigger('click'); findButton().trigger('click');
});
it('sets iDismissed to true', () => {
expect(wrapper.vm.isDismissed).toBe(true);
});
it('sets the cookie with the isDismissedKey', () => {
expect(setCookie).toHaveBeenCalledWith(isDismissedKey, true);
});
});
describe('when a dismiss cookie exists', () => {
beforeEach(() => {
parseBoolean.mockReturnValue(true);
wrapper = createComponent({ GlBanner });
});
it('sets isDismissed to true', () => {
expect(wrapper.vm.isDismissed).toBe(true);
});
expect(wrapper.vm.visible).toBe(false); it('does not render the banner', () => {
expect(wrapper.contains(GlBanner)).toBe(false);
}); });
}); });
}); });
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