BigW Consortium Gitlab

notes_spec.js 2.26 KB
Newer Older
1
/* eslint-disable space-before-function-paren, no-unused-expressions, no-var, object-shorthand, comma-dangle, max-len */
2 3
/* global Notes */

Fatih Acet committed
4
/*= require notes */
5
/*= require autosize */
Fatih Acet committed
6
/*= require gl_form */
7
/*= require lib/utils/text_utility */
Fatih Acet committed
8 9 10

(function() {
  window.gon || (window.gon = {});
11 12
  window.gl = window.gl || {};
  gl.utils = gl.utils || {};
Fatih Acet committed
13 14

  describe('Notes', function() {
15
    var commentsTemplate = 'issues/issue_with_comment.html.raw';
16
    preloadFixtures(commentsTemplate);
17

18
    beforeEach(function () {
19
      loadFixtures(commentsTemplate);
20 21
      gl.utils.disableButtonIfEmptyField = _.noop;
      window.project_uploads_path = 'http://test.host/uploads';
22
      $('body').data('page', 'projects:issues:show');
23 24 25
    });

    describe('task lists', function() {
Fatih Acet committed
26 27
      beforeEach(function() {
        $('form').on('submit', function(e) {
28
          e.preventDefault();
Fatih Acet committed
29
        });
30
        this.notes = new Notes();
Fatih Acet committed
31
      });
32

Fatih Acet committed
33 34
      it('modifies the Markdown field', function() {
        $('input[type=checkbox]').attr('checked', true).trigger('change');
35
        expect($('.js-task-list-field').val()).toBe('- [x] Task List Item');
Fatih Acet committed
36
      });
37 38 39

      it('submits the form on tasklist:changed', function() {
        var submitted = false;
Fatih Acet committed
40 41
        $('form').on('submit', function(e) {
          submitted = true;
42
          e.preventDefault();
Fatih Acet committed
43
        });
44

Fatih Acet committed
45
        $('.js-task-list-field').trigger('tasklist:changed');
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
        expect(submitted).toBe(true);
      });
    });

    describe('comments', function() {
      var textarea = '.js-note-text';

      beforeEach(function() {
        this.notes = new Notes();

        this.autoSizeSpy = spyOnEvent($(textarea), 'autosize:update');
        spyOn(this.notes, 'renderNote').and.stub();

        $(textarea).data('autosave', {
          reset: function() {}
        });

        $('form').on('submit', function(e) {
          e.preventDefault();
          $('.js-main-target-form').trigger('ajax:success');
        });
Fatih Acet committed
67
      });
68 69 70 71 72 73 74

      it('autosizes after comment submission', function() {
        $(textarea).text('This is an example comment note');
        expect(this.autoSizeSpy).not.toHaveBeenTriggered();

        $('.js-comment-button').click();
        expect(this.autoSizeSpy).toHaveBeenTriggered();
75
      });
Fatih Acet committed
76 77 78
    });
  });
}).call(this);