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

chore: Updated js file to ts files #37312

Closed
wants to merge 2 commits into from
Closed

Conversation

sagar-qa007
Copy link
Contributor

@sagar-qa007 sagar-qa007 commented Nov 11, 2024

Description

We currently maintain two separate file types across specifications, locators, and commands in our Cypress codebase. To streamline and standardise the code, improve TypeScript support, enhance readability, and simplify the process of writing new test cases, I have updated all JavaScript files to TypeScript.

Fixes #37311

Automation

/ok-to-test tags="@tag.All"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11790965886
Commit: 4f902e0
Cypress dashboard.
Tags: @tag.All
Spec:


Tue, 12 Nov 2024 06:21:59 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • Bug Fixes

    • Updated import statements for the reconnectDatasourceLocators module in multiple test files to ensure proper functionality without file extension issues.
    • Verified that the Templates modal filtering behaves correctly, ensuring filters reset after modal closure.
  • Improvements

    • Made the resolveFieldValue parameter optional in the hideAndVerifyProperties function, enhancing flexibility in form data verification for JSON forms.
    • Enhanced the migration test script with refined validation checks for UI elements and data bindings, ensuring accurate import functionality and improved readability.

Copy link
Contributor

coderabbitai bot commented Nov 11, 2024

Walkthrough

The pull request includes modifications to several test specification files in a Cypress testing environment. The primary change across these files involves updating import statements for the reconnectDatasourceLocators module by removing the .js file extension. Additionally, two test files for JSON form handling have updated the hideAndVerifyProperties function to make the resolveFieldValue parameter optional. The overall functionality and logic of the tests remain unchanged.

Changes

File Path Change Summary
app/client/cypress/e2e/Regression/ClientSide/Templates/CreateNewAppFromTemplates_spec.ts Updated import statement for reconnectDatasourceLocators, removing .js extension.
app/client/cypress/e2e/Regression/ClientSide/Templates/Filtering/TemplatesModal_filtering_spec.ts Updated import statement for reconnectDatasourceLocators, removing .js extension.
app/client/cypress/e2e/Regression/ClientSide/Widgets/JSONForm/JSONForm_HiddenFields_1_spec.ts Made resolveFieldValue parameter optional in hideAndVerifyProperties function.
app/client/cypress/e2e/Regression/ClientSide/Widgets/JSONForm/JSONForm_HiddenFields_2_spec.ts Made resolveFieldValue parameter optional in hideAndVerifyProperties function.
app/client/cypress/e2e/Regression/ClientSide/Widgets/Migration_Spec.ts Changed variable declaration from var to let for format, enhancing scoping.

Possibly related PRs

Suggested labels

Tech Debt, Task, ok-to-test, Widgets Product, Templates Product

Suggested reviewers

  • ApekshaBhosale
  • rahulbarwal

🎉 In the realm of code where tests reside,
Imports updated, no need to hide.
Functions made flexible, oh what a treat,
With parameters optional, our tests are complete!
So here's to the changes, both simple and bright,
In the world of Cypress, everything feels right! 🎉


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Nov 11, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (4)
app/client/cypress/e2e/Regression/ClientSide/Widgets/JSONForm/JSONForm_HiddenFields_1_spec.ts (3)

Line range hint 28-34: Replace cy.wait with proper assertions.

Using hardcoded waits is discouraged in Cypress. Instead, use explicit assertions or wait for specific elements/states.

Consider refactoring to:

- cy.wait(3000); //wait for text field to alter
+ cy.get(`${widgetsPage.textWidget} .bp3-ui-text`)
+   .should('not.have.value', fieldValue)
+   .should('exist');

Line range hint 22-23: Update selectors to use data- attributes.*

Current selectors rely on CSS classes which are prone to changes. Use data-* attributes for more reliable element selection.

Consider updating:

- cy.get(`${fieldPrefix}-${fieldName}`)
+ cy.get(`[data-testid="jsonform-field-${fieldName}"]`)

Also applies to: 37-38


Line range hint 19-65: Add error handling for JSON parsing.

The function assumes JSON.parse will always succeed. Consider adding proper error handling for malformed JSON data.

Consider wrapping JSON operations in try-catch:

  cy.get(`${widgetsPage.textWidget} .bp3-ui-text`).then(($el) => {
+   try {
      const formData = JSON.parse($el.text());
      const formDataValue = resolveFieldValue
        ? resolveFieldValue(formData)
        : formData[fieldName];
      cy.wrap(formDataValue).should("be.undefined");
+   } catch (e) {
+     cy.fail('Invalid JSON data in form');
+   }
  });
app/client/cypress/e2e/Regression/ClientSide/Widgets/JSONForm/JSONForm_HiddenFields_2_spec.ts (1)

Line range hint 31-31: Replace cy.wait with proper Cypress assertions

Using hardcoded waits (cy.wait(3000)) is discouraged as it makes tests brittle and slower. Instead, leverage Cypress's built-in retry-ability.

Replace the waits with proper assertions:

- cy.wait(3000); //wait for text field to alter
+ cy.get(`${widgetsPage.textWidget} .bp3-ui-text`)
+   .should('not.be.empty')
+   .should((elem) => {
+     expect(JSON.parse(elem.text())).to.exist;
+   });

Also applies to: 47-47

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ec1d737 and db92203.

📒 Files selected for processing (4)
  • app/client/cypress/e2e/Regression/ClientSide/Templates/CreateNewAppFromTemplates_spec.ts (1 hunks)
  • app/client/cypress/e2e/Regression/ClientSide/Templates/Filtering/TemplatesModal_filtering_spec.ts (1 hunks)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/JSONForm/JSONForm_HiddenFields_1_spec.ts (1 hunks)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/JSONForm/JSONForm_HiddenFields_2_spec.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • app/client/cypress/e2e/Regression/ClientSide/Templates/CreateNewAppFromTemplates_spec.ts
  • app/client/cypress/e2e/Regression/ClientSide/Templates/Filtering/TemplatesModal_filtering_spec.ts
🧰 Additional context used
📓 Path-based instructions (2)
app/client/cypress/e2e/Regression/ClientSide/Widgets/JSONForm/JSONForm_HiddenFields_1_spec.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
app/client/cypress/e2e/Regression/ClientSide/Widgets/JSONForm/JSONForm_HiddenFields_2_spec.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
🔇 Additional comments (3)
app/client/cypress/e2e/Regression/ClientSide/Widgets/JSONForm/JSONForm_HiddenFields_1_spec.ts (1)

19-19: LGTM: Function signature change is well implemented.

The optional parameter addition improves function flexibility while maintaining backward compatibility.

app/client/cypress/e2e/Regression/ClientSide/Widgets/JSONForm/JSONForm_HiddenFields_2_spec.ts (2)

19-19: LGTM: TypeScript optional parameter addition

The function signature change to make resolveFieldValue optional is a good improvement that maintains backward compatibility.


Line range hint 89-93: LGTM: Well-structured test suite

The test suite follows good practices:

  • Clear test descriptions
  • Proper test tagging
  • Multiple assertions

@@ -16,7 +16,7 @@ import {
const fieldPrefix = ".t--jsonformfield";
const backBtn = "[data-testid='t--property-pane-back-btn']";

function hideAndVerifyProperties(fieldName, fieldValue, resolveFieldValue) {
function hideAndVerifyProperties(fieldName, fieldValue, resolveFieldValue?) {
// Check if visible
cy.get(`${fieldPrefix}-${fieldName}`).should("exist");

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use data- attributes for selectors*

Current selectors don't follow best practices. Replace class-based and attribute selectors with data-* attributes.

Examples:

- .bp3-ui-text
+ [data-testid="form-text"]

- ${fieldPrefix}-${fieldName}
+ [data-testid="json-form-field-${fieldName}"]

Also, consider creating a dedicated locators file for JSON form-specific selectors to improve maintainability.

Also applies to: 39-39, 47-47, 66-66

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
app/client/cypress/e2e/Regression/ClientSide/Widgets/Migration_Spec.ts (4)

Line range hint 1-400: Refactor test structure to follow best practices

The test structure needs improvements in several areas:

  1. Replace cy.wait() calls with proper Cypress commands like cy.intercept() or cy.waitUntil()
  2. Avoid xpath selectors and use data-cy attributes instead
  3. Split this large test into smaller, focused test cases

Example refactor for a wait statement:

-cy.wait("@importNewApplication").then(() => {
+cy.intercept('POST', '**/api/v1/applications/import').as('importNewApplication');
+cy.waitUntil(() => 
+  cy.get('@importNewApplication').then((xhr) => xhr.response.statusCode === 200)
+).then(() => {

133-133: LGTM with minor suggestion

The change from var to let improves variable scoping. Consider using a more descriptive name like cardNumberFormat for better clarity.

-let format = /^\d{4}-\d{4}-\d{4}(-\d{4})?$/;
+let cardNumberFormat = /^\d{4}-\d{4}-\d{4}(-\d{4})?$/;

Line range hint 250-280: Improve test reliability by removing fixed timeouts

The test uses fixed timeouts which could lead to flaky tests. Replace them with proper Cypress commands that wait for specific conditions.

Example refactor:

-cy.wait(2000);
+cy.get(selector).should('be.visible').and('be.enabled');

Line range hint 70-90: Improve test assertions

The test assertions could be more maintainable:

  1. Move string literals to constants
  2. Use Cypress's built-in assertions instead of .then() blocks where possible
  3. Group related assertions using .should() chains

Example refactor:

-cy.readTabledataPublish("0", "1").then((cellData) => {
-  expect(cellData).to.be.equal("100");
-});
+const EXPECTED_VALUES = {
+  FIRST_ROW: "100",
+};
+cy.readTabledataPublish("0", "1")
+  .should("equal", EXPECTED_VALUES.FIRST_ROW);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between db92203 and 4f902e0.

📒 Files selected for processing (1)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/Migration_Spec.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/client/cypress/e2e/Regression/ClientSide/Widgets/Migration_Spec.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.

@sagar-qa007 sagar-qa007 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Nov 11, 2024
Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant