summaryrefslogtreecommitdiff
path: root/spec/javascripts/project_dashboard_spec.js.es6
blob: 24833b4eb57760eee1225d2e502c1d20d39529bb (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
require('~/sidebar');

(() => {
  describe('Project dashboard page', () => {
    let $pageWithSidebar = null;
    let $sidebarToggle = null;
    let sidebar = null;
    const fixtureTemplate = 'projects/dashboard.html.raw';

    const assertSidebarStateExpanded = (shouldBeExpanded) => {
      expect(sidebar.isExpanded).toBe(shouldBeExpanded);
      expect($pageWithSidebar.hasClass('page-sidebar-expanded')).toBe(shouldBeExpanded);
    };

    preloadFixtures(fixtureTemplate);
    beforeEach(() => {
      loadFixtures(fixtureTemplate);

      $pageWithSidebar = $('.page-with-sidebar');
      $sidebarToggle = $('.toggle-nav-collapse');

      // otherwise instantiating the Sidebar for the second time
      // won't do anything, as the Sidebar is a singleton class
      gl.Sidebar.singleton = null;
      sidebar = new gl.Sidebar();
    });

    it('can show the sidebar when the toggler is clicked', () => {
      assertSidebarStateExpanded(false);
      $sidebarToggle.click();
      assertSidebarStateExpanded(true);
    });

    it('should dismiss the sidebar when clone button clicked', () => {
      $sidebarToggle.click();
      assertSidebarStateExpanded(true);

      const cloneButton = $('.project-clone-holder a.clone-dropdown-btn');
      cloneButton.click();
      assertSidebarStateExpanded(false);
    });

    it('should dismiss the sidebar when download button clicked', () => {
      $sidebarToggle.click();
      assertSidebarStateExpanded(true);

      const downloadButton = $('.project-action-button .btn:has(i.fa-download)');
      downloadButton.click();
      assertSidebarStateExpanded(false);
    });

    it('should dismiss the sidebar when add button clicked', () => {
      $sidebarToggle.click();
      assertSidebarStateExpanded(true);

      const addButton = $('.project-action-button .btn:has(i.fa-plus)');
      addButton.click();
      assertSidebarStateExpanded(false);
    });

    it('should dismiss the sidebar when notification button clicked', () => {
      $sidebarToggle.click();
      assertSidebarStateExpanded(true);

      const notifButton = $('.js-notification-toggle-btns .notifications-btn');
      notifButton.click();
      assertSidebarStateExpanded(false);
    });

    it('should dismiss the sidebar when clicking on the body', () => {
      $sidebarToggle.click();
      assertSidebarStateExpanded(true);

      $('body').click();
      assertSidebarStateExpanded(false);
    });

    it('should dismiss the sidebar when clicking on the project description header', () => {
      $sidebarToggle.click();
      assertSidebarStateExpanded(true);

      $('.project-home-panel').click();
      assertSidebarStateExpanded(false);
    });
  });
})();