Skip to content

Commit

Permalink
Increase test coverage (SAP#2450)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesDoberer authored Dec 27, 2021
1 parent d929658 commit 74ce03b
Show file tree
Hide file tree
Showing 13 changed files with 300 additions and 136 deletions.
2 changes: 1 addition & 1 deletion core/src/core-api/auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LuigiConfig } from './';
import { AuthStoreSvc, AuthLayerSvc } from '../services';

/* istanbul ignore file */
/**
* Authorization helpers
* @name Authorization
Expand Down
2 changes: 1 addition & 1 deletion core/src/core-api/dom-elements.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions core/src/core-api/theming.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class LuigiTheming {
* @example
* Luigi.theming().isThemingAvailable()
*/
isThemingAvailable() {
isThemingAvailable() /* istanbul ignore next */ {
return !!LuigiConfig.getConfigValue('settings.theming');
}

Expand All @@ -98,7 +98,7 @@ class LuigiTheming {
* @memberof Theming
* @private
*/
_init() {
_init() /* istanbul ignore next */ {
const setupViewUrlDecorator = () => {
/**
* Registers the viewUrl decorator
Expand Down
5 changes: 3 additions & 2 deletions core/src/core-api/ux.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class LuigiUX {
* @since 1.5.0
*/
collapseLeftSideNav(state) {
/* istanbul ignore next */
SemiCollapsibleNavigation.setCollapsed(state);
}

Expand All @@ -143,7 +144,7 @@ class LuigiUX {
* @memberof UX
* @since 1.7.1
*/
openUserSettings() {
openUserSettings() /* istanbul ignore next */ {
Luigi.openUserSettings();
}

Expand All @@ -152,7 +153,7 @@ class LuigiUX {
* @memberof UX
* @since 1.7.1
*/
closeUserSettings() {
closeUserSettings() /* istanbul ignore next */ {
Luigi.closeUserSettings();
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/iframe.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
1 change: 1 addition & 0 deletions core/src/services/messages-listeners.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*istanbul ignore file */
class MessagesListenersClass {
convertCustomMessageInternalToUser(internalMessage) {
return internalMessage.data;
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/split-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions core/src/utilities/helpers/generic-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -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/'));
Expand Down Expand Up @@ -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';
}
Expand Down
90 changes: 71 additions & 19 deletions core/test/services/iframe.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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(() => [
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
});
});
});
12 changes: 12 additions & 0 deletions core/test/services/routing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/');
});
});
});
Loading

0 comments on commit 74ce03b

Please sign in to comment.