debian-mirror-gitlab/spec/javascripts/labels_issue_sidebar_spec.js

89 lines
2.5 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
/* eslint-disable no-new */
/* global IssuableContext */
/* global LabelsSelect */
2017-09-10 17:25:29 +05:30
import '~/gl_dropdown';
import 'select2';
import '~/api';
import '~/create_label';
import '~/issuable_context';
import '~/users_select';
import '~/labels_select';
2016-09-13 17:45:13 +05:30
(() => {
let saveLabelCount = 0;
describe('Issue dropdown sidebar', () => {
2017-08-17 22:00:37 +05:30
preloadFixtures('static/issue_sidebar_label.html.raw');
2016-09-13 17:45:13 +05:30
beforeEach(() => {
2017-08-17 22:00:37 +05:30
loadFixtures('static/issue_sidebar_label.html.raw');
2016-09-13 17:45:13 +05:30
new IssuableContext('{"id":1,"name":"Administrator","username":"root"}');
new LabelsSelect();
spyOn(jQuery, 'ajax').and.callFake((req) => {
const d = $.Deferred();
2017-08-17 22:00:37 +05:30
let LABELS_DATA = [];
2016-09-13 17:45:13 +05:30
if (req.url === '/root/test/labels.json') {
2017-08-17 22:00:37 +05:30
for (let i = 0; i < 10; i += 1) {
LABELS_DATA.push({ id: i, title: `test ${i}`, color: '#5CB85C' });
2016-09-13 17:45:13 +05:30
}
} else if (req.url === '/root/test/issues/2.json') {
2017-08-17 22:00:37 +05:30
const tmp = [];
for (let i = 0; i < saveLabelCount; i += 1) {
tmp.push({ id: i, title: `test ${i}`, color: '#5CB85C' });
2016-09-13 17:45:13 +05:30
}
2017-08-17 22:00:37 +05:30
LABELS_DATA = { labels: tmp };
2016-09-13 17:45:13 +05:30
}
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-10-01 15:18:49 +05:30
$('.dropdown-content a').each(function (i) {
if (i < saveLabelCount) {
$(this).get(0).click();
2016-09-13 17:45:13 +05:30
}
});
$('.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-10-01 15:18:49 +05:30
$('.dropdown-content a').each(function (i) {
if (i < saveLabelCount) {
$(this).get(0).click();
2016-09-13 17:45:13 +05:30
}
});
$('.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);
});
});
})();