Skip to content

Commit 9cb57dc

Browse files
committed
fix tests
1 parent 4b9d033 commit 9cb57dc

File tree

5 files changed

+31
-50
lines changed

5 files changed

+31
-50
lines changed

packages/code-editor/src/CodeEditor/CodeEditor.spec.tsx

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,18 @@ jest.mock('@codemirror/language', () => {
155155

156156
describe('packages/code-editor', () => {
157157
test('Renders default value in editor', async () => {
158-
const { editor, container } = renderCodeEditor({ defaultValue: 'content' });
158+
const { editor, container } = renderCodeEditor({
159+
defaultValue: 'content',
160+
});
161+
await editor.waitForEditorView();
162+
163+
expect(container).toHaveTextContent('content');
164+
});
165+
166+
test('Renders default value in editor with search disabled', async () => {
167+
const { editor, container } = renderCodeEditor({
168+
defaultValue: 'content',
169+
});
159170
await editor.waitForEditorView();
160171

161172
expect(container).toHaveTextContent('content');
@@ -827,43 +838,6 @@ describe('packages/code-editor', () => {
827838
});
828839
});
829840

830-
test('Pressing CMD+F brings up the search menu', async () => {
831-
const { editor, container } = renderCodeEditor({
832-
defaultValue: 'console.log("hello world");\nconsole.log("test");',
833-
});
834-
835-
await editor.waitForEditorView();
836-
837-
// Focus the editor first
838-
const contentElement = editor.getBySelector(CodeEditorSelectors.Content);
839-
userEvent.click(contentElement);
840-
841-
// Verify editor is focused
842-
await waitFor(() => {
843-
expect(container.querySelector('.cm-focused')).toBeInTheDocument();
844-
});
845-
846-
// Press Ctrl+F to open search (works on most platforms)
847-
userEvent.keyboard('{Control>}f{/Control}');
848-
849-
// Check if the search panel appears
850-
await waitFor(() => {
851-
// CodeMirror 6 search creates a panel with specific classes
852-
const searchPanel = container.querySelector(
853-
CodeEditorSelectors.SearchPanel,
854-
);
855-
expect(searchPanel).toBeInTheDocument();
856-
});
857-
858-
// Verify search input field is present and can be typed in
859-
await waitFor(() => {
860-
const searchInput = container.querySelector(
861-
CodeEditorSelectors.SearchInput,
862-
);
863-
expect(searchInput).toBeInTheDocument();
864-
});
865-
});
866-
867841
test('Pressing TAB enters correct tab', async () => {
868842
const { editor } = renderCodeEditor({
869843
defaultValue: 'console.log("test");',

packages/code-editor/src/CodeEditor/CodeEditor.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,7 @@ const BaseCodeEditor = forwardRef<CodeEditorHandle, CodeEditorProps>(
253253
const searchModule = modules?.['@codemirror/search'];
254254
const Prec = modules?.['@codemirror/state']?.Prec;
255255

256-
if (
257-
!editorContainerRef?.current ||
258-
!EditorView ||
259-
!Prec ||
260-
!commands ||
261-
!searchModule
262-
) {
256+
if (!editorContainerRef?.current || !EditorView || !Prec || !commands) {
263257
return;
264258
}
265259

@@ -275,7 +269,7 @@ const BaseCodeEditor = forwardRef<CodeEditorHandle, CodeEditorProps>(
275269

276270
commands.history(),
277271

278-
enableSearchPanel
272+
enableSearchPanel && searchModule
279273
? searchModule.search({
280274
createPanel: view => {
281275
const dom = document.createElement('div');
@@ -322,7 +316,9 @@ const BaseCodeEditor = forwardRef<CodeEditorHandle, CodeEditorProps>(
322316
key: 'Shift-Tab',
323317
run: commands.indentLess,
324318
},
325-
...(enableSearchPanel ? searchModule.searchKeymap : []),
319+
...(enableSearchPanel && searchModule
320+
? searchModule.searchKeymap
321+
: []),
326322
...commands.defaultKeymap,
327323
...commands.historyKeymap,
328324
]),

packages/code-editor/src/CodeEditor/hooks/useModuleLoaders.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ describe('useModuleLoaders', () => {
2929
expect(typeof loaders['@codemirror/commands']).toBe('function');
3030
});
3131

32+
test('includes search module when enableSearchPanel is true', () => {
33+
const props: CodeEditorProps = {
34+
...baseProps,
35+
enableSearchPanel: true,
36+
};
37+
38+
const { result } = renderHook(() => useModuleLoaders(props));
39+
40+
expect(result.current).toHaveProperty('@codemirror/search');
41+
});
42+
3243
test('includes hyperlink module when enableClickableUrls is true', () => {
3344
const props: CodeEditorProps = {
3445
...baseProps,
@@ -95,7 +106,7 @@ describe('useModuleLoaders', () => {
95106
{
96107
line: 1,
97108
column: 1,
98-
content: 'Error message',
109+
messages: ['Error message'],
99110
severity: 'error',
100111
length: 0,
101112
},
@@ -359,7 +370,7 @@ describe('useModuleLoaders', () => {
359370
{
360371
line: 1,
361372
column: 1,
362-
content: 'Error',
373+
messages: ['Error'],
363374
severity: 'error',
364375
length: 0,
365376
},

packages/code-editor/src/CodeEditor/hooks/useModuleLoaders.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ export const useModuleLoaders = ({
151151
}, [
152152
enableClickableUrls,
153153
enableCodeFolding,
154+
enableSearchPanel,
154155
forceParsing,
155156
indentUnit,
156157
tooltips,

packages/code-editor/src/CodeEditor/hooks/useModules.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ describe('useModules', () => {
5353
'@codemirror/view',
5454
'@codemirror/state',
5555
'@codemirror/commands',
56-
'@codemirror/search',
5756
];
5857

5958
expect(Object.keys(result.current.modules).sort()).toEqual(

0 commit comments

Comments
 (0)