mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Set dotnet_interactive cell metadata when converting cell into JSON. (#20044)
This commit is contained in:
@@ -27,6 +27,7 @@ import { TestNotificationService } from 'vs/platform/notification/test/common/te
|
||||
import { ICommandService, NullCommandService } from 'vs/platform/commands/common/commands';
|
||||
import { ControlType, IChartOption } from 'sql/workbench/contrib/charts/browser/chartOptions';
|
||||
import { CellModel } from 'sql/workbench/services/notebook/browser/models/cell';
|
||||
import { ICellMetadata } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
|
||||
let instantiationService: IInstantiationService;
|
||||
|
||||
@@ -1508,4 +1509,45 @@ suite('Cell Model', function (): void {
|
||||
|
||||
});
|
||||
|
||||
test('should set .NET Interactive cell metadata when converting to JSON', async function () {
|
||||
let notebookModel = new NotebookModelStub({
|
||||
name: '',
|
||||
version: '',
|
||||
mimetype: ''
|
||||
});
|
||||
let contents: nb.ICellContents = {
|
||||
cell_type: CellTypes.Code,
|
||||
source: '',
|
||||
metadata: {
|
||||
language: 'dotnet-interactive.csharp'
|
||||
}
|
||||
};
|
||||
let model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
|
||||
assert((model.metadata as ICellMetadata).dotnet_interactive === undefined, 'dotnet_interactive field should not be set in cell metadata before converting to JSON');
|
||||
let cellJson = model.toJSON();
|
||||
assert((cellJson.metadata as ICellMetadata).dotnet_interactive !== undefined, 'dotnet_interactive field should be set in JSON cell metadata');
|
||||
assert.strictEqual((cellJson.metadata as ICellMetadata).dotnet_interactive.language, 'csharp', 'Expected dotnet_interactive language field to be csharp');
|
||||
});
|
||||
|
||||
test('should overwrite pre-existing .NET Interactive cell metadata when converting to JSON', async function () {
|
||||
let notebookModel = new NotebookModelStub({
|
||||
name: '',
|
||||
version: '',
|
||||
mimetype: ''
|
||||
});
|
||||
let contents: nb.ICellContents = {
|
||||
cell_type: CellTypes.Code,
|
||||
source: '',
|
||||
metadata: {
|
||||
language: 'dotnet-interactive.csharp'
|
||||
}
|
||||
};
|
||||
(contents.metadata as ICellMetadata).dotnet_interactive = { language: 'fsharp' };
|
||||
|
||||
let model = factory.createCell(contents, { notebook: notebookModel, isTrusted: false });
|
||||
assert((model.metadata as ICellMetadata).dotnet_interactive !== undefined, 'dotnet_interactive field should exist in cell metadata');
|
||||
let cellJson = model.toJSON();
|
||||
assert((cellJson.metadata as ICellMetadata).dotnet_interactive !== undefined, 'dotnet_interactive field should be set in JSON cell metadata');
|
||||
assert.strictEqual((cellJson.metadata as ICellMetadata).dotnet_interactive.language, 'csharp', 'Expected dotnet_interactive language field to be csharp');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user