BigW Consortium Gitlab

activities_spec.js 1.53 KB
Newer Older
1
/* eslint-disable no-unused-expressions, no-prototype-builtins, no-new, no-shadow, max-len */
2

3
require('vendor/jquery.endless-scroll.js');
4 5
require('~/pager');
require('~/activities');
6 7 8

(() => {
  window.gon || (window.gon = {});
9
  const fixtureTemplate = 'static/event_filter.html.raw';
10 11 12 13 14 15 16 17 18 19 20
  const filters = [
    {
      id: 'all',
    }, {
      id: 'push',
      name: 'push events',
    }, {
      id: 'merged',
      name: 'merge events',
    }, {
      id: 'comments',
21
    }, {
22 23 24 25
      id: 'team',
    }];

  function getEventName(index) {
26
    const filter = filters[index];
27 28 29 30
    return filter.hasOwnProperty('name') ? filter.name : filter.id;
  }

  function getSelector(index) {
31
    const filter = filters[index];
32
    return `#${filter.id}_event_filter`;
33 34 35 36
  }

  describe('Activities', () => {
    beforeEach(() => {
37
      loadFixtures(fixtureTemplate);
38
      new gl.Activities();
39 40
    });

41
    for (let i = 0; i < filters.length; i += 1) {
42 43 44 45 46 47
      ((i) => {
        describe(`when selecting ${getEventName(i)}`, () => {
          beforeEach(() => {
            $(getSelector(i)).click();
          });

48
          for (let x = 0; x < filters.length; x += 1) {
49
            ((x) => {
50 51
              const shouldHighlight = i === x;
              const testName = shouldHighlight ? 'should highlight' : 'should not highlight';
52 53 54 55 56 57 58 59 60 61 62

              it(`${testName} ${getEventName(x)}`, () => {
                expect($(getSelector(x)).parent().hasClass('active')).toEqual(shouldHighlight);
              });
            })(x);
          }
        });
      })(i);
    }
  });
})();