UNPKG

@luigi-project/testing-utilities

Version:

Luigi testing utilities for standalone testing of microfrontends

97 lines (96 loc) 3.99 kB
export declare class LuigiMockUtil { private sessionStorageItemName; private visualizationContainerId; private messages; private browser; private win; constructor(browser: any, win?: any); /** * 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. */ parseLuigiMockedMessages(): Promise<void>; /** * 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: Record<string, any>): void; /** * This method serves as a mock for the luigi client pathExists() function. * It is used in e2e tests when component being tested utilizes a call to `LuigiClient.linkManager().pathExists()` * * @param path the path to check * @param exists mocked boolean representing if path should exist or not * @example For the following call in your angular component: * `LuigiClient.linkManager().pathExists('pathToCheck')` * * // You need to call the following to mock pathExists() returning `true` for a given 'pathToCheck': * await mockPathExists('pathToCheck', true); * * // You need to call the following to mock pathExists() returning `false` for a given 'pathToCheck': * await mockPathExists('pathToCheck', false); * */ mockPathExists(path: string, exists: boolean): void; /** * Checks on the printed DOM Luigi message responses for a modal with given title * having been opened. In such a case a message would be printed containing a modal.title. * Returns false if not such element was found. * @param title the title of the modal * @example * Format of the targeted message example: * { * msg: 'luigi.navigation.open', * sessionId: 0, * params: { * preserveView: true, * nodeParams: { mode: 'modal' }, * errorSkipNavigation: false, * fromContext: null, * fromClosestContext: false, * fromVirtualTreeRoot: false, * fromParent: true, * relative: true, * link: 'templates', * intent: false, * modal: { title: 'Create Component from Template' } // element to check * } * } * */ modalOpenedWithTitle(title: string): Promise<boolean>; /** * Returns output of 'mockContext' method with given data. * @param {Object} context - Object representing the context to be mocked. * @returns {string} - Stringified output of 'mockContext' method. */ getMockedContextOutput(context: Record<string, any>): string; /** * Returns output of 'mockPathExists' method with given arguments. * @param {string} path - The path for which mock data is to be set. * @param {boolean} exists - Boolean indicating whether the path exists. * @returns {string} - Stringified output of 'mockPathExists' method. */ getMockedPathExistsOutput(path: string, exists: boolean): string; /** * Returns parsed session storage data used for testing. * @param {Object} data - Object or string representing the data to be cleaned. * @returns {string} - Stringified session storage data. */ getCleanSessionStorageData(data: any): string; /** * Returns ID of Luigi visualization container added in the DOM for testing. * @returns {string} - ID of Luigi visualization container. */ getVisualizationContainerId(): string; /** * Returns list of messages, representing message elements added in the DOM for testing. * @returns {Array} - Array of message elements. */ getMSG(): any[]; /** * Returns the global window object. * @returns the global win object */ private getGlobalThis; }