2018-02-02 06:16:57 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2021-02-14 13:09:20 -05:00
|
|
|
import $ from 'jquery';
|
2022-05-13 08:08:49 -04:00
|
|
|
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
|
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
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
let $aside = null;
|
|
|
|
let $toggle = null;
|
2020-10-02 23:08:48 -04:00
|
|
|
let $toggleContainer = null;
|
|
|
|
let $expandIcon = null;
|
|
|
|
let $collapseIcon = null;
|
2018-10-17 03:13:26 -04:00
|
|
|
let $page = null;
|
|
|
|
let $labelsIcon = null;
|
|
|
|
|
2020-12-23 19:10:25 -05:00
|
|
|
const assertSidebarState = (state) => {
|
2018-10-17 03:13:26 -04:00
|
|
|
const shouldBeExpanded = state === 'expanded';
|
|
|
|
const shouldBeCollapsed = state === 'collapsed';
|
|
|
|
expect($aside.hasClass('right-sidebar-expanded')).toBe(shouldBeExpanded);
|
|
|
|
expect($page.hasClass('right-sidebar-expanded')).toBe(shouldBeExpanded);
|
2020-10-02 23:08:48 -04:00
|
|
|
expect($toggleContainer.data('is-expanded')).toBe(shouldBeExpanded);
|
|
|
|
expect($expandIcon.hasClass('hidden')).toBe(shouldBeExpanded);
|
2018-10-17 03:13:26 -04:00
|
|
|
expect($aside.hasClass('right-sidebar-collapsed')).toBe(shouldBeCollapsed);
|
|
|
|
expect($page.hasClass('right-sidebar-collapsed')).toBe(shouldBeCollapsed);
|
2020-10-02 23:08:48 -04:00
|
|
|
expect($collapseIcon.hasClass('hidden')).toBe(shouldBeCollapsed);
|
2018-10-17 03:13:26 -04:00
|
|
|
};
|
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
describe('RightSidebar', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
describe('fixture tests', () => {
|
2019-03-26 12:03:28 -04:00
|
|
|
const fixtureName = 'issues/open-issue.html';
|
2018-10-17 03:13:26 -04:00
|
|
|
let mock;
|
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
beforeEach(() => {
|
2022-05-13 08:08:49 -04:00
|
|
|
loadHTMLFixture(fixtureName);
|
2018-10-17 03:13:26 -04:00
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
new Sidebar(); // eslint-disable-line no-new
|
|
|
|
$aside = $('.right-sidebar');
|
|
|
|
$page = $('.layout-page');
|
2020-10-02 23:08:48 -04:00
|
|
|
$toggleContainer = $('.js-sidebar-toggle-container');
|
|
|
|
$expandIcon = $aside.find('.js-sidebar-expand');
|
|
|
|
$collapseIcon = $aside.find('.js-sidebar-collapse');
|
2018-10-17 03:13:26 -04:00
|
|
|
$toggle = $aside.find('.js-sidebar-toggle');
|
|
|
|
$labelsIcon = $aside.find('.sidebar-collapsed-icon');
|
|
|
|
});
|
2018-02-02 07:36:51 -05:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
2022-05-13 08:08:49 -04:00
|
|
|
|
|
|
|
resetHTMLFixture();
|
2018-10-17 03:13:26 -04:00
|
|
|
});
|
2018-02-02 07:36:51 -05:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
it('should expand/collapse the sidebar when arrow is clicked', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
assertSidebarState('expanded');
|
|
|
|
$toggle.click();
|
|
|
|
assertSidebarState('collapsed');
|
|
|
|
$toggle.click();
|
|
|
|
assertSidebarState('expanded');
|
|
|
|
});
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
it('should float over the page and when sidebar icons clicked', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
$labelsIcon.click();
|
|
|
|
assertSidebarState('expanded');
|
|
|
|
});
|
2018-10-09 13:01:49 -04:00
|
|
|
|
2020-06-08 05:08:23 -04:00
|
|
|
it('should collapse when the icon arrow clicked while it is floating on page', () => {
|
2018-10-17 03:13:26 -04:00
|
|
|
$labelsIcon.click();
|
|
|
|
assertSidebarState('expanded');
|
|
|
|
$toggle.click();
|
|
|
|
assertSidebarState('collapsed');
|
|
|
|
});
|
2017-09-28 08:27:52 -04:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('should not hide collapsed icons', () => {
|
2020-12-23 19:10:25 -05:00
|
|
|
[].forEach.call(document.querySelectorAll('.sidebar-collapsed-icon'), (el) => {
|
2022-08-09 05:09:18 -04:00
|
|
|
expect(el.querySelector('.fa, svg').classList.contains('hidden')).toBe(false);
|
2017-09-28 08:27:52 -04:00
|
|
|
});
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
});
|
2018-10-17 03:13:26 -04:00
|
|
|
});
|