Skip to content

Commit

Permalink
Add test that validates interactive and notebook editor at the same t…
Browse files Browse the repository at this point in the history
…ime (microsoft#12384)

* Add test to open both interactive and native at same time

* Add news entry
  • Loading branch information
rchiodo committed Jun 17, 2020
1 parent 9ab353a commit 71390fb
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
1 change: 1 addition & 0 deletions news/3 Code Health/11445.md
@@ -0,0 +1 @@
Add a functional test that opens both the interactive window and a notebook at the same time.
2 changes: 1 addition & 1 deletion src/test/datascience/intellisense.functional.test.tsx
Expand Up @@ -480,7 +480,7 @@ import { addMockData, enterEditorKey, getInteractiveEditor, getNativeEditor, typ
await waitForHover('Interactive', wrapper, 1, 1);
verifyHoverVisible('Interactive', wrapper, 'a=1\na\nb=2\nb');

await InteractiveHelpers.closeInteractiveWindow(window, wrapper);
await InteractiveHelpers.closeInteractiveWindow(ioc, window);
},
() => {
return ioc;
Expand Down
36 changes: 35 additions & 1 deletion src/test/datascience/interactiveWindow.functional.test.tsx
Expand Up @@ -38,6 +38,7 @@ import {
} from './interactiveWindowTestHelpers';
import { MockDocumentManager } from './mockDocumentManager';
import { MockEditor } from './mockTextEditor';
import { addCell, createNewEditor } from './nativeEditorTestHelpers';
import {
addContinuousMockData,
addInputMockData,
Expand Down Expand Up @@ -686,7 +687,7 @@ for i in range(0, 100):
activeInterpreter?.path,
'Active intrepreter not used to launch notebook'
);
await closeInteractiveWindow(window, wrapper);
await closeInteractiveWindow(ioc, window);

// Add another python path
const secondUri = Uri.file('bar.py');
Expand Down Expand Up @@ -1173,4 +1174,37 @@ for i in range(0, 100):
return ioc;
}
);

test('Open notebook and interactive at the same time', async () => {
addMockData(ioc, 'a=1\na', 1, 'text/plain');
addMockData(ioc, 'b=2\nb', 2, 'text/plain');

// Mount two different webviews
const nativeWrapper = mountWebView(ioc, 'native');
let interactiveWrapper = mountWebView(ioc, 'interactive');
await createNewEditor(ioc);
let interactiveEditor = await getOrCreateInteractiveWindow(ioc);

// Run code in both
await addCode(ioc, interactiveWrapper, 'a=1\na');
await addCell(ioc, nativeWrapper, 'a=1\na', true);

// Make sure both are correct
verifyHtmlOnCell(interactiveWrapper, 'InteractiveCell', '<span>1</span>', CellPosition.Last);
verifyHtmlOnCell(nativeWrapper, 'NativeCell', '<span>1</span>', CellPosition.Last);

// Close the interactive editor.
await closeInteractiveWindow(ioc, interactiveEditor);

// Run another cell and make sure it works in the notebook
await addCell(ioc, nativeWrapper, 'b=2\nb', true);
verifyHtmlOnCell(nativeWrapper, 'NativeCell', '<span>2</span>', CellPosition.Last);

// Rerun the interactive window
interactiveWrapper = mountWebView(ioc, 'interactive');
interactiveEditor = await getOrCreateInteractiveWindow(ioc);
await addCode(ioc, interactiveWrapper, 'a=1\na');

verifyHtmlOnCell(interactiveWrapper, 'InteractiveCell', '<span>1</span>', CellPosition.Last);
});
});
8 changes: 2 additions & 6 deletions src/test/datascience/interactiveWindowTestHelpers.tsx
Expand Up @@ -26,13 +26,9 @@ export async function getOrCreateInteractiveWindow(ioc: DataScienceIocContainer)
return (await interactiveWindowProvider.getOrCreateActive()) as InteractiveWindow;
}

export function closeInteractiveWindow(
window: IInteractiveWindow,
// tslint:disable-next-line: no-any
wrapper: ReactWrapper<any, Readonly<{}>, React.Component>
) {
export function closeInteractiveWindow(ioc: DataScienceIocContainer, window: IInteractiveWindow) {
const promise = window.dispose();
wrapper.unmount();
ioc.getWebPanel('default').dispose();
return promise;
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/datascience/testHelpers.tsx
Expand Up @@ -230,7 +230,7 @@ export function getLastOutputCell(

export function verifyHtmlOnCell(
wrapper: ReactWrapper<any, Readonly<{}>, React.Component>,
cellType: string,
cellType: 'NativeCell' | 'InteractiveCell',
html: string | undefined | RegExp,
cellIndex: number | CellPosition
) {
Expand Down

0 comments on commit 71390fb

Please sign in to comment.