diff --git a/src/features/Apiexplorer/__tests__/ApiExplorer.test.tsx b/src/features/Apiexplorer/__tests__/ApiExplorer.test.tsx index 48c96a3fd..72c3cde28 100644 --- a/src/features/Apiexplorer/__tests__/ApiExplorer.test.tsx +++ b/src/features/Apiexplorer/__tests__/ApiExplorer.test.tsx @@ -5,9 +5,8 @@ import userEvent from '@testing-library/user-event'; import useWS from '@site/src/hooks/useWs'; import useAuthContext from '@site/src/hooks/useAuthContext'; import useDynamicImportJSON from '@site/src/hooks/useDynamicImportJSON'; -import { cleanup, render, screen } from '@testing-library/react'; +import { cleanup, render, screen, act } from '@testing-library/react'; import { IAuthContext } from '@site/src/contexts/auth/auth.context'; -import { act } from 'react-dom/test-utils'; jest.mock('@docusaurus/router', () => ({ useLocation: () => ({ @@ -44,6 +43,8 @@ const mockUseDynamicImportJSON = useDynamicImportJSON as jest.MockedFunction< () => Partial> >; +const mockHandleSelectChange = jest.fn(); + mockUseDynamicImportJSON.mockImplementation(() => ({ request_info: { auth_required: 1, @@ -56,6 +57,7 @@ mockUseDynamicImportJSON.mockImplementation(() => ({ title: 'this is a test title', }, setSelected: jest.fn(), + handleTextAreaInput: mockHandleSelectChange, handleSelectChange: jest.fn(), text_data: { name: null, @@ -149,6 +151,13 @@ describe('ApiExplorerFeatures', () => { await userEvent.click(close_button); expect(dialog).not.toBeVisible(); }); + + it('should change the text when writing in the textbox', async () => { + const json_box = screen.getByPlaceholderText('Request JSON'); + expect(json_box).toBeVisible(); + await userEvent.type(json_box, 'test123'); + expect(mockHandleSelectChange).toHaveBeenCalled(); + }); }); describe('Logged in', () => { diff --git a/src/hooks/useDynamicImportJSON/__tests__/useDynamicImport.test.tsx b/src/hooks/useDynamicImportJSON/__tests__/useDynamicImport.test.tsx index b0103a7da..50669c165 100644 --- a/src/hooks/useDynamicImportJSON/__tests__/useDynamicImport.test.tsx +++ b/src/hooks/useDynamicImportJSON/__tests__/useDynamicImport.test.tsx @@ -1,7 +1,10 @@ +import React from 'react'; import '@testing-library/jest-dom'; +import userEvent from '@testing-library/user-event'; import { renderHook } from '@testing-library/react-hooks'; import { act } from 'react-dom/test-utils'; import useDynamicImportJSON from '..'; +import { cleanup, render, screen } from '@testing-library/react'; jest.mock('@docusaurus/router', () => ({ useLocation: () => ({ @@ -20,6 +23,7 @@ describe('useDynamicImportJSON', () => { afterEach(() => { jest.clearAllMocks(); + cleanup(); }); it('should populate text data with the correct values', () => { @@ -32,31 +36,74 @@ describe('useDynamicImportJSON', () => { }); }); + it('should be able to call handleTextAreaInput when typing in a textarea', async () => { + const spyHandleInputFunction = jest.spyOn(result.current, 'handleTextAreaInput'); + + render(