2017-01-12 05:52:42 +00:00
|
|
|
/* eslint-disable no-new */
|
2018-03-09 20:18:59 +00:00
|
|
|
|
|
|
|
import $ from 'jquery';
|
2018-01-31 09:27:30 +00:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2020-03-11 21:09:19 +00:00
|
|
|
import { shuffle } from 'lodash';
|
2018-01-31 09:27:30 +00:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-10-26 20:14:18 +00:00
|
|
|
import IssuableContext from '~/issuable_context';
|
2017-11-01 12:32:15 +00:00
|
|
|
import LabelsSelect from '~/labels_select';
|
2016-12-14 03:01:05 +00:00
|
|
|
|
2017-05-16 21:01:51 +00:00
|
|
|
import '~/gl_dropdown';
|
|
|
|
import 'select2';
|
|
|
|
import '~/api';
|
|
|
|
import '~/create_label';
|
|
|
|
import '~/users_select';
|
2016-08-18 12:59:09 +00:00
|
|
|
|
2018-10-17 07:16:21 +00:00
|
|
|
let saveLabelCount = 0;
|
|
|
|
let mock;
|
2018-01-31 09:27:30 +00:00
|
|
|
|
2019-09-26 18:06:29 +00: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();
|
2020-03-11 21:09:19 +00:00
|
|
|
const randomArrayOfLabels = shuffle(arrayOfLabels);
|
2019-09-26 18:06:29 +00:00
|
|
|
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 07:16:21 +00:00
|
|
|
describe('Issue dropdown sidebar', () => {
|
2019-03-26 16:03:28 +00:00
|
|
|
preloadFixtures('static/issue_sidebar_label.html');
|
2016-08-18 12:59:09 +00:00
|
|
|
|
2018-10-17 07:16:21 +00:00
|
|
|
beforeEach(() => {
|
2019-03-26 16:03:28 +00:00
|
|
|
loadFixtures('static/issue_sidebar_label.html');
|
2018-01-31 09:27:30 +00:00
|
|
|
|
2018-10-17 07:16:21 +00:00
|
|
|
mock = new MockAdapter(axios);
|
2018-01-31 09:27:30 +00:00
|
|
|
|
2018-10-17 07:16:21 +00:00
|
|
|
new IssuableContext('{"id":1,"name":"Administrator","username":"root"}');
|
|
|
|
new LabelsSelect();
|
2016-08-18 12:59:09 +00:00
|
|
|
|
2018-10-17 07:16:21 +00:00
|
|
|
mock.onGet('/root/test/labels.json').reply(() => {
|
|
|
|
const labels = Array(10)
|
|
|
|
.fill()
|
2019-09-26 18:06:29 +00:00
|
|
|
.map((_val, i) => ({
|
2018-10-17 07:16:21 +00:00
|
|
|
id: i,
|
|
|
|
title: `test ${i}`,
|
|
|
|
color: '#5CB85C',
|
|
|
|
}));
|
2018-01-31 09:27:30 +00:00
|
|
|
|
2018-10-17 07:16:21 +00:00
|
|
|
return [200, labels];
|
|
|
|
});
|
2018-01-31 09:27:30 +00:00
|
|
|
|
2018-10-17 07:16:21 +00:00
|
|
|
mock.onPut('/root/test/issues/2.json').reply(() => {
|
|
|
|
const labels = Array(saveLabelCount)
|
|
|
|
.fill()
|
2019-09-26 18:06:29 +00:00
|
|
|
.map((_val, i) => ({
|
2018-10-17 07:16:21 +00:00
|
|
|
id: i,
|
|
|
|
title: `test ${i}`,
|
|
|
|
color: '#5CB85C',
|
|
|
|
}));
|
2018-01-31 09:27:30 +00:00
|
|
|
|
2018-10-17 07:16:21 +00:00
|
|
|
return [200, { labels }];
|
2018-01-31 09:27:30 +00:00
|
|
|
});
|
2018-10-17 07:16:21 +00:00
|
|
|
});
|
2018-01-31 09:27:30 +00:00
|
|
|
|
2018-10-17 07:16:21 +00:00
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('changes collapsed tooltip when changing labels when less than 5', done => {
|
|
|
|
saveLabelCount = 5;
|
2019-09-26 18:06:29 +00:00
|
|
|
testLabelClicks('test 0, test 1, test 2, test 3, test 4', done);
|
2018-10-17 07:16:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('changes collapsed tooltip when changing labels when more than 5', done => {
|
|
|
|
saveLabelCount = 6;
|
2019-09-26 18:06:29 +00:00
|
|
|
testLabelClicks('test 0, test 1, test 2, test 3, test 4, and 1 more', done);
|
2016-08-18 12:59:09 +00:00
|
|
|
});
|
2018-10-17 07:16:21 +00:00
|
|
|
});
|