summaryrefslogtreecommitdiff
path: root/spec/javascripts/labels_issue_sidebar_spec.js
blob: ccf439aac7441a3667cdc3634f5b68b81d031e7a (plain)
1
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
52
53
54
55
56
57
58
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* eslint-disable no-new */

import $ from 'jquery';
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import IssuableContext from '~/issuable_context';
import LabelsSelect from '~/labels_select';

import '~/gl_dropdown';
import 'select2';
import '~/api';
import '~/create_label';
import '~/users_select';

let saveLabelCount = 0;
let mock;

describe('Issue dropdown sidebar', () => {
  preloadFixtures('static/issue_sidebar_label.html');

  beforeEach(() => {
    loadFixtures('static/issue_sidebar_label.html');

    mock = new MockAdapter(axios);

    new IssuableContext('{"id":1,"name":"Administrator","username":"root"}');
    new LabelsSelect();

    mock.onGet('/root/test/labels.json').reply(() => {
      const labels = Array(10)
        .fill()
        .map((_, i) => ({
          id: i,
          title: `test ${i}`,
          color: '#5CB85C',
        }));

      return [200, labels];
    });

    mock.onPut('/root/test/issues/2.json').reply(() => {
      const labels = Array(saveLabelCount)
        .fill()
        .map((_, i) => ({
          id: i,
          title: `test ${i}`,
          color: '#5CB85C',
        }));

      return [200, { labels }];
    });
  });

  afterEach(() => {
    mock.restore();
  });

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

      $('.dropdown-content a').each(function(i) {
        if (i < saveLabelCount) {
          $(this)
            .get(0)
            .click();
        }
      });

      $('.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);

      $('.dropdown-content a').each(function(i) {
        if (i < saveLabelCount) {
          $(this)
            .get(0)
            .click();
        }
      });

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