Skip to content
Snippets Groups Projects
Select Git revision
  • move-gl-dropdown
  • improve-table-pagination-spec
  • move-markdown-preview
  • winh-fix-merge-request-spec
  • master default
  • index-namespaces-lower-name
  • winh-single-karma-test
  • 10-3-stable
  • 36782-replace-team-user-role-with-add_role-user-in-specs
  • winh-modal-internal-state
  • tz-ide-file-icons
  • 38869-milestone-select
  • update-autodevops-template
  • jivl-activate-repo-cookie-preferences
  • qa-add-deploy-key
  • docs-move-article-ldap
  • 40780-choose-file
  • 22643-manual-job-page
  • refactor-cluster-show-page-conservative
  • dm-sidekiq-versioning
  • v10.4.0.pre
  • v10.3.0
  • v10.3.0-rc5
  • v10.3.0-rc4
  • v10.3.0-rc3
  • v10.3.0-rc2
  • v10.2.5
  • v10.3.0-rc1
  • v10.0.7
  • v10.1.5
  • v10.2.4
  • v10.2.3
  • v10.2.2
  • v10.2.1
  • v10.3.0.pre
  • v10.2.0
  • v10.2.0-rc4
  • v10.2.0-rc3
  • v10.1.4
  • v10.2.0-rc2
40 results

issue_spec.js

Blame
  • Forked from GitLab.org / GitLab FOSS
    13648 commits behind the upstream repository.
    issue_spec.js 4.54 KiB
    /* eslint-disable */
    
    /*= require lib/utils/text_utility */
    /*= require issue */
    
    (function() {
      var INVALID_URL = 'http://goesnowhere.nothing/whereami';
      var $boxClosed, $boxOpen, $btnClose, $btnReopen;
    
      fixture.preload('issues/closed-issue.html');
      fixture.preload('issues/issue-with-task-list.html');
      fixture.preload('issues/open-issue.html');
    
      function expectErrorMessage() {
        var $flashMessage = $('div.flash-alert');
        expect($flashMessage).toExist();
        expect($flashMessage).toBeVisible();
        expect($flashMessage).toHaveText('Unable to update this issue at this time.');
      }
    
      function expectIssueState(isIssueOpen) {
        expectVisibility($boxClosed, !isIssueOpen);
        expectVisibility($boxOpen, isIssueOpen);
    
        expectVisibility($btnClose, isIssueOpen);
        expectVisibility($btnReopen, !isIssueOpen);
      }
    
      function expectPendingRequest(req, $triggeredButton) {
        expect(req.type).toBe('PUT');
        expect(req.url).toBe($triggeredButton.attr('href'));
        expect($triggeredButton).toHaveProp('disabled', true);
      }
    
      function expectVisibility($element, shouldBeVisible) {
        if (shouldBeVisible) {
          expect($element).not.toHaveClass('hidden');
        } else {
          expect($element).toHaveClass('hidden');
        }
      }
    
      function findElements() {
          $boxClosed = $('div.status-box-closed');
          expect($boxClosed).toExist();
          expect($boxClosed).toHaveText('Closed');
    
          $boxOpen = $('div.status-box-open');
          expect($boxOpen).toExist();
          expect($boxOpen).toHaveText('Open');
    
          $btnClose = $('.btn-close.btn-grouped');
          expect($btnClose).toExist();
          expect($btnClose).toHaveText('Close issue');
    
          $btnReopen = $('.btn-reopen.btn-grouped');
          expect($btnReopen).toExist();
          expect($btnReopen).toHaveText('Reopen issue');
      }
    
      describe('Issue', function() {
        describe('task lists', function() {
          fixture.load('issues/issue-with-task-list.html');
          beforeEach(function() {
            this.issue = new Issue();
          });
    
          it('modifies the Markdown field', function() {
            spyOn(jQuery, 'ajax').and.stub();
            $('input[type=checkbox]').attr('checked', true).trigger('change');
            expect($('.js-task-list-field').val()).toBe('- [x] Task List Item');
          });
          
          it('submits an ajax request on tasklist:changed', function() {
            spyOn(jQuery, 'ajax').and.callFake(function(req) {
              expect(req.type).toBe('PATCH');
              expect(req.url).toBe('https://fixture.invalid/namespace3/project3/issues/1.json');
              expect(req.data.issue.description).not.toBe(null);
            });
    
            $('.js-task-list-field').trigger('tasklist:changed');
          });
        });
      });
    
      describe('close issue', function() {
        beforeEach(function() {
          fixture.load('issues/open-issue.html');
          findElements();
          this.issue = new Issue();
    
          expectIssueState(true);
        });
    
        it('closes an issue', function() {
          spyOn(jQuery, 'ajax').and.callFake(function(req) {
            expectPendingRequest(req, $btnClose);
            req.success({
              id: 34
            });
          });
    
          $btnClose.trigger('click');
    
          expectIssueState(false);
          expect($btnClose).toHaveProp('disabled', false);
        });
    
        it('fails to close an issue with success:false', function() {
          spyOn(jQuery, 'ajax').and.callFake(function(req) {
            expectPendingRequest(req, $btnClose);
            req.success({
              saved: false
            });
          });
    
          $btnClose.attr('href', INVALID_URL);
          $btnClose.trigger('click');
    
          expectIssueState(true);
          expect($btnClose).toHaveProp('disabled', false);
          expectErrorMessage();
        });
    
        it('fails to closes an issue with HTTP error', function() {
          spyOn(jQuery, 'ajax').and.callFake(function(req) {
            expectPendingRequest(req, $btnClose);
            req.error();
          });
    
          $btnClose.attr('href', INVALID_URL);
          $btnClose.trigger('click');
    
          expectIssueState(true);
          expect($btnClose).toHaveProp('disabled', true);
          expectErrorMessage();
        });
      });
    
      describe('reopen issue', function() {
        beforeEach(function() {
          fixture.load('issues/closed-issue.html');
          findElements();
          this.issue = new Issue();
    
          expectIssueState(false);
        });
    
        it('reopens an issue', function() {
          spyOn(jQuery, 'ajax').and.callFake(function(req) {
            expectPendingRequest(req, $btnReopen);
            req.success({
              id: 34
            });
          });
    
          $btnReopen.trigger('click');
    
          expectIssueState(true);
          expect($btnReopen).toHaveProp('disabled', false);
        });
      });
    
    }).call(this);