2017-08-17 22:00:37 +05:30
|
|
|
/* eslint-disable no-new */
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
import $ from 'jquery';
|
2018-03-17 18:26:18 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2020-04-08 14:13:33 +05:30
|
|
|
import { shuffle } from 'lodash';
|
2018-03-17 18:26:18 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import IssuableContext from '~/issuable_context';
|
|
|
|
import LabelsSelect from '~/labels_select';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
import '~/gl_dropdown';
|
|
|
|
import 'select2';
|
|
|
|
import '~/api';
|
|
|
|
import '~/create_label';
|
|
|
|
import '~/users_select';
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
let saveLabelCount = 0;
|
|
|
|
let mock;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
function testLabelClicks(labelOrder, done) {
|
|
|
|
$('.edit-link')
|
|
|
|
.get(0)
|
|
|
|
.click();
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
jest.runOnlyPendingTimers();
|
|
|
|
|
|
|
|
setImmediate(() => {
|
2019-12-21 20:55:43 +05:30
|
|
|
const labelsInDropdown = $('.dropdown-content a');
|
|
|
|
|
|
|
|
expect(labelsInDropdown.length).toBe(10);
|
|
|
|
|
|
|
|
const arrayOfLabels = labelsInDropdown.get();
|
2020-04-08 14:13:33 +05:30
|
|
|
const randomArrayOfLabels = shuffle(arrayOfLabels);
|
2019-12-21 20:55:43 +05:30
|
|
|
randomArrayOfLabels.forEach((label, i) => {
|
|
|
|
if (i < saveLabelCount) {
|
|
|
|
$(label).click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.edit-link')
|
|
|
|
.get(0)
|
|
|
|
.click();
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
setImmediate(() => {
|
2019-12-21 20:55:43 +05:30
|
|
|
expect($('.sidebar-collapsed-icon').attr('data-original-title')).toBe(labelOrder);
|
|
|
|
done();
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
});
|
2019-12-21 20:55:43 +05:30
|
|
|
}
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
describe('Issue dropdown sidebar', () => {
|
2019-07-07 11:18:12 +05:30
|
|
|
preloadFixtures('static/issue_sidebar_label.html');
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeEach(() => {
|
2019-07-07 11:18:12 +05:30
|
|
|
loadFixtures('static/issue_sidebar_label.html');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
mock = new MockAdapter(axios);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
new IssuableContext('{"id":1,"name":"Administrator","username":"root"}');
|
|
|
|
new LabelsSelect();
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
mock.onGet('/root/test/labels.json').reply(() => {
|
|
|
|
const labels = Array(10)
|
|
|
|
.fill()
|
2019-12-21 20:55:43 +05:30
|
|
|
.map((_val, i) => ({
|
2018-03-17 18:26:18 +05:30
|
|
|
id: i,
|
|
|
|
title: `test ${i}`,
|
|
|
|
color: '#5CB85C',
|
|
|
|
}));
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
return [200, labels];
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
mock.onPut('/root/test/issues/2.json').reply(() => {
|
|
|
|
const labels = Array(saveLabelCount)
|
|
|
|
.fill()
|
2019-12-21 20:55:43 +05:30
|
|
|
.map((_val, i) => ({
|
2018-03-17 18:26:18 +05:30
|
|
|
id: i,
|
|
|
|
title: `test ${i}`,
|
|
|
|
color: '#5CB85C',
|
|
|
|
}));
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
return [200, { labels }];
|
2016-09-13 17:45:13 +05:30
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('changes collapsed tooltip when changing labels when less than 5', done => {
|
|
|
|
saveLabelCount = 5;
|
2019-12-21 20:55:43 +05:30
|
|
|
testLabelClicks('test 0, test 1, test 2, test 3, test 4', done);
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('changes collapsed tooltip when changing labels when more than 5', done => {
|
|
|
|
saveLabelCount = 6;
|
2019-12-21 20:55:43 +05:30
|
|
|
testLabelClicks('test 0, test 1, test 2, test 3, test 4, and 1 more', done);
|
2016-09-13 17:45:13 +05:30
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|