Skip to content

Commit 71390fb

Browse files
authored
Add test that validates interactive and notebook editor at the same time (#12384)
* Add test to open both interactive and native at same time * Add news entry
1 parent 9ab353a commit 71390fb

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

news/3 Code Health/11445.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a functional test that opens both the interactive window and a notebook at the same time.

src/test/datascience/intellisense.functional.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ import { addMockData, enterEditorKey, getInteractiveEditor, getNativeEditor, typ
480480
await waitForHover('Interactive', wrapper, 1, 1);
481481
verifyHoverVisible('Interactive', wrapper, 'a=1\na\nb=2\nb');
482482

483-
await InteractiveHelpers.closeInteractiveWindow(window, wrapper);
483+
await InteractiveHelpers.closeInteractiveWindow(ioc, window);
484484
},
485485
() => {
486486
return ioc;

src/test/datascience/interactiveWindow.functional.test.tsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
} from './interactiveWindowTestHelpers';
3939
import { MockDocumentManager } from './mockDocumentManager';
4040
import { MockEditor } from './mockTextEditor';
41+
import { addCell, createNewEditor } from './nativeEditorTestHelpers';
4142
import {
4243
addContinuousMockData,
4344
addInputMockData,
@@ -686,7 +687,7 @@ for i in range(0, 100):
686687
activeInterpreter?.path,
687688
'Active intrepreter not used to launch notebook'
688689
);
689-
await closeInteractiveWindow(window, wrapper);
690+
await closeInteractiveWindow(ioc, window);
690691

691692
// Add another python path
692693
const secondUri = Uri.file('bar.py');
@@ -1173,4 +1174,37 @@ for i in range(0, 100):
11731174
return ioc;
11741175
}
11751176
);
1177+
1178+
test('Open notebook and interactive at the same time', async () => {
1179+
addMockData(ioc, 'a=1\na', 1, 'text/plain');
1180+
addMockData(ioc, 'b=2\nb', 2, 'text/plain');
1181+
1182+
// Mount two different webviews
1183+
const nativeWrapper = mountWebView(ioc, 'native');
1184+
let interactiveWrapper = mountWebView(ioc, 'interactive');
1185+
await createNewEditor(ioc);
1186+
let interactiveEditor = await getOrCreateInteractiveWindow(ioc);
1187+
1188+
// Run code in both
1189+
await addCode(ioc, interactiveWrapper, 'a=1\na');
1190+
await addCell(ioc, nativeWrapper, 'a=1\na', true);
1191+
1192+
// Make sure both are correct
1193+
verifyHtmlOnCell(interactiveWrapper, 'InteractiveCell', '<span>1</span>', CellPosition.Last);
1194+
verifyHtmlOnCell(nativeWrapper, 'NativeCell', '<span>1</span>', CellPosition.Last);
1195+
1196+
// Close the interactive editor.
1197+
await closeInteractiveWindow(ioc, interactiveEditor);
1198+
1199+
// Run another cell and make sure it works in the notebook
1200+
await addCell(ioc, nativeWrapper, 'b=2\nb', true);
1201+
verifyHtmlOnCell(nativeWrapper, 'NativeCell', '<span>2</span>', CellPosition.Last);
1202+
1203+
// Rerun the interactive window
1204+
interactiveWrapper = mountWebView(ioc, 'interactive');
1205+
interactiveEditor = await getOrCreateInteractiveWindow(ioc);
1206+
await addCode(ioc, interactiveWrapper, 'a=1\na');
1207+
1208+
verifyHtmlOnCell(interactiveWrapper, 'InteractiveCell', '<span>1</span>', CellPosition.Last);
1209+
});
11761210
});

src/test/datascience/interactiveWindowTestHelpers.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,9 @@ export async function getOrCreateInteractiveWindow(ioc: DataScienceIocContainer)
2626
return (await interactiveWindowProvider.getOrCreateActive()) as InteractiveWindow;
2727
}
2828

29-
export function closeInteractiveWindow(
30-
window: IInteractiveWindow,
31-
// tslint:disable-next-line: no-any
32-
wrapper: ReactWrapper<any, Readonly<{}>, React.Component>
33-
) {
29+
export function closeInteractiveWindow(ioc: DataScienceIocContainer, window: IInteractiveWindow) {
3430
const promise = window.dispose();
35-
wrapper.unmount();
31+
ioc.getWebPanel('default').dispose();
3632
return promise;
3733
}
3834

src/test/datascience/testHelpers.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export function getLastOutputCell(
230230

231231
export function verifyHtmlOnCell(
232232
wrapper: ReactWrapper<any, Readonly<{}>, React.Component>,
233-
cellType: string,
233+
cellType: 'NativeCell' | 'InteractiveCell',
234234
html: string | undefined | RegExp,
235235
cellIndex: number | CellPosition
236236
) {

0 commit comments

Comments
 (0)