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

Playwright stage 1 - add data-testid attribute #7894

Closed
wants to merge 8 commits into from

Conversation

BOHEUS
Copy link
Contributor

@BOHEUS BOHEUS commented Oct 20, 2024

Related to #6641

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This pull request adds data-testid attributes to various components throughout the codebase, enhancing testability for E2E testing with Playwright. Key changes include:

  • Added data-testid attributes to buttons, toggles, inputs, and other interactive elements
  • Implemented consistent naming conventions for test IDs across components
  • Improved selectability of components for automated testing purposes
  • Ensured additions don't affect existing component functionality

These changes align with the goals outlined in issue #6641, specifically addressing the need for better test selection and interaction in automated E2E tests.

30 file(s) reviewed, 13 comment(s)
Edit PR Review Bot Settings | Greptile

<StyledRowContent
onClick={handleClick}
clickable={disabled !== true}
data-testid={testId}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Ensure consistent naming convention for test IDs across the application

}: React.PropsWithChildren<{
onClick?: (event: React.MouseEvent<HTMLDivElement>) => void;
disabled?: boolean;
testId?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Add JSDoc comment to explain the purpose of the testId prop

@@ -135,6 +135,7 @@ export const AttachmentRow = ({ attachment }: { attachment: Attachment }) => {
onBlur={handleOnBlur}
autoFocus
onKeyDown={handleOnKeyDown}
dataTestId="file-name-input"
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider using consistent naming: 'testId' vs 'dataTestId'

@@ -121,6 +122,7 @@ export const Attachments = ({
variant="secondary"
title="Add file"
onClick={handleUploadFileClick}
dataTestId="add-file-button"
></Button>
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: Remove empty closing tag

@@ -30,6 +30,7 @@ export const AddTaskButton = ({
targetableObjects: activityTargetableObjects,
})
}
data-testid="add-task-button"
></Button>
Copy link
Contributor

Choose a reason for hiding this comment

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

style: consider adding a child element or text to the Button component

@@ -165,6 +165,10 @@ export const RecordDetailRelationSection = ({
return (
<RecordDetailSection>
<RecordDetailSectionHeader
testId={fieldDefinition.label
.toLowerCase()
.replace(' ', '-')
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Replace ' ' with a regex to handle multiple spaces

Comment on lines 102 to 106
<Button
title="Add to blocklist"
type="submit"
dataTestId="add-blocklist-button"
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider using camelCase for dataTestId to maintain consistency with React naming conventions

@@ -76,6 +76,7 @@ export const SettingsDataModelFieldIconLabelForm = ({
disabled={disabled}
maxLength={maxLength}
fullWidth
dataTestId="field-name-input"
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider using a consistent naming convention for data-testid attributes across the project

@@ -84,6 +84,7 @@ export const SettingsDataModelFieldToggle = ({
value={value}
onChange={onChange}
toggleSize="small"
testId="relative-datetime-toggle"
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider using a more specific testId. 'relative-datetime-toggle' might not accurately describe this toggle's purpose in all contexts.

@@ -146,19 +146,22 @@ export const SettingsDataModelFieldNumberDecimalsInput = ({
onClick={handleDecrementCounter}
Icon={IconMinus}
disabled={disabled}
dataTestId="decrement-decimals-button"
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider using a consistent naming convention for data-testid attributes across the codebase

@charlesBochet
Copy link
Member

@BOHEUS I'm a bit confused, I thought we decided not to add data-testid attribute (only when we had no other obvious way to interact with a DOM element)?

@BOHEUS
Copy link
Contributor Author

BOHEUS commented Oct 20, 2024

@charlesBochet that's true and that's what I did here, I added data-testid attribute to all elements which are problematic to locate, I'm aware it can be quite a lot but it's necessary to progress with e2e testing, if that's a problem, I'll try to redo it in a less-invasive way

@@ -41,6 +41,10 @@ export const ActionMenuBarEntry = ({ entry }: ActionMenuBarEntryProps) => {
<StyledButton
accent={entry.accent ?? 'default'}
onClick={() => entry.onClick?.()}
data-testid={entry.label
Copy link
Member

Choose a reason for hiding this comment

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

for example why do we need this one? can't we select based on entry.label directly (this will select the label but I guess it's still fine to trigger DOM events on parents)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one isn't necessary and can be located using text, I wanted to make life a bit easier but I'll refactor it, re-check my changes and delete attributes from places which can be located using text

@BOHEUS
Copy link
Contributor Author

BOHEUS commented Oct 20, 2024

@charlesBochet done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants