2018-10-09 11:25:53 -04:00
|
|
|
/* eslint-disable no-var, one-var, no-return-assign, vars-on-top, jasmine/no-unsafe-spy */
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2018-02-02 06:16:57 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2017-03-13 17:48:32 -04:00
|
|
|
import '~/commons/bootstrap';
|
2018-02-02 06:16:57 -05:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-12-15 07:57:08 -05:00
|
|
|
import Sidebar from '~/right_sidebar';
|
2016-08-08 17:19:46 -04:00
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
(function() {
|
|
|
|
var $aside, $icon, $labelsIcon, $page, $toggle, assertSidebarState;
|
|
|
|
|
|
|
|
$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() {
|
2017-09-28 08:27:52 -04:00
|
|
|
describe('fixture tests', () => {
|
|
|
|
var fixtureName = 'issues/open-issue.html.raw';
|
|
|
|
preloadFixtures(fixtureName);
|
|
|
|
loadJSONFixtures('todos/todos.json');
|
2018-02-02 06:16:57 -05:00
|
|
|
let mock;
|
2017-09-28 08:27:52 -04:00
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
loadFixtures(fixtureName);
|
2018-02-02 06:16:57 -05:00
|
|
|
mock = new MockAdapter(axios);
|
2018-03-07 15:55:23 -05:00
|
|
|
new Sidebar(); // eslint-disable-line no-new
|
2017-09-28 08:27:52 -04:00
|
|
|
$aside = $('.right-sidebar');
|
2017-12-08 16:19:01 -05:00
|
|
|
$page = $('.layout-page');
|
2017-09-28 08:27:52 -04:00
|
|
|
$icon = $aside.find('i');
|
|
|
|
$toggle = $aside.find('.js-sidebar-toggle');
|
|
|
|
return $labelsIcon = $aside.find('.sidebar-collapsed-icon');
|
|
|
|
});
|
2018-02-02 07:36:51 -05:00
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
2017-09-28 08:27:52 -04:00
|
|
|
it('should expand/collapse the sidebar when arrow is clicked', function() {
|
|
|
|
assertSidebarState('expanded');
|
|
|
|
$toggle.click();
|
|
|
|
assertSidebarState('collapsed');
|
|
|
|
$toggle.click();
|
|
|
|
assertSidebarState('expanded');
|
|
|
|
});
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2017-09-28 08:27:52 -04:00
|
|
|
it('should float over the page and when sidebar icons clicked', function() {
|
|
|
|
$labelsIcon.click();
|
|
|
|
return assertSidebarState('expanded');
|
|
|
|
});
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2017-09-28 08:27:52 -04:00
|
|
|
it('should collapse when the icon arrow clicked while it is floating on page', function() {
|
|
|
|
$labelsIcon.click();
|
|
|
|
assertSidebarState('expanded');
|
|
|
|
$toggle.click();
|
|
|
|
return assertSidebarState('collapsed');
|
|
|
|
});
|
|
|
|
|
2018-02-02 06:16:57 -05:00
|
|
|
it('should broadcast todo:toggle event when add todo clicked', function(done) {
|
2017-09-28 08:27:52 -04:00
|
|
|
var todos = getJSONFixture('todos/todos.json');
|
2018-02-02 09:54:18 -05:00
|
|
|
mock.onPost(/(.*)\/todos$/).reply(200, todos);
|
2017-09-28 08:27:52 -04:00
|
|
|
|
|
|
|
var todoToggleSpy = spyOnEvent(document, 'todo:toggle');
|
|
|
|
|
|
|
|
$('.issuable-sidebar-header .js-issuable-todo').click();
|
|
|
|
|
2018-02-02 06:16:57 -05:00
|
|
|
setTimeout(() => {
|
|
|
|
expect(todoToggleSpy.calls.count()).toEqual(1);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2017-09-28 08:27:52 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not hide collapsed icons', () => {
|
|
|
|
[].forEach.call(document.querySelectorAll('.sidebar-collapsed-icon'), (el) => {
|
|
|
|
expect(el.querySelector('.fa, svg').classList.contains('hidden')).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
});
|
2017-02-10 02:29:41 -05:00
|
|
|
}).call(window);
|