BigW Consortium Gitlab

labels_issue_sidebar_spec.js.es6 2.47 KB
Newer Older
1
/* eslint-disable */
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
//= require lib/utils/type_utility
//= require jquery
//= require bootstrap
//= require gl_dropdown
//= require select2
//= require jquery.nicescroll
//= require api
//= require create_label
//= require issuable_context
//= require users_select
//= require labels_select

(() => {
  let saveLabelCount = 0;
  describe('Issue dropdown sidebar', () => {
    fixture.preload('issue_sidebar_label.html');

    beforeEach(() => {
      fixture.load('issue_sidebar_label.html');
      new IssuableContext('{"id":1,"name":"Administrator","username":"root"}');
      new LabelsSelect();

      spyOn(jQuery, 'ajax').and.callFake((req) => {
        const d = $.Deferred();
        let LABELS_DATA = []

        if (req.url === '/root/test/labels.json') {
          for (let i = 0; i < 10; i++) {
            LABELS_DATA.push({id: i, title: `test ${i}`, color: '#5CB85C'});
          }
        } else if (req.url === '/root/test/issues/2.json') {
          let tmp = []
          for (let i = 0; i < saveLabelCount; i++) {
            tmp.push({id: i, title: `test ${i}`, color: '#5CB85C'});
          }
          LABELS_DATA = {labels: tmp};
        }

        d.resolve(LABELS_DATA);
        return d.promise();
      });
    });

    it('changes collapsed tooltip when changing labels when less than 5', (done) => {
      saveLabelCount = 5;
      $('.edit-link').get(0).click();

      setTimeout(() => {
        expect($('.dropdown-content a').length).toBe(10);

52 53 54
        $('.dropdown-content a').each(function (i) {
          if (i < saveLabelCount) {
            $(this).get(0).click();
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
          }
        });

        $('.edit-link').get(0).click();

        setTimeout(() => {
          expect($('.sidebar-collapsed-icon').attr('data-original-title')).toBe('test 0, test 1, test 2, test 3, test 4');
          done();
        }, 0);
      }, 0);
    });

    it('changes collapsed tooltip when changing labels when more than 5', (done) => {
      saveLabelCount = 6;
      $('.edit-link').get(0).click();

      setTimeout(() => {
        expect($('.dropdown-content a').length).toBe(10);

74 75 76
        $('.dropdown-content a').each(function (i) {
          if (i < saveLabelCount) {
            $(this).get(0).click();
77 78 79 80 81 82 83 84 85 86 87 88 89
          }
        });

        $('.edit-link').get(0).click();

        setTimeout(() => {
          expect($('.sidebar-collapsed-icon').attr('data-original-title')).toBe('test 0, test 1, test 2, test 3, test 4, and 1 more');
          done();
        }, 0);
      }, 0);
    });
  });
})();