diff --git a/frontend/src/components/Editor/Editor.test.tsx b/frontend/src/components/Editor/Editor.test.tsx new file mode 100644 index 0000000000..3260c477ce --- /dev/null +++ b/frontend/src/components/Editor/Editor.test.tsx @@ -0,0 +1,60 @@ +import { render, screen } from '@testing-library/react'; +import { useIsDarkMode } from 'hooks/useDarkMode'; +import React from 'react'; + +import Editor from './index'; + +jest.mock('hooks/useDarkMode', () => ({ + useIsDarkMode: jest.fn(), +})); + +describe('Editor', () => { + it('renders correctly with default props', () => { + const { container } = render(); + expect(container).toMatchSnapshot(); + }); + + it('renders correctly with custom props', () => { + const customProps = { + value: 'test', + language: 'javascript', + readOnly: true, + height: '50vh', + options: { minimap: { enabled: false } }, + }; + const { container } = render( + , + ); + expect(container).toMatchSnapshot(); + }); + + it('renders with dark mode theme', () => { + (useIsDarkMode as jest.Mock).mockImplementation(() => true); + + const { container } = render(); + + expect(container).toMatchSnapshot(); + }); + + it('renders with light mode theme', () => { + (useIsDarkMode as jest.Mock).mockImplementation(() => false); + + const { container } = render(); + + expect(container).toMatchSnapshot(); + }); + + it('displays "Loading..." message initially', () => { + const { rerender } = render(); + + expect(screen.getByText('Loading...')).toBeInTheDocument(); + + rerender(); + }); +}); diff --git a/frontend/src/components/Editor/__snapshots__/Editor.test.tsx.snap b/frontend/src/components/Editor/__snapshots__/Editor.test.tsx.snap new file mode 100644 index 0000000000..1670cedb9c --- /dev/null +++ b/frontend/src/components/Editor/__snapshots__/Editor.test.tsx.snap @@ -0,0 +1,69 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Editor renders correctly with custom props 1`] = ` +
+
+
+ Loading... +
+
+
+
+`; + +exports[`Editor renders correctly with default props 1`] = ` +
+
+
+ Loading... +
+
+
+
+`; + +exports[`Editor renders with dark mode theme 1`] = ` +
+
+
+ Loading... +
+
+
+
+`; + +exports[`Editor renders with light mode theme 1`] = ` +
+
+
+ Loading... +
+
+
+
+`; diff --git a/frontend/src/components/Editor/index.tsx b/frontend/src/components/Editor/index.tsx index e24fab3c80..9e5f22a2a4 100644 --- a/frontend/src/components/Editor/index.tsx +++ b/frontend/src/components/Editor/index.tsx @@ -13,6 +13,8 @@ function Editor({ const isDarkMode = useIsDarkMode(); const onChangeHandler = (newValue?: string): void => { + if (readOnly) return; + if (typeof newValue === 'string' && onChange) onChange(newValue); }; @@ -29,6 +31,7 @@ function Editor({ options={editorOptions} height={height} onChange={onChangeHandler} + data-testid="monaco-editor" /> ); }