Skip to content

Commit 1d820f3

Browse files
committed
add: tests for grpc requests
feat: add common selectors to locator.ts fix: add dataTestId prop update locator
1 parent 24a36bc commit 1d820f3

File tree

19 files changed

+433
-19
lines changed

19 files changed

+433
-19
lines changed

packages/bruno-app/src/components/Accordion/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AccordionItem, AccordionHeader, AccordionContent } from './styledWrappe
44

55
const AccordionContext = createContext();
66

7-
const Accordion = ({ children, defaultIndex }) => {
7+
const Accordion = ({ children, defaultIndex, dataTestId }) => {
88
const [openIndex, setOpenIndex] = useState(defaultIndex);
99

1010
const toggleItem = (index) => {
@@ -13,7 +13,7 @@ const Accordion = ({ children, defaultIndex }) => {
1313

1414
return (
1515
<AccordionContext.Provider value={{ openIndex, toggleItem }}>
16-
<div>{children}</div>
16+
<div data-testid={dataTestId}>{children}</div>
1717
</AccordionContext.Provider>
1818
);
1919
};

packages/bruno-app/src/components/RequestPane/GrpcBody/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ const SingleGrpcMessage = ({ message, item, collection, index, methodType, isCol
187187
onClick={onSend}
188188
disabled={!isConnectionActive}
189189
className={`p-1 rounded ${isConnectionActive ? 'hover:bg-zinc-200 dark:hover:bg-zinc-600' : 'opacity-50 cursor-not-allowed'} transition-colors`}
190+
data-testid={`grpc-send-message-${index}`}
190191
>
191192
<IconSend
192193
size={16}
@@ -300,6 +301,7 @@ const GrpcBody = ({ item, collection, handleRun }) => {
300301
<div
301302
ref={messagesContainerRef}
302303
id="grpc-messages-container"
304+
data-testid="grpc-messages-container"
303305
className={`flex-1 ${body.grpc.length === 1 || !canClientSendMultipleMessages ? 'h-full' : 'overflow-y-auto'} ${canClientSendMultipleMessages && 'pb-16'}`}
304306
>
305307
{body.grpc
@@ -326,6 +328,7 @@ const GrpcBody = ({ item, collection, handleRun }) => {
326328
<button
327329
onClick={addNewMessage}
328330
className="add-message-btn flex items-center justify-center gap-2 py-2 px-4 rounded-md border border-neutral-200 dark:border-neutral-800 bg-neutral-100 dark:bg-neutral-700 hover:bg-neutral-200 dark:hover:bg-neutral-600 transition-colors shadow-md"
331+
data-testid="grpc-add-message-button"
329332
>
330333
<IconPlus size={16} strokeWidth={1.5} className="text-neutral-700 dark:text-neutral-300" />
331334
<span className="font-medium text-sm text-neutral-700 dark:text-neutral-300">Add Message</span>

packages/bruno-app/src/components/RequestPane/GrpcQueryUrl/MethodDropdown/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const MethodDropdown = ({
7373

7474
const MethodsDropdownIcon = forwardRef((props, ref) => {
7575
return (
76-
<div ref={ref} className="flex items-center justify-center ml-2 cursor-pointer select-none">
76+
<div ref={ref} className="flex items-center justify-center ml-2 cursor-pointer select-none" data-testid="grpc-method-dropdown-trigger">
7777
{selectedGrpcMethod && <div className="mr-2">{getIconForMethodType(selectedGrpcMethod.type)}</div>}
7878
<span className="text-xs">
7979
{selectedGrpcMethod ? (

packages/bruno-app/src/components/RequestPane/GrpcQueryUrl/index.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -389,19 +389,21 @@ const GrpcQueryUrl = ({ item, collection, handleRun }) => {
389389

390390
{isConnectionActive && isStreamingMethod && (
391391
<div className="connection-controls relative flex items-center h-full gap-3">
392-
<div className="infotip" onClick={handleCancelConnection}>
392+
<div className="infotip" onClick={handleCancelConnection} data-testid="grpc-cancel-connection-button">
393393
<IconX color={theme.requestTabs.icon.color} strokeWidth={1.5} size={22} className="cursor-pointer" />
394394
<span className="infotip-text text-xs">Cancel</span>
395395
</div>
396396

397-
{isClientStreamingMethod && <div onClick={handleEndConnection}>
398-
<IconCheck
399-
color={theme.colors.text.green}
400-
strokeWidth={2}
401-
size={22}
402-
className="cursor-pointer"
403-
/>
404-
</div>}
397+
{isClientStreamingMethod && (
398+
<div onClick={handleEndConnection} data-testid="grpc-end-connection-button">
399+
<IconCheck
400+
color={theme.colors.text.green}
401+
strokeWidth={2}
402+
size={22}
403+
className="cursor-pointer"
404+
/>
405+
</div>
406+
)}
405407
</div>
406408
)}
407409

packages/bruno-app/src/components/ResponsePane/GrpcResponsePane/GrpcQueryResult/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ const GrpcQueryResult = ({ item, collection }) => {
6161
}
6262

6363
return (
64-
<StyledWrapper className="w-full h-full relative flex flex-col mt-2">
64+
<StyledWrapper className="w-full h-full relative flex flex-col mt-2" data-testid="grpc-response-content">
6565
{hasError && showErrorMessage && <GrpcError error={errorMessage} onClose={() => setShowErrorMessage(false)} />}
6666
{hasResponses && (
67-
<div className={`overflow-y-auto ${responsesList.length === 1 ? 'flex-1' : ''}`}>
67+
<div className={`overflow-y-auto ${responsesList.length === 1 ? 'flex-1' : ''}`} data-testid="grpc-responses-container">
6868
{responsesList.length === 1 ? (
6969
// Single message - render directly without accordion
70-
<div className="h-full">
70+
<div className="h-full" data-testid="grpc-single-response">
7171
<CodeEditor
7272
collection={collection}
7373
font={get(preferences, 'font.codeFont', 'default')}
@@ -80,13 +80,13 @@ const GrpcQueryResult = ({ item, collection }) => {
8080
</div>
8181
) : (
8282
// Multiple messages - use accordion
83-
<Accordion defaultIndex={0}>
83+
<Accordion defaultIndex={0} dataTestId="grpc-responses-accordion">
8484
{reversedResponsesList.map((response, index) => {
8585
// Calculate the original response number (for display purposes)
8686
const originalIndex = responsesList.length - index - 1;
8787

8888
return (
89-
<Accordion.Item key={originalIndex} index={index}>
89+
<Accordion.Item key={originalIndex} index={index} data-testid={`grpc-response-item-${originalIndex}`}>
9090
<Accordion.Header index={index} style={{ padding: '8px 12px', minHeight: '40px' }}>
9191
<div className="flex justify-between w-full">
9292
<div className="font-medium">

packages/bruno-app/src/components/ResponsePane/GrpcResponsePane/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const GrpcResponsePane = ({ item, collection }) => {
108108

109109
return (
110110
<StyledWrapper className="flex flex-col h-full relative">
111-
<div className="flex flex-wrap items-center pl-3 pr-4 tabs" role="tablist">
111+
<div className="flex flex-wrap items-center pl-3 pr-4 tabs" role="tablist" data-testid="grpc-response-tabs">
112112
{tabConfig.map((tab) => (
113113
<Tab
114114
key={tab.name}

packages/bruno-app/src/components/Tab/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ const Tab = ({ name, label, isActive, onClick, count = 0, className = '', ...pro
1111
className={tabClassName}
1212
role="tab"
1313
onClick={() => onClick(name)}
14+
data-testid={`tab-${name}`}
1415
{...props}
1516
>
1617
{label}
17-
{count > 0 && <sup className="ml-1 font-medium">{count}</sup>}
18+
{count > 0 && <sup className="ml-1 font-medium" data-testid={`tab-${name}-count`}>{count}</sup>}
1819
</div>
1920
);
2021
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
meta {
2+
name: BidiHello
3+
type: grpc
4+
seq: 4
5+
}
6+
7+
grpc {
8+
url: {{host}}
9+
method: /hello.HelloService/BidiHello
10+
body: grpc
11+
auth: inherit
12+
methodType: bidi-streaming
13+
}
14+
15+
body:grpc {
16+
name: message 1
17+
content: '''
18+
{
19+
"greeting": "cuius"
20+
}
21+
'''
22+
}
23+
24+
body:grpc {
25+
name: message 2
26+
content: '''
27+
{
28+
"greeting": "adfectus"
29+
}
30+
'''
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
meta {
2+
name: LotOfGreetings
3+
type: grpc
4+
seq: 3
5+
}
6+
7+
grpc {
8+
url: {{host}}
9+
method: /hello.HelloService/LotsOfGreetings
10+
body: grpc
11+
auth: inherit
12+
methodType: client-streaming
13+
}
14+
15+
body:grpc {
16+
name: message 1
17+
content: '''
18+
{
19+
"greeting": "sortitus"
20+
}
21+
'''
22+
}
23+
24+
body:grpc {
25+
name: message 2
26+
content: '''
27+
{
28+
"greeting": "porro"
29+
}
30+
'''
31+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
meta {
2+
name: LotOfReplies
3+
type: grpc
4+
seq: 2
5+
}
6+
7+
grpc {
8+
url: {{host}}
9+
method: /hello.HelloService/LotsOfReplies
10+
body: grpc
11+
auth: inherit
12+
methodType: server-streaming
13+
}
14+
15+
body:grpc {
16+
name: message 1
17+
content: '''
18+
{
19+
"greeting": "suadeo"
20+
}
21+
'''
22+
}

0 commit comments

Comments
 (0)