notes_spec.js 2.02 KB
Newer Older
1
/* eslint-disable */
Fatih Acet's avatar
Fatih Acet committed
2
/*= require notes */
3
/*= require autosize */
Fatih Acet's avatar
Fatih Acet committed
4
/*= require gl_form */
5
/*= require lib/utils/text_utility */
Fatih Acet's avatar
Fatih Acet committed
6 7 8 9 10 11 12 13 14

(function() {
  window.gon || (window.gon = {});

  window.disableButtonIfEmptyField = function() {
    return null;
  };

  describe('Notes', function() {
15
    describe('task lists', function() {
Fatih Acet's avatar
Fatih Acet committed
16
      fixture.preload('issue_note.html');
17

Fatih Acet's avatar
Fatih Acet committed
18 19 20
      beforeEach(function() {
        fixture.load('issue_note.html');
        $('form').on('submit', function(e) {
21
          e.preventDefault();
Fatih Acet's avatar
Fatih Acet committed
22
        });
23
        this.notes = new Notes();
Fatih Acet's avatar
Fatih Acet committed
24
      });
25

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

      it('submits the form on tasklist:changed', function() {
        var submitted = false;
Fatih Acet's avatar
Fatih Acet committed
33 34
        $('form').on('submit', function(e) {
          submitted = true;
35
          e.preventDefault();
Fatih Acet's avatar
Fatih Acet committed
36
        });
37

Fatih Acet's avatar
Fatih Acet committed
38
        $('.js-task-list-field').trigger('tasklist:changed');
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
        expect(submitted).toBe(true);
      });
    });

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

      beforeEach(function() {
        fixture.load(commentsTemplate);
        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's avatar
Fatih Acet committed
63
      });
64 65 66 67 68 69 70 71

      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's avatar
Fatih Acet committed
72 73 74 75
    });
  });

}).call(this);