Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { serializeDeepnoteFile } from '@deepnote/blocks';
import { assert } from 'chai';
import * as sinon from 'sinon';
import { when, reset, anything, mock, instance } from 'ts-mockito';
Expand All @@ -14,7 +15,9 @@ import {

import {
DeepnoteNotebookCommandListener,
getInputBlockMetadata,
getNextDeepnoteVariableName,
INPUT_BLOCK_TYPES,
InputBlockType
} from './deepnoteNotebookCommandListener';
import { formatInputBlockCellContent, getInputBlockLanguage } from './inputBlockContentFormatter';
Expand All @@ -23,9 +26,15 @@ import { IConfigurationService, IDisposable } from '../../platform/common/types'
import * as notebookUpdater from '../../kernels/execution/notebookUpdater';
import { createMockedNotebookDocument } from '../../test/datascience/editor-integration/helpers';
import { WrappedError } from '../../platform/errors/types';
import { createBlockFromPocket } from '../../platform/deepnote/pocket';
import { DATAFRAME_SQL_INTEGRATION_ID } from '../../platform/notebooks/deepnote/integrationTypes';
import { mockedVSCodeNamespaces } from '../../test/vscode-mock';
import { createMockCell } from './deepnoteTestHelpers';
import {
createDeepnoteFile,
createDeepnoteNotebook,
createDeepnoteProject,
createMockCell
} from './deepnoteTestHelpers';

suite('DeepnoteNotebookCommandListener', () => {
let commandListener: DeepnoteNotebookCommandListener;
Expand Down Expand Up @@ -347,6 +356,23 @@ suite('DeepnoteNotebookCommandListener', () => {
});
});

suite('getInputBlockMetadata', () => {
INPUT_BLOCK_TYPES.forEach((blockType) => {
test(`default ${blockType} metadata is accepted by the @deepnote/blocks serializer`, () => {
const metadata = getInputBlockMetadata(blockType, 'input_1');
const cell = new NotebookCellData(NotebookCellKind.Code, '', 'python');
cell.metadata = { __deepnotePocket: { type: blockType, ...metadata }, ...metadata };

const block = createBlockFromPocket(cell, 0);
const file = createDeepnoteFile({
project: createDeepnoteProject({ notebooks: [createDeepnoteNotebook({ blocks: [block] })] })
});

assert.doesNotThrow(() => serializeDeepnoteFile(file));
});
});
});

suite('addBlock', () => {
let sandbox: sinon.SinonSandbox;

Expand Down Expand Up @@ -538,12 +564,7 @@ suite('DeepnoteNotebookCommandListener', () => {
selection: undefined,
expectedInsertIndex: 0,
expectedVariableName: 'input_1',
expectedMetadataKeys: [
'deepnote_variable_name',
'deepnote_input_label',
'deepnote_variable_value',
'deepnote_allowed_file_extensions'
]
expectedMetadataKeys: ['deepnote_variable_name', 'deepnote_input_label', 'deepnote_variable_value']
},
{
description: 'should add button block with correct metadata',
Expand Down
5 changes: 2 additions & 3 deletions src/notebooks/deepnote/deepnoteSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ export const DeepnoteSelectInputMetadataSchema = DeepnoteBaseInputWithLabelMetad
.transform((val) => val ?? DEEPNOTE_SELECT_INPUT_DEFAULT_OPTIONS),
deepnote_variable_select_type: z
.enum(['from-options', 'from-variable'])
// .string()
.nullish()
.transform((val) => val ?? null),
.transform((val) => val ?? 'from-options'),
deepnote_allow_multiple_values: z
.boolean()
.nullish()
Expand Down Expand Up @@ -208,7 +207,7 @@ export const DeepnoteFileInputMetadataSchema = DeepnoteBaseInputWithLabelMetadat
deepnote_allowed_file_extensions: z
.string()
.nullish()
.transform((val) => val ?? null)
.transform((val) => val ?? undefined)
});

export const DeepnoteButtonMetadataSchema = DeepnoteBaseInputMetadataSchema.extend({
Expand Down
Loading