@sap-ux/ui5-test-writer 1.3.2 → 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.
@@ -40,6 +40,16 @@ export interface HeaderSectionItem extends SectionItem {
40
40
  };
41
41
  };
42
42
  }
43
+ export interface HeaderItem extends TreeAggregation {
44
+ properties?: {
45
+ title?: {
46
+ value?: string;
47
+ };
48
+ description?: {
49
+ value?: string;
50
+ };
51
+ };
52
+ }
43
53
  export interface PageWithModelV4WithProperties extends PageWithModelV4 {
44
54
  routePattern?: string;
45
55
  }
@@ -25,7 +25,12 @@ export async function getAppFeatures(basePath, fs, log, metadata, manifest) {
25
25
  // readApp calls createApplicationAccess internally if given a path, but it uses the "live" version of project-access without fs enhancement
26
26
  const appAccess = await createApplicationAccess(basePath, { fs: fs });
27
27
  const specification = await appAccess.getSpecification();
28
- const appModel = await specification.readApp({ app: appAccess, fs: fs });
28
+ const readAppOptions = {
29
+ app: appAccess,
30
+ fs: fs,
31
+ includeAnnotationProperties: true
32
+ };
33
+ const appModel = await specification.readApp(readAppOptions);
29
34
  if (!projectMetadata) {
30
35
  const metadataPath = appAccess.project?.apps['']?.services?.mainService?.local;
31
36
  if (metadataPath) {
@@ -31,6 +31,8 @@ export async function getObjectPageFeatures(objectPages, listReportPageKey, log,
31
31
  const pageFeatureData = {};
32
32
  pageFeatureData.name = objectPage.name;
33
33
  pageFeatureData.navigationParents = getObjectPageNavigationParents(objectPage.name, objectPages, listReportPageKey, parentLRTableIdentifier);
34
+ // extract header title binding path (for iCheckTitlePath)
35
+ pageFeatureData.headerTitle = getHeaderTitlePath(objectPage);
34
36
  // extract header sections (facets)
35
37
  pageFeatureData.headerSections = extractObjectPageHeaderSectionsData(objectPage);
36
38
  // extract body sections (includes section-level actions and standard create/delete buttons)
@@ -102,6 +104,24 @@ function getObjectPageNavigationParents(targetObjectPageKey, objectPages, listRe
102
104
  parentOPs
103
105
  };
104
106
  }
107
+ /**
108
+ * Returns the OData property path the Object Page header title is bound to, for use with
109
+ * `iCheckTitlePath`. Returns undefined for static titles that expose no binding path.
110
+ *
111
+ * @param objectPage - object page from the application model
112
+ * @returns the title binding path, or undefined
113
+ */
114
+ function getHeaderTitlePath(objectPage) {
115
+ if (!objectPage.model) {
116
+ return undefined;
117
+ }
118
+ const header = getAggregations(objectPage.model.root)['header'];
119
+ const titlePath = header?.properties?.title?.value;
120
+ if (!titlePath) {
121
+ return undefined;
122
+ }
123
+ return titlePath;
124
+ }
105
125
  /**
106
126
  * Extracts header sections data from an object page model.
107
127
  *
@@ -243,23 +263,68 @@ function extractSectionActions(section, convertedMetadata, schemaNamespace) {
243
263
  * @returns array of sub-section feature data
244
264
  */
245
265
  function extractBodySubSectionsData(section, parentSectionId, convertedMetadata, entitySetName) {
246
- const subSections = [];
247
- const subSectionsAggregation = getAggregations(section)['subsections'];
248
- const subSectionItems = getAggregations(subSectionsAggregation);
249
- Object.entries(subSectionItems).forEach(([subSectionKey, subSection]) => {
250
- const subSectionId = getSectionIdentifier(subSection) ?? `${parentSectionId}_${subSectionKey}`;
251
- const isTable = isTableSection(subSection);
252
- subSections.push({
253
- id: subSectionId,
254
- navigationProperty: getNavigationPropertyFromKey(subSectionKey),
255
- isTable,
256
- custom: !!subSection.custom,
257
- order: subSection?.order ?? -1, // put a negative order number to signal that order was not in spec
258
- fields: subSection.custom || isTable ? [] : extractFormFields(subSection, convertedMetadata, entitySetName),
259
- tableColumns: subSection.custom || !isTable ? {} : extractTableColumnsFromNode(subSection)
260
- });
261
- });
262
- 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
+ };
263
328
  }
264
329
  /**
265
330
  * Extracts form field property paths from a body sub-section's form aggregation.
@@ -306,6 +371,17 @@ function extractFormFields(subSection, convertedMetadata, entitySetName) {
306
371
  });
307
372
  return fields;
308
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
+ }
309
385
  /**
310
386
  * Resolves the inner `Value` paths of a `@UI.ConnectedFields#<qualifier>` annotation.
311
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.3.2",
4
+ "version": "1.4.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -29,10 +29,10 @@
29
29
  "@sap-ux/edmx-parser": "0.10.0",
30
30
  "@sap-ux/annotation-converter": "0.10.21",
31
31
  "@sap-ux/ui5-application-writer": "2.1.3",
32
+ "@sap-ux/logger": "1.0.3",
32
33
  "@sap-ux/fiori-generator-shared": "1.2.6",
33
34
  "@sap-ux/project-access": "2.1.10",
34
- "@sap-ux/preview-middleware": "1.1.1",
35
- "@sap-ux/logger": "1.0.3"
35
+ "@sap-ux/preview-middleware": "1.1.1"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@jest/globals": "30.4.1",
@@ -46,7 +46,7 @@ sap.ui.define([
46
46
  <% if (editButton?.visible) { -%>
47
47
  // Ensure the opened entity is not in Draft state before uncommenting
48
48
  // Then.onThe<%- name%>Generated.onHeader().iCheckEdit({ visible: true });
49
- // When.onThe<%- name%>Generated.onHeader().iPressEdit();
49
+ // When.onThe<%- name%>Generated.onHeader().iExecuteEdit();
50
50
  <% } -%>
51
51
  <% headerActions.forEach(function(action) { -%>
52
52
  <% if (action.visible) { -%>
@@ -61,6 +61,12 @@ sap.ui.define([
61
61
  });
62
62
  <% } -%>
63
63
 
64
+ <% if (headerTitle) { -%>
65
+ opaTest("Check header title of the Object Page", function (_Given, _When, Then) {
66
+ Then.onThe<%- name%>Generated.onHeader().iCheckTitlePath(<%- JSON.stringify(headerTitle) %>);
67
+ });
68
+
69
+ <% } -%>
64
70
  <% if (headerSections?.length > 0) { -%>
65
71
  opaTest("Check header facets of the Object Page", function (Given, When, Then) {
66
72
  <% headerSections.forEach(function(section) { -%>
@@ -83,13 +89,12 @@ sap.ui.define([
83
89
  <% } -%>
84
90
 
85
91
  <% if (bodySections?.length > 0) { -%>
86
- opaTest("Check body sections of the Object Page", function (Given, When, Then) {
87
- <% if (bodySections?.length > 1) { -%>
92
+ <% const usesWhenInBody = bodySections.length > 1 || bodySections.some(function(section) { return section.subSections && section.subSections.length > 0; }); -%>
93
+ opaTest("Check body sections of the Object Page", function (_Given, <% if (usesWhenInBody) { %>When<% } else { %>_When<% } %>, Then) {
88
94
  Then.onThe<%- name%>Generated.iCheckNumberOfSections(<%- bodySections.length %>);
89
- <% } -%>
90
95
  <% bodySections.forEach(function(section) { -%>
91
96
  <% if (bodySections.length > 1) { -%>
92
- When.onThe<%- name%>Generated.iPressSectionIconTabFilterButton("<%- section.id %>");
97
+ When.onThe<%- name%>Generated.iGoToSection({ section: "<%- section.id %>" });
93
98
  <% } -%>
94
99
  Then.onThe<%- name%>Generated.iCheckSection({ section: "<%- section.id %>" });
95
100
  <% if (section.actions && section.actions.length > 0) { -%>
@@ -125,7 +130,7 @@ sap.ui.define([
125
130
  <% } -%>
126
131
  <% if (section?.subSections?.length > 0) { -%>
127
132
  <% section.subSections.forEach(function(subSection) { -%>
128
- //When.onThe<%- name%>Generated.iGoToSection({ section: "<%- section.id %>", subSection: "<%- subSection.id %>" });
133
+ When.onThe<%- name%>Generated.iGoToSection({ section: "<%- section.id %>", subSection: "<%- subSection.id %>" });
129
134
  Then.onThe<%- name%>Generated.iCheckSubSection({ section: "<%- subSection.id %>" });
130
135
  <% if (subSection.fields && subSection.fields.length > 0) { -%>
131
136
  <% subSection.fields.forEach(function(field) { -%>
@@ -31,6 +31,9 @@ const usesFormIdentifier = (bodySections || []).some(function(section) {
31
31
  });
32
32
  return subSectionsHaveForm || sectionHasFormFields || hasFormAction;
33
33
  });
34
+ const usesWhenInBody = (bodySections || []).length > 1 || (bodySections || []).some(function(section) {
35
+ return section.subSections && section.subSections.length > 0;
36
+ });
34
37
  -%>
35
38
  <% if (usesFieldIdentifier) { -%>
36
39
  import type { FieldIdentifier } from "sap/fe/test/api/BaseAPI";
@@ -65,7 +68,7 @@ function journey() {
65
68
  <% if (editButton?.visible) { -%>
66
69
  // Ensure the opened entity is not in Draft state before uncommenting
67
70
  // Then.onThe<%- name%>Generated.onHeader().iCheckEdit({ visible: true });
68
- // When.onThe<%- name%>Generated.onHeader().iPressEdit();
71
+ // When.onThe<%- name%>Generated.onHeader().iExecuteEdit();
69
72
  <% } -%>
70
73
  <% headerActions.forEach(function(action) { -%>
71
74
  <% if (action.visible) { -%>
@@ -80,6 +83,12 @@ function journey() {
80
83
  });
81
84
  <% } -%>
82
85
 
86
+ <% if (headerTitle) { -%>
87
+ opaTest("Check header title of the Object Page", function (_Given: Given, _When: When, Then: Then) {
88
+ Then.onThe<%- name%>Generated.onHeader().iCheckTitlePath(<%- JSON.stringify(headerTitle) %>);
89
+ });
90
+
91
+ <% } -%>
83
92
  <% if (headerSections?.length > 0) { -%>
84
93
  opaTest("Check header facets of the Object Page", function (_Given: Given, _When: When, Then: Then) {
85
94
  <% headerSections.forEach(function(section) { -%>
@@ -102,13 +111,11 @@ function journey() {
102
111
  <% } -%>
103
112
 
104
113
  <% if (bodySections?.length > 0) { -%>
105
- opaTest("Check body sections of the Object Page", function (_Given: Given, <% if (bodySections?.length > 1) { %>When: When<% } else { %>_When: When<% } %>, Then: Then) {
106
- <% if (bodySections?.length > 1) { -%>
114
+ opaTest("Check body sections of the Object Page", function (_Given: Given, <% if (usesWhenInBody) { %>When: When<% } else { %>_When: When<% } %>, Then: Then) {
107
115
  Then.onThe<%- name%>Generated.iCheckNumberOfSections(<%- bodySections.length %>);
108
- <% } -%>
109
116
  <% bodySections.forEach(function(section) { -%>
110
117
  <% if (bodySections.length > 1) { -%>
111
- When.onThe<%- name%>Generated.iPressSectionIconTabFilterButton("<%- section.id %>");
118
+ When.onThe<%- name%>Generated.iGoToSection({ section: "<%- section.id %>" });
112
119
  <% } -%>
113
120
  Then.onThe<%- name%>Generated.iCheckSection({ section: "<%- section.id %>" }, {});
114
121
  <% if (section.actions && section.actions.length > 0) { -%>
@@ -144,7 +151,7 @@ function journey() {
144
151
  <% } -%>
145
152
  <% if (section?.subSections?.length > 0) { -%>
146
153
  <% section.subSections.forEach(function(subSection) { -%>
147
- //When.onThe<%- name%>Generated.iGoToSection({ section: "<%- section.id %>", subSection: "<%- subSection.id %>" });
154
+ When.onThe<%- name%>Generated.iGoToSection({ section: "<%- section.id %>", subSection: "<%- subSection.id %>" });
148
155
  Then.onThe<%- name%>Generated.iCheckSubSection({ section: "<%- subSection.id %>" }, {});
149
156
  <% if (subSection.fields && subSection.fields.length > 0) { -%>
150
157
  <% subSection.fields.forEach(function(field) { -%>
@@ -15,18 +15,11 @@
15
15
  * ╚═══════════════════════════════════════════════════════════════════════╝ *
16
16
  ******************************************************************************/
17
17
 
18
- sap.ui.define(['sap/fe/test/ObjectPage', 'sap/ui/test/actions/Press'], function(ObjectPage, Press) {
18
+ sap.ui.define(['sap/fe/test/ObjectPage'], function(ObjectPage) {
19
19
  'use strict';
20
20
 
21
21
  const CustomPageDefinitions = {
22
- actions: {
23
- iPressSectionIconTabFilterButton: function (section) {
24
- return this.waitFor({
25
- id: new RegExp(`.*--fe::FacetSection::${section}-anchor$`),
26
- actions: new Press()
27
- });
28
- }
29
- },
22
+ actions: {},
30
23
  assertions: {}
31
24
  };
32
25
 
@@ -15,17 +15,7 @@
15
15
  * ╚═══════════════════════════════════════════════════════════════════════╝ *
16
16
  ******************************************************************************/
17
17
 
18
- import type Opa5 from "sap/ui/test/Opa5";
19
- import Press from "sap/ui/test/actions/Press";
20
-
21
- export const actions = {
22
- iPressSectionIconTabFilterButton(this: Opa5, section: string) {
23
- return this.waitFor({
24
- id: new RegExp(`.*--fe::FacetSection::${section}-anchor$`),
25
- actions: new Press()
26
- });
27
- }
28
- };
18
+ export const actions = {};
29
19
 
30
20
  export const assertions = {};
31
21
 
@@ -61,6 +61,12 @@ sap.ui.define([
61
61
  });
62
62
  <% } -%>
63
63
 
64
+ <% if (headerTitle) { -%>
65
+ opaTest("Check header title of the Object Page", function (_Given, _When, Then) {
66
+ Then.onThe<%- name%>Generated.onHeader().iCheckTitlePath(<%- JSON.stringify(headerTitle) %>);
67
+ });
68
+
69
+ <% } -%>
64
70
  <% if (headerSections?.length > 0) { -%>
65
71
  opaTest("Check header facets of the Object Page", function (Given, When, Then) {
66
72
  <% headerSections.forEach(function(section) { -%>
@@ -80,6 +80,12 @@ function journey() {
80
80
  });
81
81
  <% } -%>
82
82
 
83
+ <% if (headerTitle) { -%>
84
+ opaTest("Check header title of the Object Page", function (_Given: Given, _When: When, Then: Then) {
85
+ Then.onThe<%- name%>Generated.onHeader().iCheckTitlePath(<%- JSON.stringify(headerTitle) %>);
86
+ });
87
+
88
+ <% } -%>
83
89
  <% if (headerSections?.length > 0) { -%>
84
90
  opaTest("Check header facets of the Object Page", function (_Given: Given, _When: When, Then: Then) {
85
91
  <% headerSections.forEach(function(section) { -%>