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

Commit 6030674

Browse files
committed
chore: cov fx
1 parent 8947756 commit 6030674

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React from 'react';
22
import userEvent from '@testing-library/user-event';
3-
import { cleanup, render, screen } from '@testing-library/react';
3+
import { cleanup, render, screen, waitFor } from '@testing-library/react';
44
import SubscribeRenderer from '..';
55
import useAuthContext from '@site/src/hooks/useAuthContext';
66
import useSubscription from '@site/src/hooks/useSubscription';
77
import useDynamicImportJSON from '@site/src/hooks/useDynamicImportJSON';
88
import { IAuthContext } from '@site/src/contexts/auth/auth.context';
9+
import LoginDialog from '../../LoginDialog';
910

1011
jest.mock('@site/src/hooks/useAuthContext');
1112

@@ -132,4 +133,28 @@ describe('SubscribeRenderer', () => {
132133
unmount();
133134
expect(mockUnsubscribe).toBeCalledTimes(1);
134135
});
136+
it('should call login dialog when the error code is not authourized', async () => {
137+
const setToggleModal = jest.fn();
138+
jest.spyOn(React, 'useState').mockReturnValue([false, setToggleModal]);
139+
mockUseAuthContext.mockImplementation(() => ({
140+
is_logged_in: false,
141+
is_authorized: false,
142+
}));
143+
mockUseSubscription.mockImplementation(() => ({
144+
subscribe: mockSubscribe,
145+
unsubscribe: mockUnsubscribe,
146+
error: { code: 'AuthorizationRequired' },
147+
full_response: {
148+
tick: 1,
149+
echo_req: { tick: 1 },
150+
},
151+
}));
152+
153+
render(<SubscribeRenderer name='ticks' auth={1} reqData={request_data} />);
154+
const button = await screen.findByRole('button', { name: /Send Request/i });
155+
await userEvent.click(button);
156+
await waitFor(() => {
157+
expect(setToggleModal).toHaveBeenCalled();
158+
});
159+
});
135160
});

src/features/Apiexplorer/SubscribeRenderer/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function SubscribeRenderer<T extends TSocketSubscribableEndpointNames>({
2525
}: IResponseRendererProps<T>) {
2626
const { is_logged_in } = useAuthContext();
2727
const { disableSendRequest } = useDisableSendRequest();
28-
const { full_response, is_loading, subscribe, unsubscribe, error } = useSubscription<T>(name);
28+
const { full_response, is_loading, subscribe, error } = useSubscription<T>(name);
2929
const [response_state, setResponseState] = useState(false);
3030
const [toggle_modal, setToggleModal] = useState(false);
3131
const [is_not_valid, setIsNotValid] = useState(false);

0 commit comments

Comments
 (0)