2018-06-16 09:20:30 -04:00
|
|
|
/* eslint-disable no-unused-expressions, no-prototype-builtins, no-new, no-shadow */
|
2016-12-13 22:01:05 -05:00
|
|
|
|
2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2017-05-16 17:57:05 -04:00
|
|
|
import 'vendor/jquery.endless-scroll';
|
2017-12-14 06:50:40 -05:00
|
|
|
import Activities from '~/activities';
|
2018-04-24 17:35:32 -04:00
|
|
|
import Pager from '~/pager';
|
2016-08-29 13:09:33 -04:00
|
|
|
|
2018-04-24 17:35:32 -04:00
|
|
|
describe('Activities', () => {
|
2016-08-29 13:09:33 -04:00
|
|
|
window.gon || (window.gon = {});
|
2016-12-30 16:27:40 -05:00
|
|
|
const fixtureTemplate = 'static/event_filter.html.raw';
|
2016-08-29 13:09:33 -04:00
|
|
|
const filters = [
|
|
|
|
{
|
|
|
|
id: 'all',
|
2018-04-24 17:35:32 -04:00
|
|
|
},
|
|
|
|
{
|
2016-08-29 13:09:33 -04:00
|
|
|
id: 'push',
|
|
|
|
name: 'push events',
|
2018-04-24 17:35:32 -04:00
|
|
|
},
|
|
|
|
{
|
2016-08-29 13:09:33 -04:00
|
|
|
id: 'merged',
|
|
|
|
name: 'merge events',
|
2018-04-24 17:35:32 -04:00
|
|
|
},
|
|
|
|
{
|
2016-08-29 13:09:33 -04:00
|
|
|
id: 'comments',
|
2018-04-24 17:35:32 -04:00
|
|
|
},
|
|
|
|
{
|
2016-08-29 13:09:33 -04:00
|
|
|
id: 'team',
|
2018-04-24 17:35:32 -04:00
|
|
|
},
|
|
|
|
];
|
2016-08-29 13:09:33 -04:00
|
|
|
|
|
|
|
function getEventName(index) {
|
2017-01-12 00:52:42 -05:00
|
|
|
const filter = filters[index];
|
2016-08-29 13:09:33 -04:00
|
|
|
return filter.hasOwnProperty('name') ? filter.name : filter.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSelector(index) {
|
2017-01-12 00:52:42 -05:00
|
|
|
const filter = filters[index];
|
2017-01-10 17:54:56 -05:00
|
|
|
return `#${filter.id}_event_filter`;
|
2016-08-29 13:09:33 -04:00
|
|
|
}
|
|
|
|
|
2018-04-24 17:35:32 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
loadFixtures(fixtureTemplate);
|
|
|
|
spyOn(Pager, 'init').and.stub();
|
|
|
|
new Activities();
|
2016-08-29 13:09:33 -04:00
|
|
|
});
|
2018-04-24 17:35:32 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|