Skip to content

Commit d45b5a4

Browse files
authored
fix(fpm-writer): custom form field view.xml update (#4605)
* fix issue on formelement view format * fix after comments * Create dirty-pets-listen.md * rename unit test after comment * update snapshot
1 parent 462c41f commit d45b5a4

4 files changed

Lines changed: 17 additions & 17 deletions

File tree

.changeset/dirty-pets-listen.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sap-ux/fe-fpm-writer": patch
3+
---
4+
5+
fix(fpm-writer): custom form field view.xml update
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
<% if (!config?.hasAggregation) { %><<%- macrosNamespace %>:fields><% } %>
2-
<<%- config?.aggregationNamespace %>:FormElement
1+
<<%- config?.aggregationNamespace %>:FormElement
32
<% if (data.formElementKey) { %> key="<%- data.formElementKey %>"<% } %>
43
label="<%- data.label %>"
54
<% if (data.id) { %> id="<%- data.id %>"<% } %>
65
<% if (data.metaPath) { %> metaPath="<%- data.metaPath %>"<% } %>
76
<% if (data.contextPath) { %> contextPath="<%- data.contextPath %>"<% } %>
87
<% if (data.position?.anchor) { %> anchor="<%- data.position.anchor %>"<% } %>
98
<% if (data.position?.placement) { %> placement="<%- data.position.placement %>"<% } %>>
10-
<<%- macrosNamespace %>:fields>
9+
<<%- config?.aggregationNamespace %>:fields>
1110
<core:Fragment fragmentName="<%- data.embededFragment.ns %>.<%- data.embededFragment.name %>" type="XML" />
12-
</<%- macrosNamespace %>:fields>
11+
</<%- config?.aggregationNamespace %>:fields>
1312
</<%- config?.aggregationNamespace %>:FormElement>
14-
<% if (!config?.hasAggregation) { %></<%- macrosNamespace %>:fields><% } %>

packages/fe-fpm-writer/test/unit/__snapshots__/building-block.test.ts.snap

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -767,18 +767,16 @@ exports[`Building Blocks CustomFormField building block generate CustomFormField
767767
</mvc:View>"
768768
`;
769769
770-
exports[`Building Blocks CustomFormField building block generate CustomFormField without macros:fields - creates aggregation: generate-custom-form-field-without-fields 1`] = `
770+
exports[`Building Blocks CustomFormField building block generate CustomFormField without macros:fields - inserts FormElement directly into Form: generate-custom-form-field-without-fields 1`] = `
771771
"<mvc:View xmlns:core=\\"sap.ui.core\\" xmlns:mvc=\\"sap.ui.core.mvc\\" xmlns=\\"sap.m\\" xmlns:html=\\"http://www.w3.org/1999/xhtml\\" controllerName=\\"com.test.myApp.ext.main.Main\\" xmlns:macros=\\"sap.fe.macros\\">
772772
<Page title=\\"Main\\">
773773
<content>
774774
<macros:Form id=\\"myForm\\" metaPath=\\"@com.sap.vocabularies.UI.v1.FieldGroup#General\\">
775-
<macros:fields>
776-
<macros:FormElement label=\\"Custom Form Field 2\\" id=\\"testCustomFormField2\\" anchor=\\"DataField::AnotherProperty\\" placement=\\"Before\\">
777-
<macros:fields>
778-
<core:Fragment fragmentName=\\"my.test.App.ext.fragment.CustomFormField2\\" type=\\"XML\\"/>
779-
</macros:fields>
780-
</macros:FormElement>
781-
</macros:fields>
775+
<macros:FormElement label=\\"Custom Form Field 2\\" id=\\"testCustomFormField2\\" anchor=\\"DataField::AnotherProperty\\" placement=\\"Before\\">
776+
<macros:fields>
777+
<core:Fragment fragmentName=\\"my.test.App.ext.fragment.CustomFormField2\\" type=\\"XML\\"/>
778+
</macros:fields>
779+
</macros:FormElement>
782780
</macros:Form>
783781
</content>
784782
</Page>

packages/fe-fpm-writer/test/unit/building-block.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3065,7 +3065,7 @@ describe('Building Blocks', () => {
30653065
await writeFilesForDebugging(fs);
30663066
});
30673067

3068-
test('generate CustomFormField without macros:fields - creates aggregation', async () => {
3068+
test('generate CustomFormField without macros:fields - inserts FormElement directly into Form', async () => {
30693069
const basePath = join(testAppPath, 'generate-custom-form-field-without-fields');
30703070
const aggregationPath = `/mvc:View/*[local-name()='Page']/*[local-name()='content']/macros:Form`;
30713071
const customFormFieldData: CustomFormField = {
@@ -3105,9 +3105,8 @@ describe('Building Blocks', () => {
31053105

31063106
const viewContent = fs.read(join(basePath, xmlViewFilePath));
31073107
expect(viewContent).toMatchSnapshot('generate-custom-form-field-without-fields');
3108-
expect(viewContent).toContain('<macros:fields>');
3109-
expect(viewContent).toMatch(/<macros:fields>[\s\S]*FormElement[\s\S]*<\/macros:fields>/);
3110-
expect(viewContent).toContain('FormElement');
3108+
expect(viewContent).not.toMatch(/<macros:fields>[\s\S]*<macros:FormElement/);
3109+
expect(viewContent).toContain('<macros:FormElement');
31113110
expect(viewContent).toContain('Custom Form Field 2');
31123111
expect(viewContent).toContain('anchor="DataField::AnotherProperty"');
31133112
expect(viewContent).toContain('placement="Before"');

0 commit comments

Comments
 (0)