Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move Freestyle OPA templates to ui5-test-writer #2928

Open
wants to merge 46 commits into
base: main
Choose a base branch
from

Conversation

kjose90
Copy link
Member

@kjose90 kjose90 commented Feb 17, 2025

#2932

  • Added EJS freestyle test templates to ui5-writer-tests ad logic.
  • Added addUnits flag to freestyle Fiori App to enable tests.

Copy link

changeset-bot bot commented Feb 17, 2025

🦋 Changeset detected

Latest commit: b3c74b8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 24 packages
Name Type
@sap-ux/fiori-freestyle-writer Minor
@sap-ux/fiori-generator-shared Minor
@sap-ux/ui5-test-writer Minor
@sap-ux/odata-service-inquirer Patch
@sap-ux/generator-simple-fe Patch
@sap-ux/abap-deploy-config-inquirer Patch
@sap-ux/abap-deploy-config-sub-generator Patch
@sap-ux/adp-flp-config-sub-generator Patch
@sap-ux/cap-config-writer Patch
@sap-ux/cf-deploy-config-sub-generator Patch
@sap-ux/deploy-config-generator-shared Patch
@sap-ux/fiori-elements-writer Patch
@sap-ux/flp-config-inquirer Patch
@sap-ux/flp-config-sub-generator Patch
@sap-ux/inquirer-common Patch
@sap-ux/ui5-library-reference-sub-generator Patch
@sap-ux/ui5-library-sub-generator Patch
@sap-ux/create Patch
@sap-ux/ui5-application-inquirer Patch
@sap-ux/adp-tooling Patch
@sap-ux/cf-deploy-config-inquirer Patch
@sap-ux/ui5-library-inquirer Patch
@sap-ux/ui5-library-reference-inquirer Patch
@sap-ux/preview-middleware Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

})
};
if (addTests) {
const ui5MockYamlScript = addMock ? '--config ./ui5-mock.yaml ' : '';
Copy link
Contributor

@IainSAP IainSAP Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you refactor this conditional block into a single function, in another file, please to encapsulate all the updates in a single place. We should try and keep this function (generate) at the same level of abstraction for clarity and understandability. Perhaps this will reduce the code smell (complexity > 15) https://sonarcloud.io/project/issues?id=SAP_open-ux-tools&pullRequest=2928&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored here

Copy link
Contributor

@IainSAP IainSAP Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, can we include all the test related code in a single function and move to another file perhaps to try and keep this file under a manageable size and at the same level of abstraction.

Copy link
Contributor

@IainSAP IainSAP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at the comments thx

window.suite = function() {
'use strict';
'use strict';
Copy link
Contributor

@IainSAP IainSAP Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting looks wrong here? These changes will impact on existing FE snapshots. I would assume the previous formatting was correct, so probably best to leave it as is.

@kjose90
Copy link
Member Author

kjose90 commented Feb 21, 2025

@IainSAP @devinea Previously I had combined templatepackages/ui5-test-writer/templates/common/testsuite.qunit.js to be used by both FE and FF ( commit line 1 and 11 ) However, this caused whitespace discrepancies, making it challenging to align with FE snapshots. To resolve this, I reverted the change and opted to handle testsuite.qunit.js separately under freestyle templates.

Copy link
Member

@devinea devinea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments.
I think it would be easier to maintain going forward if to split templates based on UI5 template version e.g. 1.71.0 and 1.120.0

}
]
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file can be removed as it was related to handlebars?

...opaConfig,
viewNamePage: `${viewName}Page`,
appIdWithSlash,
ui5Version: templateUi5Version,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ui5Version: templateUi5Version,
templateUi5Version: templateUi5Version,

<link rel="stylesheet" type="text/css" href="../../resources/sap/ui/thirdparty/qunit-2.css">
<script src="../../resources/sap/ui/thirdparty/qunit-2.js"></script>
<script src="../../resources/sap/ui/qunit/qunit-junit.js"></script>
<% if (ui5Version !== "1.71.0") { %><script src="opaTests.qunit.js"></script><% } -%>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<% if (ui5Version !== "1.71.0") { %><script src="opaTests.qunit.js"></script><% } -%>
<% if (templateUi5Version !== "1.71.0") { %><script src="opaTests.qunit.js"></script><% } -%>

I think it is better to rename this variable for clarity

@@ -0,0 +1,17 @@
/* global QUnit */
<% if (ui5Version === '1.71.0') { -%>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<% if (ui5Version === '1.71.0') { -%>
<% if (templateUi5Version === "1.71.0") { -%>

// eslint-disable-next-line fiori-custom/sap-no-global-define

window.suite = function() {
'use strict';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must use double quotes in UI5 template files

ui5Version: ffApp.ui5?.version,
enableTypeScript: ffApp.appOptions?.typescript
};
await generateFreestyleOPAFiles(basePath, config, fs, log);
Copy link
Contributor

@IainSAP IainSAP Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not put all the test related code (in the condition) into a single function (in another file), this keeps this file cleaner and will facilitate unit testing of the test related code :

if (addTests) {
    generateOPATests()
}

* @param {Package} packageJson - The package.json object to update.
* @param {boolean} addMock - Whether to include the UI5 mock YAML configuration.
*/
function addTestScripts(packageJson: Package, addMock: boolean): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider moving this to another function in another file along with all the test related code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants