Skip to content

Commit

Permalink
fix(fpm-writer): use correct namespace when generating typescript con…
Browse files Browse the repository at this point in the history
…trollers 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 <[email protected]>
  • Loading branch information
815are and tobiasqueck authored Feb 14, 2024
1 parent c9bba4f commit 112170a
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-nails-wonder.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExtensionAPI> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Controller from "sap/fe/core/PageController";

/**
* @namespace <%- ns %>.<%- name %>.controller
* @namespace <%- ns %>
*/
export default class <%- name %> extends Controller {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExtensionAPI> {
Expand Down Expand Up @@ -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<ExtensionAPI> {
Expand Down Expand Up @@ -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<ExtensionAPI> {
Expand Down Expand Up @@ -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<ExtensionAPI> {
Expand Down Expand Up @@ -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<ExtensionAPI> {
Expand Down Expand Up @@ -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<ExtensionAPI> {
Expand Down Expand Up @@ -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<ExtensionAPI> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 26 additions & 0 deletions packages/fe-fpm-writer/test/unit/page/custom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 112170a

Please sign in to comment.