2017-01-12 00:52:42 -05:00
|
|
|
/* eslint-disable no-new */
|
2018-03-09 15:18:59 -05:00
|
|
|
|
|
|
|
import $ from 'jquery';
|
2018-01-31 04:27:30 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-10-26 16:14:18 -04:00
|
|
|
import IssuableContext from '~/issuable_context';
|
2017-11-01 08:32:15 -04:00
|
|
|
import LabelsSelect from '~/labels_select';
|
2019-09-26 14:06:29 -04:00
|
|
|
import _ from 'underscore';
|
2016-12-13 22:01:05 -05:00
|
|
|
|
2017-05-16 17:01:51 -04:00
|
|
|
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
|
|
|
|
2019-09-26 14:06:29 -04:00
|
|
|
function testLabelClicks(labelOrder, done) {
|
|
|
|
$('.edit-link')
|
|
|
|
.get(0)
|
|
|
|
.click();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
const labelsInDropdown = $('.dropdown-content a');
|
|
|
|
|
|
|
|
expect(labelsInDropdown.length).toBe(10);
|
|
|
|
|
|
|
|
const arrayOfLabels = labelsInDropdown.get();
|
|
|
|
const randomArrayOfLabels = _.shuffle(arrayOfLabels);
|
|
|
|
randomArrayOfLabels.forEach((label, i) => {
|
|
|
|
if (i < saveLabelCount) {
|
|
|
|
$(label).click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.edit-link')
|
|
|
|
.get(0)
|
|
|
|
.click();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect($('.sidebar-collapsed-icon').attr('data-original-title')).toBe(labelOrder);
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
|
2018-10-17 03:16:21 -04:00
|
|
|
describe('Issue dropdown sidebar', () => {
|
2019-03-26 12:03:28 -04:00
|
|
|
preloadFixtures('static/issue_sidebar_label.html');
|
2016-08-18 08:59:09 -04:00
|
|
|
|
2018-10-17 03:16:21 -04:00
|
|
|
beforeEach(() => {
|
2019-03-26 12:03:28 -04:00
|
|
|
loadFixtures('static/issue_sidebar_label.html');
|
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()
|
2019-09-26 14:06:29 -04:00
|
|
|
.map((_val, i) => ({
|
2018-10-17 03:16:21 -04:00
|
|
|
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()
|
2019-09-26 14:06:29 -04:00
|
|
|
.map((_val, i) => ({
|
2018-10-17 03:16:21 -04:00
|
|
|
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;
|
2019-09-26 14:06:29 -04:00
|
|
|
testLabelClicks('test 0, test 1, test 2, test 3, test 4', done);
|
2018-10-17 03:16:21 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('changes collapsed tooltip when changing labels when more than 5', done => {
|
|
|
|
saveLabelCount = 6;
|
2019-09-26 14:06:29 -04:00
|
|
|
testLabelClicks('test 0, test 1, test 2, test 3, test 4, and 1 more', done);
|
2016-08-18 08:59:09 -04:00
|
|
|
});
|
2018-10-17 03:16:21 -04:00
|
|
|
});
|