2020-06-23 00:09:42 +05:30
|
|
|
import { GlIntersectionObserver } from '@gitlab/ui';
|
2018-03-17 18:26:18 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2021-09-04 01:27:46 +05:30
|
|
|
import { nextTick } from 'vue';
|
2021-11-11 11:23:49 +05:30
|
|
|
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
|
2022-06-21 17:19:12 +05:30
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
2018-05-09 12:01:36 +05:30
|
|
|
import '~/behaviors/markdown/render_gfm';
|
2022-01-26 12:08:38 +05:30
|
|
|
import { IssuableStatus, IssuableStatusText } from '~/issues/constants';
|
|
|
|
import IssuableApp from '~/issues/show/components/app.vue';
|
|
|
|
import DescriptionComponent from '~/issues/show/components/description.vue';
|
2022-06-21 17:19:12 +05:30
|
|
|
import EditedComponent from '~/issues/show/components/edited.vue';
|
|
|
|
import FormComponent from '~/issues/show/components/form.vue';
|
|
|
|
import TitleComponent from '~/issues/show/components/title.vue';
|
2022-01-26 12:08:38 +05:30
|
|
|
import IncidentTabs from '~/issues/show/components/incidents/incident_tabs.vue';
|
|
|
|
import PinnedLinks from '~/issues/show/components/pinned_links.vue';
|
|
|
|
import { POLLING_DELAY } from '~/issues/show/constants';
|
|
|
|
import eventHub from '~/issues/show/event_hub';
|
2021-03-11 19:13:27 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import { visitUrl } from '~/lib/utils/url_utility';
|
2020-11-24 15:15:51 +05:30
|
|
|
import {
|
|
|
|
appProps,
|
|
|
|
initialRequest,
|
|
|
|
publishedIncidentUrl,
|
|
|
|
secondRequest,
|
|
|
|
zoomMeetingUrl,
|
2021-09-04 01:27:46 +05:30
|
|
|
} from '../mock_data/mock_data';
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
jest.mock('~/lib/utils/url_utility');
|
2022-01-26 12:08:38 +05:30
|
|
|
jest.mock('~/issues/show/event_hub');
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
const REALTIME_REQUEST_STACK = [initialRequest, secondRequest];
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe('Issuable output', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
let mock;
|
|
|
|
let realtimeRequestCount = 0;
|
2020-06-23 00:09:42 +05:30
|
|
|
let wrapper;
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
const findStickyHeader = () => wrapper.findByTestId('issue-sticky-header');
|
|
|
|
const findLockedBadge = () => wrapper.findByTestId('locked');
|
|
|
|
const findConfidentialBadge = () => wrapper.findByTestId('confidential');
|
|
|
|
const findHiddenBadge = () => wrapper.findByTestId('hidden');
|
2022-06-21 17:19:12 +05:30
|
|
|
|
|
|
|
const findTitle = () => wrapper.findComponent(TitleComponent);
|
|
|
|
const findDescription = () => wrapper.findComponent(DescriptionComponent);
|
|
|
|
const findEdited = () => wrapper.findComponent(EditedComponent);
|
|
|
|
const findForm = () => wrapper.findComponent(FormComponent);
|
|
|
|
const findPinnedLinks = () => wrapper.findComponent(PinnedLinks);
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
const mountComponent = (props = {}, options = {}, data = {}) => {
|
2022-06-21 17:19:12 +05:30
|
|
|
wrapper = shallowMountExtended(IssuableApp, {
|
2021-11-11 11:23:49 +05:30
|
|
|
directives: {
|
|
|
|
GlTooltip: createMockDirective(),
|
|
|
|
},
|
2020-11-24 15:15:51 +05:30
|
|
|
propsData: { ...appProps, ...props },
|
|
|
|
provide: {
|
|
|
|
fullPath: 'gitlab-org/incidents',
|
|
|
|
iid: '19',
|
2021-03-08 18:12:59 +05:30
|
|
|
uploadMetricsFeatureAvailable: false,
|
2020-11-24 15:15:51 +05:30
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
HighlightBar: true,
|
|
|
|
IncidentTabs: true,
|
|
|
|
},
|
2021-09-04 01:27:46 +05:30
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
...data,
|
|
|
|
};
|
|
|
|
},
|
2020-11-24 15:15:51 +05:30
|
|
|
...options,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
beforeEach(() => {
|
2019-03-02 22:35:43 +05:30
|
|
|
setFixtures(`
|
|
|
|
<div>
|
2020-05-24 23:13:21 +05:30
|
|
|
<title>Title</title>
|
2019-12-21 20:55:43 +05:30
|
|
|
<div class="detail-page-description content-block">
|
|
|
|
<details open>
|
|
|
|
<summary>One</summary>
|
|
|
|
</details>
|
|
|
|
<details>
|
|
|
|
<summary>Two</summary>
|
|
|
|
</details>
|
|
|
|
</div>
|
2019-03-02 22:35:43 +05:30
|
|
|
<div class="flash-container"></div>
|
|
|
|
<span id="task_status"></span>
|
|
|
|
</div>
|
|
|
|
`);
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
mock = new MockAdapter(axios);
|
2020-04-08 14:13:33 +05:30
|
|
|
mock
|
|
|
|
.onGet('/gitlab-org/gitlab-shell/-/issues/9/realtime_changes/realtime_changes')
|
|
|
|
.reply(() => {
|
|
|
|
const res = Promise.resolve([200, REALTIME_REQUEST_STACK[realtimeRequestCount]]);
|
|
|
|
realtimeRequestCount += 1;
|
|
|
|
return res;
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
mountComponent();
|
|
|
|
|
|
|
|
jest.advanceTimersByTime(2);
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
mock.restore();
|
|
|
|
realtimeRequestCount = 0;
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.poll.stop();
|
|
|
|
wrapper.destroy();
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('should render a title/description/edited and update title/description/edited on update', () => {
|
|
|
|
return axios
|
|
|
|
.waitForAll()
|
2018-12-13 13:39:08 +05:30
|
|
|
.then(() => {
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(findTitle().props('titleText')).toContain('this is a title');
|
|
|
|
expect(findDescription().props('descriptionText')).toContain('this is a description');
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(findEdited().exists()).toBe(true);
|
|
|
|
expect(findEdited().props('updatedByPath')).toMatch(/\/some_user$/);
|
|
|
|
expect(findEdited().props('updatedAt')).toBeTruthy();
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(wrapper.vm.state.lock_version).toBe(initialRequest.lock_version);
|
2018-12-13 13:39:08 +05:30
|
|
|
})
|
|
|
|
.then(() => {
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.poll.makeRequest();
|
2020-05-24 23:13:21 +05:30
|
|
|
return axios.waitForAll();
|
2018-12-13 13:39:08 +05:30
|
|
|
})
|
|
|
|
.then(() => {
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(findTitle().props('titleText')).toContain('2');
|
|
|
|
expect(findDescription().props('descriptionText')).toContain('42');
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(findEdited().exists()).toBe(true);
|
|
|
|
expect(findEdited().props('updatedByName')).toBe('Other User');
|
|
|
|
expect(findEdited().props('updatedByPath')).toMatch(/\/other_user$/);
|
|
|
|
expect(findEdited().props('updatedAt')).toBeTruthy();
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('shows actions if permissions are correct', async () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.showForm = true;
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(findForm().exists()).toBe(true);
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('does not show actions if permissions are incorrect', async () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.showForm = true;
|
|
|
|
wrapper.setProps({ canUpdate: false });
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(findForm().exists()).toBe(false);
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('does not update formState if form is already open', async () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.updateAndShowForm();
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.state.titleText = 'testing 123';
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.updateAndShowForm();
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(wrapper.vm.store.formState.title).not.toBe('testing 123');
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
describe('Pinned links propagated', () => {
|
|
|
|
it.each`
|
|
|
|
prop | value
|
|
|
|
${'zoomMeetingUrl'} | ${zoomMeetingUrl}
|
|
|
|
${'publishedIncidentUrl'} | ${publishedIncidentUrl}
|
|
|
|
`('sets the $prop correctly on underlying pinned links', ({ prop, value }) => {
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(findPinnedLinks().props(prop)).toBe(value);
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe('updateIssuable', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
it('fetches new data after update', async () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
const updateStoreSpy = jest.spyOn(wrapper.vm, 'updateStoreState');
|
|
|
|
const getDataSpy = jest.spyOn(wrapper.vm.service, 'getData');
|
|
|
|
jest.spyOn(wrapper.vm.service, 'updateIssuable').mockResolvedValue({
|
2020-05-24 23:13:21 +05:30
|
|
|
data: { web_url: window.location.pathname },
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await wrapper.vm.updateIssuable();
|
|
|
|
expect(updateStoreSpy).toHaveBeenCalled();
|
|
|
|
expect(getDataSpy).toHaveBeenCalled();
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('correctly updates issuable data', async () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
const spy = jest.spyOn(wrapper.vm.service, 'updateIssuable').mockResolvedValue({
|
2020-05-24 23:13:21 +05:30
|
|
|
data: { web_url: window.location.pathname },
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await wrapper.vm.updateIssuable();
|
|
|
|
expect(spy).toHaveBeenCalledWith(wrapper.vm.formState);
|
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('close.form');
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('does not redirect if issue has not moved', async () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(wrapper.vm.service, 'updateIssuable').mockResolvedValue({
|
2020-05-24 23:13:21 +05:30
|
|
|
data: {
|
|
|
|
web_url: window.location.pathname,
|
2020-06-23 00:09:42 +05:30
|
|
|
confidential: wrapper.vm.isConfidential,
|
2020-05-24 23:13:21 +05:30
|
|
|
},
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await wrapper.vm.updateIssuable();
|
|
|
|
expect(visitUrl).not.toHaveBeenCalled();
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('does not redirect if issue has not moved and user has switched tabs', async () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(wrapper.vm.service, 'updateIssuable').mockResolvedValue({
|
2020-05-24 23:13:21 +05:30
|
|
|
data: {
|
|
|
|
web_url: '',
|
2020-06-23 00:09:42 +05:30
|
|
|
confidential: wrapper.vm.isConfidential,
|
2020-05-24 23:13:21 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await wrapper.vm.updateIssuable();
|
|
|
|
expect(visitUrl).not.toHaveBeenCalled();
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('redirects if returned web_url has changed', async () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(wrapper.vm.service, 'updateIssuable').mockResolvedValue({
|
2020-05-24 23:13:21 +05:30
|
|
|
data: {
|
|
|
|
web_url: '/testing-issue-move',
|
2020-06-23 00:09:42 +05:30
|
|
|
confidential: wrapper.vm.isConfidential,
|
2020-05-24 23:13:21 +05:30
|
|
|
},
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.updateIssuable();
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await wrapper.vm.updateIssuable();
|
|
|
|
expect(visitUrl).toHaveBeenCalledWith('/testing-issue-move');
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe('shows dialog when issue has unsaved changed', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
it('confirms on title change', async () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.showForm = true;
|
|
|
|
wrapper.vm.state.titleText = 'title has changed';
|
2018-03-17 18:26:18 +05:30
|
|
|
const e = { returnValue: null };
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.handleBeforeUnloadEvent(e);
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(e.returnValue).not.toBeNull();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('confirms on description change', async () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.showForm = true;
|
|
|
|
wrapper.vm.state.descriptionText = 'description has changed';
|
2018-03-17 18:26:18 +05:30
|
|
|
const e = { returnValue: null };
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.handleBeforeUnloadEvent(e);
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(e.returnValue).not.toBeNull();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('does nothing when nothing has changed', async () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const e = { returnValue: null };
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.handleBeforeUnloadEvent(e);
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
expect(e.returnValue).toBeNull();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('error when updating', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
it('closes form on error', async () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(wrapper.vm.service, 'updateIssuable').mockRejectedValue();
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await wrapper.vm.updateIssuable();
|
|
|
|
expect(eventHub.$emit).not.toHaveBeenCalledWith('close.form');
|
|
|
|
expect(document.querySelector('.flash-container .flash-text').innerText.trim()).toBe(
|
|
|
|
`Error updating issue`,
|
|
|
|
);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('returns the correct error message for issuableType', async () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(wrapper.vm.service, 'updateIssuable').mockRejectedValue();
|
|
|
|
wrapper.setProps({ issuableType: 'merge request' });
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
|
|
|
await wrapper.vm.updateIssuable();
|
|
|
|
expect(eventHub.$emit).not.toHaveBeenCalledWith('close.form');
|
|
|
|
expect(document.querySelector('.flash-container .flash-text').innerText.trim()).toBe(
|
|
|
|
`Error updating merge request`,
|
|
|
|
);
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('shows error message from backend if exists', async () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
const msg = 'Custom error message from backend';
|
2020-05-24 23:13:21 +05:30
|
|
|
jest
|
2020-06-23 00:09:42 +05:30
|
|
|
.spyOn(wrapper.vm.service, 'updateIssuable')
|
2020-05-24 23:13:21 +05:30
|
|
|
.mockRejectedValue({ response: { data: { errors: [msg] } } });
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await wrapper.vm.updateIssuable();
|
|
|
|
expect(document.querySelector('.flash-container .flash-text').innerText.trim()).toBe(
|
|
|
|
`${wrapper.vm.defaultErrorMessage}. ${msg}`,
|
|
|
|
);
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
describe('updateAndShowForm', () => {
|
2022-04-04 11:22:00 +05:30
|
|
|
it('shows locked warning if form is open & data is different', async () => {
|
|
|
|
await nextTick();
|
|
|
|
wrapper.vm.updateAndShowForm();
|
|
|
|
|
|
|
|
wrapper.vm.poll.makeRequest();
|
|
|
|
|
|
|
|
await new Promise((resolve) => {
|
|
|
|
wrapper.vm.$watch('formState.lockedWarningVisible', (value) => {
|
|
|
|
if (value) {
|
|
|
|
resolve();
|
|
|
|
}
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
2022-04-04 11:22:00 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.formState.lockedWarningVisible).toBe(true);
|
|
|
|
expect(wrapper.vm.formState.lock_version).toBe(1);
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
describe('requestTemplatesAndShowForm', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
let formSpy;
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
beforeEach(() => {
|
2020-06-23 00:09:42 +05:30
|
|
|
formSpy = jest.spyOn(wrapper.vm, 'updateAndShowForm');
|
2019-12-21 20:55:43 +05:30
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it('shows the form if template names as hash request is successful', () => {
|
|
|
|
const mockData = {
|
|
|
|
test: [{ name: 'test', id: 'test', project_path: '/', namespace_path: '/' }],
|
|
|
|
};
|
|
|
|
mock.onGet('/issuable-templates-path').reply(() => Promise.resolve([200, mockData]));
|
|
|
|
|
|
|
|
return wrapper.vm.requestTemplatesAndShowForm().then(() => {
|
|
|
|
expect(formSpy).toHaveBeenCalledWith(mockData);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows the form if template names as array request is successful', () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
const mockData = [{ name: 'test', id: 'test', project_path: '/', namespace_path: '/' }];
|
2019-12-21 20:55:43 +05:30
|
|
|
mock.onGet('/issuable-templates-path').reply(() => Promise.resolve([200, mockData]));
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
return wrapper.vm.requestTemplatesAndShowForm().then(() => {
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(formSpy).toHaveBeenCalledWith(mockData);
|
|
|
|
});
|
2019-12-21 20:55:43 +05:30
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('shows the form if template names request failed', () => {
|
2019-12-21 20:55:43 +05:30
|
|
|
mock
|
|
|
|
.onGet('/issuable-templates-path')
|
|
|
|
.reply(() => Promise.reject(new Error('something went wrong')));
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
return wrapper.vm.requestTemplatesAndShowForm().then(() => {
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(document.querySelector('.flash-container .flash-text').textContent).toContain(
|
|
|
|
'Error updating issue',
|
|
|
|
);
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(formSpy).toHaveBeenCalledWith();
|
|
|
|
});
|
2019-12-21 20:55:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe('show inline edit button', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('should render by default', () => {
|
|
|
|
expect(findTitle().props('showInlineEditButton')).toBe(true);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('should render if showInlineEditButton', async () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.setProps({ showInlineEditButton: true });
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(findTitle().props('showInlineEditButton')).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render if showInlineEditButton is false', async () => {
|
|
|
|
wrapper.setProps({ showInlineEditButton: false });
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
expect(findTitle().props('showInlineEditButton')).toBe(false);
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
});
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
describe('updateStoreState', () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
it('should make a request and update the state of the store', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
const data = { foo: 1 };
|
2020-06-23 00:09:42 +05:30
|
|
|
const getDataSpy = jest.spyOn(wrapper.vm.service, 'getData').mockResolvedValue({ data });
|
|
|
|
const updateStateSpy = jest
|
|
|
|
.spyOn(wrapper.vm.store, 'updateState')
|
|
|
|
.mockImplementation(jest.fn);
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
return wrapper.vm.updateStoreState().then(() => {
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(getDataSpy).toHaveBeenCalled();
|
|
|
|
expect(updateStateSpy).toHaveBeenCalledWith(data);
|
|
|
|
});
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('should show error message if store update fails', () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.spyOn(wrapper.vm.service, 'getData').mockRejectedValue();
|
|
|
|
wrapper.setProps({ issuableType: 'merge request' });
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
return wrapper.vm.updateStoreState().then(() => {
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(document.querySelector('.flash-container .flash-text').innerText.trim()).toBe(
|
2020-06-23 00:09:42 +05:30
|
|
|
`Error updating ${wrapper.vm.issuableType}`,
|
2020-05-24 23:13:21 +05:30
|
|
|
);
|
|
|
|
});
|
2019-03-02 22:35:43 +05:30
|
|
|
});
|
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
|
|
|
|
describe('issueChanged', () => {
|
|
|
|
beforeEach(() => {
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.store.formState.title = '';
|
|
|
|
wrapper.vm.store.formState.description = '';
|
|
|
|
wrapper.setProps({
|
|
|
|
initialDescriptionText: '',
|
|
|
|
initialTitleText: '',
|
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true when title is changed', () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.store.formState.title = 'RandomText';
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(wrapper.vm.issueChanged).toBe(true);
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false when title is empty null', () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.store.formState.title = null;
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(wrapper.vm.issueChanged).toBe(false);
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true when description is changed', () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.store.formState.description = 'RandomText';
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(wrapper.vm.issueChanged).toBe(true);
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false when description is empty null', () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.store.formState.description = null;
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(wrapper.vm.issueChanged).toBe(false);
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('returns false when `initialDescriptionText` is null and `formState.description` is empty string', () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
wrapper.vm.store.formState.description = '';
|
|
|
|
wrapper.setProps({ initialDescriptionText: null });
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(wrapper.vm.issueChanged).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('sticky header', () => {
|
|
|
|
describe('when title is in view', () => {
|
|
|
|
it('is not shown', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(findStickyHeader().exists()).toBe(false);
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when title is not in view', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper.vm.state.titleText = 'Sticky header title';
|
|
|
|
wrapper.find(GlIntersectionObserver).vm.$emit('disappear');
|
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it('shows with title', () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(findStickyHeader().text()).toContain('Sticky header title');
|
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it.each`
|
|
|
|
title | state
|
|
|
|
${'shows with Open when status is opened'} | ${IssuableStatus.Open}
|
|
|
|
${'shows with Closed when status is closed'} | ${IssuableStatus.Closed}
|
|
|
|
${'shows with Open when status is reopened'} | ${IssuableStatus.Reopened}
|
|
|
|
`('$title', async ({ state }) => {
|
|
|
|
wrapper.setProps({ issuableStatus: state });
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
await nextTick();
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
expect(findStickyHeader().text()).toContain(IssuableStatusText[state]);
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
it.each`
|
|
|
|
title | isConfidential
|
2021-11-11 11:23:49 +05:30
|
|
|
${'does not show confidential badge when issue is not confidential'} | ${false}
|
|
|
|
${'shows confidential badge when issue is confidential'} | ${true}
|
2021-01-29 00:20:46 +05:30
|
|
|
`('$title', async ({ isConfidential }) => {
|
|
|
|
wrapper.setProps({ isConfidential });
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
await nextTick();
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
expect(findConfidentialBadge().exists()).toBe(isConfidential);
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
title | isLocked
|
2021-11-11 11:23:49 +05:30
|
|
|
${'does not show locked badge when issue is not locked'} | ${false}
|
|
|
|
${'shows locked badge when issue is locked'} | ${true}
|
2021-01-29 00:20:46 +05:30
|
|
|
`('$title', async ({ isLocked }) => {
|
|
|
|
wrapper.setProps({ isLocked });
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
await nextTick();
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
expect(findLockedBadge().exists()).toBe(isLocked);
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
2021-11-11 11:23:49 +05:30
|
|
|
|
|
|
|
it.each`
|
|
|
|
title | isHidden
|
|
|
|
${'does not show hidden badge when issue is not hidden'} | ${false}
|
|
|
|
${'shows hidden badge when issue is hidden'} | ${true}
|
|
|
|
`('$title', async ({ isHidden }) => {
|
|
|
|
wrapper.setProps({ isHidden });
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
|
|
const hiddenBadge = findHiddenBadge();
|
|
|
|
|
|
|
|
expect(hiddenBadge.exists()).toBe(isHidden);
|
|
|
|
|
|
|
|
if (isHidden) {
|
|
|
|
expect(hiddenBadge.attributes('title')).toBe(
|
|
|
|
'This issue is hidden because its author has been banned',
|
|
|
|
);
|
|
|
|
expect(getBinding(hiddenBadge.element, 'gl-tooltip')).not.toBeUndefined();
|
|
|
|
}
|
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
describe('Composable description component', () => {
|
2021-09-04 01:27:46 +05:30
|
|
|
const findIncidentTabs = () => wrapper.findComponent(IncidentTabs);
|
2020-11-24 15:15:51 +05:30
|
|
|
const borderClass = 'gl-border-b-1 gl-border-b-gray-100 gl-border-b-solid gl-mb-6';
|
|
|
|
|
|
|
|
describe('when using description component', () => {
|
|
|
|
it('renders the description component', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(findDescription().exists()).toBe(true);
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render incident tabs', () => {
|
|
|
|
expect(findIncidentTabs().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds a border below the header', () => {
|
|
|
|
expect(findPinnedLinks().attributes('class')).toContain(borderClass);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when using incident tabs description wrapper', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mountComponent(
|
|
|
|
{
|
|
|
|
descriptionComponent: IncidentTabs,
|
|
|
|
showTitleBorder: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
mocks: {
|
|
|
|
$apollo: {
|
|
|
|
queries: {
|
|
|
|
alert: {
|
|
|
|
loading: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it('does not the description component', () => {
|
|
|
|
expect(findDescription().exists()).toBe(false);
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders incident tabs', () => {
|
|
|
|
expect(findIncidentTabs().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not add a border below the header', () => {
|
|
|
|
expect(findPinnedLinks().attributes('class')).not.toContain(borderClass);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
describe('taskListUpdateStarted', () => {
|
|
|
|
it('stops polling', () => {
|
|
|
|
jest.spyOn(wrapper.vm.poll, 'stop');
|
|
|
|
|
|
|
|
wrapper.vm.taskListUpdateStarted();
|
|
|
|
|
|
|
|
expect(wrapper.vm.poll.stop).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('taskListUpdateSucceeded', () => {
|
|
|
|
it('enables polling', () => {
|
|
|
|
jest.spyOn(wrapper.vm.poll, 'enable');
|
|
|
|
jest.spyOn(wrapper.vm.poll, 'makeDelayedRequest');
|
|
|
|
|
|
|
|
wrapper.vm.taskListUpdateSucceeded();
|
|
|
|
|
|
|
|
expect(wrapper.vm.poll.enable).toHaveBeenCalled();
|
|
|
|
expect(wrapper.vm.poll.makeDelayedRequest).toHaveBeenCalledWith(POLLING_DELAY);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('taskListUpdateFailed', () => {
|
|
|
|
it('enables polling and calls updateStoreState', () => {
|
|
|
|
jest.spyOn(wrapper.vm.poll, 'enable');
|
|
|
|
jest.spyOn(wrapper.vm.poll, 'makeDelayedRequest');
|
|
|
|
jest.spyOn(wrapper.vm, 'updateStoreState');
|
|
|
|
|
|
|
|
wrapper.vm.taskListUpdateFailed();
|
|
|
|
|
|
|
|
expect(wrapper.vm.poll.enable).toHaveBeenCalled();
|
|
|
|
expect(wrapper.vm.poll.makeDelayedRequest).toHaveBeenCalledWith(POLLING_DELAY);
|
|
|
|
expect(wrapper.vm.updateStoreState).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|