2018-02-02 09:17:26 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2021-02-14 13:09:20 -05:00
|
|
|
import $ from 'jquery';
|
2022-05-13 08:08:49 -04:00
|
|
|
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
2020-08-17 17:09:56 -04:00
|
|
|
import { TEST_HOST } from 'spec/test_constants';
|
2022-02-11 13:18:58 -05:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2022-09-28 02:08:11 -04:00
|
|
|
import { createAlert } from '~/flash';
|
2018-02-02 07:36:51 -05:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-12-15 07:57:08 -05:00
|
|
|
import MergeRequest from '~/merge_request';
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2022-09-28 02:08:11 -04:00
|
|
|
jest.mock('~/flash');
|
|
|
|
|
2020-05-20 08:07:52 -04:00
|
|
|
describe('MergeRequest', () => {
|
|
|
|
const test = {};
|
|
|
|
describe('task lists', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
let mock;
|
2018-02-02 09:17:26 -05:00
|
|
|
|
2020-05-20 08:07:52 -04:00
|
|
|
beforeEach(() => {
|
2022-05-13 08:08:49 -04:00
|
|
|
loadHTMLFixture('merge_requests/merge_request_with_task_list.html');
|
2018-02-02 09:17:26 -05:00
|
|
|
|
2020-05-20 08:07:52 -04:00
|
|
|
jest.spyOn(axios, 'patch');
|
2018-10-17 03:13:26 -04:00
|
|
|
mock = new MockAdapter(axios);
|
2018-02-02 09:17:26 -05:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
mock
|
2020-05-20 08:07:52 -04:00
|
|
|
.onPatch(`${TEST_HOST}/frontend-fixtures/merge-requests-project/-/merge_requests/1.json`)
|
2018-10-17 03:13:26 -04:00
|
|
|
.reply(200, {});
|
2018-02-02 09:17:26 -05:00
|
|
|
|
2020-05-20 08:07:52 -04:00
|
|
|
test.merge = new MergeRequest();
|
|
|
|
return test.merge;
|
2018-10-17 03:13:26 -04:00
|
|
|
});
|
2018-02-02 09:17:26 -05:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
2022-05-13 08:08:49 -04:00
|
|
|
resetHTMLFixture();
|
2018-10-17 03:13:26 -04:00
|
|
|
});
|
2018-02-02 09:17:26 -05:00
|
|
|
|
2022-02-11 13:18:58 -05:00
|
|
|
it('modifies the Markdown field', async () => {
|
2020-05-20 08:07:52 -04:00
|
|
|
jest.spyOn($, 'ajax').mockImplementation();
|
2018-10-17 03:13:26 -04:00
|
|
|
const changeEvent = document.createEvent('HTMLEvents');
|
|
|
|
changeEvent.initEvent('change', true, true);
|
2020-12-23 07:10:26 -05:00
|
|
|
$('input[type=checkbox]').first().attr('checked', true)[0].dispatchEvent(changeEvent);
|
2022-02-11 13:18:58 -05:00
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect($('.js-task-list-field').val()).toBe(
|
|
|
|
'- [x] Task List Item\n- [ ]\n- [ ] Task List Item 2\n',
|
|
|
|
);
|
2019-11-15 10:06:12 -05:00
|
|
|
});
|
|
|
|
|
2022-02-11 13:18:58 -05:00
|
|
|
it('ensure that task with only spaces does not get checked incorrectly', async () => {
|
2019-11-15 10:06:12 -05:00
|
|
|
// fixed in 'deckar01-task_list', '2.2.1' gem
|
2020-05-20 08:07:52 -04:00
|
|
|
jest.spyOn($, 'ajax').mockImplementation();
|
2019-11-15 10:06:12 -05:00
|
|
|
const changeEvent = document.createEvent('HTMLEvents');
|
|
|
|
changeEvent.initEvent('change', true, true);
|
2020-12-23 07:10:26 -05:00
|
|
|
$('input[type=checkbox]').last().attr('checked', true)[0].dispatchEvent(changeEvent);
|
2022-02-11 13:18:58 -05:00
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect($('.js-task-list-field').val()).toBe(
|
|
|
|
'- [ ] Task List Item\n- [ ]\n- [x] Task List Item 2\n',
|
|
|
|
);
|
2018-10-17 03:13:26 -04:00
|
|
|
});
|
2018-01-08 07:33:30 -05:00
|
|
|
|
2019-02-06 18:18:07 -05:00
|
|
|
describe('tasklist', () => {
|
2019-01-22 15:53:08 -05:00
|
|
|
const lineNumber = 8;
|
|
|
|
const lineSource = '- [ ] item 8';
|
|
|
|
const index = 3;
|
|
|
|
const checked = true;
|
|
|
|
|
2022-02-11 13:18:58 -05:00
|
|
|
it('submits an ajax request on tasklist:changed', async () => {
|
2019-02-06 18:18:07 -05:00
|
|
|
$('.js-task-list-field').trigger({
|
|
|
|
type: 'tasklist:changed',
|
|
|
|
detail: { lineNumber, lineSource, index, checked },
|
|
|
|
});
|
|
|
|
|
2022-02-11 13:18:58 -05:00
|
|
|
await waitForPromises();
|
2019-02-06 18:18:07 -05:00
|
|
|
|
2022-02-11 13:18:58 -05:00
|
|
|
expect(axios.patch).toHaveBeenCalledWith(
|
|
|
|
`${TEST_HOST}/frontend-fixtures/merge-requests-project/-/merge_requests/1.json`,
|
|
|
|
{
|
|
|
|
merge_request: {
|
|
|
|
description: '- [ ] Task List Item\n- [ ]\n- [ ] Task List Item 2\n',
|
|
|
|
lock_version: 0,
|
|
|
|
update_task: { line_number: lineNumber, line_source: lineSource, index, checked },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
2019-01-22 15:53:08 -05:00
|
|
|
});
|
2018-10-17 03:13:26 -04:00
|
|
|
|
2022-02-11 13:18:58 -05:00
|
|
|
it('shows an error notification when tasklist update failed', async () => {
|
2019-02-06 18:18:07 -05:00
|
|
|
mock
|
2020-05-20 08:07:52 -04:00
|
|
|
.onPatch(`${TEST_HOST}/frontend-fixtures/merge-requests-project/-/merge_requests/1.json`)
|
2019-02-06 18:18:07 -05:00
|
|
|
.reply(409, {});
|
|
|
|
|
|
|
|
$('.js-task-list-field').trigger({
|
|
|
|
type: 'tasklist:changed',
|
|
|
|
detail: { lineNumber, lineSource, index, checked },
|
|
|
|
});
|
|
|
|
|
2022-02-11 13:18:58 -05:00
|
|
|
await waitForPromises();
|
2019-01-22 15:53:08 -05:00
|
|
|
|
2022-09-28 02:08:11 -04:00
|
|
|
expect(createAlert).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
message:
|
|
|
|
'Someone edited this merge request at the same time you did. Please refresh the page to see changes.',
|
|
|
|
}),
|
2022-02-11 13:18:58 -05:00
|
|
|
);
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
});
|
2018-10-17 03:13:26 -04:00
|
|
|
});
|
2017-06-07 15:34:19 -04:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
describe('hideCloseButton', () => {
|
|
|
|
describe('merge request of current_user', () => {
|
|
|
|
beforeEach(() => {
|
2022-05-13 08:08:49 -04:00
|
|
|
loadHTMLFixture('merge_requests/merge_request_of_current_user.html');
|
2020-05-20 08:07:52 -04:00
|
|
|
test.el = document.querySelector('.js-issuable-actions');
|
2018-10-17 03:13:26 -04:00
|
|
|
MergeRequest.hideCloseButton();
|
2017-09-07 16:25:50 -04:00
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('hides the close button', () => {
|
2020-05-20 08:07:52 -04:00
|
|
|
const smallCloseItem = test.el.querySelector('.js-close-item');
|
2017-09-07 16:25:50 -04:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
expect(smallCloseItem).toHaveClass('hidden');
|
2017-09-07 16:25:50 -04:00
|
|
|
});
|
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2018-10-17 03:13:26 -04:00
|
|
|
});
|