Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
hardl committed Apr 11, 2024
2 parents 5992a28 + f4a7e45 commit 3d07264
Show file tree
Hide file tree
Showing 66 changed files with 3,115 additions and 1,338 deletions.
20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ The lerna-changelog tool detects changes based on PR labels and maps them to sec
-->


## [v2.10.0] (2024-04-09)

#### :rocket: Added
* [#3672](https://github.com/SAP/luigi/pull/3672) Add on close promise to Luigi Client openAsModal ([@hardl](https://github.com/hardl))
* [#3654](https://github.com/SAP/luigi/pull/3654) Cypress support for testing utilities ([@JohannesDoberer](https://github.com/JohannesDoberer))


#### :bug: Fixed
* [#3680](https://github.com/SAP/luigi/pull/3680) Fix global nav focus issue ([@hardl](https://github.com/hardl))
* [#3679](https://github.com/SAP/luigi/pull/3679) Fix loading indicator not going away when fast clicking multiple times to a nav node ([@hardl](https://github.com/hardl))
* [#3662](https://github.com/SAP/luigi/pull/3662) Fix runtime error ([@JohannesDoberer](https://github.com/JohannesDoberer))
* [#3646](https://github.com/SAP/luigi/pull/3646) Fix dynamic params for angular routing([@camelCaseChris](https://github.com/camelCaseChris))
* [#3652](https://github.com/SAP/luigi/pull/3652) Fix return type of compound container init ([@hardl](https://github.com/hardl))




## [v2.9.0] (2024-02-13)

#### :rocket: Added
Expand Down Expand Up @@ -1737,4 +1754,5 @@ The lerna-changelog tool detects changes based on PR labels and maps them to sec
[v2.7.4]: https://github.com/SAP/luigi/compare/v2.7.3...v2.7.4
[v2.7.5]: https://github.com/SAP/luigi/compare/v2.7.4...v2.7.5
[v2.8.0]: https://github.com/SAP/luigi/compare/v2.7.5...v2.8.0
[v2.9.0]: https://github.com/SAP/luigi/compare/v2.8.0...v2.9.0
[v2.9.0]: https://github.com/SAP/luigi/compare/v2.8.0...v2.9.0
[v2.10.0]: https://github.com/SAP/luigi/compare/v2.9.0...v2.10.0
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# The last matching pattern has the most precedence.
# For more details, read the following article on GitHub: https://help.github.com/articles/about-codeowners/.
# These are the default owners for the whole content of the `luigi` repository. The default owners are automatically added as reviewers when you open a pull request, unless different owners are specified in the file.
* @alexandra-simeonova @hardl @johannesdoberer @ndricimrr @vincentullal @camelCaseChris
* @hardl @johannesdoberer @ndricimrr @vincentullal @smahati
2 changes: 1 addition & 1 deletion bundle-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const filesAndLimits = [
},
{
path: 'core/public/luigi.css',
limit: 900
limit: 1000
},
{
path: 'plugins/auth/public/auth-oauth2/plugin.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
},
"peerDependencies": {
"@angular/common": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0",
"@angular/core": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0",
"@luigi-project/client": "^2.0.0",
"@luigi-project/testing-utilities": "^2.0.0"
"@angular/core": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
},
"dependencies": {
"tslib": "^2.0.0"
Expand All @@ -22,5 +20,5 @@
"@luigi-project/client": "^2.0.0",
"@luigi-project/testing-utilities": "^2.0.0"
},
"version": "2.9.0"
"version": "2.10.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,155 +23,4 @@ import { LuigiMockEngine } from '@luigi-project/testing-utilities';
* global message event of the window object and mocking the callback.
* In the normal workflow this message would picked up by Luigi Core which then sends the response back.
*/
export class LuigiMockModule {
// Add a hook to the post message api to mock the LuigiCore response to the Client
public static initPostMessageHook() {
return async (): Promise<void> => {
// Check if Luigi Client is running standalone
if (window.parent === window) {
console.debug('Detected standalone mode');

// Check and skip if Luigi environment is already mocked
if ((window as any).luigiMockEnvironment) {
return;
}

// mock target origin
if ((window as any).LuigiClient) {
(window as any).LuigiClient.setTargetOrigin('*');
}

(window as any).luigiMockEnvironment = {
msgListener: function(e: any) {
if (e.data.msg && (e.data.msg.startsWith('luigi.') || e.data.msg === 'storage')) {
console.debug('Luigi msg', e.data);

if (e.data.msg === 'luigi.get-context') {
window.postMessage(
{
msg: 'luigi.init',
emulated: true,
internal: {
viewStackSize: 1
},
context: e.data.context
},
'*'
);
}

// vizualise retrieved event data
LuigiMockEngine.visualize(JSON.stringify(e.data));

// Check and run mocked callback if it exists
const mockListener = (window as any).luigiMockEnvironment.mockListeners[e.data.msg];
if (mockListener) {
mockListener(e);
}
}
},
mockListeners: {
'luigi.navigation.pathExists': (event: any) => {
const mockData = window.sessionStorage.getItem('luigiMockData');
let mockDataParsed = mockData ? JSON.parse(mockData) : undefined;
const inputPath = event.data.data.link;
const pathExists = mockDataParsed && mockDataParsed.pathExists && mockDataParsed.pathExists[inputPath];

const response = {
msg: 'luigi.navigation.pathExists.answer',
data: {
correlationId: event.data.data.id,
pathExists: pathExists ? pathExists : false
},
emulated: true
};
window.postMessage(response, '*');
},
//ux
'luigi.ux.confirmationModal.show': (event: any) => {
const response = {
msg: 'luigi.ux.confirmationModal.hide',
data: event.data,
emulated: true
};
window.postMessage(response, '*');
},
'luigi.ux.alert.show': (event: any) => {
const response = {
msg: 'luigi.ux.alert.hide',
data: event.data,
emulated: true
};
window.postMessage(response, '*');
},
'luigi.ux.set-current-locale': (event: any) => {
const response = {
msg: 'luigi.current-locale-changed',
currentLocale: event.data.data.currentLocale,
emulated: true
};
window.postMessage(response, '*');
},
// linkManager
'luigi.navigation.open': (event: any) => {
const response = {
msg: 'luigi.navigate.ok',
data: event.data,
emulated: true
};
window.postMessage(response, '*');
},
'luigi.navigation.splitview.close': (event: any) => {
const response = {
msg: 'luigi.navigate.ok',
data: event.data,
emulated: true
};
window.postMessage(response, '*');
},
'luigi.navigation.splitview.collapse': (event: any) => {
const response = {
msg: 'luigi.navigate.ok',
data: event.data,
emulated: true
};
window.postMessage(response, '*');
},
'luigi.navigation.splitview.expand': (event: any) => {
const response = {
msg: 'luigi.navigate.ok',
data: event.data,
emulated: true
};
window.postMessage(response, '*');
},
// storage
storage: () => {}
}
};

// Listen to the global 'message' event of the window object
window.addEventListener('message', (window as any).luigiMockEnvironment.msgListener);
}
};
}

/*
* This method takes a data object of type 'any' and vizualizes a simple container
* which holds data that is useful for e2e testing.
*/
public static visualize(data: string): void {
let luigiVisualizationContainer: Element | null = document.querySelector('#luigi-debug-vis-cnt');
// Construct element structure if not already constructed
if (!luigiVisualizationContainer) {
luigiVisualizationContainer = document.createElement('div');
luigiVisualizationContainer.setAttribute('id', 'luigi-debug-vis-cnt');
// Hide the added DOM element to avoid interferring/overlapping with other elements during testing.
luigiVisualizationContainer.setAttribute('style', 'display:none');
document.body.appendChild(luigiVisualizationContainer);
}
const line: HTMLDivElement = document.createElement('div');
line.textContent = data;
luigiVisualizationContainer.appendChild(line);
}
}
export class LuigiMockModule { }
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"microfrontends",
"testing"
],
"version": "2.9.0",
"version": "2.10.0",
"engines": {
"node": ">=18"
}
Expand Down
4 changes: 2 additions & 2 deletions client-frameworks-support/testing-utilities/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client-frameworks-support/testing-utilities/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"microfrontends",
"testing"
],
"version": "2.9.0",
"version": "2.10.0",
"engines": {
"node": ">=18"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ export class LuigiMockEngine {
(window as any).luigiMockEnvironment = {
msgListener: function (e: any) {
if (e.data.msg && (e.data.msg.startsWith('luigi.') || e.data.msg === 'storage')) {
console.debug('Luigi msg', e.data);

if (e.data.msg === 'luigi.get-context') {
window.postMessage(
{
Expand Down
44 changes: 31 additions & 13 deletions client-frameworks-support/testing-utilities/src/luigi-mock-util.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
export class LuigiMockUtil {
private messages: any[];
private browser: any;
private win: any

constructor(browser: any) {
constructor(browser: any, win?: any) {
this.messages = [];
this.browser = browser;
this.win = win;
}

/**
* Returns the global window object.
* @returns the glboal win object
*/

private getGlobalThis(): any {
return this.win || globalThis;
}


/**
* Parses the elements added by LuigiMockModule into the DOM and assigns them to the local this.messages variable
* @returns {Promise<void>} - A Promise that resolves when parsing is complete.
*/
async parseLuigiMockedMessages(): Promise<void> {
try {
const getTextNodeValues = async () =>
Array.from(document.getElementById('luigi-debug-vis-cnt').childNodes).map((item) => item.textContent);
const getTextNodeValues = () => {
const targetDocument = this.getGlobalThis();
const debugCtn = targetDocument.getElementById('luigi-debug-vis-cnt');
return Array.from(debugCtn?.childNodes || []).map((item: any) => item.textContent || '');
}

const textElements: string[] = this.browser.executeScript
? await this.browser.executeScript(getTextNodeValues)
: await this.browser(getTextNodeValues);

this.messages = textElements
.map((item: string) => {
try {
Expand All @@ -34,19 +49,21 @@ export class LuigiMockUtil {
}

/**
* Mocks the context by sending luigi context messegaes with the desired mocked context as parameter.
* Mocks the context by sending luigi context messages with the desired mocked context as parameter.
* @param mockContext an object representing the context to be mocked
*/
mockContext = (mockContext: any): void => {
const postMessageToLuigi = (context: any) => {
globalThis.postMessage({ msg: 'luigi.get-context', context }, '*');
const context = mockContext;
const targetDocument = this.getGlobalThis();
const postMessageToLuigi = () => {
targetDocument.postMessage({ msg: 'luigi.get-context', context }, '*');
};

try {
if (this.browser.executeScript) {
this.browser.executeScript(postMessageToLuigi, mockContext);
this.browser.executeScript(postMessageToLuigi, context);
} else {
this.browser(postMessageToLuigi, mockContext);
this.browser(postMessageToLuigi);
}
} catch (e) {
console.debug('Failed to mock context: ', e);
Expand All @@ -70,20 +87,21 @@ export class LuigiMockUtil {
*
*/
mockPathExists = (path: string, exists: boolean): void => {
const targetDocument = this.getGlobalThis();
/**
* Sets the path exists mock data in sessionStorage.
* @param {string} path - The path for which mock data is to be set.
* @param {boolean} exists - Boolean indicating whether the path exists.
* @returns {void}
*/
const setPathExistsMockData = (path: string, exists: boolean) => {
globalThis.sessionStorage.clear();
const setPathExistsMockData = () => {
targetDocument.sessionStorage.clear();
let pathExistsMockData = {
pathExists: {
[path]: exists
}
};
globalThis.sessionStorage.setItem('luigiMockData', JSON.stringify(pathExistsMockData));
targetDocument.sessionStorage.setItem('luigiMockData', JSON.stringify(pathExistsMockData));
};
try {
if (this.browser.executeScript) {
Expand Down Expand Up @@ -153,4 +171,4 @@ export class LuigiMockUtil {
getMSG() {
return this.messages;
}
}
}
8 changes: 6 additions & 2 deletions client/luigi-client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,14 @@ export declare interface LinkManager {
* @param {string} modalSettings.height lets you specify a precise height for the modal. Allowed units are 'px', '%', 'rem', 'em', 'vh' and 'vw'.
* @param {boolean} modalSettings.keepPrevious Lets you open multiple modals. Keeps the previously opened modal and allows to open another modal on top of the previous one. By default the previous modals are discarded.
* @param {string} modalSettings.closebtn_data_testid lets you specify a `data_testid` for the close button. Default value is `lui-modal-index-0`. If multiple modals are opened the index will be increased per modal.
* @returns {promise} which is resolved when closing the modal. By using LuigiClient.linkManager().goBack({ foo: 'bar' }) to close the modal you have access the `goBackContext` when the promise will be resolved.
* @example
* LuigiClient.linkManager().openAsModal('projects/pr1/users', {title:'Users', size:'m'});
* LuigiClient.linkManager().openAsModal('projects/pr1/users', {title:'Users', size:'m'}).then((res) => {
* // Logic to execute when the modal will be closed
* console.log(res.data) //=> {foo: 'bar'}
* });
*/
openAsModal: (nodepath: string, modalSettings?: ModalSettings) => void;
openAsModal: (nodepath: string, modalSettings?: ModalSettings) => Promise<void>;

/**
* Updates the current title and size of a modal. If `routing.showModalPathInUrl` is set to `true`, the URL will be updated with the modal settings data.
Expand Down
2 changes: 1 addition & 1 deletion client/public/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"micro-frontends",
"microfrontends"
],
"version": "2.9.0"
"version": "2.10.0"
}
Loading

0 comments on commit 3d07264

Please sign in to comment.