BigW Consortium Gitlab

project_title_spec.js 1.45 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
describe('Project Title', () => {
10
  const dummyApiVersion = 'v3000';
11 12
  preloadFixtures('issues/open-issue.html.raw');
  loadJSONFixtures('projects.json');
13

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

17
    window.gon = {};
18
    window.gon.api_version = dummyApiVersion;
19

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

24 25 26 27 28 29 30 31 32 33 34 35
  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
36 37
      });
    });
38

39 40
    it('toggles dropdown', () => {
      const $menu = $('.js-dropdown-menu-projects');
41
      window.gon.current_user_id = 1;
42 43
      $('.js-projects-dropdown-toggle').click();
      expect($menu).toHaveClass('open');
44
      expect(reqUrl).toBe(`/api/${dummyApiVersion}/projects.json?simple=true`);
45 46 47 48 49 50 51 52
      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');
53
    });
Fatih Acet committed
54
  });
55 56 57 58 59

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