gitlab-org--gitlab-foss/spec/frontend/merge_request_spec.js

129 lines
3.9 KiB
JavaScript
Raw Normal View History

import $ from 'jquery';
2018-02-02 09:17:26 -05:00
import MockAdapter from 'axios-mock-adapter';
import { TEST_HOST } from 'spec/test_constants';
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
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
preloadFixtures('merge_requests/merge_request_with_task_list.html');
beforeEach(() => {
loadFixtures('merge_requests/merge_request_with_task_list.html');
2018-02-02 09:17:26 -05: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
.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
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();
});
2018-02-02 09:17:26 -05:00
2019-09-10 05:35:11 -04:00
it('modifies the Markdown field', done => {
jest.spyOn($, 'ajax').mockImplementation();
2018-10-17 03:13:26 -04:00
const changeEvent = document.createEvent('HTMLEvents');
changeEvent.initEvent('change', true, true);
$('input[type=checkbox]')
.first()
.attr('checked', true)[0]
.dispatchEvent(changeEvent);
setImmediate(() => {
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
jest.spyOn($, 'ajax').mockImplementation();
const changeEvent = document.createEvent('HTMLEvents');
changeEvent.initEvent('change', true, true);
$('input[type=checkbox]')
.last()
2018-10-17 03:13:26 -04:00
.attr('checked', true)[0]
.dispatchEvent(changeEvent);
setImmediate(() => {
expect($('.js-task-list-field').val()).toBe(
'- [ ] Task List Item\n- [ ]\n- [x] Task List Item 2\n',
);
2019-09-10 05:35:11 -04:00
done();
});
2018-10-17 03:13:26 -04:00
});
describe('tasklist', () => {
2019-01-22 15:53:08 -05:00
const lineNumber = 8;
const lineSource = '- [ ] item 8';
const index = 3;
const checked = true;
it('submits an ajax request on tasklist:changed', done => {
$('.js-task-list-field').trigger({
type: 'tasklist:changed',
detail: { lineNumber, lineSource, index, checked },
});
setImmediate(() => {
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 },
},
},
);
done();
});
2019-01-22 15:53:08 -05:00
});
2018-10-17 03:13:26 -04:00
it('shows an error notification when tasklist update failed', done => {
mock
.onPatch(`${TEST_HOST}/frontend-fixtures/merge-requests-project/-/merge_requests/1.json`)
.reply(409, {});
$('.js-task-list-field').trigger({
type: 'tasklist:changed',
detail: { lineNumber, lineSource, index, checked },
});
setImmediate(() => {
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 15:53:08 -05:00
done();
});
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(() => {
loadFixtures('merge_requests/merge_request_of_current_user.html');
test.el = document.querySelector('.js-issuable-actions');
2018-10-17 03:13:26 -04:00
MergeRequest.hideCloseButton();
});
2018-10-17 03:13:26 -04:00
it('hides the close button', () => {
const smallCloseItem = test.el.querySelector('.js-close-item');
2018-10-17 03:13:26 -04:00
expect(smallCloseItem).toHaveClass('hidden');
});
});
2016-07-24 16:45:11 -04:00
});
2018-10-17 03:13:26 -04:00
});