BigW Consortium Gitlab

merge_request_notes_spec.js 2.97 KB
Newer Older
1 2 3 4 5 6 7 8 9
/* global Notes */

import 'vendor/autosize';
import '~/gl_form';
import '~/lib/utils/text_utility';
import '~/render_gfm';
import '~/render_math';
import '~/notes';

10 11
const upArrowKeyCode = 38;

12
describe('Merge request notes', () => {
13 14 15 16
  window.gon = window.gon || {};
  window.gl = window.gl || {};
  gl.utils = gl.utils || {};

17
  const discussionTabFixture = 'merge_requests/diff_comment.html.raw';
18
  const changesTabJsonFixture = 'merge_request_diffs/inline_changes_tab_with_comments.json';
19
  preloadFixtures(discussionTabFixture, changesTabJsonFixture);
20

21 22 23 24 25 26 27
  describe('Discussion tab with diff comments', () => {
    beforeEach(() => {
      loadFixtures(discussionTabFixture);
      gl.utils.disableButtonIfEmptyField = _.noop;
      window.project_uploads_path = 'http://test.host/uploads';
      $('body').data('page', 'projects:merge_requests:show');
      window.gon.current_user_id = $('.note:last').data('author-id');
28

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
      return new Notes('', []);
    });

    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();
51

52 53 54 55
        setTimeout(() => {
          expect(
            $('.note-discussion .js-note-text'),
          ).toExist();
56

57
          $('.note-discussion .js-note-text').trigger(upArrowEvent);
58

59
          expect('click').toHaveBeenTriggeredOn('.note-discussion .js-note-edit');
60

61 62 63
          done();
        });
      });
64
    });
65
  });
66

67 68 69 70 71 72 73 74 75 76 77 78
  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);
      $('body').data('page', 'projects:merge_requests:show');
      window.gon.current_user_id = $('.note:last').data('author-id');

      return new Notes('', []);
    });
79

80 81 82 83
    describe('up arrow', () => {
      it('edits last comment in discussion when triggered in discussion form', (done) => {
        const upArrowEvent = $.Event('keydown');
        upArrowEvent.which = upArrowKeyCode;
84

85
        spyOnEvent('.note:last .js-note-edit', 'click');
86

87
        $('.js-discussion-reply-button').trigger('click');
88

89 90
        setTimeout(() => {
          $('.js-note-text').trigger(upArrowEvent);
91

92
          expect('click').toHaveBeenTriggeredOn('.note:last .js-note-edit');
93

94 95
          done();
        });
96 97 98 99
      });
    });
  });
});