test stream output reuse container
This commit is contained in:
parent
62ce585b95
commit
63b2f51fd5
3 changed files with 115 additions and 3 deletions
|
@ -441,6 +441,10 @@ class OutputEntryViewHandler {
|
|||
export class CellOutputContainer extends Disposable {
|
||||
private _outputEntries: OutputEntryViewHandler[] = [];
|
||||
|
||||
get renderedOutputEntries() {
|
||||
return this._outputEntries;
|
||||
}
|
||||
|
||||
constructor(
|
||||
private notebookEditor: INotebookEditor,
|
||||
private viewCell: CodeCellViewModel,
|
||||
|
|
103
src/vs/workbench/contrib/notebook/test/cellOutput.test.ts
Normal file
103
src/vs/workbench/contrib/notebook/test/cellOutput.test.ts
Normal file
|
@ -0,0 +1,103 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { mock } from 'vs/base/test/common/mock';
|
||||
import { IMenuService } from 'vs/platform/actions/common/actions';
|
||||
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||
import { IOpenerService } from 'vs/platform/opener/common/opener';
|
||||
import { CodeCellRenderTemplate } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
|
||||
import { CellOutputContainer } from 'vs/workbench/contrib/notebook/browser/view/renderers/cellOutput';
|
||||
import { CodeCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel';
|
||||
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
|
||||
import { BUILTIN_RENDERER_ID, CellEditType, CellKind, IOutputDto } from 'vs/workbench/contrib/notebook/common/notebookCommon';
|
||||
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
|
||||
import { setupInstantiationService, withTestNotebook } from 'vs/workbench/contrib/notebook/test/testNotebookEditor';
|
||||
|
||||
suite('NotebookViewModel Outputs', async () => {
|
||||
const instantiationService = setupInstantiationService();
|
||||
instantiationService.stub(INotebookService, new class extends mock<INotebookService>() {
|
||||
override getMimeTypeInfo(textModel: NotebookTextModel, kernelProvides: [], output: IOutputDto) {
|
||||
if (output.outputId === 'output_id_err') {
|
||||
return [{
|
||||
mimeType: 'application/vnd.code.notebook.stderr',
|
||||
rendererId: BUILTIN_RENDERER_ID,
|
||||
isTrusted: true
|
||||
}];
|
||||
}
|
||||
return [{
|
||||
mimeType: 'application/vnd.code.notebook.stdout',
|
||||
rendererId: BUILTIN_RENDERER_ID,
|
||||
isTrusted: true
|
||||
}];
|
||||
}
|
||||
});
|
||||
|
||||
instantiationService.stub(IMenuService, new class extends mock<IMenuService>() {
|
||||
override createMenu(arg: any, context: any): any {
|
||||
return {
|
||||
onDidChange: () => { },
|
||||
getActions: (arg: any) => {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
instantiationService.stub(IKeybindingService, new class extends mock<IKeybindingService>() {
|
||||
override lookupKeybinding(arg: any): any {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
const openerService = instantiationService.stub(IOpenerService, {});
|
||||
|
||||
test('stream outputs reuse output container', async () => {
|
||||
await withTestNotebook(
|
||||
[
|
||||
['var a = 1;', 'javascript', CellKind.Code, [
|
||||
{ outputId: 'output_id_1', outputs: [{ mime: 'application/vnd.code.notebook.stdout', valueBytes: [1] }] },
|
||||
{ outputId: 'output_id_2', outputs: [{ mime: 'application/vnd.code.notebook.stdout', valueBytes: [2] }] },
|
||||
{ outputId: 'output_id_err', outputs: [{ mime: 'application/vnd.code.notebook.stderr', valueBytes: [4] }] },
|
||||
{ outputId: 'output_id_3', outputs: [{ mime: 'application/vnd.code.notebook.stdout', valueBytes: [3] }] },
|
||||
], {}]
|
||||
],
|
||||
(editor, accessor) => {
|
||||
const viewModel = editor.viewModel;
|
||||
const container = new CellOutputContainer(editor, viewModel.viewCells[0] as CodeCellViewModel, {
|
||||
outputContainer: document.createElement('div'),
|
||||
outputShowMoreContainer: document.createElement('div'),
|
||||
editor: {
|
||||
getContentHeight: () => {
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
} as unknown as CodeCellRenderTemplate, openerService, instantiationService);
|
||||
container.render(100);
|
||||
assert.strictEqual(container.renderedOutputEntries.length, 4);
|
||||
assert.strictEqual(container.renderedOutputEntries[0].entry.innerContainer, container.renderedOutputEntries[1].entry.innerContainer);
|
||||
assert.notStrictEqual(container.renderedOutputEntries[1].entry.innerContainer, container.renderedOutputEntries[2].entry.innerContainer);
|
||||
assert.notStrictEqual(container.renderedOutputEntries[2].entry.innerContainer, container.renderedOutputEntries[3].entry.innerContainer);
|
||||
|
||||
viewModel.notebookDocument.applyEdits([{
|
||||
index: 0,
|
||||
editType: CellEditType.Output,
|
||||
outputs: [
|
||||
{
|
||||
outputId: 'output_id_5',
|
||||
outputs: [{ mime: 'application/vnd.code.notebook.stdout', valueBytes: [5] }]
|
||||
}
|
||||
],
|
||||
append: true
|
||||
}], true, undefined, () => undefined, undefined);
|
||||
assert.strictEqual(container.renderedOutputEntries.length, 5);
|
||||
// last one is merged with previous one
|
||||
assert.strictEqual(container.renderedOutputEntries[3].entry.innerContainer, container.renderedOutputEntries[4].entry.innerContainer);
|
||||
},
|
||||
instantiationService
|
||||
);
|
||||
});
|
||||
|
||||
});
|
|
@ -45,6 +45,7 @@ import { IWorkspaceTrustRequestService } from 'vs/platform/workspace/common/work
|
|||
import { TestWorkspaceTrustRequestService } from 'vs/workbench/services/workspaces/test/common/testWorkspaceTrustService';
|
||||
import { NotebookOptions } from 'vs/workbench/contrib/notebook/common/notebookOptions';
|
||||
import { ViewContext } from 'vs/workbench/contrib/notebook/browser/viewModel/viewContext';
|
||||
import { OutputRenderer } from 'vs/workbench/contrib/notebook/browser/view/output/outputRenderer';
|
||||
|
||||
export class TestCell extends NotebookCellTextModel {
|
||||
constructor(
|
||||
|
@ -179,7 +180,8 @@ function _createTestNotebookEditor(instantiationService: TestInstantiationServic
|
|||
}), {}, { transientCellMetadata: {}, transientDocumentMetadata: {}, transientOutputs: false });
|
||||
|
||||
const model = new NotebookEditorTestModel(notebook);
|
||||
const viewContext = new ViewContext(new NotebookOptions(instantiationService.get(IConfigurationService)), new NotebookEventDispatcher());
|
||||
const notebookOptions = new NotebookOptions(instantiationService.get(IConfigurationService));
|
||||
const viewContext = new ViewContext(notebookOptions, new NotebookEventDispatcher());
|
||||
const viewModel: NotebookViewModel = instantiationService.createInstance(NotebookViewModel, viewType, model.notebook, viewContext, null);
|
||||
|
||||
const cellList = createNotebookCellList(instantiationService, viewContext);
|
||||
|
@ -190,6 +192,7 @@ function _createTestNotebookEditor(instantiationService: TestInstantiationServic
|
|||
override dispose() {
|
||||
viewModel.dispose();
|
||||
}
|
||||
override notebookOptions = notebookOptions;
|
||||
override onDidChangeModel: Event<NotebookTextModel | undefined> = new Emitter<NotebookTextModel | undefined>().event;
|
||||
override get viewModel() { return viewModel; }
|
||||
override get textModel() { return viewModel.notebookDocument; }
|
||||
|
@ -220,6 +223,8 @@ function _createTestNotebookEditor(instantiationService: TestInstantiationServic
|
|||
override focusElement() { }
|
||||
override setCellEditorSelection() { }
|
||||
override async revealRangeInCenterIfOutsideViewportAsync() { }
|
||||
override getOutputRenderer() { return new OutputRenderer(notebookEditor, instantiationService); }
|
||||
override async layoutNotebookCell() { }
|
||||
};
|
||||
|
||||
return notebookEditor;
|
||||
|
@ -267,8 +272,8 @@ export async function withTestNotebookDiffModel<R = any>(originalCells: [source:
|
|||
return res;
|
||||
}
|
||||
|
||||
export async function withTestNotebook<R = any>(cells: [source: string, lang: string, kind: CellKind, output?: IOutputDto[], metadata?: NotebookCellMetadata][], callback: (editor: IActiveNotebookEditor, accessor: TestInstantiationService) => Promise<R> | R): Promise<R> {
|
||||
const instantiationService = setupInstantiationService();
|
||||
export async function withTestNotebook<R = any>(cells: [source: string, lang: string, kind: CellKind, output?: IOutputDto[], metadata?: NotebookCellMetadata][], callback: (editor: IActiveNotebookEditor, accessor: TestInstantiationService) => Promise<R> | R, accessor?: TestInstantiationService): Promise<R> {
|
||||
const instantiationService = accessor ?? setupInstantiationService();
|
||||
const notebookEditor = _createTestNotebookEditor(instantiationService, cells);
|
||||
|
||||
const res = await callback(notebookEditor, instantiationService);
|
||||
|
|
Loading…
Reference in a new issue