2017-01-12 00:52:42 -05:00
|
|
|
/* eslint-disable no-new */
|
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';
|
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
|
|
|
|
|
|
|
(() => {
|
|
|
|
let saveLabelCount = 0;
|
|
|
|
describe('Issue dropdown sidebar', () => {
|
2016-12-30 19:14:33 -05:00
|
|
|
preloadFixtures('static/issue_sidebar_label.html.raw');
|
2016-08-18 08:59:09 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2016-12-30 19:14:33 -05:00
|
|
|
loadFixtures('static/issue_sidebar_label.html.raw');
|
2016-08-18 08:59:09 -04:00
|
|
|
new IssuableContext('{"id":1,"name":"Administrator","username":"root"}');
|
|
|
|
new LabelsSelect();
|
|
|
|
|
|
|
|
spyOn(jQuery, 'ajax').and.callFake((req) => {
|
|
|
|
const d = $.Deferred();
|
2017-01-10 17:54:56 -05:00
|
|
|
let LABELS_DATA = [];
|
2016-08-18 08:59:09 -04:00
|
|
|
|
|
|
|
if (req.url === '/root/test/labels.json') {
|
2017-01-10 17:35:09 -05:00
|
|
|
for (let i = 0; i < 10; i += 1) {
|
2017-01-11 23:27:41 -05:00
|
|
|
LABELS_DATA.push({ id: i, title: `test ${i}`, color: '#5CB85C' });
|
2016-08-18 08:59:09 -04:00
|
|
|
}
|
|
|
|
} else if (req.url === '/root/test/issues/2.json') {
|
2017-01-12 00:52:42 -05:00
|
|
|
const tmp = [];
|
2017-01-10 17:35:09 -05:00
|
|
|
for (let i = 0; i < saveLabelCount; i += 1) {
|
2017-01-11 23:27:41 -05:00
|
|
|
tmp.push({ id: i, title: `test ${i}`, color: '#5CB85C' });
|
2016-08-18 08:59:09 -04:00
|
|
|
}
|
2017-01-11 23:27:41 -05:00
|
|
|
LABELS_DATA = { labels: tmp };
|
2016-08-18 08:59:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
d.resolve(LABELS_DATA);
|
|
|
|
return d.promise();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2016-09-27 11:23:15 -04:00
|
|
|
$('.dropdown-content a').each(function (i) {
|
|
|
|
if (i < saveLabelCount) {
|
|
|
|
$(this).get(0).click();
|
2016-08-18 08:59:09 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.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);
|
|
|
|
|
2016-09-27 11:23:15 -04:00
|
|
|
$('.dropdown-content a').each(function (i) {
|
|
|
|
if (i < saveLabelCount) {
|
|
|
|
$(this).get(0).click();
|
2016-08-18 08:59:09 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})();
|