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
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

.toLowerCase()
.replace(/ /g, '-')
.concat('-button')}
>
{entry.Icon && <entry.Icon size={theme.icon.size.md} />}
<StyledButtonLabel>{entry.label}</StyledButtonLabel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const CalendarDayCardContent = ({
delay: Math.max(0, dayEndsIn),
duration: theme.animation.duration.fast,
}}
data-testid="calendar-row"
>
<StyledDayContainer>
<StyledWeekDay>{weekDayLabel}</StyledWeekDay>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export const ActivityRow = ({
children,
onClick,
disabled,
testId,
}: 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

}>) => {
const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {
if (disabled !== true) {
Expand All @@ -28,7 +30,11 @@ export const ActivityRow = ({
};

return (
<StyledRowContent onClick={handleClick} clickable={disabled !== true}>
<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

>
{children}
</StyledRowContent>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export const EmailThreadPreview = ({ thread }: EmailThreadPreviewProps) => {
<ActivityRow
onClick={(event) => handleThreadClick(event)}
disabled={isDisabled}
testId="email-row"
>
<StyledHeading unread={!thread.read}>
<StyledParticipantsContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ export const AttachmentDropdown = ({
<Dropdown
dropdownId={dropdownId}
clickableComponent={
<LightIconButton Icon={IconDotsVertical} accent="tertiary" />
<LightIconButton
Icon={IconDotsVertical}
accent="tertiary"
testId="attachment-options-dropdown"
/>
}
dropdownComponents={
<DropdownMenu width="160px">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const AttachmentRow = ({ attachment }: { attachment: Attachment }) => {

return (
<FieldContext.Provider value={fieldContext as GenericFieldContextType}>
<ActivityRow disabled>
<ActivityRow disabled testId="attachment-row">
<StyledLeftContent>
<AttachmentIcon attachmentType={attachment.type} />
{isEditing ? (
Expand All @@ -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'

/>
) : (
<StyledLinkContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const Attachments = ({
title="Add file"
variant="secondary"
onClick={handleUploadFileClick}
dataTestId="add-file-button"
/>
</AnimatedPlaceholderEmptyContainer>
)}
Expand All @@ -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

}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const NoteCard = ({
});

return (
<StyledCard isSingleNote={isSingleNote}>
<StyledCard isSingleNote={isSingleNote} data-testid="note-card">
<StyledCardDetailsContainer
onClick={() => openActivityRightDrawer(note.id)}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const Notes = ({
targetableObjects: [targetableObject],
})
}
dataTestId="add-note-button"
/>
</AnimatedPlaceholderEmptyContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

);
};
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const TaskGroups = ({ targetableObjects }: TaskGroupsProps) => {
targetableObjects: targetableObjects ?? [],
})
}
dataTestId="add-task-button"
/>
</AnimatedPlaceholderEmptyContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const TaskRow = ({ task }: { task: Task }) => {
onClick={() => {
openActivityRightDrawer(task.id);
}}
testId="task-row"
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, e.g., task-row-${task.id}

>
<StyledLeftSideContainer>
<StyledCheckboxContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,8 @@ export const RecordInlineCellDisplayMode = ({
}: React.PropsWithChildren<unknown>) => {
const { isFocused } = useFieldFocus();

const {
editModeContentOnly,

showLabel,
label,
buttonIcon,
} = useRecordInlineCellContext();
const { editModeContentOnly, showLabel, label, buttonIcon } =
useRecordInlineCellContext();

const isDisplayModeContentEmpty = useIsFieldEmpty();
const showEditButton =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

.concat('-header')}
title={fieldDefinition.label}
link={
isToManyObjects
Expand All @@ -191,6 +195,10 @@ export const RecordDetailRelationSection = ({
className="displayOnHover"
Icon={isToOneObject ? IconPencil : IconPlus}
accent="tertiary"
testId={fieldDefinition.label
.toLowerCase()
.replace(' ', '-')
.concat('-dropdown')}
/>
}
dropdownComponents={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type RecordDetailSectionHeaderProps = {
rightAdornment?: React.ReactNode;
hideRightAdornmentOnMouseLeave?: boolean;
areRecordsAvailable?: boolean;
testId?: string;
};

export const RecordDetailSectionHeader = ({
Expand All @@ -47,6 +48,7 @@ export const RecordDetailSectionHeader = ({
rightAdornment,
hideRightAdornmentOnMouseLeave = true,
areRecordsAvailable = false,
testId,
}: RecordDetailSectionHeaderProps) => {
const [isHovered, setIsHovered] = useState(false);

Expand All @@ -55,6 +57,7 @@ export const RecordDetailSectionHeader = ({
areRecordsAvailable={areRecordsAvailable}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
data-testid={testId}
>
<StyledTitle>
<StyledTitleLabel>{title}</StyledTitleLabel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ export const SettingsAccountsBlocklistInput = ({
)}
/>
</StyledLinkContainer>
<Button title="Add to blocklist" type="submit" />
<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

</StyledContainer>
</form>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const SettingsAccountsCalendarChannelDetails = ({
title: 'Auto-creation',
description: 'Automatically create contacts for people.',
onToggle: handleContactAutoCreationToggle,
testId: 'auto-creation-toggle',
},
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const SettingsAccountsConnectedAccountsRowRightContainer = ({
);

return (
<StyledRowRightContainer>
<StyledRowRightContainer data-testid={account.handle}>
{status === SyncStatus.FAILED && (
<Status color="red" text="Sync failed" weight="medium" />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ export const SettingsAccountsMessageChannelDetails = ({
'Don’t create contacts from/to Gmail, Outlook emails',
value: !!messageChannel.excludeNonProfessionalEmails,
onToggle: handleIsNonProfessionalEmailExcludedToggle,
testId: 'exclude-non-professional-emails-toggle',
},
{
title: 'Exclude group emails',
description: 'Don’t sync emails from team@ support@ noreply@...',
value: !!messageChannel.excludeGroupEmails,
onToggle: handleIsGroupEmailExcludedToggle,
testId: 'exclude-group-emails-toggle',
},
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Parameter = {
title: string;
description: string;
onToggle: (value: boolean) => void;
testId: string;
};

type SettingsAccountsToggleSettingCardProps = {
Expand Down Expand Up @@ -55,7 +56,11 @@ export const SettingsAccountsToggleSettingCard = ({
<StyledTitle>{parameter.title}</StyledTitle>
<StyledDescription>{parameter.description}</StyledDescription>
</div>
<StyledToggle value={parameter.value} onChange={parameter.onToggle} />
<StyledToggle
value={parameter.value}
onChange={parameter.onToggle}
testId={parameter.testId}
/>
</StyledCardContent>
))}
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const CancelButton = ({
accent="tertiary"
onClick={onCancel}
disabled={disabled}
testId="cancel-button"
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const SaveButton = ({ onSave, disabled }: SaveButtonProps) => {
disabled={disabled}
onClick={onSave}
Icon={IconDeviceFloppy}
dataTestId="save-button"
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const SettingsDataModelFieldBooleanForm = ({
defaultValue={initialDefaultValue}
render={({ field: { onChange, value } }) => (
<Select
dataTestId="boolean-default-select"
className={className}
fullWidth
// TODO: temporary fix - disabling edition because after editing the defaultValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const SettingsDataModelFieldDescriptionForm = ({
value={value ?? undefined}
onChange={onChange}
disabled={disabled}
testId="field-description"
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

/>
</StyledGroup>
</StyledContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const SettingsObjectNewFieldSelector = ({
placeholder="Search a type"
value={searchQuery}
onChange={setSearchQuery}
dataTestId="field-type-search-input"
/>
</Section>
<Controller
Expand All @@ -127,7 +128,10 @@ export const SettingsObjectNewFieldSelector = ({
{fieldTypeConfigs
.filter(([, config]) => config.category === category)
.map(([key, config]) => (
<StyledCardContainer key={key}>
<StyledCardContainer
key={key}
data-testid={key.toLowerCase()}
>
<UndecoratedLink
to={`/settings/objects/${objectSlug}/new-field/configure?fieldType=${key}`}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const SettingsDataModelFieldCurrencyForm = ({
value={value}
options={OPTIONS}
onChange={onChange}
dataTestId="currency-unit-select"
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/>
<StyledTextInput
name="decimals"
fullWidth
value={value.toString()}
onChange={(value) => handleTextInputChange(value)}
disabled={disabled}
dataTestId="decimals-number-input"
/>
<StyledControlButton
variant="secondary"
onClick={handleIncrementCounter}
Icon={IconPlus}
disabled={disabled}
dataTestId="increment-decimals-button"
/>
</StyledCounterControlsIcons>
</StyledCounterInnerContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const SettingsDataModelFieldRelationForm = ({
value={value}
options={RELATION_TYPE_OPTIONS}
onChange={onChange}
dataTestId="relation-type-select"
/>
)}
/>
Expand All @@ -144,6 +145,7 @@ export const SettingsDataModelFieldRelationForm = ({
Icon: getIcon(objectMetadataItem.icon),
}))}
onChange={onChange}
dataTestId="object-destination-select"
/>
)}
/>
Expand Down Expand Up @@ -178,6 +180,7 @@ export const SettingsDataModelFieldRelationForm = ({
onChange={onChange}
fullWidth
maxLength={FIELD_NAME_MAXIMUM_LENGTH}
dataTestId="relation-name-input"
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ export const SettingsDataModelFieldSelectForm = ({
title="Add option"
Icon={IconPlus}
onClick={handleAddOption}
testId="add-option-button"
/>
</StyledFooter>
</>
Expand Down
Loading
Loading