gitlab-org--gitlab-foss/spec/javascripts/labels_issue_sidebar_spec.js.es6

91 lines
2.5 KiB
JavaScript
Raw Normal View History

/* eslint-disable no-new */
/* global IssuableContext */
/* global LabelsSelect */
require('~/lib/utils/type_utility');
require('~/gl_dropdown');
2016-12-29 16:42:48 -05:00
require('select2');
require('vendor/jquery.nicescroll');
require('~/api');
require('~/create_label');
require('~/issuable_context');
require('~/users_select');
require('~/labels_select');
2016-08-18 08:59:09 -04:00
(() => {
let saveLabelCount = 0;
describe('Issue dropdown sidebar', () => {
preloadFixtures('static/issue_sidebar_label.html.raw');
2016-08-18 08:59:09 -04:00
beforeEach(() => {
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();
let LABELS_DATA = [];
2016-08-18 08:59:09 -04:00
if (req.url === '/root/test/labels.json') {
for (let i = 0; i < 10; i += 1) {
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') {
const tmp = [];
for (let i = 0; i < saveLabelCount; i += 1) {
tmp.push({ id: i, title: `test ${i}`, color: '#5CB85C' });
2016-08-18 08:59:09 -04: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);
$('.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);
$('.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);
});
});
})();