2017-05-08 09:31:11 -04:00
|
|
|
/* global Notes */
|
|
|
|
|
|
|
|
import 'vendor/autosize';
|
|
|
|
import '~/gl_form';
|
|
|
|
import '~/lib/utils/text_utility';
|
|
|
|
import '~/render_gfm';
|
|
|
|
import '~/render_math';
|
|
|
|
import '~/notes';
|
|
|
|
|
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');
|
2017-06-20 01:18:27 -04:00
|
|
|
window.gon.current_user_id = $('.note:last').data('author-id');
|
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');
|
2017-06-20 01:18:27 -04:00
|
|
|
window.gon.current_user_id = $('.note:last').data('author-id');
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|