generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* dynamic ushell src * require sap ushell * review comments * Create preview-2.0.md * add window type * eslint * fix: eslint * fix: eslint, review comments * fix: run-time error with bootstrap * fix: move call of initConnectors * unit test for bootstrap * fix: sap.ui.define wrapper * cleanup of container type * obsolete code * added error handling if version info is not found * reverting change in ui5-proxy * eslint fixes * fix erroneous usage of sap-ui-version.json * refactoring of VersionInfo.load() usage --------- Co-authored-by: Tobias Queck <[email protected]> Co-authored-by: D048415 <[email protected]> Co-authored-by: Klaus Keller <[email protected]> Co-authored-by: Dominik Heim <[email protected]>
- Loading branch information
1 parent
13d5ee5
commit ab2e5a0
Showing
23 changed files
with
232 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@sap-ux-private/preview-middleware-client": patch | ||
"@sap-ux/preview-middleware": patch | ||
--- | ||
|
||
Preview support for UI5 2.x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment, | ||
@typescript-eslint/no-unsafe-member-access, | ||
@typescript-eslint/no-unsafe-assignment, | ||
@typescript-eslint/no-unsafe-argument, | ||
no-console */ | ||
|
||
/** | ||
* Calculates the script content for accessing the right sap/ushell/bootstrap sandbox. | ||
* @param fnCallback {Function} The callback function to be executed after the bootstrap is loaded. | ||
*/ | ||
async function ushellBootstrap(fnCallback) { | ||
let src = '/test-resources/sap/ushell/bootstrap/sandbox.js'; | ||
try { | ||
const response = await fetch('/resources/sap-ui-version.json'); | ||
const json = await response.json(); | ||
const version = json?.libraries?.find((lib) => lib.name === 'sap.ui.core')?.version; | ||
const major = version ? parseInt(version.split('.')[0], 10) : 2; | ||
if (major >= 2) { | ||
src = '/resources/sap/ushell/bootstrap/sandbox2.js'; | ||
} | ||
} catch (error) { | ||
console.warn('Failed to fetch sap-ui-version.json. Assuming it is a 1.x version.'); | ||
} | ||
|
||
// eslint-disable-next-line fiori-custom/sap-no-dom-access,fiori-custom/sap-browser-api-warning | ||
const shellBootstrap = document.getElementById('sap-ushell-bootstrap'); | ||
if (shellBootstrap) { | ||
shellBootstrap.onload = () => { | ||
window['sap-ui-config']['xx-bootTask'](fnCallback); | ||
}; | ||
shellBootstrap.setAttribute('src', src); | ||
} | ||
} | ||
|
||
// eslint-disable-next-line fiori-custom/sap-no-global-define | ||
window['sap-ui-config'] = { | ||
'xx-bootTask': ushellBootstrap | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/preview-middleware-client/test/unit/flp/bootstrap.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { documentMock } from 'mock/window'; | ||
import '../../../src/flp/bootstrap'; | ||
import { Window } from '../../../types/global'; | ||
|
||
describe('flp/ushellBootstrap', () => { | ||
const htmlElement = { | ||
onload: jest.fn(), | ||
setAttribute: jest.fn() | ||
}; | ||
documentMock.getElementById.mockReturnValue(htmlElement); | ||
const fetchMock = jest.spyOn(global, 'fetch'); | ||
|
||
const ushellBootstrap = (window as unknown as Window)['sap-ui-config']['xx-bootTask']; | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('xx-boottask defined', () => { | ||
expect(ushellBootstrap).toBeDefined(); | ||
}); | ||
|
||
test('ushell src when ui5 version is 1.x', async () => { | ||
fetchMock.mockResolvedValueOnce({ | ||
json: () => Promise.resolve({ libraries: [{name: 'sap.ui.core', version: '1.126.0'}] }) | ||
} as jest.Mocked<Response>); | ||
|
||
await ushellBootstrap(() => {}); | ||
expect(htmlElement.setAttribute).toHaveBeenCalledWith('src', '/test-resources/sap/ushell/bootstrap/sandbox.js'); | ||
}); | ||
|
||
test('ushell src when ui5 version is 2.0', async () => { | ||
fetchMock.mockResolvedValue({ | ||
json: () => Promise.resolve({ libraries: [{name: 'sap.ui.core', version: '2.0.0'}] }) | ||
} as jest.Mocked<Response>); | ||
|
||
await ushellBootstrap(() => {}); | ||
expect(htmlElement.setAttribute).toHaveBeenCalledWith('src', '/resources/sap/ushell/bootstrap/sandbox2.js'); | ||
}); | ||
|
||
test('fetching version failed', async () => { | ||
fetchMock.mockRejectedValueOnce('404'); | ||
|
||
await ushellBootstrap(() => {}); | ||
expect(htmlElement.setAttribute).toHaveBeenCalledWith('src', '/test-resources/sap/ushell/bootstrap/sandbox.js'); | ||
}); | ||
}); |
Oops, something went wrong.