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

test: Extract pageId with regex to cover more cases #34521

Merged
merged 8 commits into from
Jul 2, 2024

Conversation

sharat87
Copy link
Member

@sharat87 sharat87 commented Jun 27, 2024

There's a few places in Cypress tests that are trying to extract the page ID using .split, especially with just the path information, instead of the whole URL. So this PR changes the extraction implementation to use a regex, to support all three cases we need:

  1. Full absolute application+page URL.
  2. Just the path of an application+page URL.
  3. Just the path of an application with a custom slug.
  4. Full absolute application with a custom slug. (Supported, but we don't need this today).

We've also fixed the URL parsing for the (very) old application URLs that didn't use slugs in the URL at all. This was making FocusEntity.test.ts fail.

Fixed that test as well as improved it's error reporting.

Before this PR:
shot-2024-06-27-05-02-16

After this PR:
shot-2024-06-27-05-03-15

No conflicts to EE.

/test all

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/9713573983
Commit: 49edbce
Cypress dashboard.
Tags: ``

Summary by CodeRabbit

  • Refactor

    • Improved URL handling by centralizing page ID extraction logic across various tests and components.
    • Updated deprecated path constants to include ID extraction patterns for better consistency.
    • Enhanced code readability and maintainability by moving page ID extraction to a helper method.
  • Tests

    • Modified test cases to dynamically set applicationId and pageId instead of hardcoding values, ensuring more flexible and maintainable test scenarios.

Copy link
Contributor

coderabbitai bot commented Jun 27, 2024

Walkthrough

The changes primarily focus on abstracting URL page ID extraction methods for consistency and maintainability across multiple files. Helper functions are introduced and updated to manage these extractions, supporting various URL formats. Additionally, the updates involve refactoring and renaming variables for better readability and maintaining deprecated path structures.

Changes

Files Modified Change Summary
ApplicationURL_spec.js Replaced direct URL splitting with agHelper.extractPageIdFromUrl for extracting page IDs.
AggregateHelper.ts Updated extractPageIdFromUrl to support different URL formats and added comments for clarification.
AppSettings.ts Introduced extractPageIdFromUrl method for cleaner extraction of pageId.
appRoutes.ts Updated deprecated paths to include ID extraction regex patterns.
Editor/Explorer/helpers.test.ts Updated variables for applicationId and pageId affecting URL constructions in test cases.
navigation/FocusEntity.test.ts Refactored to use variables for applicationId and pageId in test paths, replacing hardcoded values.
pages/tests/slug.test.tsx Updated variable names and references for applicationId and pageId affecting URL constructions in tests.

Sequence Diagrams

Silently ignored as diagrams do not fit the context of these changes.

Poem

The code did change from shore to shore,
Simple URLs it knew no more.
Extraction methods, clean and neat,
Page IDs like swiftest feet.
Routes refined and tests redressed,
CodeRabbit hops, indeed impressed!
🎉🐇


Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.
  • OSS projects are currently opted into early access features by default.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@sharat87 sharat87 added the ok-to-test Required label for CI label Jun 27, 2024
@github-actions github-actions bot added skip-changelog Adding this label to a PR prevents it from being listed in the changelog Test labels Jun 27, 2024
@sharat87 sharat87 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 27, 2024
@sharat87 sharat87 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 27, 2024
@sharat87 sharat87 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 27, 2024
@sharat87 sharat87 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 27, 2024
@sharat87 sharat87 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 28, 2024
@sharat87 sharat87 marked this pull request as ready for review July 1, 2024 12:22
@sharat87 sharat87 requested a review from abhvsn July 1, 2024 12:23
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 (6)
app/client/cypress/support/Pages/AggregateHelper.ts (6)

Line range hint 866-869: Refactor: Omit unnecessary else clause.

The else clause can be omitted because the previous branch breaks early.

-    } else {
-      options = {};
-    }
-  }
+    }
+  options = {};

Line range hint 894-894: Refactor: Move default parameter to the end.

The default parameter should follow the last required parameter or should be a required parameter.

-  waitAfterClick = true,
  waitTimeInterval = 500,
  type = "click";
+  waitAfterClick = true;

Line range hint 1521-1522: Refactor: Move default parameter to the end.

The default parameter should follow the last required parameter or should be a required parameter.

-    hierarchy = [],
    propFieldName,
    toggleEle = null,
    valueToValidate,
    widgetName,
    widgetType = EntityType.Widget,
+    hierarchy = [];

Line range hint 1551-1552: Refactor: Simplify boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.

-    return this.GetElement(selector)
-      .eq(index)
-      .should(disabled ? "have.attr" : "not.have.attr", "disabled");
+    const assertion = disabled ? "have.attr" : "not.have.attr";
+    return this.GetElement(selector).eq(index).should(assertion, "disabled");

Line range hint 1589-1593: Refactor: Omit unnecessary else clause.

The else clause can be omitted because the previous branch breaks early.

-    } else {
-      this.GetElement(selector)
-        .uncheck({ force: true })
-        .should("not.be.checked");
-    }
+    }
+  this.GetElement(selector).uncheck({ force: true }).should("not.be.checked");

Line range hint 1605-1610: Refactor: Omit unnecessary else clause.

The else clause can be omitted because the previous branch breaks early.

-    } else {
-      $element[0].scrollIntoView();
-      return $element;
-    }
-  })
-  .click({ force: force })
-  .wait(waitTimeInterval);
+    }
+  $element[0].scrollIntoView();
+  return $element;
+})
+  .click({ force: force })
+  .wait(waitTimeInterval);
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8979e07 and 49edbce.

Files selected for processing (7)
  • app/client/cypress/e2e/Regression/ClientSide/OtherUIFeatures/ApplicationURL_spec.js (3 hunks)
  • app/client/cypress/support/Pages/AggregateHelper.ts (1 hunks)
  • app/client/cypress/support/Pages/AppSettings/AppSettings.ts (1 hunks)
  • app/client/src/ce/constants/routes/appRoutes.ts (1 hunks)
  • app/client/src/ce/pages/Editor/Explorer/helpers.test.ts (3 hunks)
  • app/client/src/navigation/FocusEntity.test.ts (19 hunks)
  • app/client/src/pages/tests/slug.test.tsx (2 hunks)
Additional context used
Biome
app/client/cypress/support/Pages/AggregateHelper.ts

[error] 866-869: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)


[error] 894-894: This default parameter should follow the last required parameter or should be a required parameter.

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.

(lint/style/useDefaultParameterLast)


[error] 1521-1522: This default parameter should follow the last required parameter or should be a required parameter.

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.

(lint/style/useDefaultParameterLast)


[error] 1551-1552: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 1589-1593: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)


[error] 1605-1610: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)

Additional comments not posted (14)
app/client/src/ce/pages/Editor/Explorer/helpers.test.ts (2)

6-7: LGTM!

The applicationId and pageId constants are appropriately added for use in the test cases.


45-45: LGTM!

The usage of applicationId and pageId constants in the test cases is correct and consistent.

Also applies to: 55-55

app/client/cypress/e2e/Regression/ClientSide/OtherUIFeatures/ApplicationURL_spec.js (4)

19-19: LGTM!

The usage of agHelper.extractPageIdFromUrl to extract the pageId from the URL is correct and consistent with the purpose of the test case.


25-25: LGTM!

The usage of agHelper.extractPageIdFromUrl to extract the pageId from the URL is correct and consistent with the purpose of the test case.


41-41: LGTM!

The usage of agHelper.extractPageIdFromUrl to extract the pageId from the URL is correct and consistent with the purpose of the test case.


56-56: LGTM!

The usage of agHelper.extractPageIdFromUrl to extract the pageId from the URL is correct and consistent with the purpose of the test case.

app/client/cypress/support/Pages/AppSettings/AppSettings.ts (1)

126-126: LGTM!

The usage of agHelper.extractPageIdFromUrl to extract the pageId from the URL is correct and consistent with the purpose of the CheckUrl method.

app/client/src/pages/tests/slug.test.tsx (2)

80-81: LGTM!

The applicationId and pageId constants are appropriately added for use in the test cases.


117-119: LGTM!

The usage of applicationId and pageId constants in the test cases is correct and consistent.

app/client/src/ce/constants/routes/appRoutes.ts (2)

31-31: Ensure ID_EXTRACTION_REGEX is correctly defined.

The addition of ID_EXTRACTION_REGEX to BUILDER_PATH_DEPRECATED ensures consistent ID extraction. Verify that ID_EXTRACTION_REGEX correctly handles Mongo ObjectIds and UUIDs.


32-32: Ensure ID_EXTRACTION_REGEX is correctly defined.

The addition of ID_EXTRACTION_REGEX to VIEWER_PATH_DEPRECATED ensures consistent ID extraction. Verify that ID_EXTRACTION_REGEX correctly handles Mongo ObjectIds and UUIDs.

app/client/src/navigation/FocusEntity.test.ts (1)

10-11: Good practice: Use of constants for IDs.

The use of applicationId and pageId constants improves maintainability and readability by avoiding hardcoded values.

app/client/cypress/support/Pages/AggregateHelper.ts (2)

136-141: Documentation: Ensure the comment accurately describes the method.

The comment provides a clear description of the extractPageIdFromUrl method, including the supported URL formats. Ensure it remains accurate as the method evolves.


142-146: Regex-based extraction for robustness.

The extractPageIdFromUrl method uses a regex to handle various URL formats, improving the robustness of the ID extraction process. Ensure the regex covers all required cases.

@sharat87 sharat87 merged commit 55b6e6d into release Jul 2, 2024
149 of 156 checks passed
@sharat87 sharat87 deleted the chore/pageid-extraction branch July 2, 2024 01:02
Shivam-z pushed a commit to Shivam-z/appsmith that referenced this pull request Jul 10, 2024
)

There's a few places in Cypress tests that are trying to extract the
page ID using `.split`, especially with just the path information,
instead of the whole URL. So this PR changes the extraction
implementation to use a regex, to support all three cases we need:

1. Full absolute application+page URL.
2. Just the path of an application+page URL.
3. Just the path of an application with a custom slug.
4. Full absolute application with a custom slug. (Supported, but we
don't need this today).

We've also fixed the URL parsing for the (very) old application URLs
that didn't use slugs in the URL at all. This was making
`FocusEntity.test.ts` fail.

Fixed that test as well as improved it's error reporting.

Before this PR:

![shot-2024-06-27-05-02-16](https://github.com/appsmithorg/appsmith/assets/120119/f3363376-a74d-4f3e-8196-5e72a9e758de)


After this PR:

![shot-2024-06-27-05-03-15](https://github.com/appsmithorg/appsmith/assets/120119/8dc1be04-c60f-4251-acf0-e4fd962f4f00)

No conflicts to EE.

/test all

<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/9713573983>
> Commit: 49edbce
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9713573983&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: ``

<!-- end of auto-generated comment: Cypress test results  -->












<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Refactor**
- Improved URL handling by centralizing page ID extraction logic across
various tests and components.
- Updated deprecated path constants to include ID extraction patterns
for better consistency.
- Enhanced code readability and maintainability by moving page ID
extraction to a helper method.

- **Tests**
- Modified test cases to dynamically set `applicationId` and `pageId`
instead of hardcoding values, ensuring more flexible and maintainable
test scenarios.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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 Test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants