BigW Consortium Gitlab

right_sidebar_spec.js 2.71 KB
Newer Older
1 2
/* eslint-disable space-before-function-paren, no-var, one-var, one-var-declaration-per-line, new-parens, no-return-assign, new-cap, vars-on-top, semi, padded-blocks, max-len */
/* global Sidebar */
Fatih Acet committed
3 4 5

/*= require right_sidebar */
/*= require jquery */
6
/*= require js.cookie */
Fatih Acet committed
7

Clement Ho committed
8 9
/*= require extensions/jquery.js */

Fatih Acet committed
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
(function() {
  var $aside, $icon, $labelsIcon, $page, $toggle, assertSidebarState;

  this.sidebar = null;

  $aside = null;

  $toggle = null;

  $icon = null;

  $page = null;

  $labelsIcon = null;

  assertSidebarState = function(state) {
    var shouldBeCollapsed, shouldBeExpanded;
    shouldBeExpanded = state === 'expanded';
    shouldBeCollapsed = state === 'collapsed';
    expect($aside.hasClass('right-sidebar-expanded')).toBe(shouldBeExpanded);
    expect($page.hasClass('right-sidebar-expanded')).toBe(shouldBeExpanded);
    expect($icon.hasClass('fa-angle-double-right')).toBe(shouldBeExpanded);
    expect($aside.hasClass('right-sidebar-collapsed')).toBe(shouldBeCollapsed);
    expect($page.hasClass('right-sidebar-collapsed')).toBe(shouldBeCollapsed);
    return expect($icon.hasClass('fa-angle-double-left')).toBe(shouldBeCollapsed);
  };

  describe('RightSidebar', function() {
38
    var fixtureName = 'issues/open-issue.html.raw';
39
    preloadFixtures(fixtureName);
Fatih Acet committed
40
    beforeEach(function() {
41
      loadFixtures(fixtureName);
Fatih Acet committed
42 43 44 45 46 47 48
      this.sidebar = new Sidebar;
      $aside = $('.right-sidebar');
      $page = $('.page-with-sidebar');
      $icon = $aside.find('i');
      $toggle = $aside.find('.js-sidebar-toggle');
      return $labelsIcon = $aside.find('.sidebar-collapsed-icon');
    });
49 50
    it('should expand/collapse the sidebar when arrow is clicked', function() {
      assertSidebarState('expanded');
Fatih Acet committed
51
      $toggle.click();
52
      assertSidebarState('collapsed');
Fatih Acet committed
53 54 55 56 57 58 59
      $toggle.click();
      assertSidebarState('expanded');
    });
    it('should float over the page and when sidebar icons clicked', function() {
      $labelsIcon.click();
      return assertSidebarState('expanded');
    });
Clement Ho committed
60
    it('should collapse when the icon arrow clicked while it is floating on page', function() {
Fatih Acet committed
61 62 63 64 65
      $labelsIcon.click();
      assertSidebarState('expanded');
      $toggle.click();
      return assertSidebarState('collapsed');
    });
Clement Ho committed
66 67

    it('should broadcast todo:toggle event when add todo clicked', function() {
68
      var todos = getJSONFixture('todos.json');
Clement Ho committed
69 70
      spyOn(jQuery, 'ajax').and.callFake(function() {
        var d = $.Deferred();
71
        var response = todos;
Clement Ho committed
72 73 74 75 76 77 78 79 80 81
        d.resolve(response);
        return d.promise();
      });

      var todoToggleSpy = spyOnEvent(document, 'todo:toggle');

      $('.js-issuable-todo').click();

      expect(todoToggleSpy.calls.count()).toEqual(1);
    })
Fatih Acet committed
82 83 84
  });

}).call(this);