Skip to content

Commit 1539257

Browse files
authored
feat: add test ids (#82)
1 parent 790c91f commit 1539257

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

src/components/button/button.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ export type ButtonProps = {
1010
size: 'm' | 'l';
1111
Icon?: ComponentType<IconProps>;
1212
noLabel?: boolean;
13+
testid?: string;
1314
};
1415

15-
export const Button: FC<ButtonProps> = ({ label, onClick, color, noBorder = false, size, Icon, noLabel }) => {
16+
export const Button: FC<ButtonProps> = ({ label, onClick, color, noBorder = false, size, Icon, noLabel, testid }) => {
1617
const baseClasses = `leading-none text-base transition-all duration-300 hover:ring active:ring-4 focus:outline-none flex items-center justify-center`;
1718
const sizeClasses = size === 'l' || noLabel ? 'px-m py-s' : 'p-3';
1819
const colorClasses = {
@@ -32,7 +33,8 @@ export const Button: FC<ButtonProps> = ({ label, onClick, color, noBorder = fals
3233
colorClasses[color],
3334
noBorder ? noBorderOverride : '',
3435
noLabel ? 'rounded-full px-s' : 'w-full rounded-s',
35-
)}>
36+
)}
37+
data-testid={testid}>
3638
{!noLabel && <span className={Icon ? (size === 'l' ? 'mr-3' : 'mr-xs') : ''}>{label}</span>}
3739
{Icon && <Icon size="s" color="white" />}
3840
</button>

src/components/comment-button/comment-button.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type CommentButtonProps = {
1111
plural: string;
1212
};
1313
onClick: () => void; // This should update the count and hasCommented state in the parent component
14+
testid?: string;
1415
};
1516

1617
const getCommentText = (count: number, labels: { zero: string; singular: string; plural: string }) => {
@@ -23,7 +24,7 @@ const getCommentText = (count: number, labels: { zero: string; singular: string;
2324
}
2425
};
2526

26-
export const CommentButton: React.FC<CommentButtonProps> = ({ count, hasCommented, labels, onClick }) => {
27+
export const CommentButton: React.FC<CommentButtonProps> = ({ count, hasCommented, labels, onClick, testid }) => {
2728
const label = getCommentText(count, labels);
2829

2930
const handleCommentClick = () => {
@@ -43,6 +44,7 @@ export const CommentButton: React.FC<CommentButtonProps> = ({ count, hasCommente
4344
icon={<ReplyIcon size="s" color="base" />}
4445
hoveredIcon={<ReplyIcon size="s" color="primary" />}
4546
toggledIcon={<ReplyIcon size="s" color="primary" filled={true} />}
47+
testid={testid}
4648
/>
4749
);
4850
};

src/components/copy-link-button/copy-link-button.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ export type CopyLinkProps = {
88
active: string;
99
};
1010
onClick: () => void;
11+
testid?: string;
1112
};
1213

1314
let timer: NodeJS.Timeout;
1415

15-
export const CopyLinkButton: React.FC<CopyLinkProps> = ({ labels, onClick }) => {
16+
export const CopyLinkButton: React.FC<CopyLinkProps> = ({ labels, onClick, testid }) => {
1617
const [isCopied, setIsCopied] = useState(false);
1718
const [label, setLabel] = useState(labels.default);
1819
const [disabled, setDisabled] = useState(false);
@@ -52,6 +53,7 @@ export const CopyLinkButton: React.FC<CopyLinkProps> = ({ labels, onClick }) =>
5253
color="base"
5354
disabled={disabled}
5455
icon={<ShareIcon size="s" color="base" />}
56+
testid={testid}
5557
/>
5658
);
5759
};

src/components/modal/modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface ModalProps {
1818
export const Modal: FC<ModalProps> = ({ children, title, isOpen, width, onClose, onSubmit }) => {
1919
return (
2020
<Transition appear show={isOpen} as={Fragment}>
21-
<Dialog as="div" className="relative z-30" onClose={onClose}>
21+
<Dialog as="div" className="relative z-50" onClose={onClose}>
2222
<Transition.Child
2323
as={Fragment}
2424
enter="ease-out duration-300"

src/components/toggle/toggle.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type ToggleProps = {
1212
toggledIcon?: ReactElement;
1313
hoveredIcon?: ReactElement;
1414
disabled?: boolean;
15+
testid?: string;
1516
};
1617

1718
export const Toggle: FC<ToggleProps> = ({
@@ -24,6 +25,7 @@ export const Toggle: FC<ToggleProps> = ({
2425
toggledIcon,
2526
hoveredIcon,
2627
disabled,
28+
testid,
2729
}) => {
2830
const [isHovered, setIsHovered] = useState(false);
2931

@@ -67,7 +69,8 @@ export const Toggle: FC<ToggleProps> = ({
6769
onClick={handleToggle}
6870
onMouseOver={() => setIsHovered(!disabled && !isToggled)}
6971
onMouseOut={() => setIsHovered(false)}
70-
className={classnames(baseClasses, colorClasses[color], disabled ? 'cursor-default' : '')}>
72+
className={classnames(baseClasses, colorClasses[color], disabled ? 'cursor-default' : '')}
73+
data-testid={testid}>
7174
{renderIcon()}
7275
<span className={getLabelClasses()}>{label}</span>
7376
</button>

0 commit comments

Comments
 (0)