@sap-ux/ui5-test-writer 1.16.3 → 1.17.0

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.
package/dist/types.d.ts CHANGED
@@ -272,6 +272,12 @@ export interface ActionButtonState {
272
272
  * For example: "_it/__OperationControl/deductDiscount"
273
273
  */
274
274
  dynamicPath?: string;
275
+ /**
276
+ * Set when the action has no `Core.OperationAvailable` annotation and is bound to a single
277
+ * instance: it is disabled with no selection and becomes enabled once a row is selected. Unlike
278
+ * `'dynamic'`, this flip is deterministic, so the generated test can assert both states.
279
+ */
280
+ selectionEnables?: boolean;
275
281
  /**
276
282
  * The invocation grouping type if specified (e.g., "Isolated", "ChangeSet").
277
283
  */
@@ -57,6 +57,7 @@ export declare function findOperationAvailableAnnotation(metadata: ConvertedMeta
57
57
  export declare function analyzeOperationAvailability(operationAvailable: OperationAvailableWithPaths | undefined, requiresSelection?: boolean): {
58
58
  enabled: boolean | 'dynamic';
59
59
  dynamicPath?: string;
60
+ selectionEnables?: boolean;
60
61
  };
61
62
  /**
62
63
  * Extracts the enum member value from an annotation.
@@ -94,7 +94,7 @@ export function findOperationAvailableAnnotation(metadata, actionMethodName) {
94
94
  */
95
95
  export function analyzeOperationAvailability(operationAvailable, requiresSelection) {
96
96
  if (operationAvailable === undefined) {
97
- return { enabled: !requiresSelection };
97
+ return { enabled: !requiresSelection, selectionEnables: requiresSelection === true };
98
98
  }
99
99
  if (typeof operationAvailable === 'boolean') {
100
100
  return { enabled: operationAvailable };
@@ -144,7 +144,7 @@ export function buildActionButtonState(item, metadata, criticalActions) {
144
144
  const actionTarget = item.ActionTarget;
145
145
  const isBound = actionTarget?.isBound === true;
146
146
  const requiresSelection = isBound && actionTarget?.parameters?.[0]?.isCollection !== true;
147
- const { enabled, dynamicPath } = analyzeOperationAvailability(operationAvailable, requiresSelection);
147
+ const { enabled, dynamicPath, selectionEnables } = analyzeOperationAvailability(operationAvailable, requiresSelection);
148
148
  return {
149
149
  label: item.Label || '',
150
150
  action: actionMethod,
@@ -153,6 +153,7 @@ export function buildActionButtonState(item, metadata, criticalActions) {
153
153
  visible: true,
154
154
  enabled,
155
155
  dynamicPath,
156
+ selectionEnables,
156
157
  invocationGrouping: item.InvocationGrouping ? extractEnumMemberValue(item.InvocationGrouping) : undefined,
157
158
  isCritical: criticalActions?.has(actionMethod) ?? false,
158
159
  parameterDialogFields: collectActionParameterNames(actionTarget)
@@ -184,7 +185,7 @@ export function buildActionStateFromSpecModelKey(aggregationKey, label, converte
184
185
  const isBound = actionDefinition?.isBound === true;
185
186
  const requiresSelection = isBound && actionDefinition?.parameters?.[0]?.isCollection !== true;
186
187
  const operationAvailable = findOperationAvailableAnnotation(convertedMetadata, actionMethod);
187
- const { enabled, dynamicPath } = analyzeOperationAvailability(operationAvailable, requiresSelection);
188
+ const { enabled, dynamicPath, selectionEnables } = analyzeOperationAvailability(operationAvailable, requiresSelection);
188
189
  return {
189
190
  label: label ?? '',
190
191
  action: actionMethod,
@@ -193,6 +194,7 @@ export function buildActionStateFromSpecModelKey(aggregationKey, label, converte
193
194
  visible: true,
194
195
  enabled,
195
196
  dynamicPath,
197
+ selectionEnables,
196
198
  isCritical: criticalActions?.has(actionMethod) ?? false,
197
199
  parameterDialogFields: collectActionParameterNames(actionDefinition)
198
200
  };
@@ -296,6 +296,7 @@ export function getListReportTabs(listReportPage, convertedMetadata, manifest, r
296
296
  }
297
297
  const viewNodes = resolveViewTableNodes(listReportPage.model.root);
298
298
  const nodeByKey = new Map(viewNodes.map((entry) => [entry.key, entry.node]));
299
+ const criticalActions = collectCriticalActionNames(convertedMetadata);
299
300
  const tabs = [];
300
301
  views.forEach((view, index) => {
301
302
  // Match the spec-model view node by key; fall back to model order (both lists exclude custom tabs).
@@ -309,7 +310,7 @@ export function getListReportTabs(listReportPage, convertedMetadata, manifest, r
309
310
  let deleteButton = buildButtonState();
310
311
  if (convertedMetadata && entitySet) {
311
312
  const actionNames = getToolBarActionItems(getToolBarActionsFromTableNode(tableNode));
312
- toolBarActions = safeCheckActionButtonStates(convertedMetadata, entitySet, actionNames, log);
313
+ toolBarActions = safeCheckActionButtonStates(convertedMetadata, entitySet, actionNames, log, criticalActions);
313
314
  const buttonVisibility = safeCheckButtonVisibilityFromMetadata(convertedMetadata, entitySet, log);
314
315
  createButton = buildButtonState(buttonVisibility?.create);
315
316
  deleteButton = buildButtonState(buttonVisibility?.delete);
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.16.3",
4
+ "version": "1.17.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -76,43 +76,86 @@ sap.ui.define([
76
76
  // });
77
77
 
78
78
  <%_ if (tabs && tabs.length > 0) { -%>
79
- opaTest("Check table columns and actions per tab", function (Given, When, Then) {
80
- <%_ tabs.forEach(function(tab) { _%>
79
+ <%_ tabs.forEach(function(tab) { -%>
80
+ /// View "<%- tab.key %>" ///
81
+ <%_ if (tab.createButton.visible && !isALP) { -%>
82
+ opaTest(<%- JSON.stringify("Check the create button in view " + tab.key) %>, function (Given, When, Then) {
81
83
  When.onThe<%- startLR%>Generated.iGoToView({ key: "<%- tab.key %>" });
82
- <%_ if (tab.createButton.visible && !isALP) { _%>
83
84
  Then.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iCheckCreate({ visible: true });
84
85
  // When.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iPressCreate();
85
- <%_ } _%>
86
- <%_ if (tab.deleteButton.visible) { _%>
86
+ });
87
+
88
+ <%_ } -%>
89
+ <%_ if (tab.deleteButton.visible) { -%>
90
+ opaTest(<%- JSON.stringify("Check the delete button in view " + tab.key) %>, function (Given, When, Then) {
91
+ When.onThe<%- startLR%>Generated.iGoToView({ key: "<%- tab.key %>" });
87
92
  // When.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iPressDelete();
88
93
  Then.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iCheckDelete({ visible: true });
94
+ });
95
+
96
+ <%_ } -%>
97
+ <%_ tab.toolBarActions.forEach(function(item) { -%>
98
+ <%_ if (item.visible) { -%>
99
+ opaTest(<%- JSON.stringify("Check the " + item.label + " action in view " + tab.key) %>, function (Given, When, Then) {
100
+ When.onThe<%- startLR%>Generated.iGoToView({ key: "<%- tab.key %>" });
101
+ <%_ if (item.menuActions) { _%>
102
+ <%_ if (item.splitButton) { _%>
103
+ // "<%- item.label %>" is a split menu button (has a default action); its drop-down cannot be opened via the test API, so its menu items are not checked. Pressing it triggers the default action:
104
+ Then.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iCheckAction("<%- item.label %>");
105
+ // When.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iExecuteAction("<%- item.label %>");
106
+ <%_ } else { _%>
107
+ Then.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iCheckAction("<%- item.label %>");
108
+ When.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iExecuteAction("<%- item.label %>");
109
+ <%_ item.menuActions.forEach(function(menuAction) { _%>
110
+ <%_ if (menuAction.visible) { _%>
111
+ Then.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iCheckMenuAction("<%- menuAction.label %>");
112
+ // When.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iExecuteMenuAction("<%- menuAction.label %>");
113
+ <%_ } _%>
114
+ <%_ }); _%>
89
115
  <%_ } _%>
90
- <%_ tab.toolBarActions.forEach(function(item) { _%>
91
- <%_ if (item.visible) { _%>
116
+ <%_ } else { _%>
92
117
  // When.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iPressAction("<%- item.label %>");
93
118
  Then.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iCheckAction("<%- item.label %>", { enabled: <%- item.enabled === true %> });
94
119
  <%_ } _%>
95
- <%_ }); _%>
96
- <%_ if (Object.keys(tab.tableColumns).length > 0) { _%>
120
+ });
121
+
122
+ <%_ } -%>
123
+ <%_ }); -%>
124
+ <%_ if (Object.keys(tab.tableColumns).length > 0) { -%>
125
+ opaTest(<%- JSON.stringify("Check table columns in view " + tab.key) %>, function (Given, When, Then) {
126
+ When.onThe<%- startLR%>Generated.iGoToView({ key: "<%- tab.key %>" });
97
127
  Then.onThe<%- startLR %>Generated.onTable("<%- tab.key %>").iCheckColumns(undefined, <%- JSON.stringify(tab.tableColumns) %>);
98
- <%_ } _%>
128
+ });
129
+
130
+ <%_ } -%>
131
+ opaTest(<%- JSON.stringify("Check table rows in view " + tab.key) %>, function (Given, When, Then) {
132
+ When.onThe<%- startLR%>Generated.iGoToView({ key: "<%- tab.key %>" });
133
+ <%_ if (!hideFilterBar) { -%>
134
+ // Populate the table so the row check has data.
135
+ When.onThe<%- startLR%>Generated.onFilterBar().iExecuteSearch();
136
+ <%_ } -%>
99
137
  Then.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iCheckRows();
100
- <%_ }); -%>
101
138
  });
139
+
140
+ <%_ }); -%>
102
141
  <%_ } else { -%>
103
- <%_ if ((toolBarActions && toolBarActions.length > 0 ) || (tableColumns && Object.keys(tableColumns).length > 0)) { -%>
104
- opaTest("Check table columns and actions", function (Given, When, Then) {
105
- <%_ if (toolBarActions && toolBarActions.length > 0) { -%>
106
- <%_ if (createButton.visible && !isALP) { _%>
142
+ <%_ if (createButton.visible && !isALP) { -%>
143
+ opaTest("Check the create button", function (Given, When, Then) {
107
144
  Then.onThe<%- startLR%>Generated.onTable(defaultTableId).iCheckCreate({ visible: true });
108
145
  // When.onThe<%- startLR%>Generated.onTable(defaultTableId).iPressCreate();
109
- <%_ } _%>
110
- <%_ if (deleteButton.visible) { _%>
146
+ });
147
+
148
+ <%_ } -%>
149
+ <%_ if (deleteButton.visible) { -%>
150
+ opaTest("Check the delete button", function (Given, When, Then) {
111
151
  // When.onThe<%- startLR%>Generated.onTable(defaultTableId).iPressDelete();
112
152
  Then.onThe<%- startLR%>Generated.onTable(defaultTableId).iCheckDelete({ visible: true });
113
- <%_ } _%>
114
- <%_ toolBarActions.forEach(function(item) { _%>
115
- <%_ if (item.visible) { _%>
153
+ });
154
+
155
+ <%_ } -%>
156
+ <%_ (toolBarActions || []).forEach(function(item) { -%>
157
+ <%_ if (item.visible) { -%>
158
+ opaTest(<%- JSON.stringify("Check the " + item.label + " action") %>, function (Given, When, Then) {
116
159
  <%_ if (item.menuActions) { _%>
117
160
  <%_ if (item.splitButton) { _%>
118
161
  // "<%- item.label %>" is a split menu button (has a default action); its drop-down cannot be opened via the test API, so its menu items are not checked. Pressing it triggers the default action:
@@ -132,16 +175,17 @@ sap.ui.define([
132
175
  // When.onThe<%- startLR%>Generated.onTable(defaultTableId).iPressAction("<%- item.label %>");
133
176
  Then.onThe<%- startLR%>Generated.onTable(defaultTableId).iCheckAction("<%- item.label %>", { enabled: <%- item.enabled === true %> });
134
177
  <%_ } _%>
135
- <%_ } _%>
136
- <%_ }); -%>
137
- <%_ } -%>
138
- <%_ if (tableColumns && Object.keys(tableColumns).length > 0) { -%>
178
+ });
179
+
180
+ <%_ } -%>
181
+ <%_ }); -%>
182
+ <%_ if (tableColumns && Object.keys(tableColumns).length > 0) { -%>
183
+ opaTest("Check table columns", function (Given, When, Then) {
139
184
  Then.onThe<%- startLR %>Generated.onTable(defaultTableId).iCheckColumns(undefined, <%- JSON.stringify(tableColumns) %>);
140
- <%_ } -%>
141
185
  });
186
+
142
187
  <%_ } -%>
143
188
  <%_ } -%>
144
-
145
189
  <%_ if (startLR) { -%>
146
190
  opaTest("Navigate to ObjectPage", function (Given, When, Then) {
147
191
  // Note: this test will fail if the ListReport page doesn't show any data
@@ -20,7 +20,6 @@ import type { Given, When, Then } from "./types/OpaJourneyTypes.gen";
20
20
  <%_
21
21
  const usesFilterFieldIdentifier =
22
22
  !hideFilterBar && filterBarItems && filterBarItems.some(function(item) { return item.custom; });
23
- const toolBarHasMenu = (toolBarActions || []).some(function(item) { return item.visible && item.menuActions && !item.splitButton; });
24
23
  -%>
25
24
  <% if (usesFilterFieldIdentifier) { -%>
26
25
  import type { FilterFieldIdentifier } from "sap/fe/test/api/FilterBarAPI";
@@ -82,43 +81,87 @@ function journey() {
82
81
  // });
83
82
 
84
83
  <%_ if (tabs && tabs.length > 0) { -%>
85
- opaTest("Check table columns and actions per tab", function (_Given: Given, When: When, Then: Then) {
86
- <%_ tabs.forEach(function(tab) { _%>
84
+ <%_ tabs.forEach(function(tab) { -%>
85
+ /// View "<%- tab.key %>" ///
86
+ <%_ if (tab.createButton.visible && !isALP) { -%>
87
+ opaTest(<%- JSON.stringify("Check the create button in view " + tab.key) %>, function (_Given: Given, When: When, Then: Then) {
87
88
  When.onThe<%- startLR%>Generated.iGoToView({ key: "<%- tab.key %>" });
88
- <%_ if (tab.createButton.visible && !isALP) { _%>
89
89
  Then.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iCheckCreate({ visible: true });
90
90
  // When.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iPressCreate();
91
- <%_ } _%>
92
- <%_ if (tab.deleteButton.visible) { _%>
91
+ });
92
+
93
+ <%_ } -%>
94
+ <%_ if (tab.deleteButton.visible) { -%>
95
+ opaTest(<%- JSON.stringify("Check the delete button in view " + tab.key) %>, function (_Given: Given, When: When, Then: Then) {
96
+ When.onThe<%- startLR%>Generated.iGoToView({ key: "<%- tab.key %>" });
93
97
  // When.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iPressDelete();
94
98
  Then.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iCheckDelete({ visible: true });
99
+ });
100
+
101
+ <%_ } -%>
102
+ <%_ tab.toolBarActions.forEach(function(item) { -%>
103
+ <%_ if (item.visible) { -%>
104
+ opaTest(<%- JSON.stringify("Check the " + item.label + " action in view " + tab.key) %>, function (_Given: Given, When: When, Then: Then) {
105
+ When.onThe<%- startLR%>Generated.iGoToView({ key: "<%- tab.key %>" });
106
+ <%_ if (item.menuActions) { _%>
107
+ <%_ if (item.splitButton) { _%>
108
+ // "<%- item.label %>" is a split menu button (has a default action); its drop-down cannot be opened via the test API, so its menu items are not checked. Pressing it triggers the default action:
109
+ Then.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iCheckAction("<%- item.label %>");
110
+ // When.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iExecuteAction("<%- item.label %>");
111
+ <%_ } else { _%>
112
+ Then.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iCheckAction("<%- item.label %>");
113
+ When.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iExecuteAction("<%- item.label %>");
114
+ <%_ item.menuActions.forEach(function(menuAction) { _%>
115
+ <%_ if (menuAction.visible) { _%>
116
+ Then.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iCheckMenuAction("<%- menuAction.label %>");
117
+ // When.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iExecuteMenuAction("<%- menuAction.label %>");
118
+ <%_ } _%>
119
+ <%_ }); _%>
95
120
  <%_ } _%>
96
- <%_ tab.toolBarActions.forEach(function(item) { _%>
97
- <%_ if (item.visible) { _%>
121
+ <%_ } else { _%>
98
122
  // When.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iPressAction("<%- item.label %>");
99
123
  Then.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iCheckAction("<%- item.label %>", { enabled: <%- item.enabled === true %> });
100
124
  <%_ } _%>
101
- <%_ }); _%>
102
- <%_ if (Object.keys(tab.tableColumns).length > 0) { _%>
125
+ });
126
+
127
+ <%_ } -%>
128
+ <%_ }); -%>
129
+ <%_ if (Object.keys(tab.tableColumns).length > 0) { -%>
130
+ opaTest(<%- JSON.stringify("Check table columns in view " + tab.key) %>, function (_Given: Given, When: When, Then: Then) {
131
+ When.onThe<%- startLR%>Generated.iGoToView({ key: "<%- tab.key %>" });
103
132
  Then.onThe<%- startLR %>Generated.onTable("<%- tab.key %>").iCheckColumns(undefined, <%- JSON.stringify(tab.tableColumns) %>);
104
- <%_ } _%>
133
+ });
134
+
135
+ <%_ } -%>
136
+ opaTest(<%- JSON.stringify("Check table rows in view " + tab.key) %>, function (_Given: Given, When: When, Then: Then) {
137
+ When.onThe<%- startLR%>Generated.iGoToView({ key: "<%- tab.key %>" });
138
+ <%_ if (!hideFilterBar) { -%>
139
+ // Populate the table so the row check has data.
140
+ When.onThe<%- startLR%>Generated.onFilterBar().iExecuteSearch();
141
+ <%_ } -%>
105
142
  Then.onThe<%- startLR%>Generated.onTable("<%- tab.key %>").iCheckRows();
106
- <%_ }); -%>
107
143
  });
144
+
145
+ <%_ }); -%>
108
146
  <%_ } else { -%>
109
- <%_ if ((toolBarActions && toolBarActions.length > 0 ) || (tableColumns && Object.keys(tableColumns).length > 0)) { -%>
110
- opaTest("Check table columns and actions", function (_Given: Given, <% if (toolBarHasMenu) { %>When: When<% } else { %>_When: When<% } %>, Then: Then) {
111
- <%_ if (toolBarActions && toolBarActions.length > 0) { -%>
112
- <%_ if (createButton.visible && !isALP) { _%>
147
+ <%_ if (createButton.visible && !isALP) { -%>
148
+ opaTest("Check the create button", function (_Given: Given, _When: When, Then: Then) {
113
149
  Then.onThe<%- startLR%>Generated.onTable(defaultTableId).iCheckCreate({ visible: true });
114
150
  // When.onThe<%- startLR%>Generated.onTable(defaultTableId).iPressCreate();
115
- <%_ } _%>
116
- <%_ if (deleteButton.visible) { _%>
151
+ });
152
+
153
+ <%_ } -%>
154
+ <%_ if (deleteButton.visible) { -%>
155
+ opaTest("Check the delete button", function (_Given: Given, _When: When, Then: Then) {
117
156
  // When.onThe<%- startLR%>Generated.onTable(defaultTableId).iPressDelete();
118
157
  Then.onThe<%- startLR%>Generated.onTable(defaultTableId).iCheckDelete({ visible: true });
119
- <%_ } _%>
120
- <%_ toolBarActions.forEach(function(item) { _%>
121
- <%_ if (item.visible) { _%>
158
+ });
159
+
160
+ <%_ } -%>
161
+ <%_ (toolBarActions || []).forEach(function(item) { -%>
162
+ <%_ if (item.visible) { -%>
163
+ <%_ const usesWhen = item.menuActions && !item.splitButton; _%>
164
+ opaTest(<%- JSON.stringify("Check the " + item.label + " action") %>, function (_Given: Given, <% if (usesWhen) { %>When: When<% } else { %>_When: When<% } %>, Then: Then) {
122
165
  <%_ if (item.menuActions) { _%>
123
166
  <%_ if (item.splitButton) { _%>
124
167
  // "<%- item.label %>" is a split menu button (has a default action); its drop-down cannot be opened via the test API, so its menu items are not checked. Pressing it triggers the default action:
@@ -138,16 +181,17 @@ function journey() {
138
181
  // When.onThe<%- startLR%>Generated.onTable(defaultTableId).iPressAction("<%- item.label %>");
139
182
  Then.onThe<%- startLR%>Generated.onTable(defaultTableId).iCheckAction("<%- item.label %>", { enabled: <%- item.enabled === true %> });
140
183
  <%_ } _%>
141
- <%_ } _%>
142
- <%_ }); -%>
143
- <%_ } -%>
144
- <%_ if (tableColumns && Object.keys(tableColumns).length > 0) { -%>
184
+ });
185
+
186
+ <%_ } -%>
187
+ <%_ }); -%>
188
+ <%_ if (tableColumns && Object.keys(tableColumns).length > 0) { -%>
189
+ opaTest("Check table columns", function (_Given: Given, _When: When, Then: Then) {
145
190
  Then.onThe<%- startLR %>Generated.onTable(defaultTableId).iCheckColumns(undefined, <%- JSON.stringify(tableColumns) %>);
146
- <%_ } -%>
147
191
  });
192
+
148
193
  <%_ } -%>
149
194
  <%_ } -%>
150
-
151
195
  <%_ if (startLR) { -%>
152
196
  opaTest("Navigate to ObjectPage", function (_Given: Given, When: When, Then: Then) {
153
197
  // Note: this test will fail if the ListReport page doesn't show any data