2018-03-09 20:18:59 +00:00
|
|
|
import $ from 'jquery';
|
2018-02-02 14:17:26 +00:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2018-02-02 12:36:51 +00:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-12-15 12:57:08 +00:00
|
|
|
import MergeRequest from '~/merge_request';
|
2017-06-08 16:15:34 +00:00
|
|
|
import CloseReopenReportToggle from '~/close_reopen_report_toggle';
|
2017-07-07 15:04:43 +00:00
|
|
|
import IssuablesHelper from '~/helpers/issuables_helper';
|
2020-05-20 12:07:52 +00:00
|
|
|
import { TEST_HOST } from 'spec/test_constants';
|
2016-07-24 20:45:11 +00:00
|
|
|
|
2020-05-20 12:07:52 +00:00
|
|
|
describe('MergeRequest', () => {
|
|
|
|
const test = {};
|
|
|
|
describe('task lists', () => {
|
2018-10-17 07:13:26 +00:00
|
|
|
let mock;
|
2018-02-02 14:17:26 +00:00
|
|
|
|
2019-03-26 16:03:28 +00:00
|
|
|
preloadFixtures('merge_requests/merge_request_with_task_list.html');
|
2020-05-20 12:07:52 +00:00
|
|
|
beforeEach(() => {
|
2019-03-26 16:03:28 +00:00
|
|
|
loadFixtures('merge_requests/merge_request_with_task_list.html');
|
2018-02-02 14:17:26 +00:00
|
|
|
|
2020-05-20 12:07:52 +00:00
|
|
|
jest.spyOn(axios, 'patch');
|
2018-10-17 07:13:26 +00:00
|
|
|
mock = new MockAdapter(axios);
|
2018-02-02 14:17:26 +00:00
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
mock
|
2020-05-20 12:07:52 +00:00
|
|
|
.onPatch(`${TEST_HOST}/frontend-fixtures/merge-requests-project/-/merge_requests/1.json`)
|
2018-10-17 07:13:26 +00:00
|
|
|
.reply(200, {});
|
2018-02-02 14:17:26 +00:00
|
|
|
|
2020-05-20 12:07:52 +00:00
|
|
|
test.merge = new MergeRequest();
|
|
|
|
return test.merge;
|
2018-10-17 07:13:26 +00:00
|
|
|
});
|
2018-02-02 14:17:26 +00:00
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
2018-02-02 14:17:26 +00:00
|
|
|
|
2019-09-10 09:35:11 +00:00
|
|
|
it('modifies the Markdown field', done => {
|
2020-05-20 12:07:52 +00:00
|
|
|
jest.spyOn($, 'ajax').mockImplementation();
|
2018-10-17 07:13:26 +00:00
|
|
|
const changeEvent = document.createEvent('HTMLEvents');
|
|
|
|
changeEvent.initEvent('change', true, true);
|
|
|
|
$('input[type=checkbox]')
|
2019-11-15 15:06:12 +00:00
|
|
|
.first()
|
|
|
|
.attr('checked', true)[0]
|
|
|
|
.dispatchEvent(changeEvent);
|
2020-05-20 12:07:52 +00:00
|
|
|
setImmediate(() => {
|
2019-11-15 15:06:12 +00:00
|
|
|
expect($('.js-task-list-field').val()).toBe(
|
|
|
|
'- [x] Task List Item\n- [ ] \n- [ ] Task List Item 2\n',
|
|
|
|
);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('ensure that task with only spaces does not get checked incorrectly', done => {
|
|
|
|
// fixed in 'deckar01-task_list', '2.2.1' gem
|
2020-05-20 12:07:52 +00:00
|
|
|
jest.spyOn($, 'ajax').mockImplementation();
|
2019-11-15 15:06:12 +00:00
|
|
|
const changeEvent = document.createEvent('HTMLEvents');
|
|
|
|
changeEvent.initEvent('change', true, true);
|
|
|
|
$('input[type=checkbox]')
|
|
|
|
.last()
|
2018-10-17 07:13:26 +00:00
|
|
|
.attr('checked', true)[0]
|
|
|
|
.dispatchEvent(changeEvent);
|
2020-05-20 12:07:52 +00:00
|
|
|
setImmediate(() => {
|
2019-11-15 15:06:12 +00:00
|
|
|
expect($('.js-task-list-field').val()).toBe(
|
|
|
|
'- [ ] Task List Item\n- [ ] \n- [x] Task List Item 2\n',
|
|
|
|
);
|
2019-09-10 09:35:11 +00:00
|
|
|
done();
|
|
|
|
});
|
2018-10-17 07:13:26 +00:00
|
|
|
});
|
2018-01-08 12:33:30 +00:00
|
|
|
|
2019-02-06 23:18:07 +00:00
|
|
|
describe('tasklist', () => {
|
2019-01-22 20:53:08 +00:00
|
|
|
const lineNumber = 8;
|
|
|
|
const lineSource = '- [ ] item 8';
|
|
|
|
const index = 3;
|
|
|
|
const checked = true;
|
|
|
|
|
2019-02-06 23:18:07 +00:00
|
|
|
it('submits an ajax request on tasklist:changed', done => {
|
|
|
|
$('.js-task-list-field').trigger({
|
|
|
|
type: 'tasklist:changed',
|
|
|
|
detail: { lineNumber, lineSource, index, checked },
|
|
|
|
});
|
|
|
|
|
2020-05-20 12:07:52 +00:00
|
|
|
setImmediate(() => {
|
2019-02-06 23:18:07 +00:00
|
|
|
expect(axios.patch).toHaveBeenCalledWith(
|
2020-05-20 12:07:52 +00:00
|
|
|
`${TEST_HOST}/frontend-fixtures/merge-requests-project/-/merge_requests/1.json`,
|
2019-02-06 23:18:07 +00:00
|
|
|
{
|
|
|
|
merge_request: {
|
2019-11-15 15:06:12 +00:00
|
|
|
description: '- [ ] Task List Item\n- [ ] \n- [ ] Task List Item 2\n',
|
2019-01-15 21:05:36 +00:00
|
|
|
lock_version: 0,
|
2019-02-06 23:18:07 +00:00
|
|
|
update_task: { line_number: lineNumber, line_source: lineSource, index, checked },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2019-01-22 20:53:08 +00:00
|
|
|
});
|
2018-10-17 07:13:26 +00:00
|
|
|
|
2020-05-20 12:07:52 +00:00
|
|
|
it('shows an error notification when tasklist update failed', done => {
|
2019-02-06 23:18:07 +00:00
|
|
|
mock
|
2020-05-20 12:07:52 +00:00
|
|
|
.onPatch(`${TEST_HOST}/frontend-fixtures/merge-requests-project/-/merge_requests/1.json`)
|
2019-02-06 23:18:07 +00:00
|
|
|
.reply(409, {});
|
|
|
|
|
|
|
|
$('.js-task-list-field').trigger({
|
|
|
|
type: 'tasklist:changed',
|
|
|
|
detail: { lineNumber, lineSource, index, checked },
|
|
|
|
});
|
|
|
|
|
2020-05-20 12:07:52 +00:00
|
|
|
setImmediate(() => {
|
2019-02-06 23:18:07 +00:00
|
|
|
expect(document.querySelector('.flash-container .flash-text').innerText.trim()).toBe(
|
|
|
|
'Someone edited this merge request at the same time you did. Please refresh the page to see changes.',
|
|
|
|
);
|
2019-01-22 20:53:08 +00:00
|
|
|
|
2019-02-06 23:18:07 +00:00
|
|
|
done();
|
|
|
|
});
|
2016-07-24 20:45:11 +00:00
|
|
|
});
|
|
|
|
});
|
2018-10-17 07:13:26 +00:00
|
|
|
});
|
2017-06-07 19:34:19 +00:00
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
describe('class constructor', () => {
|
|
|
|
beforeEach(() => {
|
2020-05-20 12:07:52 +00:00
|
|
|
jest.spyOn($, 'ajax').mockImplementation();
|
2018-10-17 07:13:26 +00:00
|
|
|
});
|
2018-01-08 12:33:30 +00:00
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
it('calls .initCloseReopenReport', () => {
|
2020-05-20 12:07:52 +00:00
|
|
|
jest.spyOn(IssuablesHelper, 'initCloseReopenReport').mockImplementation(() => {});
|
2017-06-07 19:34:19 +00:00
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
new MergeRequest(); // eslint-disable-line no-new
|
2017-06-07 19:34:19 +00:00
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
expect(IssuablesHelper.initCloseReopenReport).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls .initDroplab', () => {
|
2020-05-20 12:07:52 +00:00
|
|
|
const container = {
|
|
|
|
querySelector: jest.fn().mockName('container.querySelector'),
|
|
|
|
};
|
2018-10-17 07:13:26 +00:00
|
|
|
const dropdownTrigger = {};
|
|
|
|
const dropdownList = {};
|
|
|
|
const button = {};
|
2017-06-07 19:34:19 +00:00
|
|
|
|
2020-05-20 12:07:52 +00:00
|
|
|
jest.spyOn(CloseReopenReportToggle.prototype, 'initDroplab').mockImplementation(() => {});
|
|
|
|
jest.spyOn(document, 'querySelector').mockReturnValue(container);
|
|
|
|
|
|
|
|
container.querySelector
|
|
|
|
.mockReturnValueOnce(dropdownTrigger)
|
|
|
|
.mockReturnValueOnce(dropdownList)
|
|
|
|
.mockReturnValueOnce(button);
|
2017-06-07 19:34:19 +00:00
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
new MergeRequest(); // eslint-disable-line no-new
|
|
|
|
|
|
|
|
expect(document.querySelector).toHaveBeenCalledWith('.js-issuable-close-dropdown');
|
|
|
|
expect(container.querySelector).toHaveBeenCalledWith('.js-issuable-close-toggle');
|
|
|
|
expect(container.querySelector).toHaveBeenCalledWith('.js-issuable-close-menu');
|
|
|
|
expect(container.querySelector).toHaveBeenCalledWith('.js-issuable-close-button');
|
|
|
|
expect(CloseReopenReportToggle.prototype.initDroplab).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2017-06-07 19:34:19 +00:00
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
describe('hideCloseButton', () => {
|
|
|
|
describe('merge request of another user', () => {
|
|
|
|
beforeEach(() => {
|
2019-03-26 16:03:28 +00:00
|
|
|
loadFixtures('merge_requests/merge_request_with_task_list.html');
|
2020-05-20 12:07:52 +00:00
|
|
|
test.el = document.querySelector('.js-issuable-actions');
|
2017-07-07 15:04:43 +00:00
|
|
|
new MergeRequest(); // eslint-disable-line no-new
|
2018-10-17 07:13:26 +00:00
|
|
|
MergeRequest.hideCloseButton();
|
|
|
|
});
|
2017-06-07 19:34:19 +00:00
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
it('hides the dropdown close item and selects the next item', () => {
|
2020-05-20 12:07:52 +00:00
|
|
|
const closeItem = test.el.querySelector('li.close-item');
|
|
|
|
const smallCloseItem = test.el.querySelector('.js-close-item');
|
|
|
|
const reportItem = test.el.querySelector('li.report-item');
|
2018-10-17 07:13:26 +00:00
|
|
|
|
|
|
|
expect(closeItem).toHaveClass('hidden');
|
|
|
|
expect(smallCloseItem).toHaveClass('hidden');
|
|
|
|
expect(reportItem).toHaveClass('droplab-item-selected');
|
|
|
|
expect(reportItem).not.toHaveClass('hidden');
|
2017-06-07 19:34:19 +00:00
|
|
|
});
|
|
|
|
});
|
2017-09-07 20:25:50 +00:00
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
describe('merge request of current_user', () => {
|
|
|
|
beforeEach(() => {
|
2019-03-26 16:03:28 +00:00
|
|
|
loadFixtures('merge_requests/merge_request_of_current_user.html');
|
2020-05-20 12:07:52 +00:00
|
|
|
test.el = document.querySelector('.js-issuable-actions');
|
2018-10-17 07:13:26 +00:00
|
|
|
MergeRequest.hideCloseButton();
|
2017-09-07 20:25:50 +00:00
|
|
|
});
|
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
it('hides the close button', () => {
|
2020-05-20 12:07:52 +00:00
|
|
|
const closeButton = test.el.querySelector('.btn-close');
|
|
|
|
const smallCloseItem = test.el.querySelector('.js-close-item');
|
2017-09-07 20:25:50 +00:00
|
|
|
|
2018-10-17 07:13:26 +00:00
|
|
|
expect(closeButton).toHaveClass('hidden');
|
|
|
|
expect(smallCloseItem).toHaveClass('hidden');
|
2017-09-07 20:25:50 +00:00
|
|
|
});
|
|
|
|
});
|
2016-07-24 20:45:11 +00:00
|
|
|
});
|
2018-10-17 07:13:26 +00:00
|
|
|
});
|