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

72 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-11-08 19:23:39 +05:30
/* eslint-disable no-unused-expressions, no-prototype-builtins, no-new, no-shadow */
2017-08-17 22:00:37 +05:30
2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2017-09-10 17:25:29 +05:30
import 'vendor/jquery.endless-scroll';
2018-03-17 18:26:18 +05:30
import Activities from '~/activities';
2018-10-15 14:42:47 +05:30
import Pager from '~/pager';
2016-11-03 12:29:30 +05:30
2018-10-15 14:42:47 +05:30
describe('Activities', () => {
2016-11-03 12:29:30 +05:30
window.gon || (window.gon = {});
2017-08-17 22:00:37 +05:30
const fixtureTemplate = 'static/event_filter.html.raw';
2016-11-03 12:29:30 +05:30
const filters = [
{
id: 'all',
2018-10-15 14:42:47 +05:30
},
{
2016-11-03 12:29:30 +05:30
id: 'push',
name: 'push events',
2018-10-15 14:42:47 +05:30
},
{
2016-11-03 12:29:30 +05:30
id: 'merged',
name: 'merge events',
2018-10-15 14:42:47 +05:30
},
{
2016-11-03 12:29:30 +05:30
id: 'comments',
2018-10-15 14:42:47 +05:30
},
{
2016-11-03 12:29:30 +05:30
id: 'team',
2018-10-15 14:42:47 +05:30
},
];
2016-11-03 12:29:30 +05:30
function getEventName(index) {
2017-08-17 22:00:37 +05:30
const filter = filters[index];
2016-11-03 12:29:30 +05:30
return filter.hasOwnProperty('name') ? filter.name : filter.id;
}
function getSelector(index) {
2017-08-17 22:00:37 +05:30
const filter = filters[index];
return `#${filter.id}_event_filter`;
2016-11-03 12:29:30 +05:30
}
2018-10-15 14:42:47 +05:30
beforeEach(() => {
loadFixtures(fixtureTemplate);
spyOn(Pager, 'init').and.stub();
new Activities();
2016-11-03 12:29:30 +05:30
});
2018-10-15 14:42:47 +05:30
for (let i = 0; i < filters.length; i += 1) {
(i => {
describe(`when selecting ${getEventName(i)}`, () => {
beforeEach(() => {
$(getSelector(i)).click();
});
for (let x = 0; x < filters.length; x += 1) {
(x => {
const shouldHighlight = i === x;
const testName = shouldHighlight ? 'should highlight' : 'should not highlight';
it(`${testName} ${getEventName(x)}`, () => {
expect(
$(getSelector(x))
.parent()
.hasClass('active'),
).toEqual(shouldHighlight);
});
})(x);
}
});
})(i);
}
});