Skip to content

Commit d0b920d

Browse files
committed
test fixes
1 parent 72a438b commit d0b920d

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

packages/browser-repl/src/components/shell.spec.tsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import util from 'util';
12
import React, { useState, useEffect } from 'react';
23
import sinon from 'sinon';
34
import { render, screen, waitFor, configure } from '@testing-library/react';
@@ -168,19 +169,6 @@ describe('shell', function () {
168169
expect(filterEvaluateCalls(fakeRuntime.evaluate.args)).to.be.empty;
169170
});
170171

171-
it('calls onEditorChanged', function () {
172-
const onEditorChanged = sinon.spy();
173-
174-
render(
175-
<ShellWrapper runtime={fakeRuntime} onEditorChanged={onEditorChanged} />
176-
);
177-
178-
expect(onEditorChanged.callCount).to.equal(1);
179-
const editor = onEditorChanged.firstCall.args[0];
180-
expect(editor.focus).to.exist;
181-
expect(filterEvaluateCalls(fakeRuntime.evaluate.args)).to.be.empty;
182-
});
183-
184172
it('takes isOperationInProgress', function () {
185173
const isOperationInProgress = true;
186174

@@ -532,7 +520,8 @@ describe('shell', function () {
532520
let called = 0;
533521
// eslint-disable-next-line @typescript-eslint/require-await
534522
fakeRuntime.getShellPrompt = async () => {
535-
if (called++ <= 1) {
523+
called++;
524+
if (called === 1) {
536525
return 'mongos';
537526
}
538527
return 'rs0:primary';

packages/browser-repl/src/components/shell.tsx

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,29 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
206206
useImperativeHandle(
207207
ref,
208208
() => {
209-
return editorRef.current as EditorRef;
209+
return {
210+
foldAll() {
211+
return editorRef.current?.foldAll() ?? false;
212+
},
213+
unfoldAll() {
214+
return editorRef.current?.unfoldAll() ?? false;
215+
},
216+
copyAll() {
217+
return editorRef.current?.copyAll() ?? false;
218+
},
219+
prettify() {
220+
return editorRef.current?.prettify() ?? false;
221+
},
222+
focus() {
223+
return editorRef.current?.focus() ?? false;
224+
},
225+
applySnippet(template: string) {
226+
return editorRef.current?.applySnippet(template) ?? false;
227+
},
228+
get editor() {
229+
return editorRef.current?.editor ?? null;
230+
},
231+
};
210232
},
211233
[]
212234
);
@@ -223,7 +245,7 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
223245
>(() => noop);
224246

225247
const focusEditor = useCallback(() => {
226-
editorRef?.current?.focus();
248+
editorRef.current?.focus();
227249
}, [editorRef]);
228250

229251
const listener = useMemo<RuntimeEvaluationListener>(() => {
@@ -406,19 +428,6 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
406428
shellInputContainerRef.current.scrollIntoView();
407429
}, [shellInputContainerRef]);
408430

409-
useEffect(() => {
410-
scrollToBottom();
411-
412-
void updateShellPrompt().then(async () => {
413-
if (initialEvaluate) {
414-
const evalLines = normalizeInitialEvaluate(initialEvaluate);
415-
for (const input of evalLines) {
416-
await onInput(input);
417-
}
418-
}
419-
});
420-
}, [initialEvaluate, onInput, scrollToBottom, updateShellPrompt, output]);
421-
422431
const onShellClicked = useCallback(
423432
(event: React.MouseEvent): void => {
424433
// Focus on input when clicking the shell background (not clicking output).
@@ -437,6 +446,21 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
437446
return Promise.resolve(false);
438447
}, [isOperationInProgress, runtime]);
439448

449+
const initialEvaluateRef = useRef(initialEvaluate);
450+
451+
useEffect(() => {
452+
scrollToBottom();
453+
454+
void updateShellPrompt().then(async () => {
455+
if (initialEvaluateRef.current) {
456+
const evalLines = normalizeInitialEvaluate(initialEvaluateRef.current);
457+
for (const input of evalLines) {
458+
await onInput(input);
459+
}
460+
}
461+
});
462+
}, [onInput, scrollToBottom, updateShellPrompt]);
463+
440464
/* eslint-disable jsx-a11y/no-static-element-interactions */
441465
/* eslint-disable jsx-a11y/click-events-have-key-events */
442466
return (

0 commit comments

Comments
 (0)