Skip to content

Add test that validates interactive and notebook editor at the same time #12384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/3 Code Health/11445.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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