Commit ba76ddf2 authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett

Only trigger loadCheck on open toggle, not close. Update specs and add...

Only trigger loadCheck on open toggle, not close. Update specs and add right_sidebar_spec test for additions
parent 68269d7a
...@@ -67,13 +67,13 @@ const PARTICIPANTS_ROW_COUNT = 7; ...@@ -67,13 +67,13 @@ const PARTICIPANTS_ROW_COUNT = 7;
originalText = $(this).data("original-text"); originalText = $(this).data("original-text");
if (currentText === originalText) { if (currentText === originalText) {
$(this).text(lessText); $(this).text(lessText);
if (gl.lazyLoader) gl.lazyLoader.loadCheck();
} else { } else {
$(this).text(originalText); $(this).text(originalText);
} }
$(".js-participants-hidden").toggle(); $(".js-participants-hidden").toggle();
if (gl.lazyLoader) gl.lazyLoader.loadCheck();
}; };
return IssuableContext; return IssuableContext;
......
...@@ -29,29 +29,32 @@ import Cookies from 'js-cookie'; ...@@ -29,29 +29,32 @@ import Cookies from 'js-cookie';
$('.dropdown').on('loading.gl.dropdown', this.sidebarDropdownLoading); $('.dropdown').on('loading.gl.dropdown', this.sidebarDropdownLoading);
$('.dropdown').on('loaded.gl.dropdown', this.sidebarDropdownLoaded); $('.dropdown').on('loaded.gl.dropdown', this.sidebarDropdownLoaded);
$document.on('click', '.js-sidebar-toggle', function(e, triggered) { $document.on('click', '.js-sidebar-toggle', this.sidebarToggleClicked);
var $allGutterToggleIcons, $this, $thisIcon;
e.preventDefault();
$this = $(this);
$thisIcon = $this.find('i');
$allGutterToggleIcons = $('.js-sidebar-toggle i');
if ($thisIcon.hasClass('fa-angle-double-right')) {
$allGutterToggleIcons.removeClass('fa-angle-double-right').addClass('fa-angle-double-left');
$('aside.right-sidebar').removeClass('right-sidebar-expanded').addClass('right-sidebar-collapsed');
$('.page-with-sidebar').removeClass('right-sidebar-expanded').addClass('right-sidebar-collapsed');
} else {
$allGutterToggleIcons.removeClass('fa-angle-double-left').addClass('fa-angle-double-right');
$('aside.right-sidebar').removeClass('right-sidebar-collapsed').addClass('right-sidebar-expanded');
$('.page-with-sidebar').removeClass('right-sidebar-collapsed').addClass('right-sidebar-expanded');
}
if (!triggered) {
Cookies.set("collapsed_gutter", $('.right-sidebar').hasClass('right-sidebar-collapsed'));
}
if (gl.lazyLoader) gl.lazyLoader.loadCheck();
});
return $(document).off('click', '.js-issuable-todo').on('click', '.js-issuable-todo', this.toggleTodo); return $(document).off('click', '.js-issuable-todo').on('click', '.js-issuable-todo', this.toggleTodo);
}; };
Sidebar.prototype.sidebarToggleClicked = function (e, triggered) {
var $allGutterToggleIcons, $this, $thisIcon;
e.preventDefault();
$this = $(this);
$thisIcon = $this.find('i');
$allGutterToggleIcons = $('.js-sidebar-toggle i');
if ($thisIcon.hasClass('fa-angle-double-right')) {
$allGutterToggleIcons.removeClass('fa-angle-double-right').addClass('fa-angle-double-left');
$('aside.right-sidebar').removeClass('right-sidebar-expanded').addClass('right-sidebar-collapsed');
$('.page-with-sidebar').removeClass('right-sidebar-expanded').addClass('right-sidebar-collapsed');
} else {
$allGutterToggleIcons.removeClass('fa-angle-double-left').addClass('fa-angle-double-right');
$('aside.right-sidebar').removeClass('right-sidebar-collapsed').addClass('right-sidebar-expanded');
$('.page-with-sidebar').removeClass('right-sidebar-collapsed').addClass('right-sidebar-expanded');
if (gl.lazyLoader) gl.lazyLoader.loadCheck();
}
if (!triggered) {
Cookies.set("collapsed_gutter", $('.right-sidebar').hasClass('right-sidebar-collapsed'));
}
};
Sidebar.prototype.toggleTodo = function(e) { Sidebar.prototype.toggleTodo = function(e) {
var $btnText, $this, $todoLoading, ajaxType, url; var $btnText, $this, $todoLoading, ajaxType, url;
$this = $(e.currentTarget); $this = $(e.currentTarget);
......
/* global IssuableContext */ /* global IssuableContext */
import '~/issuable_context'; import '~/issuable_context';
import $ from 'jquery';
describe('IssuableContext', () => { describe('IssuableContext', () => {
describe('toggleHiddenParticipants', () => { describe('toggleHiddenParticipants', () => {
const event = jasmine.createSpyObj('event', ['preventDefault']); const event = jasmine.createSpyObj('event', ['preventDefault']);
beforeEach(() => {
spyOn($.fn, 'data').and.returnValue('data');
spyOn($.fn, 'text').and.returnValue('data');
});
afterEach(() => { afterEach(() => {
gl.lazyLoader = undefined; gl.lazyLoader = undefined;
}); });
......
...@@ -32,56 +32,86 @@ import '~/right_sidebar'; ...@@ -32,56 +32,86 @@ import '~/right_sidebar';
}; };
describe('RightSidebar', function() { describe('RightSidebar', function() {
var fixtureName = 'issues/open-issue.html.raw'; describe('fixture tests', () => {
preloadFixtures(fixtureName); var fixtureName = 'issues/open-issue.html.raw';
loadJSONFixtures('todos/todos.json'); preloadFixtures(fixtureName);
loadJSONFixtures('todos/todos.json');
beforeEach(function() {
loadFixtures(fixtureName); beforeEach(function() {
this.sidebar = new Sidebar; loadFixtures(fixtureName);
$aside = $('.right-sidebar'); this.sidebar = new Sidebar;
$page = $('.page-with-sidebar'); $aside = $('.right-sidebar');
$icon = $aside.find('i'); $page = $('.page-with-sidebar');
$toggle = $aside.find('.js-sidebar-toggle'); $icon = $aside.find('i');
return $labelsIcon = $aside.find('.sidebar-collapsed-icon'); $toggle = $aside.find('.js-sidebar-toggle');
}); return $labelsIcon = $aside.find('.sidebar-collapsed-icon');
it('should expand/collapse the sidebar when arrow is clicked', function() { });
assertSidebarState('expanded'); it('should expand/collapse the sidebar when arrow is clicked', function() {
$toggle.click(); assertSidebarState('expanded');
assertSidebarState('collapsed'); $toggle.click();
$toggle.click(); assertSidebarState('collapsed');
assertSidebarState('expanded'); $toggle.click();
}); assertSidebarState('expanded');
it('should float over the page and when sidebar icons clicked', function() { });
$labelsIcon.click(); it('should float over the page and when sidebar icons clicked', function() {
return assertSidebarState('expanded'); $labelsIcon.click();
}); return assertSidebarState('expanded');
it('should collapse when the icon arrow clicked while it is floating on page', function() { });
$labelsIcon.click(); it('should collapse when the icon arrow clicked while it is floating on page', function() {
assertSidebarState('expanded'); $labelsIcon.click();
$toggle.click(); assertSidebarState('expanded');
return assertSidebarState('collapsed'); $toggle.click();
return assertSidebarState('collapsed');
});
it('should broadcast todo:toggle event when add todo clicked', function() {
var todos = getJSONFixture('todos/todos.json');
spyOn(jQuery, 'ajax').and.callFake(function() {
var d = $.Deferred();
var response = todos;
d.resolve(response);
return d.promise();
});
var todoToggleSpy = spyOnEvent(document, 'todo:toggle');
$('.issuable-sidebar-header .js-issuable-todo').click();
expect(todoToggleSpy.calls.count()).toEqual(1);
});
it('should not hide collapsed icons', () => {
[].forEach.call(document.querySelectorAll('.sidebar-collapsed-icon'), (el) => {
expect(el.querySelector('.fa, svg').classList.contains('hidden')).toBeFalsy();
});
});
}); });
it('should broadcast todo:toggle event when add todo clicked', function() { describe('sidebarToggleClicked', () => {
var todos = getJSONFixture('todos/todos.json'); const event = jasmine.createSpyObj('event', ['preventDefault']);
spyOn(jQuery, 'ajax').and.callFake(function() {
var d = $.Deferred(); beforeEach(() => {
var response = todos; spyOn($.fn, 'hasClass').and.returnValue(false);
d.resolve(response); });
return d.promise();
afterEach(() => {
gl.lazyLoader = undefined;
}); });
var todoToggleSpy = spyOnEvent(document, 'todo:toggle'); it('calls loadCheck if lazyLoader is set', () => {
gl.lazyLoader = jasmine.createSpyObj('lazyLoader', ['loadCheck']);
$('.issuable-sidebar-header .js-issuable-todo').click(); Sidebar.prototype.sidebarToggleClicked(event);
expect(todoToggleSpy.calls.count()).toEqual(1); expect(gl.lazyLoader.loadCheck).toHaveBeenCalled();
}); });
it('does not throw if lazyLoader is not defined', () => {
gl.lazyLoader = undefined;
const toggle = Sidebar.prototype.sidebarToggleClicked.bind(null, event);
it('should not hide collapsed icons', () => { expect(toggle).not.toThrow();
[].forEach.call(document.querySelectorAll('.sidebar-collapsed-icon'), (el) => {
expect(el.querySelector('.fa, svg').classList.contains('hidden')).toBeFalsy();
}); });
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment