From 112170a1112709160066443971e148811556b65f Mon Sep 17 00:00:00 2001 From: Andis Redmans <90789422+815are@users.noreply.github.com> Date: Wed, 14 Feb 2024 14:32:58 +0200 Subject: [PATCH] fix(fpm-writer): use correct namespace when generating typescript controllers of controller extension and custom page controllers (#1661) * fix: controller extension namespace issue using template for typescript controller extension namespace issue using template for typescript * fix: use namespace solution for custom pages use namespace solution for custom pages * changelog changelog * fix: snapshot snapshot * test: additional tests for custom page additional tests for custom page * fix: test name test name --------- Co-authored-by: Tobias Queck --- .changeset/brown-nails-wonder.md | 5 ++ .../controller-extension/Controller.ts | 2 +- .../page/custom/1.84/ext/Controller.ts | 2 +- .../page/custom/1.94/ext/Controller.ts | 2 +- .../controller-extension.test.ts.snap | 14 +-- .../page/__snapshots__/custom.test.ts.snap | 90 +++++++++++++++++++ .../test/unit/page/custom.test.ts | 26 ++++++ .../test/__snapshots__/fpm.test.ts.snap | 2 +- 8 files changed, 132 insertions(+), 11 deletions(-) create mode 100644 .changeset/brown-nails-wonder.md diff --git a/.changeset/brown-nails-wonder.md b/.changeset/brown-nails-wonder.md new file mode 100644 index 0000000000..e183b6f0ef --- /dev/null +++ b/.changeset/brown-nails-wonder.md @@ -0,0 +1,5 @@ +--- +'@sap-ux/fe-fpm-writer': patch +--- + +fix: use correct namespace when generating typescript controllers of controller extension and custom page controllers diff --git a/packages/fe-fpm-writer/templates/controller-extension/Controller.ts b/packages/fe-fpm-writer/templates/controller-extension/Controller.ts index 72cf0fa55d..898f851744 100644 --- a/packages/fe-fpm-writer/templates/controller-extension/Controller.ts +++ b/packages/fe-fpm-writer/templates/controller-extension/Controller.ts @@ -2,7 +2,7 @@ import ControllerExtension from 'sap/ui/core/mvc/ControllerExtension'; import ExtensionAPI from 'sap/fe/<%- typeof extension === "object" ? `templates/${extension.pageType}` : "core" -%>/ExtensionAPI'; /** - * @namespace <%- ns %>.<%- name %> + * @namespace <%- ns %> * @controller */ export default class <%- name %> extends ControllerExtension { diff --git a/packages/fe-fpm-writer/templates/page/custom/1.84/ext/Controller.ts b/packages/fe-fpm-writer/templates/page/custom/1.84/ext/Controller.ts index f169de98bd..5a6f37587d 100644 --- a/packages/fe-fpm-writer/templates/page/custom/1.84/ext/Controller.ts +++ b/packages/fe-fpm-writer/templates/page/custom/1.84/ext/Controller.ts @@ -1,7 +1,7 @@ import Controller from 'sap/ui/core/mvc/Controller'; /** If UI5 version 1.94 or newer can be used, the change the base controller to sap/fe/core/PageController to get full FEv4 FPM support */ /** - * @namespace <%- ns %>.<%- name %>.controller + * @namespace <%- ns %> */ export default class <%- name %> extends Controller { diff --git a/packages/fe-fpm-writer/templates/page/custom/1.94/ext/Controller.ts b/packages/fe-fpm-writer/templates/page/custom/1.94/ext/Controller.ts index 90e74136dd..668199e86f 100644 --- a/packages/fe-fpm-writer/templates/page/custom/1.94/ext/Controller.ts +++ b/packages/fe-fpm-writer/templates/page/custom/1.94/ext/Controller.ts @@ -1,7 +1,7 @@ import Controller from "sap/fe/core/PageController"; /** - * @namespace <%- ns %>.<%- name %>.controller + * @namespace <%- ns %> */ export default class <%- name %> extends Controller { diff --git a/packages/fe-fpm-writer/test/unit/__snapshots__/controller-extension.test.ts.snap b/packages/fe-fpm-writer/test/unit/__snapshots__/controller-extension.test.ts.snap index f41d960261..eda3e38b3e 100644 --- a/packages/fe-fpm-writer/test/unit/__snapshots__/controller-extension.test.ts.snap +++ b/packages/fe-fpm-writer/test/unit/__snapshots__/controller-extension.test.ts.snap @@ -687,7 +687,7 @@ exports[`ControllerExtension generateControllerExtension Typescript controller N import ExtensionAPI from 'sap/fe/templates/ListReport/ExtensionAPI'; /** - * @namespace my.test.App.ext.controller.NewExtension + * @namespace my.test.App.ext.controller * @controller */ export default class NewExtension extends ControllerExtension { @@ -744,7 +744,7 @@ exports[`ControllerExtension generateControllerExtension Typescript controller N import ExtensionAPI from 'sap/fe/templates/ObjectPage/ExtensionAPI'; /** - * @namespace my.test.App.ext.controller.NewExtension + * @namespace my.test.App.ext.controller * @controller */ export default class NewExtension extends ControllerExtension { @@ -801,7 +801,7 @@ exports[`ControllerExtension generateControllerExtension Typescript controller N import ExtensionAPI from 'sap/fe/templates/ListReport/ExtensionAPI'; /** - * @namespace my.test.App.ext.controller.NewExtension + * @namespace my.test.App.ext.controller * @controller */ export default class NewExtension extends ControllerExtension { @@ -858,7 +858,7 @@ exports[`ControllerExtension generateControllerExtension Typescript controller N import ExtensionAPI from 'sap/fe/core/ExtensionAPI'; /** - * @namespace my.test.App.ext.controller.NewExtension + * @namespace my.test.App.ext.controller * @controller */ export default class NewExtension extends ControllerExtension { @@ -915,7 +915,7 @@ exports[`ControllerExtension generateControllerExtension Typescript controller N import ExtensionAPI from 'sap/fe/templates/ListReport/ExtensionAPI'; /** - * @namespace my.test.App.ext.controller.NewExtension + * @namespace my.test.App.ext.controller * @controller */ export default class NewExtension extends ControllerExtension { @@ -972,7 +972,7 @@ exports[`ControllerExtension generateControllerExtension Typescript controller N import ExtensionAPI from 'sap/fe/templates/ListReport/ExtensionAPI'; /** - * @namespace my.test.App.ext.controller.NewExtension + * @namespace my.test.App.ext.controller * @controller */ export default class NewExtension extends ControllerExtension { @@ -1029,7 +1029,7 @@ exports[`ControllerExtension generateControllerExtension Typescript controller N import ExtensionAPI from 'sap/fe/templates/ObjectPage/ExtensionAPI'; /** - * @namespace my.test.App.ext.controller.NewExtension + * @namespace my.test.App.ext.controller * @controller */ export default class NewExtension extends ControllerExtension { diff --git a/packages/fe-fpm-writer/test/unit/page/__snapshots__/custom.test.ts.snap b/packages/fe-fpm-writer/test/unit/page/__snapshots__/custom.test.ts.snap index 5dece0e550..5821b93716 100644 --- a/packages/fe-fpm-writer/test/unit/page/__snapshots__/custom.test.ts.snap +++ b/packages/fe-fpm-writer/test/unit/page/__snapshots__/custom.test.ts.snap @@ -15,6 +15,96 @@ exports[`CustomPage Test property custom "tabSizing" 6 spaces 1`] = ` CustomPageTitle=CustomPage" `; +exports[`CustomPage Typescript controller latest version with minimal input 1`] = ` +"import Controller from \\"sap/fe/core/PageController\\"; + +/** + * @namespace my.test.App.ext.customPage + */ +export default class CustomPage extends Controller { + + /** + * Called when a controller is instantiated and its View controls (if available) are already created. + * Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization. + * @memberOf my.test.App.ext.customPage.CustomPage + */ + // public onInit(): void { + // + //} + + /** + * Similar to onAfterRendering, but this hook is invoked before the controller's View is re-rendered + * (NOT before the first rendering! onInit() is used for that one!). + * @memberOf my.test.App.ext.customPage.CustomPage + */ + // public onBeforeRendering(): void { + // + // } + + /** + * Called when the View has been rendered (so its HTML is part of the document). Post-rendering manipulations of the HTML could be done here. + * This hook is the same one that SAPUI5 controls get after being rendered. + * @memberOf my.test.App.ext.customPage.CustomPage + */ + // public onAfterRendering(): void { + // + // } + + /** + * Called when the Controller is destroyed. Use this one to free resources and finalize activities. + * @memberOf my.test.App.ext.customPage.CustomPage + */ + // public onExit(): void { + // + // } +}" +`; + +exports[`CustomPage Typescript controller lower UI5 version(1.84) 1`] = ` +"import Controller from 'sap/ui/core/mvc/Controller'; /** If UI5 version 1.94 or newer can be used, the change the base controller to sap/fe/core/PageController to get full FEv4 FPM support */ + +/** + * @namespace my.test.App.ext.customPage + */ +export default class CustomPage extends Controller { + + /** + * Called when a controller is instantiated and its View controls (if available) are already created. + * Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization. + * @memberOf my.test.App.ext.customPage.CustomPage + */ + // public onInit(): void { + // + //} + + /** + * Similar to onAfterRendering, but this hook is invoked before the controller's View is re-rendered + * (NOT before the first rendering! onInit() is used for that one!). + * @memberOf my.test.App.ext.customPage.CustomPage + */ + // public onBeforeRendering(): void { + // + // } + + /** + * Called when the View has been rendered (so its HTML is part of the document). Post-rendering manipulations of the HTML could be done here. + * This hook is the same one that SAPUI5 controls get after being rendered. + * @memberOf my.test.App.ext.customPage.CustomPage + */ + // public onAfterRendering(): void { + // + // } + + /** + * Called when the Controller is destroyed. Use this one to free resources and finalize activities. + * @memberOf my.test.App.ext.customPage.CustomPage + */ + // public onExit(): void { + // + // } +}" +`; + exports[`CustomPage generateCustomPage: different navigations inbound navigation defined as array (for FCL) 1`] = ` Object { "config": Object { diff --git a/packages/fe-fpm-writer/test/unit/page/custom.test.ts b/packages/fe-fpm-writer/test/unit/page/custom.test.ts index 00b28c1852..c2fd5deb1d 100644 --- a/packages/fe-fpm-writer/test/unit/page/custom.test.ts +++ b/packages/fe-fpm-writer/test/unit/page/custom.test.ts @@ -272,4 +272,30 @@ describe('CustomPage', () => { expect(result).toEqual(expectedAfterSave); }); }); + + describe('Typescript controller', () => { + const minimalInput: CustomPage = { + name: 'CustomPage', + entity: 'RootEntity', + typescript: true + }; + test('latest version with minimal input', () => { + const target = join(testDir, 'minimal-input'); + fs.write(join(target, 'webapp/manifest.json'), testAppManifest); + //act + generateCustomPage(target, minimalInput, fs); + //check + expect(fs.read(join(target, 'webapp/ext/customPage/CustomPage.controller.ts'))).toMatchSnapshot(); + }); + + test('lower UI5 version(1.84)', () => { + const target = join(testDir, 'minimal-input'); + fs.write(join(target, 'webapp/manifest.json'), testAppManifest); + const testInput = { ...minimalInput, minUI5Version: '1.84.62' }; + //act + generateCustomPage(target, testInput, fs); + //check + expect(fs.read(join(target, 'webapp/ext/customPage/CustomPage.controller.ts'))).toMatchSnapshot(); + }); + }); }); diff --git a/packages/fiori-elements-writer/test/__snapshots__/fpm.test.ts.snap b/packages/fiori-elements-writer/test/__snapshots__/fpm.test.ts.snap index 0b08e94d84..ca4e661dd3 100644 --- a/packages/fiori-elements-writer/test/__snapshots__/fpm.test.ts.snap +++ b/packages/fiori-elements-writer/test/__snapshots__/fpm.test.ts.snap @@ -3965,7 +3965,7 @@ export default class Component extends BaseComponent { "contents": "import Controller from \\"sap/fe/core/PageController\\"; /** - * @namespace fefpmts.ext.main.Main.controller + * @namespace fefpmts.ext.main */ export default class Main extends Controller {