summaryrefslogtreecommitdiff
path: root/spec/javascripts/search_spec.js
blob: 522851c584b1b66108b3d76ca225f738ec760fb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import $ from 'jquery';
import Api from '~/api';
import Search from '~/pages/search/show/search';

describe('Search', () => {
  const fixturePath = 'search/show.html.raw';
  const searchTerm = 'some search';
  const fillDropdownInput = (dropdownSelector) => {
    const dropdownElement = document.querySelector(dropdownSelector).parentNode;
    const inputElement = dropdownElement.querySelector('.dropdown-input-field');
    inputElement.value = searchTerm;
    return inputElement;
  };

  preloadFixtures(fixturePath);

  beforeEach(() => {
    loadFixtures(fixturePath);
    new Search(); // eslint-disable-line no-new
  });

  it('requests groups from backend when filtering', (done) => {
    spyOn(Api, 'groups').and.callFake((term) => {
      expect(term).toBe(searchTerm);
      done();
    });
    const inputElement = fillDropdownInput('.js-search-group-dropdown');

    $(inputElement).trigger('input');
  });

  it('requests projects from backend when filtering', (done) => {
    spyOn(Api, 'projects').and.callFake((term) => {
      expect(term).toBe(searchTerm);
      done();
    });
    const inputElement = fillDropdownInput('.js-search-project-dropdown');

    $(inputElement).trigger('input');
  });
});