BigW Consortium Gitlab

merge_request_spec.js 4.21 KB
Newer Older
1
/* eslint-disable space-before-function-paren, no-return-assign */
2
/* global MergeRequest */
Fatih Acet committed
3

4
import '~/merge_request';
5
import CloseReopenReportToggle from '~/close_reopen_report_toggle';
6
import IssuablesHelper from '~/helpers/issuables_helper';
Fatih Acet committed
7 8 9

(function() {
  describe('MergeRequest', function() {
Luke "Jared" Bennett committed
10
    describe('task lists', function() {
Simon Knox committed
11
      preloadFixtures('merge_requests/merge_request_with_task_list.html.raw');
Fatih Acet committed
12
      beforeEach(function() {
Simon Knox committed
13
        loadFixtures('merge_requests/merge_request_with_task_list.html.raw');
Fatih Acet committed
14 15 16 17
        return this.merge = new MergeRequest();
      });
      it('modifies the Markdown field', function() {
        spyOn(jQuery, 'ajax').and.stub();
18 19 20
        const changeEvent = document.createEvent('HTMLEvents');
        changeEvent.initEvent('change', true, true);
        $('input[type=checkbox]').attr('checked', true)[0].dispatchEvent(changeEvent);
Fatih Acet committed
21 22 23 24 25
        return expect($('.js-task-list-field').val()).toBe('- [x] Task List Item');
      });
      return it('submits an ajax request on tasklist:changed', function() {
        spyOn(jQuery, 'ajax').and.callFake(function(req) {
          expect(req.type).toBe('PATCH');
Simon Knox committed
26
          expect(req.url).toBe(`${gl.TEST_HOST}/frontend-fixtures/merge-requests-project/merge_requests/1.json`);
Fatih Acet committed
27 28 29 30 31
          return expect(req.data.merge_request.description).not.toBe(null);
        });
        return $('.js-task-list-field').trigger('tasklist:changed');
      });
    });
Luke "Jared" Bennett committed
32 33 34

    describe('class constructor', () => {
      it('calls .initCloseReopenReport', () => {
35
        spyOn(IssuablesHelper, 'initCloseReopenReport');
Luke "Jared" Bennett committed
36

37
        new MergeRequest(); // eslint-disable-line no-new
Luke "Jared" Bennett committed
38

39
        expect(IssuablesHelper.initCloseReopenReport).toHaveBeenCalled();
Luke "Jared" Bennett committed
40 41
      });

42
      it('calls .initDroplab', () => {
Luke "Jared" Bennett committed
43 44 45 46 47
        const container = jasmine.createSpyObj('container', ['querySelector']);
        const dropdownTrigger = {};
        const dropdownList = {};
        const button = {};

48
        spyOn(CloseReopenReportToggle.prototype, 'initDroplab');
Luke "Jared" Bennett committed
49 50 51
        spyOn(document, 'querySelector').and.returnValue(container);
        container.querySelector.and.returnValues(dropdownTrigger, dropdownList, button);

52
        new MergeRequest(); // eslint-disable-line no-new
Luke "Jared" Bennett committed
53 54 55 56 57

        expect(document.querySelector).toHaveBeenCalledWith('.js-issuable-close-dropdown');
        expect(container.querySelector).toHaveBeenCalledWith('.js-issuable-close-toggle');
        expect(container.querySelector).toHaveBeenCalledWith('.js-issuable-close-menu');
        expect(container.querySelector).toHaveBeenCalledWith('.js-issuable-close-button');
58
        expect(CloseReopenReportToggle.prototype.initDroplab).toHaveBeenCalled();
Luke "Jared" Bennett committed
59 60
      });
    });
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

    describe('hideCloseButton', () => {
      describe('merge request of another user', () => {
        beforeEach(() => {
          loadFixtures('merge_requests/merge_request_with_task_list.html.raw');
          this.el = document.querySelector('.merge-request .issuable-actions');
          const merge = new MergeRequest();
          merge.hideCloseButton();
        });

        it('hides the dropdown close item and selects the next item', () => {
          const closeItem = this.el.querySelector('li.close-item');
          const smallCloseItem = this.el.querySelector('.js-close-item');
          const reportItem = this.el.querySelector('li.report-item');

          expect(closeItem).toHaveClass('hidden');
          expect(smallCloseItem).toHaveClass('hidden');
          expect(reportItem).toHaveClass('droplab-item-selected');
          expect(reportItem).not.toHaveClass('hidden');
        });
      });

      describe('merge request of current_user', () => {
        beforeEach(() => {
          loadFixtures('merge_requests/merge_request_of_current_user.html.raw');
          this.el = document.querySelector('.merge-request .issuable-actions');
          const merge = new MergeRequest();
          merge.hideCloseButton();
        });

        it('hides the close button', () => {
          const closeButton = this.el.querySelector('.btn-close');
          const smallCloseItem = this.el.querySelector('.js-close-item');

          expect(closeButton).toHaveClass('hidden');
          expect(smallCloseItem).toHaveClass('hidden');
        });
      });
    });
Fatih Acet committed
100
  });
101
}).call(window);