debian-mirror-gitlab/spec/frontend/issue_show/components/app_spec.js

569 lines
18 KiB
JavaScript
Raw Normal View History

2020-06-23 00:09:42 +05:30
import { GlIntersectionObserver } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
2018-03-17 18:26:18 +05:30
import MockAdapter from 'axios-mock-adapter';
2020-05-24 23:13:21 +05:30
import { TEST_HOST } from 'helpers/test_constants';
2018-03-17 18:26:18 +05:30
import axios from '~/lib/utils/axios_utils';
2020-05-24 23:13:21 +05:30
import { visitUrl } from '~/lib/utils/url_utility';
2018-05-09 12:01:36 +05:30
import '~/behaviors/markdown/render_gfm';
2020-06-23 00:09:42 +05:30
import IssuableApp from '~/issue_show/components/app.vue';
2017-09-10 17:25:29 +05:30
import eventHub from '~/issue_show/event_hub';
2020-03-13 15:44:24 +05:30
import { initialRequest, secondRequest } from '../mock_data';
2017-09-10 17:25:29 +05:30
function formatText(text) {
return text.trim().replace(/\s\s+/g, ' ');
}
2020-05-24 23:13:21 +05:30
jest.mock('~/lib/utils/url_utility');
jest.mock('~/issue_show/event_hub');
2020-03-13 15:44:24 +05:30
const REALTIME_REQUEST_STACK = [initialRequest, secondRequest];
2018-03-17 18:26:18 +05:30
2020-06-23 00:09:42 +05:30
const zoomMeetingUrl = 'https://gitlab.zoom.us/j/95919234811';
const publishedIncidentUrl = 'https://status.com/';
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;
const findStickyHeader = () => wrapper.find('[data-testid="issue-sticky-header"]');
2017-09-10 17:25:29 +05:30
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
2020-06-23 00:09:42 +05:30
window.IntersectionObserver = class {
disconnect = jest.fn();
observe = jest.fn();
};
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-06-23 00:09:42 +05:30
wrapper = mount(IssuableApp, {
2017-09-10 17:25:29 +05:30
propsData: {
canUpdate: true,
canDestroy: true,
2020-04-08 14:13:33 +05:30
endpoint: '/gitlab-org/gitlab-shell/-/issues/9/realtime_changes',
2020-05-24 23:13:21 +05:30
updateEndpoint: TEST_HOST,
2017-09-10 17:25:29 +05:30
issuableRef: '#1',
2020-06-23 00:09:42 +05:30
issuableStatus: 'opened',
2017-09-10 17:25:29 +05:30
initialTitleHtml: '',
initialTitleText: '',
2018-03-17 18:26:18 +05:30
initialDescriptionHtml: 'test',
initialDescriptionText: 'test',
2019-03-02 22:35:43 +05:30
lockVersion: 1,
2018-03-17 18:26:18 +05:30
markdownPreviewPath: '/',
markdownDocsPath: '/',
2017-09-10 17:25:29 +05:30
projectNamespace: '/',
projectPath: '/',
2019-12-21 20:55:43 +05:30
issuableTemplateNamesPath: '/issuable-templates-path',
2020-06-23 00:09:42 +05:30
zoomMeetingUrl,
publishedIncidentUrl,
2017-09-10 17:25:29 +05:30
},
2020-06-23 00:09:42 +05:30
});
2017-09-10 17:25:29 +05:30
});
afterEach(() => {
2020-06-23 00:09:42 +05:30
delete window.IntersectionObserver;
2018-03-17 18:26:18 +05:30
mock.restore();
realtimeRequestCount = 0;
2017-09-10 17:25:29 +05:30
2020-06-23 00:09:42 +05:30
wrapper.vm.poll.stop();
wrapper.destroy();
wrapper = null;
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', () => {
2017-09-10 17:25:29 +05:30
let editedText;
2020-05-24 23:13:21 +05:30
return axios
.waitForAll()
2018-12-13 13:39:08 +05:30
.then(() => {
2020-06-23 00:09:42 +05:30
editedText = wrapper.find('.edited-text');
2018-12-13 13:39:08 +05:30
})
.then(() => {
expect(document.querySelector('title').innerText).toContain('this is a title (#1)');
2020-06-23 00:09:42 +05:30
expect(wrapper.find('.title').text()).toContain('this is a title');
expect(wrapper.find('.md').text()).toContain('this is a description!');
expect(wrapper.find('.js-task-list-field').element.value).toContain(
2018-12-13 13:39:08 +05:30
'this is a description',
);
2020-06-23 00:09:42 +05:30
expect(formatText(editedText.text())).toMatch(/Edited[\s\S]+?by Some User/);
expect(editedText.find('.author-link').attributes('href')).toMatch(/\/some_user$/);
expect(editedText.find('time').text()).toBeTruthy();
expect(wrapper.vm.state.lock_version).toEqual(1);
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(() => {
expect(document.querySelector('title').innerText).toContain('2 (#1)');
2020-06-23 00:09:42 +05:30
expect(wrapper.find('.title').text()).toContain('2');
expect(wrapper.find('.md').text()).toContain('42');
expect(wrapper.find('.js-task-list-field').element.value).toContain('42');
expect(wrapper.find('.edited-text').text()).toBeTruthy();
expect(formatText(wrapper.find('.edited-text').text())).toMatch(
2018-12-13 13:39:08 +05:30
/Edited[\s\S]+?by Other User/,
);
2020-06-23 00:09:42 +05:30
expect(editedText.find('.author-link').attributes('href')).toMatch(/\/other_user$/);
expect(editedText.find('time').text()).toBeTruthy();
expect(wrapper.vm.state.lock_version).toEqual(2);
2020-05-24 23:13:21 +05:30
});
2017-09-10 17:25:29 +05:30
});
2020-05-24 23:13:21 +05:30
it('shows actions if permissions are correct', () => {
2020-06-23 00:09:42 +05:30
wrapper.vm.showForm = true;
2017-09-10 17:25:29 +05:30
2020-06-23 00:09:42 +05:30
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.contains('.markdown-selector')).toBe(true);
2017-09-10 17:25:29 +05:30
});
});
2020-05-24 23:13:21 +05:30
it('does not show actions if permissions are incorrect', () => {
2020-06-23 00:09:42 +05:30
wrapper.vm.showForm = true;
wrapper.setProps({ canUpdate: false });
2017-09-10 17:25:29 +05:30
2020-06-23 00:09:42 +05:30
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.contains('.markdown-selector')).toBe(false);
2017-09-10 17:25:29 +05:30
});
});
2020-05-24 23:13:21 +05:30
it('does not update formState if form is already open', () => {
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
2020-06-23 00:09:42 +05:30
return wrapper.vm.$nextTick().then(() => {
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-05-24 23:13:21 +05:30
it('opens reCAPTCHA modal if update rejected as spam', () => {
let modal;
2020-06-23 00:09:42 +05:30
jest.spyOn(wrapper.vm.service, 'updateIssuable').mockResolvedValue({
2020-05-24 23:13:21 +05:30
data: {
recaptcha_html: '<div class="g-recaptcha">recaptcha_html</div>',
},
2017-09-10 17:25:29 +05:30
});
2020-05-24 23:13:21 +05:30
2020-06-23 00:09:42 +05:30
wrapper.vm.canUpdate = true;
wrapper.vm.showForm = true;
2020-05-24 23:13:21 +05:30
2020-06-23 00:09:42 +05:30
return wrapper.vm
2020-05-24 23:13:21 +05:30
.$nextTick()
.then(() => {
2020-06-23 00:09:42 +05:30
wrapper.vm.$refs.recaptchaModal.scriptSrc = '//scriptsrc';
return wrapper.vm.updateIssuable();
2020-05-24 23:13:21 +05:30
})
.then(() => {
2020-06-23 00:09:42 +05:30
modal = wrapper.find('.js-recaptcha-modal');
expect(modal.isVisible()).toBe(true);
expect(modal.find('.g-recaptcha').text()).toEqual('recaptcha_html');
2020-05-24 23:13:21 +05:30
expect(document.body.querySelector('.js-recaptcha-script').src).toMatch('//scriptsrc');
})
.then(() => {
2020-06-23 00:09:42 +05:30
modal.find('.close').trigger('click');
return wrapper.vm.$nextTick();
2020-05-24 23:13:21 +05:30
})
.then(() => {
2020-06-23 00:09:42 +05:30
expect(modal.isVisible()).toBe(false);
2020-05-24 23:13:21 +05:30
expect(document.body.querySelector('.js-recaptcha-script')).toBeNull();
});
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 }) => {
expect(wrapper.vm[prop]).toEqual(value);
expect(wrapper.find(`[data-testid="${prop}"]`).attributes('href')).toBe(value);
});
});
2017-09-10 17:25:29 +05:30
describe('updateIssuable', () => {
2020-05-24 23:13:21 +05:30
it('fetches new data after update', () => {
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 },
});
2020-06-23 00:09:42 +05:30
return wrapper.vm.updateIssuable().then(() => {
2020-05-24 23:13:21 +05:30
expect(updateStoreSpy).toHaveBeenCalled();
expect(getDataSpy).toHaveBeenCalled();
});
2017-09-10 17:25:29 +05:30
});
2020-05-24 23:13:21 +05:30
it('correctly updates issuable data', () => {
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
2020-06-23 00:09:42 +05:30
return wrapper.vm.updateIssuable().then(() => {
expect(spy).toHaveBeenCalledWith(wrapper.vm.formState);
2020-05-24 23:13:21 +05:30
expect(eventHub.$emit).toHaveBeenCalledWith('close.form');
});
2017-09-10 17:25:29 +05:30
});
2020-05-24 23:13:21 +05:30
it('does not redirect if issue has not moved', () => {
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
2020-06-23 00:09:42 +05:30
return wrapper.vm.updateIssuable().then(() => {
2020-05-24 23:13:21 +05:30
expect(visitUrl).not.toHaveBeenCalled();
});
});
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
it('does not redirect if issue has not moved and user has switched tabs', () => {
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
},
});
2020-06-23 00:09:42 +05:30
return wrapper.vm.updateIssuable().then(() => {
2018-10-15 14:42:47 +05:30
expect(visitUrl).not.toHaveBeenCalled();
2017-09-10 17:25:29 +05:30
});
});
2020-05-24 23:13:21 +05:30
it('redirects if returned web_url has changed', () => {
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
2020-06-23 00:09:42 +05:30
return wrapper.vm.updateIssuable().then(() => {
2018-10-15 14:42:47 +05:30
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', () => {
2020-05-24 23:13:21 +05:30
it('confirms on title change', () => {
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);
return wrapper.vm.$nextTick().then(() => {
2018-03-17 18:26:18 +05:30
expect(e.returnValue).not.toBeNull();
});
});
2020-05-24 23:13:21 +05:30
it('confirms on description change', () => {
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);
return wrapper.vm.$nextTick().then(() => {
2018-03-17 18:26:18 +05:30
expect(e.returnValue).not.toBeNull();
});
});
2020-05-24 23:13:21 +05:30
it('does nothing when nothing 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);
return wrapper.vm.$nextTick().then(() => {
2018-03-17 18:26:18 +05:30
expect(e.returnValue).toBeNull();
});
});
});
describe('error when updating', () => {
2020-05-24 23:13:21 +05:30
it('closes form on error', () => {
2020-06-23 00:09:42 +05:30
jest.spyOn(wrapper.vm.service, 'updateIssuable').mockRejectedValue();
return wrapper.vm.updateIssuable().then(() => {
2019-03-02 22:35:43 +05:30
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
2020-05-24 23:13:21 +05:30
it('returns the correct error message for issuableType', () => {
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
2020-06-23 00:09:42 +05:30
return wrapper.vm
2020-05-24 23:13:21 +05:30
.$nextTick()
2020-06-23 00:09:42 +05:30
.then(wrapper.vm.updateIssuable)
2020-05-24 23:13:21 +05:30
.then(() => {
2019-03-02 22:35:43 +05:30
expect(eventHub.$emit).not.toHaveBeenCalledWith('close.form');
expect(document.querySelector('.flash-container .flash-text').innerText.trim()).toBe(
`Error updating merge request`,
);
2018-03-17 18:26:18 +05:30
});
2017-09-10 17:25:29 +05:30
});
2019-03-02 22:35:43 +05:30
2020-05-24 23:13:21 +05:30
it('shows error message from backend if exists', () => {
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
2020-06-23 00:09:42 +05:30
return wrapper.vm.updateIssuable().then(() => {
2019-03-02 22:35:43 +05:30
expect(document.querySelector('.flash-container .flash-text').innerText.trim()).toBe(
2020-06-23 00:09:42 +05:30
`${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
2020-05-24 23:13:21 +05:30
describe('deleteIssuable', () => {
it('changes URL when deleted', () => {
2020-06-23 00:09:42 +05:30
jest.spyOn(wrapper.vm.service, 'deleteIssuable').mockResolvedValue({
2018-03-17 18:26:18 +05:30
data: {
2020-05-24 23:13:21 +05:30
web_url: '/test',
2018-03-17 18:26:18 +05:30
},
2017-09-10 17:25:29 +05:30
});
2018-03-17 18:26:18 +05:30
2020-06-23 00:09:42 +05:30
return wrapper.vm.deleteIssuable().then(() => {
2018-10-15 14:42:47 +05:30
expect(visitUrl).toHaveBeenCalledWith('/test');
2017-09-10 17:25:29 +05:30
});
});
2020-05-24 23:13:21 +05:30
it('stops polling when deleting', () => {
2020-06-23 00:09:42 +05:30
const spy = jest.spyOn(wrapper.vm.poll, 'stop');
jest.spyOn(wrapper.vm.service, 'deleteIssuable').mockResolvedValue({
2020-05-24 23:13:21 +05:30
data: {
web_url: '/test',
},
});
2019-03-02 22:35:43 +05:30
2020-06-23 00:09:42 +05:30
return wrapper.vm.deleteIssuable().then(() => {
2020-05-24 23:13:21 +05:30
expect(spy).toHaveBeenCalledWith();
2017-09-10 17:25:29 +05:30
});
});
2020-05-24 23:13:21 +05:30
it('closes form on error', () => {
2020-06-23 00:09:42 +05:30
jest.spyOn(wrapper.vm.service, 'deleteIssuable').mockRejectedValue();
2017-09-10 17:25:29 +05:30
2020-06-23 00:09:42 +05:30
return wrapper.vm.deleteIssuable().then(() => {
2019-03-02 22:35:43 +05:30
expect(eventHub.$emit).not.toHaveBeenCalledWith('close.form');
expect(document.querySelector('.flash-container .flash-text').innerText.trim()).toBe(
'Error deleting issue',
);
2017-09-10 17:25:29 +05:30
});
});
});
2019-12-21 20:55:43 +05:30
describe('updateAndShowForm', () => {
2020-05-24 23:13:21 +05:30
it('shows locked warning if form is open & data is different', () => {
2020-06-23 00:09:42 +05:30
return wrapper.vm
2020-05-24 23:13:21 +05:30
.$nextTick()
2017-09-10 17:25:29 +05:30
.then(() => {
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.poll.makeRequest();
2019-12-21 20:55:43 +05:30
return new Promise(resolve => {
2020-06-23 00:09:42 +05:30
wrapper.vm.$watch('formState.lockedWarningVisible', value => {
if (value) {
resolve();
}
2019-12-21 20:55:43 +05:30
});
});
2017-09-10 17:25:29 +05:30
})
.then(() => {
2020-06-23 00:09:42 +05:30
expect(wrapper.vm.formState.lockedWarningVisible).toEqual(true);
expect(wrapper.vm.formState.lock_version).toEqual(1);
expect(wrapper.contains('.alert')).toBe(true);
2020-05-24 23:13:21 +05:30
});
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
});
2020-05-24 23:13:21 +05:30
it('shows the form if template names request is successful', () => {
2019-12-21 20:55:43 +05:30
const mockData = [{ name: 'Bug' }];
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', () => {
it('should not render by default', () => {
2020-06-23 00:09:42 +05:30
expect(wrapper.contains('.btn-edit')).toBe(true);
2018-03-17 18:26:18 +05:30
});
it('should render if showInlineEditButton', () => {
2020-06-23 00:09:42 +05:30
wrapper.setProps({ showInlineEditButton: true });
2018-12-13 13:39:08 +05:30
2020-06-23 00:09:42 +05:30
return wrapper.vm.$nextTick(() => {
expect(wrapper.contains('.btn-edit')).toBe(true);
});
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 false when `initialTitleText` is null and `formState.title` is empty string', () => {
2020-06-23 00:09:42 +05:30
wrapper.vm.store.formState.title = '';
wrapper.setProps({ initialTitleText: 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', () => {
expect(wrapper.contains('.issue-sticky-header')).toBe(false);
});
});
describe('when title is not in view', () => {
beforeEach(() => {
wrapper.vm.state.titleText = 'Sticky header title';
wrapper.find(GlIntersectionObserver).vm.$emit('disappear');
});
it('is shown with title', () => {
expect(findStickyHeader().text()).toContain('Sticky header title');
});
it('is shown with Open when status is opened', () => {
wrapper.setProps({ issuableStatus: 'opened' });
return wrapper.vm.$nextTick(() => {
expect(findStickyHeader().text()).toContain('Open');
});
});
it('is shown with Closed when status is closed', () => {
wrapper.setProps({ issuableStatus: 'closed' });
return wrapper.vm.$nextTick(() => {
expect(findStickyHeader().text()).toContain('Closed');
});
});
2019-07-31 22:56:46 +05:30
});
});
2017-09-10 17:25:29 +05:30
});