gitlab-org--gitlab-foss/spec/frontend/activities_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-06-16 09:20:30 -04:00
/* eslint-disable no-unused-expressions, no-prototype-builtins, no-new, no-shadow */
import $ from 'jquery';
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
import Activities from '~/activities';
2018-04-24 17:35:32 -04:00
import Pager from '~/pager';
2018-04-24 17:35:32 -04:00
describe('Activities', () => {
window.gon || (window.gon = {});
const fixtureTemplate = 'static/event_filter.html';
const filters = [
{
id: 'all',
2018-04-24 17:35:32 -04:00
},
{
id: 'push',
name: 'push events',
2018-04-24 17:35:32 -04:00
},
{
id: 'merged',
name: 'merge events',
2018-04-24 17:35:32 -04:00
},
{
id: 'comments',
2018-04-24 17:35:32 -04:00
},
{
id: 'team',
2018-04-24 17:35:32 -04:00
},
];
function getEventName(index) {
const filter = filters[index];
return filter.hasOwnProperty('name') ? filter.name : filter.id;
}
function getSelector(index) {
const filter = filters[index];
return `#${filter.id}_event_filter`;
}
2018-04-24 17:35:32 -04:00
beforeEach(() => {
loadHTMLFixture(fixtureTemplate);
jest.spyOn(Pager, 'init').mockImplementation(() => {});
2018-04-24 17:35:32 -04:00
new Activities();
});
2018-04-24 17:35:32 -04:00
afterEach(() => {
resetHTMLFixture();
});
2018-04-24 17:35:32 -04:00
for (let i = 0; i < filters.length; i += 1) {
((i) => {
2018-04-24 17:35:32 -04:00
describe(`when selecting ${getEventName(i)}`, () => {
beforeEach(() => {
$(getSelector(i)).click();
});
for (let x = 0; x < filters.length; x += 1) {
((x) => {
2018-04-24 17:35:32 -04:00
const shouldHighlight = i === x;
const testName = shouldHighlight ? 'should highlight' : 'should not highlight';
it(`${testName} ${getEventName(x)}`, () => {
expect($(getSelector(x)).parent().hasClass('active')).toEqual(shouldHighlight);
2018-04-24 17:35:32 -04:00
});
})(x);
}
});
})(i);
}
});