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

fix: Enhance URL handling in table by rendering URL column types with <a> tag. #37179

Merged
merged 15 commits into from
Nov 6, 2024

Conversation

rahulbarwal
Copy link
Contributor

@rahulbarwal rahulbarwal commented Nov 1, 2024

Description

Problem

URLs in table were not being rendered as links, resulting in inconsistent user experience(missing context menus.

Root cause

URLs were rendered in <div> instead of <a>, making the component lack links related features..

Solution

This PR handles...

  • Rendering URLs as links in BasicCell for a better user experience.

  • Adding specific types for column properties for more robust data validation and type checking.

  • Adding unit tests for BasicCell functionality to ensure accurate rendering and behavior.

  • Simplifies the AutoToolTipComponent by removing unncessary LinkWrapper component

Fixes #24769
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

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

🔍 Cypress test results

Tip

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


Tue, 05 Nov 2024 10:23:38 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced type safety for compactMode and columnType properties across various components.
    • Improved rendering logic in the AutoToolTipComponent for better control based on columnType.
    • Optimized rendering in the BasicCell component using useMemo.
  • Bug Fixes

    • Resolved inconsistencies in type definitions for BasicCell, PlainTextCell, and SelectCell components.
    • Updated tooltip behavior in the AutoToolTipComponent to ensure accurate rendering.
  • Tests

    • Introduced a new test suite for the BasicCell component, ensuring proper rendering and interaction behaviors.
    • Refined test cases for the AutoToolTipComponent to verify accurate rendering under various conditions.
    • Updated test case for URL column verification to check attributes directly instead of navigation.

Copy link
Contributor

coderabbitai bot commented Nov 1, 2024

Walkthrough

The changes introduced in this pull request focus on enhancing type safety and improving the rendering logic of components within the Table Widget. Key modifications include updating property types from string to specific enums (ColumnTypes and CompactMode) across various components. Additionally, the rendering logic in the AutoToolTipComponent has been restructured to utilize a switch statement for better control. A new test suite for the BasicCell component has also been added to ensure expected behavior under different scenarios.

Changes

File Change Summary
app/client/src/widgets/TableWidgetV2/component/Constants.ts Updated compactMode type from string to CompactMode.
app/client/src/widgets/TableWidgetV2/component/cellComponents/AutoToolTipComponent.tsx Restructured rendering logic using switch for columnType; integrated LinkWrapper logic directly; updated columnType type from string to ColumnTypes.
app/client/src/widgets/TableWidgetV2/component/cellComponents/BasicCell.test.tsx Added a new test suite with four test cases for the BasicCell component.
app/client/src/widgets/TableWidgetV2/component/cellComponents/BasicCell.tsx Added useMemo for optimized rendering based on columnType; updated compactMode and columnType types to CompactMode and ColumnTypes, respectively.
app/client/src/widgets/TableWidgetV2/component/cellComponents/PlainTextCell.tsx Updated columnType type from string to ColumnTypes.
app/client/src/widgets/TableWidgetV2/component/cellComponents/SelectCell.tsx Updated columnType type from string to ColumnTypes.
app/client/src/widgets/TableWidgetV2/component/cellComponents/AutoTooltipComponent.test.tsx Modified test cases for AutoToolTipComponent, updating expected behavior for empty tooltips.
app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/TableV2_Url_Column_spec.ts Updated URL column test to check anchor element attributes instead of navigation.

Assessment against linked issues

Objective Addressed Explanation
Fix right-click issue on URL links in table widget (#24769) It is unclear if the changes directly resolve the right-click functionality for URL links.

Possibly related PRs

Suggested labels

Enhancement, Community Reported, High, Help enterprise

Suggested reviewers

  • ApekshaBhosale
  • rishabhrathod01
  • sagar-qa007

"In the realm of code where types align,
A widget's charm begins to shine.
With enums in place, and logic refined,
The table now dances, perfectly designed!
Testing the cells, each click a delight,
Enhancements abound, making everything right!" 🎉


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>, 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.

@rahulbarwal rahulbarwal self-assigned this Nov 1, 2024
@github-actions github-actions bot added Bug Something isn't working Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage Production Table Widget Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets labels Nov 1, 2024
@rahulbarwal rahulbarwal added the ok-to-test Required label for CI label Nov 1, 2024
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Nov 1, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11624484613.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37179.
recreate: .

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: 2

🧹 Outside diff range and nitpick comments (7)
app/client/src/widgets/TableWidgetV2/component/cellComponents/BasicCell.test.tsx (1)

8-24: Consider adding validation cases for URL props

While the default props are comprehensive, consider adding test cases for:

  • Invalid URL formats
  • Empty URL handling
  • URL encoding scenarios
// Example additional test props:
const urlTestCases = [
  { url: "https://example.com/path with spaces", expected: "https://example.com/path%20with%20spaces" },
  { url: "", expected: "#" },
  { url: "invalid-url", expected: "#" }
];
app/client/src/widgets/TableWidgetV2/component/cellComponents/BasicCell.tsx (1)

Line range hint 78-93: Address TODO comment regarding any type

While the type improvements are good, there's a TODO comment about fixing the any type that should be addressed.

Would you like me to help create a more specific type for the value prop?

app/client/src/widgets/TableWidgetV2/component/cellComponents/AutoToolTipComponent.tsx (1)

165-171: Remove unnecessary break after return

The break statement after the return is unreachable and should be removed.

    case ColumnTypes.BUTTON:
      if (props.title) {
        return content;
      }
-      break;
app/client/src/widgets/TableWidgetV2/component/cellComponents/SelectCell.tsx (1)

Line range hint 65-101: Consider splitting SelectProps interface

The SelectProps interface has grown quite large with many responsibilities. Consider splitting it into smaller, focused interfaces:

  • ISelectEditProps for edit-mode properties
  • ISelectViewProps for view-mode properties
  • ISelectCommonProps for shared properties

Example structure:

interface ISelectCommonProps extends BaseCellComponentProps {
  columnType: ColumnTypes;
  value: string;
  // ... other common props
}

interface ISelectEditProps extends ISelectCommonProps {
  onFilterChange: (text: string, rowIndex: number, ...) => void;
  onItemSelect: (value: string | number, ...) => void;
  // ... other edit-specific props
}

interface ISelectViewProps extends ISelectCommonProps {
  // ... view-specific props
}

type SelectProps = ISelectEditProps & ISelectViewProps;
app/client/src/widgets/TableWidgetV2/component/cellComponents/PlainTextCell.tsx (2)

Line range hint 89-99: Consider adding URL validation

While the URL handling logic is correct, consider adding URL format validation to prevent invalid URLs from being rendered as links.

 if (value && columnType === ColumnTypes.URL && displayText) {
+  try {
+    new URL(value.toString());
     text = displayText;
+  } catch (e) {
+    text = value.toString();
+  }
 } else if (columnType === ColumnTypes.CURRENCY) {

Line range hint 235-244: Add default case to switch statement

Consider adding a default case to handle any future column types that might be added to the ColumnTypes enum.

   switch (columnType) {
     case ColumnTypes.NUMBER:
       return [InputTypes.NUMBER, "NUMBER"];
     case ColumnTypes.CURRENCY:
       return [InputTypes.CURRENCY, "NUMBER"];
     default:
       return [InputTypes.TEXT, "TEXT"];
+    // Add comment explaining why TEXT is the default choice
   }
app/client/src/widgets/TableWidgetV2/component/Constants.ts (1)

549-549: Type enhancement looks good.

The change from string to CompactModeTypes enum improves type safety by restricting possible values.

Consider adding JSDoc comments to document the properties of BaseCellComponentProps interface, especially describing the purpose and impact of each CompactModeTypes value.

Example:

/**
 * Base properties for table cell components
 */
export interface BaseCellComponentProps {
  /** Controls the cell's display mode. Affects row height and styling. */
  compactMode: CompactModeTypes;
  // ... other properties
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 951be4a and 054ab9c.

📒 Files selected for processing (6)
  • app/client/src/widgets/TableWidgetV2/component/Constants.ts (1 hunks)
  • app/client/src/widgets/TableWidgetV2/component/cellComponents/AutoToolTipComponent.tsx (3 hunks)
  • app/client/src/widgets/TableWidgetV2/component/cellComponents/BasicCell.test.tsx (1 hunks)
  • app/client/src/widgets/TableWidgetV2/component/cellComponents/BasicCell.tsx (5 hunks)
  • app/client/src/widgets/TableWidgetV2/component/cellComponents/PlainTextCell.tsx (1 hunks)
  • app/client/src/widgets/TableWidgetV2/component/cellComponents/SelectCell.tsx (2 hunks)
🔇 Additional comments (14)
app/client/src/widgets/TableWidgetV2/component/cellComponents/BasicCell.test.tsx (2)

1-7: LGTM: Imports are well-organized and complete

All necessary testing utilities and component dependencies are properly imported.


30-42: ⚠️ Potential issue

Add tests for right-click functionality

The linked issue #24769 specifically mentions right-click functionality on URL columns, but this isn't covered in the current test suite.

Add test case for right-click functionality:

it("handles right-click on URL links", () => {
  render(
    <BasicCell
      {...defaultProps}
      columnType={ColumnTypes.URL}
      url="http://example.com"
    />,
  );
  const link = screen.getByRole("link");
  fireEvent.contextMenu(link);
  // Add assertions for context menu behavior
});
app/client/src/widgets/TableWidgetV2/component/cellComponents/BasicCell.tsx (3)

2-2: LGTM: Import changes align with new requirements

The added imports support the enhanced type safety and performance optimizations.

Also applies to: 5-5, 10-10


59-59: Type change validation needed for StyledEditIcon

The compactMode prop type has been updated from string to CompactModeTypes enum.

✅ Verification successful

Type change is safe and correctly implemented

The change from string to CompactModeTypes is type-safe because:

  • CompactModeTypes is properly defined as an enum with values "SHORT", "DEFAULT", "TALL"
  • StyledEditIcon in BasicCell.tsx already uses CompactModeTypes in its styled-component props interface
  • All usages pass the compactMode prop directly without string literals
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any existing usage of StyledEditIcon to verify compatibility
rg -l "StyledEditIcon" | xargs rg "compactMode.*=.*['\"].*['\"]"

Length of output: 68


Script:

#!/bin/bash
# Let's first check where StyledEditIcon is defined
rg -l "StyledEditIcon"

# Then search for all usages of compactMode with StyledEditIcon
rg "StyledEditIcon.*compactMode" -A 2 -B 2

# Also check the enum definition
rg "enum.*CompactModeTypes"

# And check all places where compactMode is used with any component
rg "compactMode={" -A 1 -B 1

Length of output: 661


Script:

#!/bin/bash
# Let's check the actual usage of StyledEditIcon with proper escaping
rg "compactMode\s*=" app/client/src/widgets/TableWidgetV2/component/cellComponents/BasicCell.tsx app/client/src/widgets/TableWidgetV2/component/cellComponents/HeaderCell.tsx

# Check the enum definition to understand valid values
cat app/client/src/widgets/TableWidgetV2/component/Constants.ts

# Check if StyledEditIcon is using compactMode in its styled-components definition
rg "const StyledEditIcon.*=.*styled" -A 5 app/client/src/widgets/TableWidgetV2/component/cellComponents/BasicCell.tsx app/client/src/widgets/TableWidgetV2/component/cellComponents/HeaderCell.tsx

Length of output: 18233


169-169: Verify content ref usage with URL rendering

The content ref is now being applied to a wrapper around the URL anchor tag. Ensure this doesn't affect any existing functionality that relies on the ref.

app/client/src/widgets/TableWidgetV2/component/cellComponents/AutoToolTipComponent.tsx (5)

140-140: LGTM: Type safety improvement

The change from string to ColumnTypes enum enhances type checking and prevents invalid column type assignments.


162-164: LGTM: Clean separation of concerns

The isHyperLink flag improves code readability and reusability.


172-183: LGTM: Enhanced URL rendering

The URL case properly handles both the link text and icon, improving visual feedback for users.


213-213: LGTM: Clean content rendering

The contentToRender variable is properly used here, maintaining consistency with the switch statement logic above.


199-208: 🛠️ Refactor suggestion

Consider URL sanitization and handler optimization

Two suggestions for improvement:

  1. URLs should be sanitized before opening in a new window to prevent potential security issues.
  2. The onClick handler could be memoized to prevent unnecessary re-renders.

Consider applying this optimization:

const handleUrlClick = React.useCallback(
  (e: React.MouseEvent<HTMLDivElement>) => {
    e.stopPropagation();
    // Add URL sanitization here
    window.open(props.url, "_blank");
  },
  [props.url]
);
app/client/src/widgets/TableWidgetV2/component/cellComponents/SelectCell.tsx (2)

14-14: LGTM: Type safety improvement

The change from string to ColumnTypes enum improves type safety and maintains consistency across the table components.

Also applies to: 65-65


Line range hint 236-259: Verify URL handling in BasicCell

Since this component delegates rendering to BasicCell, we should verify that URL columns are properly rendered as clickable links.

✅ Verification successful

Let me analyze the actual file location and URL handling implementation before making any conclusions about the verification.


URL handling is properly implemented in BasicCell

The code correctly renders URL columns as clickable links using an anchor tag when columnType is ColumnTypes.URL. The implementation is clean and follows React best practices with proper memoization.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for URL handling logic in BasicCell
ast-grep --pattern 'columnType === $_ { $$$' BasicCell.tsx

Length of output: 121


Script:

#!/bin/bash
# First, let's find the correct path to BasicCell
fd -e tsx -e ts "BasicCell"

# Then search for URL handling in those files
rg -l "columnType.*url" $(fd -e tsx -e ts "BasicCell")

# Get the implementation details with context
rg -A 5 "columnType.*url" $(fd -e tsx -e ts "BasicCell")

Length of output: 1281


Script:

#!/bin/bash
# Let's get more context around the URL handling implementation
rg -B 10 -A 10 "columnType.*url" app/client/src/widgets/TableWidgetV2/component/cellComponents/BasicCell.tsx

# Also check for any URL-related rendering logic
ast-grep --pattern 'const $_ = useMemo(() => {
  $$$
  url
  $$$
}, [$_]);' app/client/src/widgets/TableWidgetV2/component/cellComponents/BasicCell.tsx

Length of output: 843

app/client/src/widgets/TableWidgetV2/component/cellComponents/PlainTextCell.tsx (2)

42-42: LGTM: Type safety improvement

The change from string to ColumnTypes enum enhances type safety and prevents invalid column type assignments.


Line range hint 315-316: LGTM: Clean URL handling implementation

The separation of URL value and display text through dedicated props provides a clean solution for the right-click functionality requirement.

@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Nov 1, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11625124500.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37179.
recreate: .

@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Nov 1, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11625241932.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37179.
recreate: .

Copy link

github-actions bot commented Nov 1, 2024

Deploy-Preview-URL: https://ce-37179.dp.appsmith.com

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 (1)
app/client/src/widgets/TableWidgetV2/component/cellComponents/AutoTooltipComponent.test.tsx (1)

Line range hint 1-150: Comprehensive test coverage for URL handling.

The test suite effectively covers the core functionality including URL handling, tooltip behavior, and text truncation. However, given the PR's focus on URL column types and <a> tag rendering, consider adding these test cases:

  1. Verify proper rendering of URL columns with the <a> tag
  2. Test URL validation
  3. Test accessibility attributes for URL links

Would you like me to help generate these additional test cases?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2ffbe75 and 83d6004.

📒 Files selected for processing (1)
  • app/client/src/widgets/TableWidgetV2/component/cellComponents/AutoTooltipComponent.test.tsx (1 hunks)
🔇 Additional comments (1)
app/client/src/widgets/TableWidgetV2/component/cellComponents/AutoTooltipComponent.test.tsx (1)

57-59: Verify the empty tooltip test case behavior.

The test case now uses "Empty button" instead of an empty string. Let's verify this aligns with the component's expected behavior.

✅ Verification successful

Test case modification is appropriate

The change from empty string to "Empty button" in the test case is correct. Looking at the test file, it's clear this is a behavioral test verifying that tooltips don't appear for non-truncated button text, regardless of the title value. The test maintains its original intent while using a more descriptive test value that better represents real-world usage.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for empty string handling in the component implementation
ast-grep --pattern 'function AutoToolTipComponent($$$) {
  $$$
  if (title === "") {
    $$$
  }
  $$$
}'

Length of output: 107


Script:

#!/bin/bash
# Let's check the actual implementation of AutoToolTipComponent
rg -A 10 "export (default )?function AutoToolTipComponent" --type typescript

# Also check for any empty string handling in the component
rg "title(\s+)?==(\s+)?['\"]\"" --type typescript

# Let's also check the test file content for context
cat "app/client/src/widgets/TableWidgetV2/component/cellComponents/AutoTooltipComponent.test.tsx"

Length of output: 4498


Script:

#!/bin/bash
# Let's check the implementation file
cat "app/client/src/widgets/TableWidgetV2/component/cellComponents/AutoTooltipComponent.tsx"

# Also check for any related files that might define the component's behavior
fd AutoTooltipComponent.tsx -x cat {}

Length of output: 253

jsartisan
jsartisan previously approved these changes Nov 4, 2024
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Nov 4, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11663305463.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37179.
recreate: .

Copy link

github-actions bot commented Nov 4, 2024

Deploy-Preview-URL: https://ce-37179.dp.appsmith.com

@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Nov 5, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11677499937.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37179.
recreate: .

Copy link

github-actions bot commented Nov 5, 2024

Deploy-Preview-URL: https://ce-37179.dp.appsmith.com

… to streamline the test suite

This can be removed because, its only usage in `BasicCell` was sending URL type, which now handles it itself by rendering `<a>` tag instead of a div tag.
…tes, improving URL navigation verification in widget tests
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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b47908e and b7c5d17.

📒 Files selected for processing (1)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/TableV2_Url_Column_spec.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/TableV2_Url_Column_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 (1)
app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/TableV2_Url_Column_spec.ts (1)

Line range hint 1-42: Consider adding more comprehensive test coverage.

The test only verifies URL attributes but doesn't test:

  • URL click behavior
  • Error states
  • Different URL formats

Let's check if there are other URL-related tests:

Comment on lines +24 to +31
agHelper
.GetElement(`${table._tableRowColumnData(0, 0, "v2")} a`)
.should(
"have.attr",
"href",
"https://randomuser.me/api/portraits/med/women/39.jpg",
)
.should("have.attr", "target", "_blank");
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

Refactor selectors and reduce code duplication.

  1. Use data-* attributes instead of complex selectors.
  2. Extract duplicate assertion logic into a reusable helper function.
  3. Move test URLs to constants.

Consider refactoring to:

const TEST_URLS = {
  WOMAN_PROFILE: "https://randomuser.me/api/portraits/med/women/39.jpg",
  MAN_PROFILE: "https://randomuser.me/api/portraits/med/men/52.jpg"
};

const verifyUrlColumn = (rowIndex: number, expectedUrl: string) => {
  agHelper
    .GetElement(`[data-table-url-cell="${rowIndex}"]`)
    .should("have.attr", "href", expectedUrl)
    .should("have.attr", "target", "_blank");
};

// Usage in test
verifyUrlColumn(0, TEST_URLS.WOMAN_PROFILE);
verifyUrlColumn(3, TEST_URLS.MAN_PROFILE);

Also applies to: 32-39

@rahulbarwal rahulbarwal merged commit 0288f5b into release Nov 6, 2024
45 checks passed
@rahulbarwal rahulbarwal deleted the rahulbarwal/issue24769 branch November 6, 2024 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI Production Table Widget Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Unable to right click on the link present in URL column type of table widget
3 participants