2021-03-11 19:13:27 +05:30
|
|
|
import { GlAvatar, GlButton } from '@gitlab/ui';
|
|
|
|
import { mount, shallowMount } from '@vue/test-utils';
|
2021-03-08 18:12:59 +05:30
|
|
|
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
|
2021-03-11 19:13:27 +05:30
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
import * as JiraConnectApi from '~/jira_connect/api';
|
2021-03-08 18:12:59 +05:30
|
|
|
import GroupsListItem from '~/jira_connect/components/groups_list_item.vue';
|
2021-04-17 20:07:23 +05:30
|
|
|
import { persistAlert } from '~/jira_connect/utils';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { mockGroup1 } from '../mock_data';
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
jest.mock('~/jira_connect/utils');
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
describe('GroupsListItem', () => {
|
|
|
|
let wrapper;
|
2021-03-11 19:13:27 +05:30
|
|
|
const mockSubscriptionPath = 'subscriptionPath';
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
const reloadSpy = jest.fn();
|
|
|
|
|
|
|
|
global.AP = {
|
|
|
|
navigator: {
|
|
|
|
reload: reloadSpy,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const createComponent = ({ mountFn = shallowMount } = {}) => {
|
2021-03-08 18:12:59 +05:30
|
|
|
wrapper = extendedWrapper(
|
2021-03-11 19:13:27 +05:30
|
|
|
mountFn(GroupsListItem, {
|
2021-03-08 18:12:59 +05:30
|
|
|
propsData: {
|
|
|
|
group: mockGroup1,
|
|
|
|
},
|
2021-03-11 19:13:27 +05:30
|
|
|
provide: {
|
|
|
|
subscriptionsPath: mockSubscriptionPath,
|
|
|
|
},
|
2021-03-08 18:12:59 +05:30
|
|
|
}),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
const findGlAvatar = () => wrapper.find(GlAvatar);
|
|
|
|
const findGroupName = () => wrapper.findByTestId('group-list-item-name');
|
|
|
|
const findGroupDescription = () => wrapper.findByTestId('group-list-item-description');
|
2021-03-11 19:13:27 +05:30
|
|
|
const findLinkButton = () => wrapper.find(GlButton);
|
|
|
|
const clickLinkButton = () => findLinkButton().trigger('click');
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
describe('template', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders group avatar', () => {
|
|
|
|
expect(findGlAvatar().exists()).toBe(true);
|
|
|
|
expect(findGlAvatar().props('src')).toBe(mockGroup1.avatar_url);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders group name', () => {
|
|
|
|
expect(findGroupName().text()).toBe(mockGroup1.full_name);
|
|
|
|
});
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
it('renders group description', () => {
|
|
|
|
expect(findGroupDescription().text()).toBe(mockGroup1.description);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders Link button', () => {
|
|
|
|
expect(findLinkButton().exists()).toBe(true);
|
|
|
|
expect(findLinkButton().text()).toBe('Link');
|
|
|
|
});
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
describe('on Link button click', () => {
|
|
|
|
let addSubscriptionSpy;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ mountFn: mount });
|
|
|
|
|
|
|
|
addSubscriptionSpy = jest.spyOn(JiraConnectApi, 'addSubscription').mockResolvedValue();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets button to loading and sends request', async () => {
|
|
|
|
expect(findLinkButton().props('loading')).toBe(false);
|
|
|
|
|
|
|
|
clickLinkButton();
|
|
|
|
|
|
|
|
await wrapper.vm.$nextTick();
|
|
|
|
|
|
|
|
expect(findLinkButton().props('loading')).toBe(true);
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
await waitForPromises();
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(addSubscriptionSpy).toHaveBeenCalledWith(mockSubscriptionPath, mockGroup1.full_path);
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(persistAlert).toHaveBeenCalledWith({
|
|
|
|
linkUrl: '/help/integration/jira_development_panel.html#usage',
|
|
|
|
message:
|
|
|
|
'You should now see GitLab.com activity inside your Jira Cloud issues. %{linkStart}Learn more%{linkEnd}',
|
|
|
|
title: 'Namespace successfully linked',
|
|
|
|
variant: 'success',
|
|
|
|
});
|
2021-03-11 19:13:27 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('when request is successful', () => {
|
|
|
|
it('reloads the page', async () => {
|
|
|
|
clickLinkButton();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(reloadSpy).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when request has errors', () => {
|
|
|
|
const mockErrorMessage = 'error message';
|
|
|
|
const mockError = { response: { data: { error: mockErrorMessage } } };
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
addSubscriptionSpy = jest
|
|
|
|
.spyOn(JiraConnectApi, 'addSubscription')
|
|
|
|
.mockRejectedValue(mockError);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('emits `error` event', async () => {
|
|
|
|
clickLinkButton();
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(reloadSpy).not.toHaveBeenCalled();
|
|
|
|
expect(wrapper.emitted('error')[0][0]).toBe(mockErrorMessage);
|
|
|
|
});
|
|
|
|
});
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
|
|
|
});
|