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

186 lines
6.3 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-17 18:26:18 +05:30
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import MergeRequest from '~/merge_request';
2017-09-10 17:25:29 +05:30
import CloseReopenReportToggle from '~/close_reopen_report_toggle';
import IssuablesHelper from '~/helpers/issuables_helper';
2016-09-13 17:45:13 +05:30
2018-12-13 13:39:08 +05:30
describe('MergeRequest', function() {
describe('task lists', function() {
let mock;
2018-03-17 18:26:18 +05:30
2019-07-07 11:18:12 +05:30
preloadFixtures('merge_requests/merge_request_with_task_list.html');
2018-12-13 13:39:08 +05:30
beforeEach(function() {
2019-07-07 11:18:12 +05:30
loadFixtures('merge_requests/merge_request_with_task_list.html');
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
spyOn(axios, 'patch').and.callThrough();
mock = new MockAdapter(axios);
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
mock
.onPatch(`${gl.TEST_HOST}/frontend-fixtures/merge-requests-project/merge_requests/1.json`)
.reply(200, {});
2018-03-17 18:26:18 +05:30
2019-12-26 22:10:19 +05:30
this.merge = new MergeRequest();
return this.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();
});
2018-03-17 18:26:18 +05:30
2019-12-04 20:38:33 +05:30
it('modifies the Markdown field', done => {
2018-12-13 13:39:08 +05:30
spyOn($, 'ajax').and.stub();
const changeEvent = document.createEvent('HTMLEvents');
changeEvent.initEvent('change', true, true);
$('input[type=checkbox]')
2019-12-26 22:10:19 +05:30
.first()
.attr('checked', true)[0]
.dispatchEvent(changeEvent);
setTimeout(() => {
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
spyOn($, 'ajax').and.stub();
const changeEvent = document.createEvent('HTMLEvents');
changeEvent.initEvent('change', true, true);
$('input[type=checkbox]')
.last()
2018-12-13 13:39:08 +05:30
.attr('checked', true)[0]
.dispatchEvent(changeEvent);
2019-12-04 20:38:33 +05:30
setTimeout(() => {
2019-12-26 22:10:19 +05:30
expect($('.js-task-list-field').val()).toBe(
'- [ ] Task List Item\n- [ ] \n- [x] Task List Item 2\n',
);
2019-12-04 20:38:33 +05:30
done();
});
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;
it('submits an ajax request on tasklist:changed', done => {
$('.js-task-list-field').trigger({
type: 'tasklist:changed',
detail: { lineNumber, lineSource, index, checked },
});
setTimeout(() => {
expect(axios.patch).toHaveBeenCalledWith(
`${gl.TEST_HOST}/frontend-fixtures/merge-requests-project/merge_requests/1.json`,
{
merge_request: {
2019-12-26 22:10:19 +05:30
description: '- [ ] Task List Item\n- [ ] \n- [ ] Task List Item 2\n',
2019-07-31 22:56:46 +05:30
lock_version: 0,
2019-03-02 22:35:43 +05:30
update_task: { line_number: lineNumber, line_source: lineSource, index, checked },
},
},
);
done();
});
});
2020-01-01 13:55:28 +05:30
// https://gitlab.com/gitlab-org/gitlab/issues/34861
2019-12-26 22:10:19 +05:30
// eslint-disable-next-line jasmine/no-disabled-tests
xit('shows an error notification when tasklist update failed', done => {
2019-03-02 22:35:43 +05:30
mock
.onPatch(`${gl.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 },
});
setTimeout(() => {
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.',
);
done();
});
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('class constructor', () => {
beforeEach(() => {
spyOn($, 'ajax').and.stub();
});
2017-09-10 17:25:29 +05:30
2018-12-13 13:39:08 +05:30
it('calls .initCloseReopenReport', () => {
spyOn(IssuablesHelper, 'initCloseReopenReport');
2017-09-10 17:25:29 +05:30
2018-12-13 13:39:08 +05:30
new MergeRequest(); // eslint-disable-line no-new
2017-09-10 17:25:29 +05:30
2018-12-13 13:39:08 +05:30
expect(IssuablesHelper.initCloseReopenReport).toHaveBeenCalled();
});
it('calls .initDroplab', () => {
const container = jasmine.createSpyObj('container', ['querySelector']);
const dropdownTrigger = {};
const dropdownList = {};
const button = {};
spyOn(CloseReopenReportToggle.prototype, 'initDroplab');
spyOn(document, 'querySelector').and.returnValue(container);
container.querySelector.and.returnValues(dropdownTrigger, dropdownList, button);
2017-09-10 17:25:29 +05:30
2018-12-13 13:39:08 +05:30
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-09-10 17:25:29 +05:30
2018-12-13 13:39:08 +05:30
describe('hideCloseButton', () => {
describe('merge request of another user', () => {
beforeEach(() => {
2019-07-07 11:18:12 +05:30
loadFixtures('merge_requests/merge_request_with_task_list.html');
2018-12-13 13:39:08 +05:30
this.el = document.querySelector('.js-issuable-actions');
2017-09-10 17:25:29 +05:30
new MergeRequest(); // eslint-disable-line no-new
2018-12-13 13:39:08 +05:30
MergeRequest.hideCloseButton();
});
2017-09-10 17:25:29 +05:30
2018-12-13 13:39:08 +05:30
it('hides the dropdown close item and selects the next item', () => {
const closeItem = this.el.querySelector('li.close-item');
const smallCloseItem = this.el.querySelector('.js-close-item');
const reportItem = this.el.querySelector('li.report-item');
expect(closeItem).toHaveClass('hidden');
expect(smallCloseItem).toHaveClass('hidden');
expect(reportItem).toHaveClass('droplab-item-selected');
expect(reportItem).not.toHaveClass('hidden');
2017-09-10 17:25:29 +05:30
});
});
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
describe('merge request of current_user', () => {
beforeEach(() => {
2019-07-07 11:18:12 +05:30
loadFixtures('merge_requests/merge_request_of_current_user.html');
2018-12-13 13:39:08 +05:30
this.el = document.querySelector('.js-issuable-actions');
MergeRequest.hideCloseButton();
2018-03-17 18:26:18 +05:30
});
2018-12-13 13:39:08 +05:30
it('hides the close button', () => {
const closeButton = this.el.querySelector('.btn-close');
const smallCloseItem = this.el.querySelector('.js-close-item');
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
expect(closeButton).toHaveClass('hidden');
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
});