debian-mirror-gitlab/spec/frontend/groups/components/invite_members_banner_spec.js

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

140 lines
4.1 KiB
JavaScript
Raw Normal View History

2021-11-11 11:23:49 +05:30
import { GlBanner } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2021-11-11 11:23:49 +05:30
import MockAdapter from 'axios-mock-adapter';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
2020-11-24 15:15:51 +05:30
import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
import InviteMembersBanner from '~/groups/components/invite_members_banner.vue';
2021-06-08 01:23:25 +05:30
import eventHub from '~/invite_members/event_hub';
2021-11-11 11:23:49 +05:30
import axios from '~/lib/utils/axios_utils';
2023-04-23 21:23:45 +05:30
import { HTTP_STATUS_OK } from '~/lib/utils/http_status';
2020-11-24 15:15:51 +05:30
jest.mock('~/lib/utils/common_utils');
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";
const buttonText = 'Invite your colleagues';
2021-11-11 11:23:49 +05:30
const provide = {
svgPath: '/illustrations/background',
inviteMembersPath: 'groups/members',
trackLabel: 'invite_members_banner',
calloutsPath: 'call/out/path',
calloutsFeatureId: 'some-feature-id',
groupId: '1',
};
2020-11-24 15:15:51 +05:30
const createComponent = (stubs = {}) => {
return shallowMount(InviteMembersBanner, {
2021-11-11 11:23:49 +05:30
provide,
2020-11-24 15:15:51 +05:30
stubs,
});
};
describe('InviteMembersBanner', () => {
let wrapper;
let trackingSpy;
2021-11-11 11:23:49 +05:30
let mockAxios;
2020-11-24 15:15:51 +05:30
beforeEach(() => {
2021-11-11 11:23:49 +05:30
mockAxios = new MockAdapter(axios);
2020-11-24 15:15:51 +05:30
document.body.dataset.page = 'any:page';
trackingSpy = mockTracking('_category_', undefined, jest.spyOn);
});
afterEach(() => {
2021-11-11 11:23:49 +05:30
mockAxios.restore();
2020-11-24 15:15:51 +05:30
unmockTracking();
});
describe('tracking', () => {
2021-11-11 11:23:49 +05:30
const mockTrackingOnWrapper = () => {
unmockTracking();
trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn);
};
2020-11-24 15:15:51 +05:30
beforeEach(() => {
wrapper = createComponent({ GlBanner });
});
const trackCategory = undefined;
it('sends the displayEvent when the banner is displayed', () => {
2021-11-11 11:23:49 +05:30
const displayEvent = 'invite_members_banner_displayed';
2020-11-24 15:15:51 +05:30
expect(trackingSpy).toHaveBeenCalledWith(trackCategory, displayEvent, {
2021-11-11 11:23:49 +05:30
label: provide.trackLabel,
2020-11-24 15:15:51 +05:30
});
});
2021-06-08 01:23:25 +05:30
describe('when the button is clicked', () => {
beforeEach(() => {
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
2022-10-11 01:57:18 +05:30
wrapper.findComponent(GlBanner).vm.$emit('primary');
2021-06-08 01:23:25 +05:30
});
it('calls openModal through the eventHub', () => {
expect(eventHub.$emit).toHaveBeenCalledWith('openModal', {
source: 'invite_members_banner',
});
});
2020-11-24 15:15:51 +05:30
});
it('sends the dismissEvent when the banner is dismissed', () => {
2021-11-11 11:23:49 +05:30
mockTrackingOnWrapper();
2023-04-23 21:23:45 +05:30
mockAxios.onPost(provide.calloutsPath).replyOnce(HTTP_STATUS_OK);
2021-11-11 11:23:49 +05:30
const dismissEvent = 'invite_members_banner_dismissed';
2022-10-11 01:57:18 +05:30
wrapper.findComponent(GlBanner).vm.$emit('close');
2020-11-24 15:15:51 +05:30
expect(trackingSpy).toHaveBeenCalledWith(trackCategory, dismissEvent, {
2021-11-11 11:23:49 +05:30
label: provide.trackLabel,
2020-11-24 15:15:51 +05:30
});
});
});
describe('rendering', () => {
const findBanner = () => {
2022-10-11 01:57:18 +05:30
return wrapper.findComponent(GlBanner);
2020-11-24 15:15:51 +05:30
};
beforeEach(() => {
wrapper = createComponent();
});
it('uses the svgPath for the banner svgpath', () => {
2021-11-11 11:23:49 +05:30
expect(findBanner().attributes('svgpath')).toBe(provide.svgPath);
2020-11-24 15:15:51 +05:30
});
it('uses the title from options for title', () => {
expect(findBanner().attributes('title')).toBe(title);
});
it('includes the body text from options', () => {
expect(findBanner().html()).toContain(body);
});
it('uses the button_text text from options for buttontext', () => {
expect(findBanner().attributes('buttontext')).toBe(buttonText);
});
});
describe('dismissing', () => {
beforeEach(() => {
wrapper = createComponent({ GlBanner });
});
2021-11-11 11:23:49 +05:30
it('should render the banner when not dismissed', () => {
2022-10-11 01:57:18 +05:30
expect(wrapper.findComponent(GlBanner).exists()).toBe(true);
2020-11-24 15:15:51 +05:30
});
2021-11-11 11:23:49 +05:30
it('should close the banner when dismiss is clicked', async () => {
2023-04-23 21:23:45 +05:30
mockAxios.onPost(provide.calloutsPath).replyOnce(HTTP_STATUS_OK);
2022-10-11 01:57:18 +05:30
expect(wrapper.findComponent(GlBanner).exists()).toBe(true);
wrapper.findComponent(GlBanner).vm.$emit('close');
2020-11-24 15:15:51 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
2022-10-11 01:57:18 +05:30
expect(wrapper.findComponent(GlBanner).exists()).toBe(false);
2020-11-24 15:15:51 +05:30
});
});
});