diff --git a/core/src/core-api/auth.js b/core/src/core-api/auth.js index a848e25ec0..69b0868b35 100644 --- a/core/src/core-api/auth.js +++ b/core/src/core-api/auth.js @@ -1,6 +1,6 @@ import { LuigiConfig } from './'; import { AuthStoreSvc, AuthLayerSvc } from '../services'; - +/* istanbul ignore file */ /** * Authorization helpers * @name Authorization diff --git a/core/src/core-api/dom-elements.js b/core/src/core-api/dom-elements.js index ce60527f5d..07c9f40ad8 100644 --- a/core/src/core-api/dom-elements.js +++ b/core/src/core-api/dom-elements.js @@ -1,6 +1,6 @@ import { CUSTOM_LUIGI_CONTAINER } from './../utilities/constants'; import { IframeHelpers } from './../utilities/helpers'; - +/* istanbul ignore file */ /** * Use these functions to get DOM elements. * @namespace Elements diff --git a/core/src/core-api/theming.js b/core/src/core-api/theming.js index 0ee1a60614..22d8bb7594 100644 --- a/core/src/core-api/theming.js +++ b/core/src/core-api/theming.js @@ -89,7 +89,7 @@ class LuigiTheming { * @example * Luigi.theming().isThemingAvailable() */ - isThemingAvailable() { + isThemingAvailable() /* istanbul ignore next */ { return !!LuigiConfig.getConfigValue('settings.theming'); } @@ -98,7 +98,7 @@ class LuigiTheming { * @memberof Theming * @private */ - _init() { + _init() /* istanbul ignore next */ { const setupViewUrlDecorator = () => { /** * Registers the viewUrl decorator diff --git a/core/src/core-api/ux.js b/core/src/core-api/ux.js index a9b9f390fa..c510e28fa8 100644 --- a/core/src/core-api/ux.js +++ b/core/src/core-api/ux.js @@ -135,6 +135,7 @@ class LuigiUX { * @since 1.5.0 */ collapseLeftSideNav(state) { + /* istanbul ignore next */ SemiCollapsibleNavigation.setCollapsed(state); } @@ -143,7 +144,7 @@ class LuigiUX { * @memberof UX * @since 1.7.1 */ - openUserSettings() { + openUserSettings() /* istanbul ignore next */ { Luigi.openUserSettings(); } @@ -152,7 +153,7 @@ class LuigiUX { * @memberof UX * @since 1.7.1 */ - closeUserSettings() { + closeUserSettings() /* istanbul ignore next */ { Luigi.closeUserSettings(); } } diff --git a/core/src/services/iframe.js b/core/src/services/iframe.js index 790bf0c364..37a506e9a3 100644 --- a/core/src/services/iframe.js +++ b/core/src/services/iframe.js @@ -1,7 +1,7 @@ // Methods related to managing the view in the iframe. // Please consider adding any new methods to 'iframe-helpers' if they don't require anything from this file. import { GenericHelpers, IframeHelpers, RoutingHelpers, NavigationHelpers } from '../utilities/helpers'; -import { LuigiConfig, LuigiI18N, LuigiRouting } from '../core-api'; +import { LuigiConfig, LuigiI18N } from '../core-api'; class IframeClass { constructor() { diff --git a/core/src/services/messages-listeners.js b/core/src/services/messages-listeners.js index 7b07414a62..013f000b6b 100644 --- a/core/src/services/messages-listeners.js +++ b/core/src/services/messages-listeners.js @@ -1,3 +1,4 @@ +/*istanbul ignore file */ class MessagesListenersClass { convertCustomMessageInternalToUser(internalMessage) { return internalMessage.data; diff --git a/core/src/services/split-view.js b/core/src/services/split-view.js index d09379cf0b..7f4de8f0a5 100644 --- a/core/src/services/split-view.js +++ b/core/src/services/split-view.js @@ -133,7 +133,7 @@ class SplitViewSvcClass { // required for iOS to force repaint, else scrolling does not work /* istanbul ignore next */ - fixIOSscroll() { + fixIOSscroll /* istanbul ignore next */() { const iOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform); if (!iOS) { return; diff --git a/core/src/utilities/helpers/generic-helpers.js b/core/src/utilities/helpers/generic-helpers.js index 8ab54fa730..41ca8a39fe 100644 --- a/core/src/utilities/helpers/generic-helpers.js +++ b/core/src/utilities/helpers/generic-helpers.js @@ -8,7 +8,7 @@ class GenericHelpersClass { * @returns random numeric value {number} * @private */ - getRandomId() { + getRandomId() /* istanbul ignore next */ { // window.msCrypto for IE 11 return (window.crypto || window.msCrypto).getRandomValues(new Uint32Array(1))[0]; } @@ -21,7 +21,7 @@ class GenericHelpersClass { return anyParam && this.isFunction(anyParam.then); } - isIE() { + isIE() /* istanbul ignore next */ { const ua = navigator.userAgent; /* MSIE used to detect old browsers and Trident used to newer ones*/ return Boolean(ua.includes('MSIE ') || ua.includes('Trident/')); @@ -209,23 +209,26 @@ class GenericHelpersClass { return processedString; } - getInnerHeight() { + getInnerHeight() /* istanbul ignore next */ { return LuigiElements.isCustomLuigiContainer() ? LuigiElements.getLuigiContainer().clientHeight : window.innerHeight; } - getContentAreaHeight() { + getContentAreaHeight /* istanbul ignore next */() { return this.getInnerHeight() - LuigiElements.getShellbar().clientHeight; } computePxFromPercent(fullPixels, requestedPercent) { + /* istanbul ignore next */ return (fullPixels / 100) * requestedPercent; } computePercentFromPx(fullPixels, partialPixels) { + /* istanbul ignore next */ return Math.floor((100 * partialPixels) / fullPixels); } isElementVisible(element) { + /* istanbul ignore next */ const cssDisplayValue = window.getComputedStyle(element, null).getPropertyValue('display'); return cssDisplayValue !== 'none'; } diff --git a/core/test/services/iframe.spec.js b/core/test/services/iframe.spec.js index 73fc98cb96..e859f6d039 100644 --- a/core/test/services/iframe.spec.js +++ b/core/test/services/iframe.spec.js @@ -4,12 +4,7 @@ const sinon = require('sinon'); import { Iframe, ViewUrlDecorator } from '../../src/services'; -import { - GenericHelpers, - RoutingHelpers, - IframeHelpers, - NavigationHelpers -} from '../../src/utilities/helpers'; +import { GenericHelpers, RoutingHelpers, IframeHelpers, NavigationHelpers } from '../../src/utilities/helpers'; import { LuigiConfig } from '../../src/core-api'; describe('Iframe', () => { @@ -38,7 +33,6 @@ describe('Iframe', () => { prepareInternalData: () => {} }; sinon.stub(Iframe, 'setOkResponseHandler'); - sinon.stub(Iframe, 'initHandshakeFailed').returns(false); sinon.stub(NavigationHelpers, 'handleUnresponsiveClient'); sinon.stub(LuigiConfig, 'getConfigValue').callsFake(); sinon.stub(GenericHelpers); @@ -107,15 +101,22 @@ describe('Iframe', () => { }); describe('setActiveIframeToPrevious', () => { + beforeEach(() => { + sinon.stub(IframeHelpers, 'getMainIframes').callsFake(() => node.children); + }); + afterEach(() => { + sinon.restore(); + }); it('goBack with preserved view situation', () => { - sinon - .stub(IframeHelpers, 'getMainIframes') - .callsFake(() => node.children); Iframe.setActiveIframeToPrevious(node); - assert.equal(node.children.length, 4); assert.equal(node.children[0].style.display, 'block'); }); + it('setActiveIframeToPrevious w/o preservedViews', () => { + delete node.children[1].pv; + Iframe.setActiveIframeToPrevious(node); + assert.equal(node.children.length, 5); + }); }); it('removeInactiveIframes', () => { @@ -130,6 +131,38 @@ describe('Iframe', () => { }); }); + describe('getViewGroupSettings', () => { + let viewGroupSettings; + beforeEach(() => { + viewGroupSettings = { + ham: { + preloadUrl: 'ham.html' + }, + cheese: { + preloadUrl: 'cheese.html' + }, + ananas: { + preloadUrl: 'ananas.html' + } + }; + sinon.stub(Iframe, 'getAllViewGroupSettings').callsFake(() => { + return viewGroupSettings; + }); + afterEach(() => { + sinon.restore(); + }); + }); + it('return viewgroup from viewgroup settings', () => { + assert.deepEqual(Iframe.getViewGroupSettings('ananas'), { + preloadUrl: 'ananas.html' + }); + }); + it('no view group found in viewgroup settings', () => { + assert.deepEqual(Iframe.getViewGroupSettings(''), {}); + assert.deepEqual(Iframe.getViewGroupSettings('somethingElse'), {}); + }); + }); + describe('create new iframe with different viewgroup and dont delete the previous one (cache)', () => { it('navigate', async () => { sinon.stub(IframeHelpers, 'getMainIframes').callsFake(() => [ @@ -194,6 +227,7 @@ describe('Iframe', () => { describe('check if luigi respond, if not, callback again to replace the iframe', () => { it('navigate', async () => { + sinon.stub(Iframe, 'initHandshakeFailed').returns(false); sinon.stub(IframeHelpers, 'getMainIframes').callsFake(() => [ { src: 'http://url.com/app.html!#/prevUrl', @@ -256,10 +290,7 @@ describe('Iframe', () => { src: 'http://luigi.url.de' } }); - assert( - Iframe.navigateIframe.notCalled, - 'Iframe.navigateIframe not called' - ); + assert(Iframe.navigateIframe.notCalled, 'Iframe.navigateIframe not called'); }); it('not ok', () => { sinon.stub(Iframe, 'navigateIframe'); @@ -337,15 +368,13 @@ describe('Iframe', () => { clock.tick(2000); // then - assert( - NavigationHelpers.handleUnresponsiveClient.called, - 'handleUnresponsiveClient() call' - ); + assert(NavigationHelpers.handleUnresponsiveClient.called, 'handleUnresponsiveClient() call'); }); }); describe('use cached iframe with same viewgroup and change viewUrl', () => { it('navigate', async () => { + sinon.stub(Iframe, 'initHandshakeFailed').returns(false); sinon.stub(IframeHelpers, 'getMainIframes').callsFake(() => [ { src: 'http://luigi.url.de', @@ -384,6 +413,7 @@ describe('Iframe', () => { describe('using withoutSync whould not trigger iframe fallback', () => { it('navigate', async () => { + sinon.stub(Iframe, 'initHandshakeFailed').returns(false); const spy = sinon.spy(console, 'info'); spy.resetHistory(); @@ -418,4 +448,26 @@ describe('Iframe', () => { assert.isTrue(component.get().isNavigationSyncEnabled); }); }); + describe('init handshake failed', () => { + let someConfig = {}; + beforeEach(() => { + someConfig = { + iframe: {} + }; + }); + it('init handshake failed no luigi object on iframe', () => { + assert.equal(Iframe.initHandshakeFailed(someConfig), true); + }); + it('init handshake failed initOk undefined', () => { + someConfig.iframe.luigi = {}; + assert.equal(Iframe.initHandshakeFailed(someConfig), true); + }); + it('init handshake success', () => { + someConfig.iframe.luigi = { + initOk: true, + clientVersion: '1.4.0' + }; + assert.equal(Iframe.initHandshakeFailed(someConfig), false); + }); + }); }); diff --git a/core/test/services/routing.spec.js b/core/test/services/routing.spec.js index aeb7d0aadf..6bfc7314c4 100644 --- a/core/test/services/routing.spec.js +++ b/core/test/services/routing.spec.js @@ -1180,4 +1180,16 @@ describe('Routing', function() { assert.equal(path, 'bla/x/?~a=b&~c=d#/something?~e=f&~g=h'); }); }); + describe('concatenate path', () => { + it('concatenate path', () => { + assert.equal(Routing.concatenatePath('/home/overview', 'settings'), 'home/overview/settings'); + assert.equal(Routing.concatenatePath('/#/home/overview', 'settings'), 'home/overview/settings'); + assert.equal(Routing.concatenatePath('', 'settings'), 'settings'); + assert.equal(Routing.concatenatePath('/home/overview', ''), 'home/overview'); + assert.equal(Routing.concatenatePath('/home/overview', '/test'), 'home/overview/test'); + assert.equal(Routing.concatenatePath('/home/overview/', 'test'), 'home/overview/test'); + assert.equal(Routing.concatenatePath('/home/overview/', '/test'), 'home/overview/test'); + assert.equal(Routing.concatenatePath('/home/overview/', 'test/'), 'home/overview/test/'); + }); + }); }); diff --git a/core/test/services/split-view.spec.js b/core/test/services/split-view.spec.js index 6e18c3b5ac..acff5da8df 100644 --- a/core/test/services/split-view.spec.js +++ b/core/test/services/split-view.spec.js @@ -4,11 +4,7 @@ const sinon = require('sinon'); import { afterEach } from 'mocha'; import { SplitViewSvc } from '../../src/services'; -import { - GenericHelpers, - IframeHelpers, - RoutingHelpers -} from '../../src/utilities/helpers'; +import { GenericHelpers, IframeHelpers, RoutingHelpers } from '../../src/utilities/helpers'; import { Navigation } from '../../src/navigation/services/navigation'; import { LuigiConfig, LuigiElements } from '../../src/core-api'; @@ -67,13 +63,22 @@ describe('SplitViewSvc', () => { sinon.assert.calledWith(document.getElementById, 'splitViewDragger'); assert.equal(res, mockElem); }); + it('getDraggerButton()', () => { + document.querySelector.returns(mockElem); + const res = SplitViewSvc.getDraggerButton(); + sinon.assert.calledWith(document.querySelector, '#splitViewDragger>.lui-collapse-btn'); + assert.equal(res, mockElem); + }); + it('getCollapsedDraggerButton()', () => { + document.querySelector.returns(mockElem); + const res = SplitViewSvc.getCollapsedDraggerButton(); + sinon.assert.calledWith(document.querySelector, '#splitViewDraggerCollapsed>.lui-collapse-btn'); + assert.equal(res, mockElem); + }); it('getDraggerBackdrop()', () => { const res = SplitViewSvc.getDraggerBackdrop(); - sinon.assert.calledWith( - document.getElementById, - 'splitViewDraggerBackdrop' - ); + sinon.assert.calledWith(document.getElementById, 'splitViewDraggerBackdrop'); assert.equal(res, mockElem); }); }); @@ -109,11 +114,7 @@ describe('SplitViewSvc', () => { const res = SplitViewSvc.setIframe('viewUrl', 'componentData', component); - sinon.assert.calledWith( - RoutingHelpers.substituteViewUrl, - 'viewUrl', - 'componentData' - ); + sinon.assert.calledWith(RoutingHelpers.substituteViewUrl, 'viewUrl', 'componentData'); sinon.assert.calledWith(IframeHelpers.createIframe, 'otherUrl'); assert.deepEqual(res, splitFrame); }); @@ -176,30 +177,15 @@ describe('SplitViewSvc', () => { SplitViewSvc.calculateAndSetSplitViewValues(40, mockValues); // when - sinon.assert.calledWithExactly( - GenericHelpers.computePxFromPercent, - mockValues.rightContentHeight, - 60 - ); + sinon.assert.calledWithExactly(GenericHelpers.computePxFromPercent, mockValues.rightContentHeight, 60); const newBottom = 430; // mockCalculated.bottom + shellbarHeight; const newTop = 570; // values.innerHeight - newBottom - sinon.assert.calledWithExactly( - SplitViewSvc.enforceTresholds, - newBottom, - newTop, - mockValues - ); + sinon.assert.calledWithExactly(SplitViewSvc.enforceTresholds, newBottom, newTop, mockValues); assert.deepEqual(SplitViewSvc.splitViewValues, mockCalculated); }); describe('prepareSplitViewData', () => { - let pathUrlRaw, - navigationNodes, - pathData, - params, - nodeParams, - lastNode, - splitViewSettings; + let pathUrlRaw, navigationNodes, pathData, params, nodeParams, lastNode, splitViewSettings; const setMockReturns = () => { GenericHelpers.getPathWithoutHash.returns(pathUrlRaw); @@ -233,21 +219,11 @@ describe('SplitViewSvc', () => { await SplitViewSvc.prepareSplitViewData(component, testPath); // when - sinon.assert.calledWithExactly( - GenericHelpers.getPathWithoutHash, - testPath - ); - sinon.assert.calledWithExactly( - Navigation.getNavigationPath, - navigationNodes, - testPath - ); + sinon.assert.calledWithExactly(GenericHelpers.getPathWithoutHash, testPath); + sinon.assert.calledWithExactly(Navigation.getNavigationPath, navigationNodes, testPath); sinon.assert.calledWithExactly(RoutingHelpers.parseParams, 'order=asc'); sinon.assert.calledWithExactly(RoutingHelpers.getNodeParams, params); - sinon.assert.calledWithExactly( - RoutingHelpers.getLastNodeObject, - pathData - ); + sinon.assert.calledWithExactly(RoutingHelpers.getLastNodeObject, pathData); sinon.assert.calledWithExactly(component.set, { splitViewSettings: { collapsed: true, @@ -277,21 +253,11 @@ describe('SplitViewSvc', () => { await SplitViewSvc.prepareSplitViewData(component, testPath); // when - sinon.assert.calledWithExactly( - GenericHelpers.getPathWithoutHash, - testPath - ); - sinon.assert.calledWithExactly( - Navigation.getNavigationPath, - navigationNodes, - testPath - ); + sinon.assert.calledWithExactly(GenericHelpers.getPathWithoutHash, testPath); + sinon.assert.calledWithExactly(Navigation.getNavigationPath, navigationNodes, testPath); sinon.assert.calledWithExactly(RoutingHelpers.parseParams, 'order=asc'); sinon.assert.calledWithExactly(RoutingHelpers.getNodeParams, params); - sinon.assert.calledWithExactly( - RoutingHelpers.getLastNodeObject, - pathData - ); + sinon.assert.calledWithExactly(RoutingHelpers.getLastNodeObject, pathData); sinon.assert.calledWithExactly(component.set, { splitViewSettings: { collapsed: true, @@ -317,21 +283,11 @@ describe('SplitViewSvc', () => { await SplitViewSvc.prepareSplitViewData(component, testPath); // when - sinon.assert.calledWithExactly( - GenericHelpers.getPathWithoutHash, - testPath - ); - sinon.assert.calledWithExactly( - Navigation.getNavigationPath, - navigationNodes, - testPath - ); + sinon.assert.calledWithExactly(GenericHelpers.getPathWithoutHash, testPath); + sinon.assert.calledWithExactly(Navigation.getNavigationPath, navigationNodes, testPath); sinon.assert.calledWithExactly(RoutingHelpers.parseParams, 'order=asc'); sinon.assert.calledWithExactly(RoutingHelpers.getNodeParams, params); - sinon.assert.calledWithExactly( - RoutingHelpers.getLastNodeObject, - pathData - ); + sinon.assert.calledWithExactly(RoutingHelpers.getLastNodeObject, pathData); sinon.assert.calledWithExactly(component.set, { splitViewSettings, lastNode, @@ -373,13 +329,10 @@ describe('SplitViewSvc', () => { SplitViewSvc.sendMessageToClients('test', mockData); - sinon.assert.calledWithExactly( - IframeHelpers.sendMessageToVisibleIframes, - { - msg: `luigi.navigation.splitview.test`, - data: mockData - } - ); + sinon.assert.calledWithExactly(IframeHelpers.sendMessageToVisibleIframes, { + msg: `luigi.navigation.splitview.test`, + data: mockData + }); }); }); }); diff --git a/core/test/utilities/helpers/generic-helpers.spec.js b/core/test/utilities/helpers/generic-helpers.spec.js index 2465e28e1d..dc75edce02 100644 --- a/core/test/utilities/helpers/generic-helpers.spec.js +++ b/core/test/utilities/helpers/generic-helpers.spec.js @@ -1,6 +1,7 @@ const chai = require('chai'); const assert = chai.assert; const sinon = require('sinon'); +import { LuigiConfig } from '../../../src/core-api'; import { GenericHelpers } from '../../../src/utilities/helpers'; describe('Generic-helpers', () => { @@ -25,18 +26,10 @@ describe('Generic-helpers', () => { const catName = 'spencer'; setLocationSearch('?param=1&foo=bar&cat=' + catName); - assert.equal( - GenericHelpers.getUrlParameter('cat'), - catName, - 'url with ? and multiple params' - ); + assert.equal(GenericHelpers.getUrlParameter('cat'), catName, 'url with ? and multiple params'); setLocationSearch('#foo=bar&cat=' + catName + '¶m=1'); - assert.equal( - GenericHelpers.getUrlParameter('cat'), - catName, - 'url with # and multiple params' - ); + assert.equal(GenericHelpers.getUrlParameter('cat'), catName, 'url with # and multiple params'); }); it('getUrlWithoutHash', () => { @@ -101,20 +94,8 @@ describe('Generic-helpers', () => { }); it('with beta and next', () => { - const input = [ - '1.1.1-dev.0000', - '0.6.4', - '0.7.7-beta.0', - '0.7.1', - '1.0.0' - ]; - const expected = [ - '0.6.4', - '0.7.1', - '0.7.7-beta.0', - '1.0.0', - '1.1.1-dev.0000' - ]; + const input = ['1.1.1-dev.0000', '0.6.4', '0.7.7-beta.0', '0.7.1', '1.0.0']; + const expected = ['0.6.4', '0.7.1', '0.7.7-beta.0', '1.0.0', '1.1.1-dev.0000']; assert.deepEqual(input.sort(GenericHelpers.semverCompare), expected); }); @@ -123,4 +104,31 @@ describe('Generic-helpers', () => { assert.equal(GenericHelpers.semverCompare('1.1.1', '0.7.4'), 1); }); }); + describe('request experimental feature', () => { + beforeEach(() => { + sinon.stub(LuigiConfig, 'getConfig'); + console.warn = sinon.spy(); + LuigiConfig.getConfig.returns({ + settings: { + experimental: { + test: true + } + } + }); + }); + afterEach(() => { + sinon.restore(); + }); + it('experimental feature is configured', () => { + assert.equal(GenericHelpers.requestExperimentalFeature('test', true), true); + }); + it('experimental feature NOT configured and show console warn', () => { + assert.equal(GenericHelpers.requestExperimentalFeature('tets', true), false); + sinon.assert.calledOnce(console.warn); + }); + it('experimental feature NOT configured and no console warn', () => { + assert.equal(GenericHelpers.requestExperimentalFeature('tets', false), false); + sinon.assert.neverCalledWith(console.warn); + }); + }); }); diff --git a/core/test/utilities/helpers/navigation-helpers.spec.js b/core/test/utilities/helpers/navigation-helpers.spec.js index 36a2074bb4..56213c5822 100644 --- a/core/test/utilities/helpers/navigation-helpers.spec.js +++ b/core/test/utilities/helpers/navigation-helpers.spec.js @@ -4,7 +4,7 @@ const chai = require('chai'); const assert = chai.assert; const sinon = require('sinon'); import { AuthHelpers, NavigationHelpers, RoutingHelpers } from '../../../src/utilities/helpers'; -import { LuigiAuth, LuigiConfig } from '../../../src/core-api'; +import { LuigiAuth, LuigiConfig, LuigiFeatureToggles } from '../../../src/core-api'; import { Routing } from '../../../src/services/routing'; import { Navigation } from '../../../src/navigation/services/navigation'; @@ -562,7 +562,141 @@ describe('Navigation-helpers', () => { assert.equal(NavigationHelpers.generateTooltipText(node, 'LuigiNode'), ''); }); }); - + describe('check visible for feature toggles', () => { + let nodeToCheckPermission; + beforeEach(() => { + nodeToCheckPermission = { + visibleForFeatureToggles: ['testFt'] + }; + sinon.stub(LuigiFeatureToggles, 'getActiveFeatureToggleList'); + }); + afterEach(() => { + sinon.restore(); + }); + it('Node is visible with Ft "testFT"', async () => { + LuigiFeatureToggles.getActiveFeatureToggleList.returns(['testFt']); + assert.equal(NavigationHelpers.checkVisibleForFeatureToggles(nodeToCheckPermission), true); + }); + it('Node is NOT visible with Ft "testFT2"', async () => { + nodeToCheckPermission.visibleForFeatureToggles = ['!testFt2']; + LuigiFeatureToggles.getActiveFeatureToggleList.returns(['testFt', 'testFt2']); + assert.equal(NavigationHelpers.checkVisibleForFeatureToggles(nodeToCheckPermission), false); + }); + it('Node is NOT visible with Ft "testFT"', async () => { + LuigiFeatureToggles.getActiveFeatureToggleList.returns(['test']); + assert.equal(NavigationHelpers.checkVisibleForFeatureToggles(nodeToCheckPermission), false); + }); + }); + describe('generate top nav nodes', () => { + let pathData; + beforeEach(() => { + pathData = [ + { + children: [ + { + pathSegment: 'overview', + label: 'overview', + viewUrl: 'https://fiddle.luigi-project.io/examples/microfrontends/multipurpose.html' + }, + { + pathSegment: 'projects', + label: 'Projects', + viewUrl: 'https://fiddle.luigi-project.io/examples/microfrontends/multipurpose.html', + children: [ + { + pathSegment: 'settings', + label: 'Settings', + viewUrl: 'https://fiddle.luigi-project.io/examples/microfrontends/multipurpose.html' + } + ] + }, + { + pathSegment: 'user_management', + label: 'User Management', + category: { label: 'test' }, + viewUrl: 'https://fiddle.luigi-project.io/examples/microfrontends/multipurpose.html', + children: [ + { + pathSegment: 'developers', + label: 'Developers', + viewUrl: 'https://fiddle.luigi-project.io/examples/microfrontends/multipurpose.html' + } + ] + } + ] + }, + { + pathSegment: 'overview', + label: 'overview', + viewUrl: 'https://fiddle.luigi-project.io/examples/microfrontends/multipurpose.html' + } + ]; + }); + it('check visible nodes and children of top nav', async () => { + let tnd = await NavigationHelpers.generateTopNavNodes(pathData); + assert.equal(tnd.visibleNodeCount, 3); + assert.equal(tnd.children[0].label, 'overview'); + assert.equal(tnd.children[1].label, 'Projects'); + assert.equal(tnd.children[2].label, 'test'); + assert.equal(tnd.children[2].isCat, true); + }); + }); + describe('prepare for test id if no testId is configured', () => { + it('prepare test id', () => { + assert.equal(NavigationHelpers.prepareForTests('Te st'), 'test'); + assert.equal(NavigationHelpers.prepareForTests('TEST'), 'test'); + assert.equal(NavigationHelpers.prepareForTests('te&st'), 'te%26st'); + assert.equal(NavigationHelpers.prepareForTests(''), ''); + assert.equal(NavigationHelpers.prepareForTests('Das', 'ist', 'ein', 'Test'), 'das_ist_ein_test'); + }); + }); + describe('load and store expanded categories', () => { + beforeEach(() => { + global['localStorage'] = { + getItem: sinon.stub(), + setItem: sinon.stub() + }; + }); + afterEach(() => { + sinon.restore(); + sinon.reset(); + }); + it('load expanded category', () => { + localStorage.getItem.returns('["home:cat"]'); + assert.deepEqual(NavigationHelpers.loadExpandedCategories(), ['home:cat']); + }); + it('load expanded categories', () => { + localStorage.getItem.returns('["home:cat1", "home:cat2"]'); + assert.deepEqual(NavigationHelpers.loadExpandedCategories(), ['home:cat1', 'home:cat2']); + }); + it('store expanded state with empty expanded cat', () => { + const expandedList = NavigationHelpers.storeExpandedState('home:cat', true); + sinon.assert.calledWithExactly( + global.localStorage.setItem, + 'luigi.preferences.navigation.expandedCategories', + JSON.stringify(['home:cat']) + ); + assert.deepEqual(expandedList, ['home:cat']); + }); + it('store expanded state with stored cat', () => { + sinon.stub(NavigationHelpers, 'loadExpandedCategories').returns(['home:cat', 'home:cat2']); + assert.deepEqual(NavigationHelpers.storeExpandedState('home:cat2', true), ['home:cat', 'home:cat2']); + sinon.assert.calledWithExactly( + global.localStorage.setItem, + 'luigi.preferences.navigation.expandedCategories', + JSON.stringify(['home:cat', 'home:cat2']) + ); + }); + it('store expanded state with stored cat', () => { + sinon.stub(NavigationHelpers, 'loadExpandedCategories').returns(['home:cat', 'home:cat2']); + assert.deepEqual(NavigationHelpers.storeExpandedState('home:cat2', false), ['home:cat']); + sinon.assert.calledWithExactly( + global.localStorage.setItem, + 'luigi.preferences.navigation.expandedCategories', + JSON.stringify(['home:cat']) + ); + }); + }); describe('renderIconClassName', () => { it('should render sap-icon to standard icon suite', () => { assert.equal(NavigationHelpers.renderIconClassName('home'), 'sap-icon--home'); @@ -580,4 +714,4 @@ describe('Navigation-helpers', () => { assert.equal(NavigationHelpers.renderIconClassName(''), ''); }); }); -}); +}); \ No newline at end of file