2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2018-03-17 18:26:18 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2017-08-17 22:00:37 +05:30
|
|
|
import '~/commons/bootstrap';
|
2018-03-17 18:26:18 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import Sidebar from '~/right_sidebar';
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
let $aside = null;
|
|
|
|
let $toggle = null;
|
|
|
|
let $icon = null;
|
|
|
|
let $page = null;
|
|
|
|
let $labelsIcon = null;
|
|
|
|
|
|
|
|
const assertSidebarState = function(state) {
|
|
|
|
const shouldBeExpanded = state === 'expanded';
|
|
|
|
const 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);
|
|
|
|
expect($icon.hasClass('fa-angle-double-left')).toBe(shouldBeCollapsed);
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('RightSidebar', function() {
|
|
|
|
describe('fixture tests', () => {
|
2019-05-18 00:54:41 +05:30
|
|
|
const fixtureName = 'issues/open-issue.html';
|
2018-12-13 13:39:08 +05:30
|
|
|
preloadFixtures(fixtureName);
|
|
|
|
loadJSONFixtures('todos/todos.json');
|
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
loadFixtures(fixtureName);
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
new Sidebar(); // eslint-disable-line no-new
|
|
|
|
$aside = $('.right-sidebar');
|
|
|
|
$page = $('.layout-page');
|
|
|
|
$icon = $aside.find('i');
|
|
|
|
$toggle = $aside.find('.js-sidebar-toggle');
|
|
|
|
$labelsIcon = $aside.find('.sidebar-collapsed-icon');
|
|
|
|
});
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('should expand/collapse the sidebar when arrow is clicked', function() {
|
|
|
|
assertSidebarState('expanded');
|
|
|
|
$toggle.click();
|
|
|
|
assertSidebarState('collapsed');
|
|
|
|
$toggle.click();
|
|
|
|
assertSidebarState('expanded');
|
|
|
|
});
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('should float over the page and when sidebar icons clicked', function() {
|
|
|
|
$labelsIcon.click();
|
|
|
|
assertSidebarState('expanded');
|
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('should collapse when the icon arrow clicked while it is floating on page', function() {
|
|
|
|
$labelsIcon.click();
|
|
|
|
assertSidebarState('expanded');
|
|
|
|
$toggle.click();
|
|
|
|
assertSidebarState('collapsed');
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('should broadcast todo:toggle event when add todo clicked', function(done) {
|
|
|
|
const todos = getJSONFixture('todos/todos.json');
|
|
|
|
mock.onPost(/(.*)\/todos$/).reply(200, todos);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
const todoToggleSpy = spyOnEvent(document, 'todo:toggle');
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
$('.issuable-sidebar-header .js-issuable-todo').click();
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
setTimeout(() => {
|
|
|
|
expect(todoToggleSpy.calls.count()).toEqual(1);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
done();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it('should not hide collapsed icons', () => {
|
|
|
|
[].forEach.call(document.querySelectorAll('.sidebar-collapsed-icon'), el => {
|
|
|
|
expect(el.querySelector('.fa, svg').classList.contains('hidden')).toBeFalsy();
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
2017-08-17 22:00:37 +05:30
|
|
|
});
|
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|