Commit 85fc8ab4 authored by Justin Ho's avatar Justin Ho

Add specs for Unlink button

Similar to spec in groups_list_item_spec.js
Update translations
parent 868ccd00
......@@ -17149,6 +17149,9 @@ msgstr ""
msgid "Integrations|Failed to load namespaces. Please try again."
msgstr ""
msgid "Integrations|Failed to unlink namespace. Please try again."
msgstr ""
msgid "Integrations|Includes Standard plus entire commit message, commit hash, and issue IDs"
msgstr ""
......
import { GlEmptyState, GlTable } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { GlButton, GlEmptyState, GlTable } from '@gitlab/ui';
import { mount, shallowMount } from '@vue/test-utils';
import waitForPromises from 'helpers/wait_for_promises';
import * as JiraConnectApi from '~/jira_connect/api';
import SubscriptionsList from '~/jira_connect/components/subscriptions_list.vue';
import createStore from '~/jira_connect/store';
import { SET_ALERT } from '~/jira_connect/store/mutation_types';
import { reloadPage } from '~/jira_connect/utils';
import { mockSubscription } from '../mock_data';
jest.mock('~/jira_connect/utils');
describe('SubscriptionsList', () => {
let wrapper;
let store;
const createComponent = ({ mountFn = shallowMount, provide = {} } = {}) => {
store = createStore();
const createComponent = ({ provide = {} } = {}) => {
wrapper = shallowMount(SubscriptionsList, {
wrapper = mountFn(SubscriptionsList, {
provide,
store,
});
};
......@@ -19,6 +30,8 @@ describe('SubscriptionsList', () => {
const findGlEmptyState = () => wrapper.findComponent(GlEmptyState);
const findGlTable = () => wrapper.findComponent(GlTable);
const findUnlinkButton = () => findGlTable().findComponent(GlButton);
const clickUnlinkButton = () => findUnlinkButton().trigger('click');
describe('template', () => {
it('renders GlEmptyState when subscriptions is empty', () => {
......@@ -39,4 +52,71 @@ describe('SubscriptionsList', () => {
expect(findGlTable().exists()).toBe(true);
});
});
describe('on "Unlink" button click', () => {
let removeSubscriptionSpy;
beforeEach(() => {
createComponent({
mountFn: mount,
provide: {
subscriptions: [mockSubscription],
},
});
removeSubscriptionSpy = jest.spyOn(JiraConnectApi, 'removeSubscription').mockResolvedValue();
});
it('sets button to loading and sends request', async () => {
expect(findUnlinkButton().props('loading')).toBe(false);
clickUnlinkButton();
await wrapper.vm.$nextTick();
expect(findUnlinkButton().props('loading')).toBe(true);
await waitForPromises();
expect(removeSubscriptionSpy).toHaveBeenCalledWith(mockSubscription.unlink_path);
});
describe('when request is successful', () => {
it('reloads the page', async () => {
clickUnlinkButton();
await waitForPromises();
expect(reloadPage).toHaveBeenCalled();
});
});
describe('when request has errors', () => {
const mockErrorMessage = 'error message';
const mockError = { response: { data: { error: mockErrorMessage } } };
beforeEach(() => {
jest.spyOn(JiraConnectApi, 'removeSubscription').mockRejectedValue(mockError);
jest.spyOn(store, 'commit');
});
it('sets alert', async () => {
clickUnlinkButton();
await waitForPromises();
expect(reloadPage).not.toHaveBeenCalled();
expect(store.commit.mock.calls).toEqual(
expect.arrayContaining([
[
SET_ALERT,
{
message: mockErrorMessage,
variant: 'danger',
},
],
]),
);
});
});
});
});
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