|
1 | 1 | import React from 'react'; |
2 | 2 | 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'; |
4 | 4 | import SubscribeRenderer from '..'; |
5 | 5 | import useAuthContext from '@site/src/hooks/useAuthContext'; |
6 | 6 | import useSubscription from '@site/src/hooks/useSubscription'; |
7 | 7 | import useDynamicImportJSON from '@site/src/hooks/useDynamicImportJSON'; |
8 | 8 | import { IAuthContext } from '@site/src/contexts/auth/auth.context'; |
| 9 | +import LoginDialog from '../../LoginDialog'; |
9 | 10 |
|
10 | 11 | jest.mock('@site/src/hooks/useAuthContext'); |
11 | 12 |
|
@@ -132,4 +133,28 @@ describe('SubscribeRenderer', () => { |
132 | 133 | unmount(); |
133 | 134 | expect(mockUnsubscribe).toBeCalledTimes(1); |
134 | 135 | }); |
| 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 | + }); |
135 | 160 | }); |
0 commit comments