diff options
author | Paul Slaughter <pslaughter@gitlab.com> | 2019-05-24 13:11:29 -0500 |
---|---|---|
committer | Paul Slaughter <pslaughter@gitlab.com> | 2019-05-30 21:00:52 -0500 |
commit | 00c8264faf6e02f741240b5c430cebcebd730280 (patch) | |
tree | 4f051776be659cd41d1cf8a6f69961eee1ec98a5 /spec/frontend | |
parent | 5e88463d3089e3b764ae6347b9ce709a01acb8b7 (diff) | |
download | gitlab-ce-00c8264faf6e02f741240b5c430cebcebd730280.tar.gz |
Jestify activities spec
Also add `jQuery` to global in `test_setup`.
This was needed because:
- `vendor/jquery.endless-scroll` depends on it.
- Adding it to `global` in the spec itself didn't work.
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/activities_spec.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/spec/frontend/activities_spec.js b/spec/frontend/activities_spec.js new file mode 100644 index 00000000000..d14be3a1f26 --- /dev/null +++ b/spec/frontend/activities_spec.js @@ -0,0 +1,70 @@ +/* eslint-disable no-unused-expressions, no-prototype-builtins, no-new, no-shadow */ + +import $ from 'jquery'; +import Activities from '~/activities'; +import Pager from '~/pager'; + +describe('Activities', () => { + window.gon || (window.gon = {}); + const fixtureTemplate = 'static/event_filter.html'; + const filters = [ + { + id: 'all', + }, + { + id: 'push', + name: 'push events', + }, + { + id: 'merged', + name: 'merge events', + }, + { + id: 'comments', + }, + { + id: 'team', + }, + ]; + + 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`; + } + + beforeEach(() => { + loadFixtures(fixtureTemplate); + jest.spyOn(Pager, 'init').mockImplementation(() => {}); + new Activities(); + }); + + 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); + } +}); |