Skip to content

Commit c5d2bf4

Browse files
author
Kevin White
committed
Refactor mock components in Bedrock.test.tsx for improved data-testid handling
1 parent 01c7d2f commit c5d2bf4

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

webview-ui/src/components/settings/providers/__tests__/Bedrock.test.tsx

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import { ProviderSettings } from "@roo-code/types"
66
// Mock the vscrui Checkbox component
77
jest.mock("vscrui", () => ({
88
Checkbox: ({ children, checked, onChange }: any) => (
9-
<label data-testid={`checkbox-${children?.toString().replace(/\\s+/g, "-").toLowerCase()}`}>
9+
<label data-testid={`checkbox-${children?.toString().replace(/\s+/g, "-").toLowerCase()}`}>
1010
<input
1111
type="checkbox"
1212
checked={checked}
1313
onChange={() => onChange(!checked)} // Toggle the checked state
14-
data-testid={`checkbox-input-${children?.toString().replace(/\\s+/g, "-").toLowerCase()}`}
14+
data-testid={`checkbox-input-${children?.toString().replace(/\s+/g, "-").toLowerCase()}`}
1515
/>
1616
{children}
1717
</label>
@@ -20,28 +20,31 @@ jest.mock("vscrui", () => ({
2020

2121
// Mock the VSCodeTextField component
2222
jest.mock("@vscode/webview-ui-toolkit/react", () => ({
23-
VSCodeTextField: ({ children, value, onInput, placeholder, className, style, "data-testid": dataTestId }: any) => {
24-
// Special case for VPC endpoint field with data-testid
25-
if (dataTestId === "vpc-endpoint-input") {
26-
return (
27-
<div data-testid="vpc-endpoint-text-field" className={className} style={style}>
28-
{children}
29-
<input
30-
type="text"
31-
value={value}
32-
onChange={(e) => onInput && onInput(e)}
33-
placeholder={placeholder}
34-
data-testid="vpc-endpoint-input"
35-
/>
36-
</div>
37-
)
38-
}
39-
40-
// Regular text fields
23+
VSCodeTextField: ({
24+
children,
25+
value,
26+
onInput,
27+
placeholder,
28+
className,
29+
style,
30+
"data-testid": dataTestId,
31+
...rest
32+
}: any) => {
33+
// For all text fields - apply data-testid directly to input if provided
4134
return (
42-
<div data-testid="vscode-text-field" className={className} style={style}>
35+
<div
36+
data-testid={dataTestId ? `${dataTestId}-text-field` : "vscode-text-field"}
37+
className={className}
38+
style={style}>
4339
{children}
44-
<input type="text" value={value} onChange={(e) => onInput && onInput(e)} placeholder={placeholder} />
40+
<input
41+
type="text"
42+
value={value}
43+
onChange={(e) => onInput && onInput(e)}
44+
placeholder={placeholder}
45+
data-testid={dataTestId}
46+
{...rest}
47+
/>
4548
</div>
4649
)
4750
},

0 commit comments

Comments
 (0)