BigW Consortium Gitlab

notes_spec.js 2.21 KB
Newer Older
1
/* eslint-disable space-before-function-paren, no-unused-expressions, no-undef, no-var, object-shorthand, comma-dangle, semi, padded-blocks, max-len */
Fatih Acet committed
2
/*= require notes */
3
/*= require autosize */
Fatih Acet committed
4
/*= require gl_form */
5
/*= require lib/utils/text_utility */
Fatih Acet committed
6 7 8

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

  describe('Notes', function() {
13 14
    var commentsTemplate = 'issues/issue_with_comment.raw';
    fixture.preload(commentsTemplate);
15

16 17 18 19 20 21 22
    beforeEach(function () {
      fixture.load(commentsTemplate);
      gl.utils.disableButtonIfEmptyField = _.noop;
      window.project_uploads_path = 'http://test.host/uploads';
    });

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

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

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

Fatih Acet committed
42
        $('.js-task-list-field').trigger('tasklist:changed');
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
        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
64
      });
65 66 67 68 69 70 71 72

      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();
      })
Fatih Acet committed
73 74 75 76
    });
  });

}).call(this);