Skip to content

RM40477: improving-data-test-ids-for-actions#109

Open
alexluca06 wants to merge 3 commits intomaster-flower-platformfrom
alexluca-RM40477-actions-better-data-test-ids
Open

RM40477: improving-data-test-ids-for-actions#109
alexluca06 wants to merge 3 commits intomaster-flower-platformfrom
alexluca-RM40477-actions-better-data-test-ids

Conversation

@alexluca06
Copy link
Collaborator

Proposed Change:

What is your change

Change type

Put an x in the boxes that apply

  • Bugfix
  • New feature

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request improves the reliability and flexibility of data-testid attributes for context menu items. By allowing developers to define a custom key for each action, it makes UI tests more robust and less susceptible to breakage from changes in item order or other dynamic factors.

Highlights

  • Enhanced data-testid generation for ContextMenu actions: The data-testid for context menu items can now be derived from a custom key property on the action, which can be a string or a function, providing more stable and meaningful identifiers for UI testing.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/components/ContextMenu/ContextMenu.tsx
    • Updated the logic for generating the key used in data-testid attributes for Menu.Item components.
    • Implemented support for using a custom action.key (which can be a string or a function) as the data-testid suffix, falling back to the item's index if no custom key is provided.
  • src/components/ContextMenu/IAction.ts
    • Introduced a new optional key property to the IAction interface.
    • The key property can accept either a string or a function that returns a string, allowing for dynamic data-testid generation.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a key property for context menu actions to allow for stable identifiers, which is a good improvement for testability and React's rendering logic. The implementation correctly computes the key from the new property. However, I've noticed an inconsistency where actions using renderInMenu do not use this new stable key for React's key prop. This could lead to rendering bugs and should be addressed.

<Menu className="rct9k-context-menu" secondary vertical>
{visibleActions.map((action: IAction) => {
const key = visibleActions.indexOf(action);
const key = (action.key instanceof Function ? action.key({ ...this.props.paramsForAction }) : action.key) || visibleActions.indexOf(action);

Choose a reason for hiding this comment

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

high

While this new logic for key is a great improvement for generating stable identifiers, it's not applied consistently. For actions that use renderInMenu (the else branch of the ternary operator on line 97), the React key prop is still being assigned the item's index (visibleActions.indexOf(action)) on line 112. This should be updated to use the new key variable to ensure consistent behavior and prevent potential rendering issues with React.

For example, line 112 should be changed to:

: React.cloneElement(action.renderInMenu({ ...this.props.paramsForAction, closeContextMenu: this.close }), { key: key, "data-testid": testids.menuItem + "_" + key })

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

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.

1 participant