Skip to content

Commit

Permalink
chore: call getServerInfo on reset
Browse files Browse the repository at this point in the history
  • Loading branch information
ameerul-deriv committed Sep 18, 2024
1 parent 6686628 commit 808e9e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/pages/endpoint/screens/Endpoint/Endpoint.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Controller, useForm } from 'react-hook-form';
import { getServerInfo } from '@/constants';
import { Button, Input, Text } from '@deriv-com/ui';
import { LocalStorageConstants, LocalStorageUtils } from '@deriv-com/utils';
import './Endpoint.scss';
Expand Down Expand Up @@ -86,7 +87,7 @@ const Endpoint = () => {
LocalStorageUtils.setValue<string>(LocalStorageConstants.configServerURL, '');
LocalStorageUtils.setValue<string>(LocalStorageConstants.configAppId, '');
reset();
window.location.reload();
getServerInfo();
}}
variant='outlined'
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import Endpoint from '../Endpoint';

const mockGetServerInfo = jest.fn();

jest.mock('@/constants', () => ({
getServerInfo: jest.fn(() => mockGetServerInfo()),
}));

describe('<Endpoint />', () => {
it('should render the endpoint component', () => {
render(<Endpoint />);
Expand All @@ -28,7 +34,7 @@ describe('<Endpoint />', () => {
expect(JSON.parse(localStorage.getItem('config.app_id') || '')).toBe('123');
});

it('should reset the server_url and app_id when user clicks on the reset button', async () => {
it('should call getServerInfo and reset the inputs when user clicks on the reset button', async () => {
render(<Endpoint />);

const serverUrlInput = screen.getByTestId('dt_endpoint_server_url_input');
Expand All @@ -41,5 +47,6 @@ describe('<Endpoint />', () => {

expect(JSON.parse(localStorage.getItem('config.server_url') || '')).toBe('');
expect(JSON.parse(localStorage.getItem('config.app_id') || '')).toBe('');
expect(mockGetServerInfo).toHaveBeenCalled();
});
});

0 comments on commit 808e9e5

Please sign in to comment.