gitlab-org--gitlab-foss/spec/javascripts/labels_issue_sidebar_spec.js

118 lines
2.6 KiB
JavaScript
Raw Normal View History

/* eslint-disable no-new */
import $ from 'jquery';
2018-01-31 04:27:30 -05:00
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';
2016-08-18 08:59:09 -04:00
2018-10-17 03:16:21 -04:00
let saveLabelCount = 0;
let mock;
2018-01-31 04:27:30 -05:00
2018-10-17 03:16:21 -04:00
describe('Issue dropdown sidebar', () => {
preloadFixtures('static/issue_sidebar_label.html.raw');
2016-08-18 08:59:09 -04:00
2018-10-17 03:16:21 -04:00
beforeEach(() => {
loadFixtures('static/issue_sidebar_label.html.raw');
2018-01-31 04:27:30 -05:00
2018-10-17 03:16:21 -04:00
mock = new MockAdapter(axios);
2018-01-31 04:27:30 -05:00
2018-10-17 03:16:21 -04:00
new IssuableContext('{"id":1,"name":"Administrator","username":"root"}');
new LabelsSelect();
2016-08-18 08:59:09 -04:00
2018-10-17 03:16:21 -04:00
mock.onGet('/root/test/labels.json').reply(() => {
const labels = Array(10)
.fill()
.map((_, i) => ({
id: i,
title: `test ${i}`,
color: '#5CB85C',
}));
2018-01-31 04:27:30 -05:00
2018-10-17 03:16:21 -04:00
return [200, labels];
});
2018-01-31 04:27:30 -05:00
2018-10-17 03:16:21 -04:00
mock.onPut('/root/test/issues/2.json').reply(() => {
const labels = Array(saveLabelCount)
.fill()
.map((_, i) => ({
id: i,
title: `test ${i}`,
color: '#5CB85C',
}));
2018-01-31 04:27:30 -05:00
2018-10-17 03:16:21 -04:00
return [200, { labels }];
2018-01-31 04:27:30 -05:00
});
2018-10-17 03:16:21 -04:00
});
2018-01-31 04:27:30 -05:00
2018-10-17 03:16:21 -04:00
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();
}
});
2016-08-18 08:59:09 -04:00
2018-10-17 03:13:26 -04:00
$('.edit-link')
.get(0)
.click();
2016-08-18 08:59:09 -04:00
setTimeout(() => {
2018-10-17 03:16:21 -04:00
expect($('.sidebar-collapsed-icon').attr('data-original-title')).toBe(
'test 0, test 1, test 2, test 3, test 4',
);
done();
2016-08-18 08:59:09 -04:00
}, 0);
2018-10-17 03:16:21 -04:00
}, 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();
}
});
2016-08-18 08:59:09 -04:00
2018-10-17 03:13:26 -04:00
$('.edit-link')
.get(0)
.click();
2016-08-18 08:59:09 -04:00
setTimeout(() => {
2018-10-17 03:16:21 -04:00
expect($('.sidebar-collapsed-icon').attr('data-original-title')).toBe(
'test 0, test 1, test 2, test 3, test 4, and 1 more',
);
done();
2016-08-18 08:59:09 -04:00
}, 0);
2018-10-17 03:16:21 -04:00
}, 0);
2016-08-18 08:59:09 -04:00
});
2018-10-17 03:16:21 -04:00
});