Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 71bdc29

Browse files
authored
Merge pull request #178 from sanjam-deriv/disableTextbox
2 parents d78e8a1 + 482a327 commit 71bdc29

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

src/features/Apiexplorer/RequestJSONBox/__tests__/RequestJsonBox.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ describe('RequestResponseRenderer', () => {
7373
expect(placeholder).toHaveLength(1);
7474
});
7575

76+
it('should disable text box if no api call is selected in the dropdown', () => {
77+
const newProps = {
78+
handleChange: jest.fn(),
79+
request_example: '',
80+
name: null as TSocketEndpointNames,
81+
auth: 0,
82+
};
83+
cleanup();
84+
render(<RequestJSONBox {...newProps} />);
85+
const textarea = screen.getByLabelText('Request JSON');
86+
expect(textarea).toBeDisabled();
87+
});
88+
7689
it('should render response renderer component', async () => {
7790
const primaryButton = screen.getByRole('button', { name: /Send Request/i });
7891
const secondaryButton = screen.getByRole('button', { name: /clear/i });

src/features/Apiexplorer/RequestJSONBox/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { TSocketEndpointNames } from '@site/src/configs/websocket/types';
22
import clsx from 'clsx';
3-
import React, { useEffect, useMemo } from 'react';
3+
import React, { useEffect, useMemo, useState } from 'react';
44
import RequestResponseRenderer from '../RequestResponseRenderer';
55
import style from './RequestJSONBox.module.scss';
66
import SubscribeRenderer from '../SubscribeRenderer';
@@ -22,6 +22,15 @@ function RequestJSONBox<T extends TSocketEndpointNames>({
2222
const is_subscribe = useMemo(() => {
2323
return request_example?.includes('subscribe');
2424
}, [request_example]);
25+
const [isdisabled, setIsDisabled] = useState(false);
26+
27+
useEffect(() => {
28+
if (name === null) {
29+
setIsDisabled(true);
30+
} else {
31+
setIsDisabled(false);
32+
}
33+
}, [name]);
2534

2635
return (
2736
<div className={style.playgroundBox}>
@@ -35,6 +44,7 @@ function RequestJSONBox<T extends TSocketEndpointNames>({
3544
placeholder={'Request JSON'}
3645
onChange={handleChange}
3746
value={request_example}
47+
disabled={isdisabled}
3848
></textarea>
3949
{is_subscribe ? (
4050
<SubscribeRenderer

src/features/Apiexplorer/__tests__/ApiExplorer.test.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,6 @@ describe('ApiExplorerFeatures', () => {
151151
await userEvent.click(close_button);
152152
expect(dialog).not.toBeVisible();
153153
});
154-
155-
it('should change the text when writing in the textbox', async () => {
156-
const json_box = screen.getByPlaceholderText('Request JSON');
157-
expect(json_box).toBeVisible();
158-
await userEvent.type(json_box, 'test123');
159-
expect(mockHandleSelectChange).toHaveBeenCalled();
160-
});
161154
});
162155

163156
describe('Logged in', () => {

0 commit comments

Comments
 (0)