issuable_spec.js 2.26 KB
Newer Older
1
/* global IssuableIndex */
2

3
import '~/lib/utils/url_utility';
4
import '~/issuable_index';
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

(() => {
  const BASE_URL = '/user/project/issues?scope=all&state=closed';
  const DEFAULT_PARAMS = '&utf8=%E2%9C%93';

  function updateForm(formValues, form) {
    $.each(formValues, (id, value) => {
      $(`#${id}`, form).val(value);
    });
  }

  function resetForm(form) {
    $('input[name!="utf8"]', form).each((index, input) => {
      input.setAttribute('value', '');
    });
  }

  describe('Issuable', () => {
23
    preloadFixtures('static/issuable_filter.html.raw');
24 25

    beforeEach(() => {
26
      loadFixtures('static/issuable_filter.html.raw');
27
      IssuableIndex.init();
28 29 30
    });

    it('should be defined', () => {
31
      expect(window.IssuableIndex).toBeDefined();
32 33 34 35 36 37 38
    });

    describe('filtering', () => {
      let $filtersForm;

      beforeEach(() => {
        $filtersForm = $('.js-filter-form');
39
        loadFixtures('static/issuable_filter.html.raw');
40 41 42 43
        resetForm($filtersForm);
      });

      it('should contain only the default parameters', () => {
Bryce Johnson's avatar
Bryce Johnson committed
44
        spyOn(gl.utils, 'visitUrl');
45

46
        IssuableIndex.filterResults($filtersForm);
47

Bryce Johnson's avatar
Bryce Johnson committed
48
        expect(gl.utils.visitUrl).toHaveBeenCalledWith(BASE_URL + DEFAULT_PARAMS);
49 50 51
      });

      it('should filter for the phrase "broken"', () => {
Bryce Johnson's avatar
Bryce Johnson committed
52
        spyOn(gl.utils, 'visitUrl');
53 54

        updateForm({ search: 'broken' }, $filtersForm);
55
        IssuableIndex.filterResults($filtersForm);
56 57
        const params = `${DEFAULT_PARAMS}&search=broken`;

Bryce Johnson's avatar
Bryce Johnson committed
58
        expect(gl.utils.visitUrl).toHaveBeenCalledWith(BASE_URL + params);
59 60 61
      });

      it('should keep query parameters after modifying filter', () => {
Bryce Johnson's avatar
Bryce Johnson committed
62
        spyOn(gl.utils, 'visitUrl');
63 64 65 66

        // initial filter
        updateForm({ milestone_title: 'v1.0' }, $filtersForm);

67
        IssuableIndex.filterResults($filtersForm);
68
        let params = `${DEFAULT_PARAMS}&milestone_title=v1.0`;
Bryce Johnson's avatar
Bryce Johnson committed
69
        expect(gl.utils.visitUrl).toHaveBeenCalledWith(BASE_URL + params);
70 71 72 73

        // update filter
        updateForm({ label_name: 'Frontend' }, $filtersForm);

74
        IssuableIndex.filterResults($filtersForm);
75
        params = `${DEFAULT_PARAMS}&milestone_title=v1.0&label_name=Frontend`;
Bryce Johnson's avatar
Bryce Johnson committed
76
        expect(gl.utils.visitUrl).toHaveBeenCalledWith(BASE_URL + params);
77 78 79 80
      });
    });
  });
})();