@sap-ux/ui5-test-writer 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -263,23 +263,68 @@ function extractSectionActions(section, convertedMetadata, schemaNamespace) {
263
263
  * @returns array of sub-section feature data
264
264
  */
265
265
  function extractBodySubSectionsData(section, parentSectionId, convertedMetadata, entitySetName) {
266
- const subSections = [];
267
- const subSectionsAggregation = getAggregations(section)['subsections'];
268
- const subSectionItems = getAggregations(subSectionsAggregation);
269
- Object.entries(subSectionItems).forEach(([subSectionKey, subSection]) => {
270
- const subSectionId = getSectionIdentifier(subSection) ?? `${parentSectionId}_${subSectionKey}`;
271
- const isTable = isTableSection(subSection);
272
- subSections.push({
273
- id: subSectionId,
274
- navigationProperty: getNavigationPropertyFromKey(subSectionKey),
275
- isTable,
276
- custom: !!subSection.custom,
277
- order: subSection?.order ?? -1, // put a negative order number to signal that order was not in spec
278
- fields: subSection.custom || isTable ? [] : extractFormFields(subSection, convertedMetadata, entitySetName),
279
- tableColumns: subSection.custom || !isTable ? {} : extractTableColumnsFromNode(subSection)
280
- });
281
- });
282
- return subSections;
266
+ const subSectionItems = getAggregations(getAggregations(section)['subsections']);
267
+ const childEntries = Object.entries(subSectionItems);
268
+ // all-FieldGroup CollectionFacet is collapsed into one sub-section with inherited id from parent
269
+ // Table or nested CollectionFacet sub-sections are kept as distinct sub-sections with their own ids
270
+ return isFormOnlyCollectionFacet(childEntries)
271
+ ? [buildMergedFormSubSection(childEntries, parentSectionId, section.order, convertedMetadata, entitySetName)]
272
+ : childEntries.map(([key, child]) => buildSubSection(key, child, parentSectionId, convertedMetadata, entitySetName));
273
+ }
274
+ /**
275
+ * Checks if a body section is a CollectionFacet that contains only form facets (FieldGroups) and no tables or custom facets.
276
+ *
277
+ * @param childEntries - the section's sub-section aggregation entries
278
+ * @returns true if every child is a plain form facet
279
+ */
280
+ function isFormOnlyCollectionFacet(childEntries) {
281
+ return (childEntries.length > 0 &&
282
+ childEntries.every(([, child]) => !child.custom && !isTableSection(child) && isFormSection(child)));
283
+ }
284
+ /**
285
+ * Merges the fields of all FieldGroups of a form-only CollectionFacet into one sub-section keyed by the
286
+ * section id.
287
+ *
288
+ * @param childEntries - the section's sub-section aggregation entries (all form facets)
289
+ * @param parentSectionId - identifier of the parent section, used as the sub-section id
290
+ * @param sectionOrder - order of the parent section, adopted by the collapsed sub-section
291
+ * @param convertedMetadata - optional converted OData metadata
292
+ * @param entitySetName - the entity set the section is bound to
293
+ * @returns the merged sub-section feature data
294
+ */
295
+ function buildMergedFormSubSection(childEntries, parentSectionId, sectionOrder, convertedMetadata, entitySetName) {
296
+ const fields = dedupeFormFields(childEntries.flatMap(([, child]) => extractFormFields(child, convertedMetadata, entitySetName)));
297
+ return {
298
+ id: parentSectionId,
299
+ navigationProperty: undefined,
300
+ isTable: false,
301
+ custom: false,
302
+ order: sectionOrder ?? -1,
303
+ fields,
304
+ tableColumns: {}
305
+ };
306
+ }
307
+ /**
308
+ * Builds feature data for a single body sub-section (form or table).
309
+ *
310
+ * @param subSectionKey - the sub-section aggregation key
311
+ * @param subSection - the sub-section entry from the application model
312
+ * @param parentSectionId - identifier of the parent section (fallback key prefix)
313
+ * @param convertedMetadata - optional converted OData metadata
314
+ * @param entitySetName - the entity set the section is bound to
315
+ * @returns the sub-section feature data
316
+ */
317
+ function buildSubSection(subSectionKey, subSection, parentSectionId, convertedMetadata, entitySetName) {
318
+ const isTable = isTableSection(subSection);
319
+ return {
320
+ id: getSectionIdentifier(subSection) ?? `${parentSectionId}_${subSectionKey}`,
321
+ navigationProperty: getNavigationPropertyFromKey(subSectionKey),
322
+ isTable,
323
+ custom: !!subSection.custom,
324
+ order: subSection?.order ?? -1, // put a negative order number to signal that order was not in spec
325
+ fields: subSection.custom || isTable ? [] : extractFormFields(subSection, convertedMetadata, entitySetName),
326
+ tableColumns: subSection.custom || !isTable ? {} : extractTableColumnsFromNode(subSection)
327
+ };
283
328
  }
284
329
  /**
285
330
  * Extracts form field property paths from a body sub-section's form aggregation.
@@ -326,6 +371,17 @@ function extractFormFields(subSection, convertedMetadata, entitySetName) {
326
371
  });
327
372
  return fields;
328
373
  }
374
+ /**
375
+ * Returns a new field list with duplicates removed, keeping the first occurrence of each identifier.
376
+ *
377
+ * @param fields - the fields to dedupe
378
+ * @returns a new deduped field list
379
+ */
380
+ function dedupeFormFields(fields) {
381
+ return fields.filter((field, index) => fields.findIndex((candidate) => candidate.property === field.property &&
382
+ candidate.connectedFields === field.connectedFields &&
383
+ candidate.fieldGroup === field.fieldGroup) === index);
384
+ }
329
385
  /**
330
386
  * Resolves the inner `Value` paths of a `@UI.ConnectedFields#<qualifier>` annotation.
331
387
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sap-ux/ui5-test-writer",
3
3
  "description": "SAP UI5 tests writer",
4
- "version": "1.4.0",
4
+ "version": "1.4.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",