2017-01-10 18:02:20 -05:00
|
|
|
/* 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, max-len */
|
2016-12-14 00:26:26 -05:00
|
|
|
/* global Sidebar */
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-01-09 18:23:54 -05:00
|
|
|
require('~/right_sidebar');
|
|
|
|
require('~/extensions/jquery.js');
|
2016-08-08 17:19:46 -04:00
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
(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() {
|
2016-11-22 19:48:14 -05:00
|
|
|
var fixtureName = 'issues/open-issue.html.raw';
|
2016-12-30 19:14:33 -05:00
|
|
|
preloadFixtures(fixtureName);
|
2017-02-13 19:09:57 -05:00
|
|
|
loadJSONFixtures('todos/todos.json');
|
2017-01-13 11:04:41 -05:00
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
beforeEach(function() {
|
2016-12-30 19:14:33 -05:00
|
|
|
loadFixtures(fixtureName);
|
2016-07-24 16:45:11 -04:00
|
|
|
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');
|
|
|
|
});
|
2016-11-22 19:48:14 -05:00
|
|
|
it('should expand/collapse the sidebar when arrow is clicked', function() {
|
|
|
|
assertSidebarState('expanded');
|
2016-07-24 16:45:11 -04:00
|
|
|
$toggle.click();
|
2016-11-22 19:48:14 -05:00
|
|
|
assertSidebarState('collapsed');
|
2016-07-24 16:45:11 -04:00
|
|
|
$toggle.click();
|
|
|
|
assertSidebarState('expanded');
|
|
|
|
});
|
|
|
|
it('should float over the page and when sidebar icons clicked', function() {
|
|
|
|
$labelsIcon.click();
|
|
|
|
return assertSidebarState('expanded');
|
|
|
|
});
|
2016-08-08 17:19:46 -04:00
|
|
|
it('should collapse when the icon arrow clicked while it is floating on page', function() {
|
2016-07-24 16:45:11 -04:00
|
|
|
$labelsIcon.click();
|
|
|
|
assertSidebarState('expanded');
|
|
|
|
$toggle.click();
|
|
|
|
return assertSidebarState('collapsed');
|
|
|
|
});
|
2016-08-08 17:19:46 -04:00
|
|
|
|
|
|
|
it('should broadcast todo:toggle event when add todo clicked', function() {
|
2017-02-13 19:09:57 -05:00
|
|
|
var todos = getJSONFixture('todos/todos.json');
|
2016-08-08 17:19:46 -04:00
|
|
|
spyOn(jQuery, 'ajax').and.callFake(function() {
|
|
|
|
var d = $.Deferred();
|
2017-01-03 17:38:53 -05:00
|
|
|
var response = todos;
|
2016-08-08 17:19:46 -04:00
|
|
|
d.resolve(response);
|
|
|
|
return d.promise();
|
|
|
|
});
|
|
|
|
|
|
|
|
var todoToggleSpy = spyOnEvent(document, 'todo:toggle');
|
|
|
|
|
|
|
|
$('.js-issuable-todo').click();
|
|
|
|
|
|
|
|
expect(todoToggleSpy.calls.count()).toEqual(1);
|
2017-01-10 17:54:56 -05:00
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-02-10 02:29:41 -05:00
|
|
|
}).call(window);
|