BigW Consortium Gitlab

project_title_spec.js 1.36 KB
Newer Older
1
/* global Project */
Fatih Acet committed
2

Mike Greiling committed
3
import 'select2/select2';
4 5 6 7
import '~/gl_dropdown';
import '~/api';
import '~/project_select';
import '~/project';
Fatih Acet committed
8

9 10 11
describe('Project Title', () => {
  preloadFixtures('issues/open-issue.html.raw');
  loadJSONFixtures('projects.json');
12

13 14
  beforeEach(() => {
    loadFixtures('issues/open-issue.html.raw');
15

16 17
    window.gon = {};
    window.gon.api_version = 'v3';
18

19 20 21
    // eslint-disable-next-line no-new
    new Project();
  });
22

23 24 25 26 27 28 29 30 31 32 33 34
  describe('project list', () => {
    let reqUrl;
    let reqData;

    beforeEach(() => {
      const fakeResponseData = getJSONFixture('projects.json');
      spyOn(jQuery, 'ajax').and.callFake((req) => {
        const def = $.Deferred();
        reqUrl = req.url;
        reqData = req.data;
        def.resolve(fakeResponseData);
        return def.promise();
Fatih Acet committed
35 36
      });
    });
37

38 39 40 41 42 43 44 45 46 47 48 49 50
    it('toggles dropdown', () => {
      const $menu = $('.js-dropdown-menu-projects');
      $('.js-projects-dropdown-toggle').click();
      expect($menu).toHaveClass('open');
      expect(reqUrl).toBe('/api/v3/projects.json?simple=true');
      expect(reqData).toEqual({
        search: '',
        order_by: 'last_activity_at',
        per_page: 20,
        membership: true,
      });
      $menu.find('.dropdown-menu-close-icon').click();
      expect($menu).not.toHaveClass('open');
51
    });
Fatih Acet committed
52
  });
53 54 55 56 57

  afterEach(() => {
    window.gon = {};
  });
});