Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(framework): support sap-* config URL params #3138

Merged
merged 4 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/base/hash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
WeIr8BhWti5PEgIpG30j/drpLD4=
KJ0tn0Kg8EEEQiQ6XKfqbAsP3eQ=
27 changes: 20 additions & 7 deletions packages/base/src/InitialConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,36 @@ const parseConfigurationScript = () => {
const parseURLParameters = () => {
const params = new URLSearchParams(window.location.search);

// Process "sap-*" params first
params.forEach((value, key) => {
if (!key.startsWith("sap-ui")) {
const parts = key.split("sap-").length;
if (parts === 0 || parts === key.split("sap-ui-").length) {
return;
}

const lowerCaseValue = value.toLowerCase();

const param = key.split("sap-ui-")[1];
applyURLParam(key, value, "sap");
});

if (booleanMapping.has(value)) {
value = booleanMapping.get(lowerCaseValue);
// Process "sap-ui-*" params
params.forEach((value, key) => {
if (!key.startsWith("sap-ui")) {
return;
}

initialConfig[param] = value;
applyURLParam(key, value, "sap-ui");
});
};

const applyURLParam = (key, value, paramType) => {
const lowerCaseValue = value.toLowerCase();
const param = key.split(`${paramType}-`)[1];

if (booleanMapping.has(value)) {
value = booleanMapping.get(lowerCaseValue);
}
initialConfig[param] = value;
};

const applyOpenUI5Configuration = () => {
const OpenUI5Support = getFeature("OpenUI5Support");
if (!OpenUI5Support || !OpenUI5Support.isLoaded()) {
Expand Down
48 changes: 47 additions & 1 deletion packages/base/test/specs/ConfigurationURL.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const assert = require("chai").assert;

describe("Some settings can be set via URL params", () => {
describe("Some settings can be set via SAP UI URL params", () => {
before(() => {
browser.url("http://localhost:9191/test-resources/pages/Configuration.html?sap-ui-rtl=true&sap-ui-language=ja&sap-ui-calendarType=Japanese&sap-ui-theme=sap_belize_hcb&sap-ui-animationMode=basic");
});
Expand Down Expand Up @@ -45,3 +45,49 @@ describe("Some settings can be set via URL params", () => {
assert.strictEqual(res, 'basic', "animationMode is basic");
});
});


describe("Some settings can be set via SAP URL params", () => {
before(() => {
browser.url("http://localhost:9191/test-resources/pages/Configuration.html?sap-language=bg&sap-theme=sap_fiori_3_dark");
});

it("Tests that language is applied", () => {
const res = browser.execute( () => {
const config = window['sap-ui-webcomponents-bundle'].configuration;
return config.getLanguage();
});
assert.strictEqual(res, 'bg', "language is bulgarian");
});

it("Tests that theme is applied", () => {
const res = browser.execute( () => {
const config = window['sap-ui-webcomponents-bundle'].configuration;
return config.getTheme();
});
assert.strictEqual(res, 'sap_fiori_3_dark', "Thems is Fiori Dark");
});
});


describe("SAP UI params take precedence over the SAP params", () => {
before(() => {
browser.url("http://localhost:9191/test-resources/pages/Configuration.html?sap-language=bg&sap-ui-language=de&sap-theme=sap_fiori_3_dark&sap-theme=sap_fiori_3_hcb");
});

it("Tests that language is applied via sap-ui-language", () => {
const res = browser.execute( () => {
const config = window['sap-ui-webcomponents-bundle'].configuration;
return config.getLanguage();
});
assert.strictEqual(res, 'de', "language is german");
});

it("Tests that theme is applied via sap-ui-theme", () => {
const res = browser.execute( () => {
const config = window['sap-ui-webcomponents-bundle'].configuration;
return config.getTheme();
});
assert.strictEqual(res, 'sap_fiori_3_hcb', "Thems is Fiori HCB");
});
});