2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2017-12-19 05:12:32 -05:00
|
|
|
import _ from 'underscore';
|
2017-10-31 05:18:30 -04:00
|
|
|
import 'autosize';
|
2017-05-08 09:31:11 -04:00
|
|
|
import '~/gl_form';
|
|
|
|
import '~/lib/utils/text_utility';
|
2018-03-20 00:01:17 -04:00
|
|
|
import '~/behaviors/markdown/render_gfm';
|
2017-12-15 05:21:49 -05:00
|
|
|
import Notes from '~/notes';
|
2017-05-08 09:31:11 -04:00
|
|
|
|
2017-06-20 01:18:27 -04:00
|
|
|
const upArrowKeyCode = 38;
|
|
|
|
|
2017-05-08 09:59:18 -04:00
|
|
|
describe('Merge request notes', () => {
|
2017-05-08 09:31:11 -04:00
|
|
|
window.gon = window.gon || {};
|
|
|
|
window.gl = window.gl || {};
|
|
|
|
gl.utils = gl.utils || {};
|
|
|
|
|
2017-06-20 01:18:27 -04:00
|
|
|
const discussionTabFixture = 'merge_requests/diff_comment.html.raw';
|
2017-06-13 18:12:31 -04:00
|
|
|
const changesTabJsonFixture = 'merge_request_diffs/inline_changes_tab_with_comments.json';
|
2017-06-20 01:18:27 -04:00
|
|
|
preloadFixtures(discussionTabFixture, changesTabJsonFixture);
|
2017-05-08 09:31:11 -04:00
|
|
|
|
2017-06-20 01:18:27 -04:00
|
|
|
describe('Discussion tab with diff comments', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
loadFixtures(discussionTabFixture);
|
|
|
|
gl.utils.disableButtonIfEmptyField = _.noop;
|
|
|
|
window.project_uploads_path = 'http://test.host/uploads';
|
2017-10-06 16:36:15 -04:00
|
|
|
$('body').attr('data-page', 'projects:merge_requests:show');
|
2018-02-20 17:20:48 -05:00
|
|
|
window.gon.current_user_id = $('.note:last').data('authorId');
|
2017-05-08 09:31:11 -04:00
|
|
|
|
2017-06-20 01:18:27 -04:00
|
|
|
return new Notes('', []);
|
|
|
|
});
|
|
|
|
|
2017-10-06 16:36:15 -04:00
|
|
|
afterEach(() => {
|
|
|
|
// Undo what we did to the shared <body>
|
|
|
|
$('body').removeAttr('data-page');
|
|
|
|
});
|
|
|
|
|
2017-06-20 01:18:27 -04:00
|
|
|
describe('up arrow', () => {
|
|
|
|
it('edits last comment when triggered in main form', () => {
|
|
|
|
const upArrowEvent = $.Event('keydown');
|
|
|
|
upArrowEvent.which = upArrowKeyCode;
|
|
|
|
|
|
|
|
spyOnEvent('.note:last .js-note-edit', 'click');
|
|
|
|
|
|
|
|
$('.js-note-text').trigger(upArrowEvent);
|
|
|
|
|
|
|
|
expect('click').toHaveBeenTriggeredOn('.note:last .js-note-edit');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('edits last comment in discussion when triggered in discussion form', (done) => {
|
|
|
|
const upArrowEvent = $.Event('keydown');
|
|
|
|
upArrowEvent.which = upArrowKeyCode;
|
|
|
|
|
|
|
|
spyOnEvent('.note-discussion .js-note-edit', 'click');
|
|
|
|
|
|
|
|
$('.js-discussion-reply-button').click();
|
2017-05-08 09:31:11 -04:00
|
|
|
|
2017-06-20 01:18:27 -04:00
|
|
|
setTimeout(() => {
|
|
|
|
expect(
|
|
|
|
$('.note-discussion .js-note-text'),
|
|
|
|
).toExist();
|
2017-05-08 09:31:11 -04:00
|
|
|
|
2017-06-20 01:18:27 -04:00
|
|
|
$('.note-discussion .js-note-text').trigger(upArrowEvent);
|
2017-05-08 09:31:11 -04:00
|
|
|
|
2017-06-20 01:18:27 -04:00
|
|
|
expect('click').toHaveBeenTriggeredOn('.note-discussion .js-note-edit');
|
2017-05-08 09:31:11 -04:00
|
|
|
|
2017-06-20 01:18:27 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-05-08 09:31:11 -04:00
|
|
|
});
|
2017-06-20 01:18:27 -04:00
|
|
|
});
|
2017-05-08 09:31:11 -04:00
|
|
|
|
2017-06-20 01:18:27 -04:00
|
|
|
describe('Changes tab with diff comments', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const diffsResponse = getJSONFixture(changesTabJsonFixture);
|
|
|
|
const noteFormHtml = `<form class="js-new-note-form">
|
|
|
|
<textarea class="js-note-text"></textarea>
|
|
|
|
</form>`;
|
|
|
|
setFixtures(diffsResponse.html + noteFormHtml);
|
2017-10-06 16:36:15 -04:00
|
|
|
$('body').attr('data-page', 'projects:merge_requests:show');
|
2018-02-20 17:20:48 -05:00
|
|
|
window.gon.current_user_id = $('.note:last').data('authorId');
|
2017-06-20 01:18:27 -04:00
|
|
|
|
|
|
|
return new Notes('', []);
|
|
|
|
});
|
2017-05-08 09:31:11 -04:00
|
|
|
|
2017-10-06 16:36:15 -04:00
|
|
|
afterEach(() => {
|
|
|
|
// Undo what we did to the shared <body>
|
|
|
|
$('body').removeAttr('data-page');
|
|
|
|
});
|
|
|
|
|
2017-06-20 01:18:27 -04:00
|
|
|
describe('up arrow', () => {
|
|
|
|
it('edits last comment in discussion when triggered in discussion form', (done) => {
|
|
|
|
const upArrowEvent = $.Event('keydown');
|
|
|
|
upArrowEvent.which = upArrowKeyCode;
|
2017-05-08 09:31:11 -04:00
|
|
|
|
2017-06-20 01:18:27 -04:00
|
|
|
spyOnEvent('.note:last .js-note-edit', 'click');
|
2017-05-08 09:31:11 -04:00
|
|
|
|
2017-06-20 01:18:27 -04:00
|
|
|
$('.js-discussion-reply-button').trigger('click');
|
2017-05-08 09:31:11 -04:00
|
|
|
|
2017-06-20 01:18:27 -04:00
|
|
|
setTimeout(() => {
|
|
|
|
$('.js-note-text').trigger(upArrowEvent);
|
2017-05-08 09:31:11 -04:00
|
|
|
|
2017-06-20 01:18:27 -04:00
|
|
|
expect('click').toHaveBeenTriggeredOn('.note:last .js-note-edit');
|
2017-05-08 09:31:11 -04:00
|
|
|
|
2017-06-20 01:18:27 -04:00
|
|
|
done();
|
|
|
|
});
|
2017-05-08 09:31:11 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|