debian-mirror-gitlab/spec/frontend/merge_request_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

128 lines
4.1 KiB
JavaScript
Raw Normal View History

2018-03-17 18:26:18 +05:30
import MockAdapter from 'axios-mock-adapter';
2021-03-11 19:13:27 +05:30
import $ from 'jquery';
2022-07-16 23:28:13 +05:30
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
2020-10-24 23:57:45 +05:30
import { TEST_HOST } from 'spec/test_constants';
2022-04-04 11:22:00 +05:30
import waitForPromises from 'helpers/wait_for_promises';
2022-11-25 23:54:43 +05:30
import { createAlert } from '~/flash';
2018-03-17 18:26:18 +05:30
import axios from '~/lib/utils/axios_utils';
2023-04-23 21:23:45 +05:30
import { HTTP_STATUS_CONFLICT, HTTP_STATUS_OK } from '~/lib/utils/http_status';
2018-03-17 18:26:18 +05:30
import MergeRequest from '~/merge_request';
2016-09-13 17:45:13 +05:30
2022-11-25 23:54:43 +05:30
jest.mock('~/flash');
2020-06-23 00:09:42 +05:30
describe('MergeRequest', () => {
const test = {};
describe('task lists', () => {
2018-12-13 13:39:08 +05:30
let mock;
2018-03-17 18:26:18 +05:30
2020-06-23 00:09:42 +05:30
beforeEach(() => {
2022-07-16 23:28:13 +05:30
loadHTMLFixture('merge_requests/merge_request_with_task_list.html');
2018-03-17 18:26:18 +05:30
2020-06-23 00:09:42 +05:30
jest.spyOn(axios, 'patch');
2018-12-13 13:39:08 +05:30
mock = new MockAdapter(axios);
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
mock
2020-06-23 00:09:42 +05:30
.onPatch(`${TEST_HOST}/frontend-fixtures/merge-requests-project/-/merge_requests/1.json`)
2023-04-23 21:23:45 +05:30
.reply(HTTP_STATUS_OK, {});
2018-03-17 18:26:18 +05:30
2020-06-23 00:09:42 +05:30
test.merge = new MergeRequest();
return test.merge;
2018-12-13 13:39:08 +05:30
});
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
afterEach(() => {
mock.restore();
2022-07-16 23:28:13 +05:30
resetHTMLFixture();
2018-12-13 13:39:08 +05:30
});
2018-03-17 18:26:18 +05:30
2022-04-04 11:22:00 +05:30
it('modifies the Markdown field', async () => {
2020-06-23 00:09:42 +05:30
jest.spyOn($, 'ajax').mockImplementation();
2018-12-13 13:39:08 +05:30
const changeEvent = document.createEvent('HTMLEvents');
changeEvent.initEvent('change', true, true);
2021-03-08 18:12:59 +05:30
$('input[type=checkbox]').first().attr('checked', true)[0].dispatchEvent(changeEvent);
2022-04-04 11:22:00 +05:30
await waitForPromises();
expect($('.js-task-list-field').val()).toBe(
'- [x] Task List Item\n- [ ]\n- [ ] Task List Item 2\n',
);
2019-12-26 22:10:19 +05:30
});
2022-04-04 11:22:00 +05:30
it('ensure that task with only spaces does not get checked incorrectly', async () => {
2019-12-26 22:10:19 +05:30
// fixed in 'deckar01-task_list', '2.2.1' gem
2020-06-23 00:09:42 +05:30
jest.spyOn($, 'ajax').mockImplementation();
2019-12-26 22:10:19 +05:30
const changeEvent = document.createEvent('HTMLEvents');
changeEvent.initEvent('change', true, true);
2021-03-08 18:12:59 +05:30
$('input[type=checkbox]').last().attr('checked', true)[0].dispatchEvent(changeEvent);
2022-04-04 11:22:00 +05:30
await waitForPromises();
expect($('.js-task-list-field').val()).toBe(
'- [ ] Task List Item\n- [ ]\n- [x] Task List Item 2\n',
);
2016-09-13 17:45:13 +05:30
});
2017-09-10 17:25:29 +05:30
2019-03-02 22:35:43 +05:30
describe('tasklist', () => {
const lineNumber = 8;
const lineSource = '- [ ] item 8';
const index = 3;
const checked = true;
2022-04-04 11:22:00 +05:30
it('submits an ajax request on tasklist:changed', async () => {
2019-03-02 22:35:43 +05:30
$('.js-task-list-field').trigger({
type: 'tasklist:changed',
detail: { lineNumber, lineSource, index, checked },
});
2022-04-04 11:22:00 +05:30
await waitForPromises();
2019-03-02 22:35:43 +05:30
2022-04-04 11:22:00 +05:30
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-03-02 22:35:43 +05:30
});
2022-04-04 11:22:00 +05:30
it('shows an error notification when tasklist update failed', async () => {
2019-03-02 22:35:43 +05:30
mock
2020-06-23 00:09:42 +05:30
.onPatch(`${TEST_HOST}/frontend-fixtures/merge-requests-project/-/merge_requests/1.json`)
2023-04-23 21:23:45 +05:30
.reply(HTTP_STATUS_CONFLICT, {});
2019-03-02 22:35:43 +05:30
$('.js-task-list-field').trigger({
type: 'tasklist:changed',
detail: { lineNumber, lineSource, index, checked },
});
2022-04-04 11:22:00 +05:30
await waitForPromises();
2019-03-02 22:35:43 +05:30
2022-11-25 23:54:43 +05:30
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-04-04 11:22:00 +05:30
);
2018-03-17 18:26:18 +05:30
});
2018-12-13 13:39:08 +05:30
});
});
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
describe('hideCloseButton', () => {
describe('merge request of current_user', () => {
beforeEach(() => {
2022-07-16 23:28:13 +05:30
loadHTMLFixture('merge_requests/merge_request_of_current_user.html');
2020-06-23 00:09:42 +05:30
test.el = document.querySelector('.js-issuable-actions');
2018-12-13 13:39:08 +05:30
MergeRequest.hideCloseButton();
2018-03-17 18:26:18 +05:30
});
2018-12-13 13:39:08 +05:30
it('hides the close button', () => {
2020-06-23 00:09:42 +05:30
const smallCloseItem = test.el.querySelector('.js-close-item');
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
expect(smallCloseItem).toHaveClass('hidden');
2018-03-17 18:26:18 +05:30
});
});
2016-09-13 17:45:13 +05:30
});
2018-12-13 13:39:08 +05:30
});