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

123 lines
4.6 KiB
JavaScript
Raw Normal View History

/* eslint-disable space-before-function-paren, no-return-assign */
import $ from 'jquery';
2018-02-02 09:17:26 -05:00
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
2017-12-15 07:57:08 -05:00
import MergeRequest from '~/merge_request';
2017-06-08 12:15:34 -04:00
import CloseReopenReportToggle from '~/close_reopen_report_toggle';
2017-07-07 11:04:43 -04:00
import IssuablesHelper from '~/helpers/issuables_helper';
2016-07-24 16:45:11 -04:00
(function() {
describe('MergeRequest', function() {
2017-06-07 15:34:19 -04:00
describe('task lists', function() {
2018-02-02 09:17:26 -05:00
let mock;
preloadFixtures('merge_requests/merge_request_with_task_list.html.raw');
2016-07-24 16:45:11 -04:00
beforeEach(function() {
loadFixtures('merge_requests/merge_request_with_task_list.html.raw');
2018-02-02 09:17:26 -05:00
spyOn(axios, 'patch').and.callThrough();
mock = new MockAdapter(axios);
mock.onPatch(`${gl.TEST_HOST}/frontend-fixtures/merge-requests-project/merge_requests/1.json`).reply(200, {});
2016-07-24 16:45:11 -04:00
return this.merge = new MergeRequest();
});
2018-02-02 09:17:26 -05:00
afterEach(() => {
mock.restore();
});
2016-07-24 16:45:11 -04:00
it('modifies the Markdown field', function() {
spyOn($, 'ajax').and.stub();
const changeEvent = document.createEvent('HTMLEvents');
changeEvent.initEvent('change', true, true);
$('input[type=checkbox]').attr('checked', true)[0].dispatchEvent(changeEvent);
2016-07-24 16:45:11 -04:00
return expect($('.js-task-list-field').val()).toBe('- [x] Task List Item');
});
it('submits an ajax request on tasklist:changed', (done) => {
2018-02-02 09:17:26 -05:00
$('.js-task-list-field').trigger('tasklist:changed');
2018-02-02 09:17:26 -05:00
setTimeout(() => {
expect(axios.patch).toHaveBeenCalledWith(`${gl.TEST_HOST}/frontend-fixtures/merge-requests-project/merge_requests/1.json`, {
merge_request: { description: '- [ ] Task List Item' },
});
done();
2016-07-24 16:45:11 -04:00
});
});
});
2017-06-07 15:34:19 -04:00
describe('class constructor', () => {
beforeEach(() => {
spyOn($, 'ajax').and.stub();
});
2017-06-07 15:34:19 -04:00
it('calls .initCloseReopenReport', () => {
2017-07-07 11:04:43 -04:00
spyOn(IssuablesHelper, 'initCloseReopenReport');
2017-06-07 15:34:19 -04:00
2017-07-07 11:04:43 -04:00
new MergeRequest(); // eslint-disable-line no-new
2017-06-07 15:34:19 -04:00
2017-07-07 11:04:43 -04:00
expect(IssuablesHelper.initCloseReopenReport).toHaveBeenCalled();
2017-06-07 15:34:19 -04:00
});
2017-06-08 12:15:34 -04:00
it('calls .initDroplab', () => {
2017-06-07 15:34:19 -04:00
const container = jasmine.createSpyObj('container', ['querySelector']);
const dropdownTrigger = {};
const dropdownList = {};
const button = {};
2017-06-08 12:15:34 -04:00
spyOn(CloseReopenReportToggle.prototype, 'initDroplab');
2017-06-07 15:34:19 -04:00
spyOn(document, 'querySelector').and.returnValue(container);
container.querySelector.and.returnValues(dropdownTrigger, dropdownList, button);
2017-07-07 11:04:43 -04:00
new MergeRequest(); // eslint-disable-line no-new
2017-06-07 15:34:19 -04:00
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');
2017-06-08 12:15:34 -04:00
expect(CloseReopenReportToggle.prototype.initDroplab).toHaveBeenCalled();
2017-06-07 15:34:19 -04:00
});
});
describe('hideCloseButton', () => {
describe('merge request of another user', () => {
beforeEach(() => {
loadFixtures('merge_requests/merge_request_with_task_list.html.raw');
this.el = document.querySelector('.js-issuable-actions');
2018-01-16 03:54:18 -05:00
new MergeRequest(); // eslint-disable-line no-new
MergeRequest.hideCloseButton();
});
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');
});
});
describe('merge request of current_user', () => {
beforeEach(() => {
loadFixtures('merge_requests/merge_request_of_current_user.html.raw');
this.el = document.querySelector('.js-issuable-actions');
2018-01-16 03:54:18 -05:00
MergeRequest.hideCloseButton();
});
it('hides the close button', () => {
const closeButton = this.el.querySelector('.btn-close');
const smallCloseItem = this.el.querySelector('.js-close-item');
expect(closeButton).toHaveClass('hidden');
expect(smallCloseItem).toHaveClass('hidden');
});
});
});
2016-07-24 16:45:11 -04:00
});
}).call(window);