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

72 lines
1.7 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';
2022-07-16 23:28:13 +05:30
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
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 = {});
2019-07-07 11:18:12 +05:30
const fixtureTemplate = 'static/event_filter.html';
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(() => {
2022-07-16 23:28:13 +05:30
loadHTMLFixture(fixtureTemplate);
2019-09-04 21:01:54 +05:30
jest.spyOn(Pager, 'init').mockImplementation(() => {});
2018-10-15 14:42:47 +05:30
new Activities();
2016-11-03 12:29:30 +05:30
});
2018-10-15 14:42:47 +05:30
2022-07-16 23:28:13 +05:30
afterEach(() => {
resetHTMLFixture();
});
2018-10-15 14:42:47 +05:30
for (let i = 0; i < filters.length; i += 1) {
2021-03-08 18:12:59 +05:30
((i) => {
2018-10-15 14:42:47 +05:30
describe(`when selecting ${getEventName(i)}`, () => {
beforeEach(() => {
$(getSelector(i)).click();
});
for (let x = 0; x < filters.length; x += 1) {
2021-03-08 18:12:59 +05:30
((x) => {
2018-10-15 14:42:47 +05:30
const shouldHighlight = i === x;
const testName = shouldHighlight ? 'should highlight' : 'should not highlight';
it(`${testName} ${getEventName(x)}`, () => {
2021-03-08 18:12:59 +05:30
expect($(getSelector(x)).parent().hasClass('active')).toEqual(shouldHighlight);
2018-10-15 14:42:47 +05:30
});
})(x);
}
});
})(i);
}
});