chore(client): data-testid for message containers#11079
chore(client): data-testid for message containers#11079mondo192 wants to merge 1 commit intodanny-avila:mainfrom
Conversation
Add data-testid="assistant-message" and data-testid="user-message" testIdAttributes for E2E testing in downstream repositories.
There was a problem hiding this comment.
Pull request overview
This PR adds data-testid attributes to message containers across the client application to enable more reliable E2E testing in downstream repositories by providing stable test identifiers that won't break when CSS class names change.
- Adds
data-testid="user-message"anddata-testid="assistant-message"to message container elements - Implements consistent conditional logic using
isCreatedByUserto differentiate between user and assistant messages - Updates 5 message rendering components to ensure comprehensive coverage across different parts of the application
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| client/src/components/Share/Message.tsx | Adds data-testid to message container in the share view component |
| client/src/components/Messages/ContentRender.tsx | Adds data-testid to message container in the content render component |
| client/src/components/Chat/Messages/ui/MessageRender.tsx | Adds data-testid to message container in the main message render component |
| client/src/components/Chat/Messages/SearchMessage.tsx | Adds data-testid to MessageBody component in search message view |
| client/src/components/Chat/Messages/MessageParts.tsx | Adds data-testid to message container for multi-part messages |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 'relative flex w-11/12 flex-col', | ||
| msg.isCreatedByUser ? 'user-turn' : 'agent-turn', | ||
| )} | ||
| data-testid={msg.isCreatedByUser ? 'user-message' : 'assistant-message'} |
There was a problem hiding this comment.
The data-testid attribute should be unique within a page. In a conversation with multiple messages, there will be multiple elements with the same 'user-message' or 'assistant-message' test ID, which violates HTML best practices and makes E2E testing unreliable. Consider making the test ID unique by incorporating the message ID, for example: data-testid={msg.isCreatedByUser ? user-message-${msg.messageId}:assistant-message-${msg.messageId}}
| data-testid={msg.isCreatedByUser ? 'user-message' : 'assistant-message'} | |
| data-testid={ | |
| msg.isCreatedByUser | |
| ? `user-message-${msg.messageId}` | |
| : `assistant-message-${msg.messageId}` | |
| } |
| 'relative flex w-11/12 flex-col', | ||
| isCreatedByUser ? 'user-turn' : 'agent-turn', | ||
| )} | ||
| data-testid={isCreatedByUser ? 'user-message' : 'assistant-message'} |
There was a problem hiding this comment.
The data-testid attribute should be unique within a page. In a conversation with multiple messages, there will be multiple elements with the same 'user-message' or 'assistant-message' test ID, which violates HTML best practices and makes E2E testing unreliable. Consider making the test ID unique by incorporating the message ID, for example: data-testid={isCreatedByUser ? user-message-${messageId}:assistant-message-${messageId}}
| data-testid={isCreatedByUser ? 'user-message' : 'assistant-message'} | |
| data-testid={ | |
| isCreatedByUser ? `user-message-${messageId}` : `assistant-message-${messageId}` | |
| } |
| const MessageBody = ({ message, messageLabel, fontSize }) => ( | ||
| <div | ||
| className={cn('relative flex w-11/12 flex-col', message.isCreatedByUser ? '' : 'agent-turn')} | ||
| data-testid={message.isCreatedByUser ? 'user-message' : 'assistant-message'} |
There was a problem hiding this comment.
The data-testid attribute should be unique within a page. In a conversation with multiple messages, there will be multiple elements with the same 'user-message' or 'assistant-message' test ID, which violates HTML best practices and makes E2E testing unreliable. Consider making the test ID unique by incorporating the message ID, for example: data-testid={isCreatedByUser ? user-message-${messageId}:assistant-message-${messageId}} (where messageId would need to be passed as a prop to the MessageBody component)
| </div> | ||
| <div | ||
| className={cn('relative flex w-11/12 flex-col', isCreatedByUser ? '' : 'agent-turn')} | ||
| data-testid={isCreatedByUser ? 'user-message' : 'assistant-message'} |
There was a problem hiding this comment.
The data-testid attribute should be unique within a page. In a conversation with multiple messages, there will be multiple elements with the same 'user-message' or 'assistant-message' test ID, which violates HTML best practices and makes E2E testing unreliable. Consider making the test ID unique by incorporating the message ID, for example: data-testid={isCreatedByUser ? user-message-${messageId}:assistant-message-${messageId}}
| data-testid={isCreatedByUser ? 'user-message' : 'assistant-message'} | |
| data-testid={isCreatedByUser ? `user-message-${messageId}` : `assistant-message-${messageId}`} |
| 'relative flex w-11/12 flex-col', | ||
| msg.isCreatedByUser ? 'user-turn' : 'agent-turn', | ||
| )} | ||
| data-testid={msg.isCreatedByUser ? 'user-message' : 'assistant-message'} |
There was a problem hiding this comment.
The data-testid attribute should be unique within a page. In a conversation with multiple messages, there will be multiple elements with the same 'user-message' or 'assistant-message' test ID, which violates HTML best practices and makes E2E testing unreliable. Consider making the test ID unique by incorporating the message ID, for example: data-testid={msg.isCreatedByUser ? user-message-${msg.messageId}:assistant-message-${msg.messageId}}
| data-testid={msg.isCreatedByUser ? 'user-message' : 'assistant-message'} | |
| data-testid={ | |
| msg.isCreatedByUser | |
| ? `user-message-${msg.messageId}` | |
| : `assistant-message-${msg.messageId}` | |
| } |
Summary
Add
data-testid="assistant-message"anddata-testid="user-message"attributes to message containers for stable E2E testing in downstream repositories.Using CSS selectors like
.agent-turnis fragile as they can break if class names are refactored. Test IDs provide an explicit contract for testing that won't break when styling changes.Change Type
Please delete any irrelevant options.
Testing
data-testid="user-message"data-testid="assistant-message"Test Configuration:
N/A
Checklist
Please delete any irrelevant options.