@sap-ux/ui5-test-writer 0.1.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # @sap-ux/ui5-test-writer
2
+
3
+ OPA files writer for use within Yeoman generator and other prompting libraries.
4
+
5
+
6
+ ## Installation
7
+ Npm
8
+ `npm install --save @sap-ux/ui5-test-writer`
9
+
10
+ Yarn
11
+ `yarn add @sap-ux/ui5-test-writer`
12
+
13
+ Pnpm
14
+ `pnpm add @sap-ux/ui5-test-writer`
15
+
16
+ ## Usage
17
+
18
+ 2 public methods are available: one to generate all OPA test files for a Fiori elements for OData V4 application, another one to generate an additional page object file for a Fiori elements for OData V4 application.
19
+
20
+
21
+ ### Generate all OPA test files for a Fiori elements for OData V4 application
22
+
23
+ Calling the `generateOPAFiles` function
24
+ ```javascript
25
+ import { generateOPAFiles } from '@sap-ux/ui5-test-writer'
26
+
27
+ const exampleWriter = async () => {
28
+ const myProjectPath = 'path/to/my/project'; // Path to the root of the Fiori app
29
+ const fs = await generateOPAFiles(myProjectPath, { scriptName: 'myOpaTest' });
30
+ return new Promise((resolve) => {
31
+ fs.commit(resolve); // When using with Yeoman it handle the fs commit.
32
+ });
33
+ }
34
+
35
+ // Calling the function
36
+ await exampleWriter();
37
+
38
+ ```
39
+
40
+ ### Generate an additional page object file
41
+
42
+ Calling the `generatePageObjectFile` function
43
+ ```javascript
44
+ import { generatePageObjectFile } from '@sap-ux/ui5-test-writer'
45
+
46
+ const exampleWriter = async () => {
47
+ const myProjectPath = 'path/to/my/project'; // Path to the root of the Fiori app
48
+ const targetKey = 'MyNewPage'; // Key of the target in the app descriptor (in sap.ui5/routing/targets)
49
+ const fs = await generatePageObjectFile(myProjectPath, { targetKey });
50
+ return new Promise((resolve) => {
51
+ fs.commit(resolve); // When using with Yeoman it handle the fs commit.
52
+ });
53
+ }
54
+
55
+ // Calling the function
56
+ await exampleWriter();
57
+
58
+ ```
59
+
60
+ ## Keywords
61
+ SAP Fiori Elements
package/dist/i18n.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { TOptions } from 'i18next';
2
+ /**
3
+ * Initialize i18next with the translations for this module.
4
+ */
5
+ export declare function initI18n(): Promise<void>;
6
+ /**
7
+ * Helper function facading the call to i18next.
8
+ *
9
+ * @param key i18n key
10
+ * @param options additional options
11
+ * @returns {string} localized string stored for the given key
12
+ */
13
+ export declare function t(key: string, options?: TOptions): string;
14
+ //# sourceMappingURL=i18n.d.ts.map
package/dist/i18n.js ADDED
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.t = exports.initI18n = void 0;
16
+ const i18next_1 = __importDefault(require("i18next"));
17
+ const ui5_test_writer_i18n_json_1 = __importDefault(require("./translations/ui5-test-writer.i18n.json"));
18
+ const NS = 'ui5-test-writer';
19
+ /**
20
+ * Initialize i18next with the translations for this module.
21
+ */
22
+ function initI18n() {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ yield i18next_1.default.init({
25
+ resources: {
26
+ en: {
27
+ [NS]: ui5_test_writer_i18n_json_1.default
28
+ }
29
+ },
30
+ lng: 'en',
31
+ fallbackLng: 'en',
32
+ defaultNS: NS,
33
+ ns: [NS]
34
+ });
35
+ });
36
+ }
37
+ exports.initI18n = initI18n;
38
+ /**
39
+ * Helper function facading the call to i18next.
40
+ *
41
+ * @param key i18n key
42
+ * @param options additional options
43
+ * @returns {string} localized string stored for the given key
44
+ */
45
+ function t(key, options) {
46
+ return i18next_1.default.t(key, options);
47
+ }
48
+ exports.t = t;
49
+ initI18n();
50
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1,32 @@
1
+ import type { Editor } from 'mem-fs-editor';
2
+ /**
3
+ * Generate OPA test files for a Fiori elements for OData V4 application.
4
+ * Note: this can potentially overwrite existing files in the webapp/test folder.
5
+ *
6
+ * @param basePath - the absolute target path where the application will be generated
7
+ * @param opaConfig - parameters for the generation
8
+ * @param opaConfig.scriptName - the name of the OPA journey file. If not specified, 'FirstJourney' will be used
9
+ * @param opaConfig.appID - the appID. If not specified, will be read from the manifest in sap.app/id
10
+ * @param fs - an optional reference to a mem-fs editor
11
+ * @returns Reference to a mem-fs-editor
12
+ */
13
+ export declare function generateOPAFiles(basePath: string, opaConfig: {
14
+ scriptName?: string;
15
+ appID?: string;
16
+ }, fs?: Editor): Editor;
17
+ /**
18
+ * Generate a page object file for a Fiori elements for OData V4 application.
19
+ * Note: this doesn't modify other existing files in the webapp/test folder.
20
+ *
21
+ * @param basePath - the absolute target path where the application will be generated
22
+ * @param pageObjectParameters - parameters for the page
23
+ * @param pageObjectParameters.targetKey - the key of the target in the manifest file corresponding to the page
24
+ * @param pageObjectParameters.appID - the appID. If not specified, will be read from the manifest in sap.app/id
25
+ * @param fs - an optional reference to a mem-fs editor
26
+ * @returns Reference to a mem-fs-editor
27
+ */
28
+ export declare function generatePageObjectFile(basePath: string, pageObjectParameters: {
29
+ targetKey: string;
30
+ appID?: string;
31
+ }, fs?: Editor): Editor;
32
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,266 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generatePageObjectFile = exports.generateOPAFiles = void 0;
4
+ const path_1 = require("path");
5
+ const mem_fs_1 = require("mem-fs");
6
+ const mem_fs_editor_1 = require("mem-fs-editor");
7
+ const types_1 = require("./types");
8
+ const i18n_1 = require("./i18n");
9
+ /**
10
+ * Reads the manifest for an app.
11
+ *
12
+ * @param fs - a reference to a mem-fs editor
13
+ * @param basePath - the root folder of the app
14
+ * @returns the manifest object. An exception is thrown if the manifest cannot be read.
15
+ */
16
+ function readManifest(fs, basePath) {
17
+ const manifest = fs.readJSON(path_1.join(basePath, 'webapp/manifest.json'));
18
+ if (!manifest) {
19
+ throw new types_1.ValidationError(i18n_1.t('error.cannotReadManifest', {
20
+ filePath: path_1.join(basePath, 'webapp/manifest.json')
21
+ }));
22
+ }
23
+ return manifest;
24
+ }
25
+ /**
26
+ * Retrieves the application type of the main datasource (FreeStyle, FE V2 or FE V4).
27
+ *
28
+ * @param manifest - the app descriptor of the app
29
+ * @returns the application type. An exception is thrown if it can't be found or if it's not supported
30
+ */
31
+ function getAppTypeFromManifest(manifest) {
32
+ var _a, _b;
33
+ const appTargets = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.routing) === null || _b === void 0 ? void 0 : _b.targets;
34
+ let isFEV4 = false;
35
+ for (const targetKey in appTargets) {
36
+ const target = appTargets[targetKey];
37
+ if (target.type === 'Component' && target.name && target.name in types_1.SupportedPageTypes) {
38
+ isFEV4 = true;
39
+ }
40
+ }
41
+ if (!isFEV4) {
42
+ throw new types_1.ValidationError(i18n_1.t('error.badApplicationType'));
43
+ }
44
+ return 'v4'; // For the time being, only FE V4 is supported
45
+ }
46
+ /**
47
+ * Retrieves appID and appPath from the manifest.
48
+ *
49
+ * @param manifest - the app descriptor of the app
50
+ * @param forcedAppID - the appID in case we don't want to read it from the manifest
51
+ * @returns appID and appPath
52
+ */
53
+ function getAppFromManifest(manifest, forcedAppID) {
54
+ var _a;
55
+ const appID = forcedAppID || ((_a = manifest['sap.app']) === null || _a === void 0 ? void 0 : _a.id);
56
+ const appPath = appID === null || appID === void 0 ? void 0 : appID.split('.').join('/');
57
+ if (!appID || !appPath) {
58
+ throw new types_1.ValidationError(i18n_1.t('error.cannotReadAppID'));
59
+ }
60
+ return { appID, appPath };
61
+ }
62
+ /**
63
+ * Create the page configuration object from the app descriptor and the target key.
64
+ *
65
+ * @param manifest - the app descriptor of the app
66
+ * @param targetKey - the key of the target in the manifest
67
+ * @param forcedAppID - the appID in case we don't want to read it from the manifest
68
+ * @returns Page configuration object, or undefined if the target type is not supported
69
+ */
70
+ function createPageConfig(manifest, targetKey, forcedAppID) {
71
+ var _a, _b, _c, _d;
72
+ const appTargets = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.routing) === null || _b === void 0 ? void 0 : _b.targets;
73
+ const target = appTargets && appTargets[targetKey];
74
+ const { appID, appPath } = getAppFromManifest(manifest, forcedAppID);
75
+ if ((target === null || target === void 0 ? void 0 : target.type) === 'Component' && (target === null || target === void 0 ? void 0 : target.name) &&
76
+ target.name in types_1.SupportedPageTypes && (target === null || target === void 0 ? void 0 : target.id) && ((_d = (_c = target === null || target === void 0 ? void 0 : target.options) === null || _c === void 0 ? void 0 : _c.settings) === null || _d === void 0 ? void 0 : _d.entitySet)) {
77
+ return {
78
+ appPath,
79
+ appID,
80
+ targetKey,
81
+ componentID: target.id,
82
+ entitySet: target.options.settings.entitySet,
83
+ template: types_1.SupportedPageTypes[target.name],
84
+ isStartup: false
85
+ };
86
+ }
87
+ else {
88
+ return undefined;
89
+ }
90
+ }
91
+ /**
92
+ * Create the configuration object from the app descriptor.
93
+ *
94
+ * @param manifest - the app descriptor of the target app
95
+ * @param opaConfig - parameters for the generation
96
+ * @param opaConfig.scriptName - the name of the OPA journey file. If not specified, 'FirstJourney' will be used
97
+ * @param opaConfig.appID - the appID. If not specified, will be read from the manifest in sap.app/id
98
+ * @returns OPA test configuration object
99
+ */
100
+ function createConfig(manifest, opaConfig) {
101
+ var _a, _b, _c, _d, _e, _f;
102
+ // General application info
103
+ const { appID, appPath } = getAppFromManifest(manifest, opaConfig.appID);
104
+ const config = {
105
+ appID,
106
+ appPath,
107
+ pages: [],
108
+ opaJourneyFileName: opaConfig.scriptName || 'FirstJourney'
109
+ };
110
+ // Identify startup targets from the routes
111
+ const appRoutes = ((_c = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.routing) === null || _b === void 0 ? void 0 : _b.routes) !== null && _c !== void 0 ? _c : []);
112
+ // Find the route with an empty pattern (except for the trailing query part)
113
+ const startupRoute = appRoutes.find((route) => {
114
+ return route.pattern.replace(':?query:', '') === '';
115
+ });
116
+ let startupTargets = (_d = startupRoute === null || startupRoute === void 0 ? void 0 : startupRoute.target) !== null && _d !== void 0 ? _d : [];
117
+ if (!Array.isArray(startupTargets)) {
118
+ startupTargets = [startupTargets];
119
+ }
120
+ // Create page configurations in supported cases
121
+ const appTargets = (_f = (_e = manifest['sap.ui5']) === null || _e === void 0 ? void 0 : _e.routing) === null || _f === void 0 ? void 0 : _f.targets;
122
+ for (const targetKey in appTargets) {
123
+ const pageConfig = createPageConfig(manifest, targetKey, opaConfig.appID);
124
+ if (pageConfig) {
125
+ pageConfig.isStartup = startupTargets.includes(targetKey);
126
+ config.pages.push(pageConfig);
127
+ }
128
+ }
129
+ return config;
130
+ }
131
+ /**
132
+ * Finds the initial ListReport page and the first Object page from the app.
133
+ *
134
+ * @param pages - the page configs of the app
135
+ * @param manifest - the app descriptor of the target app
136
+ * @returns the page fonfigs for the LR and the OP if they're found
137
+ */
138
+ function findLROP(pages, manifest) {
139
+ var _a, _b, _c, _d, _e, _f, _g, _h;
140
+ const pageLR = pages.find((page) => {
141
+ return page.isStartup && page.template === 'ListReport';
142
+ });
143
+ if (!pageLR) {
144
+ return {};
145
+ }
146
+ const appTargets = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.routing) === null || _b === void 0 ? void 0 : _b.targets;
147
+ const appRoutes = ((_e = (_d = (_c = manifest['sap.ui5']) === null || _c === void 0 ? void 0 : _c.routing) === null || _d === void 0 ? void 0 : _d.routes) !== null && _e !== void 0 ? _e : []);
148
+ const target = (appTargets && appTargets[pageLR.targetKey]);
149
+ if (!((_g = (_f = target === null || target === void 0 ? void 0 : target.options) === null || _f === void 0 ? void 0 : _f.settings) === null || _g === void 0 ? void 0 : _g.navigation)) {
150
+ return { pageLR }; // No navigation from LR
151
+ }
152
+ // Find all targets that can be navigated from the LR page
153
+ const navigatedTargetKeys = [];
154
+ for (const navKey in target.options.settings.navigation) {
155
+ const navObject = target.options.settings.navigation[navKey];
156
+ const navigatedRoute = ((_h = navObject.detail) === null || _h === void 0 ? void 0 : _h.route) &&
157
+ appRoutes.find((route) => {
158
+ var _a;
159
+ return route.name === ((_a = navObject.detail) === null || _a === void 0 ? void 0 : _a.route);
160
+ });
161
+ if (Array.isArray(navigatedRoute === null || navigatedRoute === void 0 ? void 0 : navigatedRoute.target)) {
162
+ navigatedTargetKeys.push(...navigatedRoute.target);
163
+ }
164
+ else if (navigatedRoute === null || navigatedRoute === void 0 ? void 0 : navigatedRoute.target) {
165
+ navigatedTargetKeys.push(navigatedRoute.target);
166
+ }
167
+ }
168
+ // Find the first navigated page that is valid and not the starting LR
169
+ let pageOP;
170
+ for (let i = 0; i < navigatedTargetKeys.length && !pageOP; i++) {
171
+ if (navigatedTargetKeys[i] === pageLR.targetKey) {
172
+ continue; // This can happen in the FCL case where the LR is also part of the route's targets to the OP
173
+ }
174
+ pageOP = pages.find((page) => {
175
+ return page.targetKey === navigatedTargetKeys[i];
176
+ });
177
+ }
178
+ return { pageLR, pageOP };
179
+ }
180
+ /**
181
+ * Writes a page object in a mem-fs-editor.
182
+ *
183
+ * @param pageConfig - the page configuration object
184
+ * @param rootTemplateDirPath - template root directory
185
+ * @param testOutDirPath - output test directory (.../webapp/test)
186
+ * @param fs - a reference to a mem-fs editor
187
+ */
188
+ function writePageObject(pageConfig, rootTemplateDirPath, testOutDirPath, fs) {
189
+ fs.copyTpl(path_1.join(rootTemplateDirPath, `integration/pages/${pageConfig.template}.js`), path_1.join(testOutDirPath, `integration/pages/${pageConfig.targetKey}.js`), pageConfig, undefined, {
190
+ globOptions: { dot: true }
191
+ });
192
+ }
193
+ /**
194
+ * Generate OPA test files for a Fiori elements for OData V4 application.
195
+ * Note: this can potentially overwrite existing files in the webapp/test folder.
196
+ *
197
+ * @param basePath - the absolute target path where the application will be generated
198
+ * @param opaConfig - parameters for the generation
199
+ * @param opaConfig.scriptName - the name of the OPA journey file. If not specified, 'FirstJourney' will be used
200
+ * @param opaConfig.appID - the appID. If not specified, will be read from the manifest in sap.app/id
201
+ * @param fs - an optional reference to a mem-fs editor
202
+ * @returns Reference to a mem-fs-editor
203
+ */
204
+ function generateOPAFiles(basePath, opaConfig, fs) {
205
+ var _a, _b;
206
+ const editor = fs || mem_fs_editor_1.create(mem_fs_1.create());
207
+ const manifest = readManifest(editor, basePath);
208
+ const applicationType = getAppTypeFromManifest(manifest);
209
+ const config = createConfig(manifest, opaConfig);
210
+ const rootCommonTemplateDirPath = path_1.join(__dirname, '../templates/common');
211
+ const rootV4TemplateDirPath = path_1.join(__dirname, `../templates/${applicationType}`); // Only v4 is supported for the time being
212
+ const testOutDirPath = path_1.join(basePath, 'webapp/test');
213
+ // Common test files
214
+ editor.copy(path_1.join(rootCommonTemplateDirPath), testOutDirPath);
215
+ // Integration (OPA) test files - version-specific
216
+ editor.copyTpl(path_1.join(rootV4TemplateDirPath, 'integration', 'opaTests.*.*'), path_1.join(testOutDirPath, 'integration'), config, undefined, {
217
+ globOptions: { dot: true }
218
+ });
219
+ // Pages files (one for each page in the app)
220
+ config.pages.forEach((page) => {
221
+ writePageObject(page, rootV4TemplateDirPath, testOutDirPath, editor);
222
+ });
223
+ // OPA Journey file
224
+ const startPages = config.pages.filter((page) => page.isStartup).map((page) => page.targetKey);
225
+ const LROP = findLROP(config.pages, manifest);
226
+ const journeyParams = {
227
+ startPages,
228
+ startLR: (_a = LROP.pageLR) === null || _a === void 0 ? void 0 : _a.targetKey,
229
+ navigatedOP: (_b = LROP.pageOP) === null || _b === void 0 ? void 0 : _b.targetKey
230
+ };
231
+ editor.copyTpl(path_1.join(rootV4TemplateDirPath, 'integration/FirstJourney.js'), path_1.join(testOutDirPath, `integration/${config.opaJourneyFileName}.js`), journeyParams, undefined, {
232
+ globOptions: { dot: true }
233
+ });
234
+ return editor;
235
+ }
236
+ exports.generateOPAFiles = generateOPAFiles;
237
+ /**
238
+ * Generate a page object file for a Fiori elements for OData V4 application.
239
+ * Note: this doesn't modify other existing files in the webapp/test folder.
240
+ *
241
+ * @param basePath - the absolute target path where the application will be generated
242
+ * @param pageObjectParameters - parameters for the page
243
+ * @param pageObjectParameters.targetKey - the key of the target in the manifest file corresponding to the page
244
+ * @param pageObjectParameters.appID - the appID. If not specified, will be read from the manifest in sap.app/id
245
+ * @param fs - an optional reference to a mem-fs editor
246
+ * @returns Reference to a mem-fs-editor
247
+ */
248
+ function generatePageObjectFile(basePath, pageObjectParameters, fs) {
249
+ const editor = fs || mem_fs_editor_1.create(mem_fs_1.create());
250
+ const manifest = readManifest(editor, basePath);
251
+ const applicationType = getAppTypeFromManifest(manifest);
252
+ const pageConfig = createPageConfig(manifest, pageObjectParameters.targetKey, pageObjectParameters.appID);
253
+ if (pageConfig) {
254
+ const rootTemplateDirPath = path_1.join(__dirname, `../templates/${applicationType}`); // Only v4 is supported for the time being
255
+ const testOutDirPath = path_1.join(basePath, 'webapp/test');
256
+ writePageObject(pageConfig, rootTemplateDirPath, testOutDirPath, editor);
257
+ }
258
+ else {
259
+ throw new types_1.ValidationError(i18n_1.t('error.cannotGeneratePageFile', {
260
+ targetKey: pageObjectParameters.targetKey
261
+ }));
262
+ }
263
+ return editor;
264
+ }
265
+ exports.generatePageObjectFile = generatePageObjectFile;
266
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,8 @@
1
+ {
2
+ "error": {
3
+ "cannotReadManifest": "Cannot read manifest file {{ filePath }}",
4
+ "cannotReadAppID": "Cannot read appID in the manifest file",
5
+ "badApplicationType": "Cannot determine application type from the manifest, or unsupported type",
6
+ "cannotGeneratePageFile": "Cannot generate page file for target {{ targetKey }}"
7
+ }
8
+ }
@@ -0,0 +1,47 @@
1
+ export declare const SupportedPageTypes: {
2
+ [id: string]: string;
3
+ };
4
+ export declare type FEV4OPAPageConfig = {
5
+ appID: string;
6
+ appPath: string;
7
+ template: string;
8
+ componentID: string;
9
+ entitySet: string;
10
+ targetKey: string;
11
+ isStartup: boolean;
12
+ };
13
+ export declare type FEV4OPAConfig = {
14
+ appID: string;
15
+ appPath: string;
16
+ pages: FEV4OPAPageConfig[];
17
+ opaJourneyFileName: string;
18
+ };
19
+ export declare type FEV4ManifestTarget = {
20
+ type?: string;
21
+ name?: string;
22
+ id?: string;
23
+ options?: {
24
+ settings?: {
25
+ entitySet?: string;
26
+ navigation?: {
27
+ [id: string]: {
28
+ detail?: {
29
+ route?: string;
30
+ };
31
+ };
32
+ };
33
+ };
34
+ };
35
+ };
36
+ /**
37
+ * General validation error thrown if app config options contain invalid combinations
38
+ */
39
+ export declare class ValidationError extends Error {
40
+ /**
41
+ * ValidationError constructor.
42
+ *
43
+ * @param message - the error message
44
+ */
45
+ constructor(message: string);
46
+ }
47
+ //# sourceMappingURL=types.d.ts.map
package/dist/types.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidationError = exports.SupportedPageTypes = void 0;
4
+ exports.SupportedPageTypes = {
5
+ 'sap.fe.templates.ListReport': 'ListReport',
6
+ 'sap.fe.templates.ObjectPage': 'ObjectPage',
7
+ 'sap.fe.core.fpm': 'FPM'
8
+ };
9
+ /**
10
+ * General validation error thrown if app config options contain invalid combinations
11
+ */
12
+ class ValidationError extends Error {
13
+ /**
14
+ * ValidationError constructor.
15
+ *
16
+ * @param message - the error message
17
+ */
18
+ constructor(message) {
19
+ super(`Validation error: ${message}`);
20
+ this.name = this.constructor.name;
21
+ }
22
+ }
23
+ exports.ValidationError = ValidationError;
24
+ //# sourceMappingURL=types.js.map
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@sap-ux/ui5-test-writer",
3
+ "description": "SAP UI5 tests writer",
4
+ "version": "0.1.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/SAP/open-ux-tools.git",
8
+ "directory": "packages/ui5-test-writer"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aui5-test-writer"
12
+ },
13
+ "license": "Apache-2.0",
14
+ "main": "dist/index.js",
15
+ "files": [
16
+ "LICENSE",
17
+ "dist",
18
+ "templates",
19
+ "!dist/*.map",
20
+ "!dist/**/*.map"
21
+ ],
22
+ "dependencies": {
23
+ "ejs": "3.1.7",
24
+ "mem-fs": "2.1.0",
25
+ "mem-fs-editor": "9.4.0",
26
+ "@sap-ux/ui5-config": "0.14.5",
27
+ "i18next": "20.3.2"
28
+ },
29
+ "devDependencies": {
30
+ "@types/ejs": "3.1.0",
31
+ "@types/mem-fs": "1.1.2",
32
+ "@types/fs-extra": "9.0.13",
33
+ "@types/mem-fs-editor": "7.0.1",
34
+ "fs-extra": "10.0.0"
35
+ },
36
+ "engines": {
37
+ "pnpm": ">=6.26.1 < 7.0.0 || >=7.1.0",
38
+ "node": ">= 14.16.0 < 15.0.0 || >=16.1.0 < 17.0.0 || >=18.0.0 < 19.0.0"
39
+ },
40
+ "scripts": {
41
+ "build": "rimraf dist && tsc",
42
+ "clean": "rimraf dist test/test-output coverage",
43
+ "watch": "tsc --watch",
44
+ "lint": "eslint . --ext .ts",
45
+ "lint:fix": "eslint . --ext .ts --fix",
46
+ "test": "jest --ci --forceExit --detectOpenHandles --colors",
47
+ "test-u": "jest --ci --forceExit --detectOpenHandles --colors -u",
48
+ "link": "pnpm link --global",
49
+ "unlink": "pnpm unlink --global"
50
+ }
51
+ }
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>QUnit test suite</title>
5
+ <script src="../resources/sap/ui/qunit/qunit-redirect.js"></script>
6
+ <script src="testsuite.qunit.js" data-sap-ui-testsuite></script>
7
+ </head>
8
+ <body></body>
9
+ </html>
@@ -0,0 +1,11 @@
1
+ window.suite = function() {
2
+ 'use strict';
3
+
4
+ // eslint-disable-next-line
5
+ var oSuite = new parent.jsUnitTestSuite(),
6
+
7
+ sContextPath = location.pathname.substring(0, location.pathname.lastIndexOf('/') + 1);
8
+ oSuite.addTestPage(sContextPath + 'integration/opaTests.qunit.html');
9
+
10
+ return oSuite;
11
+ };
@@ -0,0 +1,36 @@
1
+ sap.ui.define([
2
+ "sap/ui/test/opaQunit"
3
+ ], function (opaTest) {
4
+ "use strict";
5
+
6
+ var Journey = {
7
+ run: function() {
8
+ QUnit.module("First journey");
9
+
10
+ opaTest("Start application", function (Given, When, Then) {
11
+ Given.iStartMyApp();
12
+ <% startPages.forEach(function(pageName) { %>
13
+ Then.onThe<%- pageName%>.iSeeThisPage();
14
+ <% });%>
15
+ });
16
+
17
+ <% if (startLR) { %>
18
+ opaTest("Navigate to ObjectPage", function (Given, When, Then) {
19
+ // Note: this test will fail if the ListReport page doesn't show any data
20
+ When.onThe<%- startLR%>.onFilterBar().iExecuteSearch();
21
+ Then.onThe<%- startLR%>.onTable().iCheckRows();
22
+ <% if (navigatedOP) { %>
23
+ When.onThe<%- startLR%>.onTable().iPressRow(0);
24
+ Then.onThe<%- navigatedOP%>.iSeeThisPage();
25
+ <%} %>
26
+ });
27
+ <%} %>
28
+ opaTest("Teardown", function (Given, When, Then) {
29
+ // Cleanup
30
+ Given.iTearDownMyApp();
31
+ });
32
+ }
33
+ }
34
+
35
+ return Journey;
36
+ });
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Integration tests</title>
5
+ <meta charset="utf-8">
6
+
7
+ <script id="sap-ui-bootstrap"
8
+ src="/resources/sap-ui-core.js"
9
+ data-sap-ui-theme='sap_fiori_3'
10
+ data-sap-ui-resourceroots='{
11
+ "<%- appID %>": "../../"
12
+ }'
13
+ data-sap-ui-animation="false"
14
+ data-sap-ui-compatVersion="edge"
15
+ data-sap-ui-async="true">
16
+ </script>
17
+
18
+ <link rel="stylesheet" type="text/css" href="/resources/sap/ui/thirdparty/qunit-2.css">
19
+
20
+ <script src="/resources/sap/ui/thirdparty/qunit-2.js"></script>
21
+ <script src="/resources/sap/ui/qunit/qunit-junit.js"></script>
22
+
23
+ <script src="opaTests.qunit.js"></script>
24
+
25
+ </head>
26
+ <body>
27
+ <div id="qunit"></div>
28
+ <div id="qunit-fixture"></div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,24 @@
1
+ sap.ui.require(
2
+ [
3
+ 'sap/fe/test/JourneyRunner',
4
+ '<%- appPath %>/test/integration/<%- opaJourneyFileName %>',
5
+ <%- pages.map((page) => {return "\t\t'" + page.appPath + '/test/integration/pages/' + page.targetKey + "'";}).join(',\n')%>
6
+ ],
7
+ function(JourneyRunner, opaJourney, <%- pages.map(function(page) {return page.targetKey;}).join(', ')%>) {
8
+ 'use strict';
9
+ var JourneyRunner = new JourneyRunner({
10
+ // start index.html in web folder
11
+ launchUrl: sap.ui.require.toUrl('<%- appPath %>') + '/index.html'
12
+ });
13
+
14
+
15
+ JourneyRunner.run(
16
+ {
17
+ pages: {
18
+ <%- pages.map((page) => {return '\t\t\t\t\tonThe' + page.targetKey + ': ' + page.targetKey}).join(',\n')%>
19
+ }
20
+ },
21
+ opaJourney.run
22
+ );
23
+ }
24
+ );
@@ -0,0 +1,13 @@
1
+ sap.ui.define(['sap/fe/test/TemplatePage'], function(TemplatePage) {
2
+ 'use strict';
3
+
4
+ var CustomPageDefinitions = {
5
+ actions: {},
6
+ assertions: {}
7
+ };
8
+
9
+ return new TemplatePage(
10
+ '<%- appID %>::<%- componentID %>',
11
+ CustomPageDefinitions
12
+ );
13
+ });
@@ -0,0 +1,17 @@
1
+ sap.ui.define(['sap/fe/test/ListReport'], function(ListReport) {
2
+ 'use strict';
3
+
4
+ var CustomPageDefinitions = {
5
+ actions: {},
6
+ assertions: {}
7
+ };
8
+
9
+ return new ListReport(
10
+ {
11
+ appId: '<%- appID %>',
12
+ componentId: '<%- componentID %>',
13
+ entitySet: '<%- entitySet %>'
14
+ },
15
+ CustomPageDefinitions
16
+ );
17
+ });
@@ -0,0 +1,17 @@
1
+ sap.ui.define(['sap/fe/test/ObjectPage'], function(ObjectPage) {
2
+ 'use strict';
3
+
4
+ var CustomPageDefinitions = {
5
+ actions: {},
6
+ assertions: {}
7
+ };
8
+
9
+ return new ObjectPage(
10
+ {
11
+ appId: '<%- appID %>',
12
+ componentId: '<%- componentID %>',
13
+ entitySet: '<%- entitySet %>'
14
+ },
15
+ CustomPageDefinitions
16
+ );
17
+ });