BigW Consortium Gitlab

labels_issue_sidebar_spec.js 2.5 KB
Newer Older
1
/* eslint-disable no-new */
2 3
/* global IssuableContext */
/* global LabelsSelect */
4

5 6 7 8 9 10 11 12
import '~/gl_dropdown';
import 'select2';
import 'vendor/jquery.nicescroll';
import '~/api';
import '~/create_label';
import '~/issuable_context';
import '~/users_select';
import '~/labels_select';
13 14 15 16

(() => {
  let saveLabelCount = 0;
  describe('Issue dropdown sidebar', () => {
17
    preloadFixtures('static/issue_sidebar_label.html.raw');
18 19

    beforeEach(() => {
20
      loadFixtures('static/issue_sidebar_label.html.raw');
21 22 23 24 25
      new IssuableContext('{"id":1,"name":"Administrator","username":"root"}');
      new LabelsSelect();

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

        if (req.url === '/root/test/labels.json') {
29
          for (let i = 0; i < 10; i += 1) {
30
            LABELS_DATA.push({ id: i, title: `test ${i}`, color: '#5CB85C' });
31 32
          }
        } else if (req.url === '/root/test/issues/2.json') {
33
          const tmp = [];
34
          for (let i = 0; i < saveLabelCount; i += 1) {
35
            tmp.push({ id: i, title: `test ${i}`, color: '#5CB85C' });
36
          }
37
          LABELS_DATA = { labels: tmp };
38 39 40 41 42 43 44 45 46 47 48 49 50 51
        }

        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);
    });
  });
})();