|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +import { expect } from 'chai'; |
| 5 | +import { DeepnoteInputBlockCellStatusBarItemProvider } from './deepnoteInputBlockCellStatusBarProvider'; |
| 6 | +import { NotebookCell, NotebookCellKind, NotebookDocument } from 'vscode'; |
| 7 | +import { Uri } from 'vscode'; |
| 8 | + |
| 9 | +suite('DeepnoteInputBlockCellStatusBarItemProvider', () => { |
| 10 | + let provider: DeepnoteInputBlockCellStatusBarItemProvider; |
| 11 | + |
| 12 | + setup(() => { |
| 13 | + provider = new DeepnoteInputBlockCellStatusBarItemProvider(); |
| 14 | + }); |
| 15 | + |
| 16 | + teardown(() => { |
| 17 | + provider.dispose(); |
| 18 | + }); |
| 19 | + |
| 20 | + function createMockCell(metadata?: Record<string, unknown>): NotebookCell { |
| 21 | + return { |
| 22 | + index: 0, |
| 23 | + notebook: {} as NotebookDocument, |
| 24 | + kind: NotebookCellKind.Code, |
| 25 | + document: { |
| 26 | + uri: Uri.file('/test/notebook.deepnote'), |
| 27 | + fileName: '/test/notebook.deepnote', |
| 28 | + isUntitled: false, |
| 29 | + languageId: 'json', |
| 30 | + version: 1, |
| 31 | + isDirty: false, |
| 32 | + isClosed: false, |
| 33 | + getText: () => '', |
| 34 | + save: async () => true, |
| 35 | + eol: 1, |
| 36 | + lineCount: 1, |
| 37 | + lineAt: () => ({}) as any, |
| 38 | + offsetAt: () => 0, |
| 39 | + positionAt: () => ({}) as any, |
| 40 | + validateRange: () => ({}) as any, |
| 41 | + validatePosition: () => ({}) as any |
| 42 | + } as any, |
| 43 | + metadata: metadata || {}, |
| 44 | + outputs: [], |
| 45 | + executionSummary: undefined |
| 46 | + } as any; |
| 47 | + } |
| 48 | + |
| 49 | + suite('Input Block Type Detection', () => { |
| 50 | + test('Should return status bar item for input-text block', () => { |
| 51 | + const cell = createMockCell({ __deepnotePocket: { type: 'input-text' } }); |
| 52 | + const item = provider.provideCellStatusBarItems(cell); |
| 53 | + |
| 54 | + expect(item).to.not.be.undefined; |
| 55 | + expect(item?.text).to.equal('Input Text'); |
| 56 | + }); |
| 57 | + |
| 58 | + test('Should return status bar item for input-textarea block', () => { |
| 59 | + const cell = createMockCell({ __deepnotePocket: { type: 'input-textarea' } }); |
| 60 | + const item = provider.provideCellStatusBarItems(cell); |
| 61 | + |
| 62 | + expect(item).to.not.be.undefined; |
| 63 | + expect(item?.text).to.equal('Input Textarea'); |
| 64 | + }); |
| 65 | + |
| 66 | + test('Should return status bar item for input-select block', () => { |
| 67 | + const cell = createMockCell({ __deepnotePocket: { type: 'input-select' } }); |
| 68 | + const item = provider.provideCellStatusBarItems(cell); |
| 69 | + |
| 70 | + expect(item).to.not.be.undefined; |
| 71 | + expect(item?.text).to.equal('Input Select'); |
| 72 | + }); |
| 73 | + |
| 74 | + test('Should return status bar item for input-slider block', () => { |
| 75 | + const cell = createMockCell({ __deepnotePocket: { type: 'input-slider' } }); |
| 76 | + const item = provider.provideCellStatusBarItems(cell); |
| 77 | + |
| 78 | + expect(item).to.not.be.undefined; |
| 79 | + expect(item?.text).to.equal('Input Slider'); |
| 80 | + }); |
| 81 | + |
| 82 | + test('Should return status bar item for input-checkbox block', () => { |
| 83 | + const cell = createMockCell({ __deepnotePocket: { type: 'input-checkbox' } }); |
| 84 | + const item = provider.provideCellStatusBarItems(cell); |
| 85 | + |
| 86 | + expect(item).to.not.be.undefined; |
| 87 | + expect(item?.text).to.equal('Input Checkbox'); |
| 88 | + }); |
| 89 | + |
| 90 | + test('Should return status bar item for input-date block', () => { |
| 91 | + const cell = createMockCell({ __deepnotePocket: { type: 'input-date' } }); |
| 92 | + const item = provider.provideCellStatusBarItems(cell); |
| 93 | + |
| 94 | + expect(item).to.not.be.undefined; |
| 95 | + expect(item?.text).to.equal('Input Date'); |
| 96 | + }); |
| 97 | + |
| 98 | + test('Should return status bar item for input-date-range block', () => { |
| 99 | + const cell = createMockCell({ __deepnotePocket: { type: 'input-date-range' } }); |
| 100 | + const item = provider.provideCellStatusBarItems(cell); |
| 101 | + |
| 102 | + expect(item).to.not.be.undefined; |
| 103 | + expect(item?.text).to.equal('Input Date Range'); |
| 104 | + }); |
| 105 | + |
| 106 | + test('Should return status bar item for input-file block', () => { |
| 107 | + const cell = createMockCell({ __deepnotePocket: { type: 'input-file' } }); |
| 108 | + const item = provider.provideCellStatusBarItems(cell); |
| 109 | + |
| 110 | + expect(item).to.not.be.undefined; |
| 111 | + expect(item?.text).to.equal('Input File'); |
| 112 | + }); |
| 113 | + |
| 114 | + test('Should return status bar item for button block', () => { |
| 115 | + const cell = createMockCell({ __deepnotePocket: { type: 'button' } }); |
| 116 | + const item = provider.provideCellStatusBarItems(cell); |
| 117 | + |
| 118 | + expect(item).to.not.be.undefined; |
| 119 | + expect(item?.text).to.equal('Button'); |
| 120 | + }); |
| 121 | + }); |
| 122 | + |
| 123 | + suite('Non-Input Block Types', () => { |
| 124 | + test('Should return undefined for code block', () => { |
| 125 | + const cell = createMockCell({ __deepnotePocket: { type: 'code' } }); |
| 126 | + const item = provider.provideCellStatusBarItems(cell); |
| 127 | + |
| 128 | + expect(item).to.be.undefined; |
| 129 | + }); |
| 130 | + |
| 131 | + test('Should return undefined for sql block', () => { |
| 132 | + const cell = createMockCell({ __deepnotePocket: { type: 'sql' } }); |
| 133 | + const item = provider.provideCellStatusBarItems(cell); |
| 134 | + |
| 135 | + expect(item).to.be.undefined; |
| 136 | + }); |
| 137 | + |
| 138 | + test('Should return undefined for markdown block', () => { |
| 139 | + const cell = createMockCell({ __deepnotePocket: { type: 'text-cell-p' } }); |
| 140 | + const item = provider.provideCellStatusBarItems(cell); |
| 141 | + |
| 142 | + expect(item).to.be.undefined; |
| 143 | + }); |
| 144 | + |
| 145 | + test('Should return undefined for cell with no type metadata', () => { |
| 146 | + const cell = createMockCell({}); |
| 147 | + const item = provider.provideCellStatusBarItems(cell); |
| 148 | + |
| 149 | + expect(item).to.be.undefined; |
| 150 | + }); |
| 151 | + |
| 152 | + test('Should return undefined for cell with undefined metadata', () => { |
| 153 | + const cell = createMockCell(undefined); |
| 154 | + const item = provider.provideCellStatusBarItems(cell); |
| 155 | + |
| 156 | + expect(item).to.be.undefined; |
| 157 | + }); |
| 158 | + }); |
| 159 | + |
| 160 | + suite('Status Bar Item Properties', () => { |
| 161 | + test('Should have correct tooltip for input-text', () => { |
| 162 | + const cell = createMockCell({ __deepnotePocket: { type: 'input-text' } }); |
| 163 | + const item = provider.provideCellStatusBarItems(cell); |
| 164 | + |
| 165 | + expect(item?.tooltip).to.equal('Deepnote Input Text'); |
| 166 | + }); |
| 167 | + |
| 168 | + test('Should have correct tooltip for button', () => { |
| 169 | + const cell = createMockCell({ __deepnotePocket: { type: 'button' } }); |
| 170 | + const item = provider.provideCellStatusBarItems(cell); |
| 171 | + |
| 172 | + expect(item?.tooltip).to.equal('Deepnote Button'); |
| 173 | + }); |
| 174 | + |
| 175 | + test('Should format multi-word block types correctly', () => { |
| 176 | + const cell = createMockCell({ __deepnotePocket: { type: 'input-date-range' } }); |
| 177 | + const item = provider.provideCellStatusBarItems(cell); |
| 178 | + |
| 179 | + expect(item?.text).to.equal('Input Date Range'); |
| 180 | + expect(item?.tooltip).to.equal('Deepnote Input Date Range'); |
| 181 | + }); |
| 182 | + }); |
| 183 | + |
| 184 | + suite('Case Insensitivity', () => { |
| 185 | + test('Should handle uppercase block type', () => { |
| 186 | + const cell = createMockCell({ __deepnotePocket: { type: 'INPUT-TEXT' } }); |
| 187 | + const item = provider.provideCellStatusBarItems(cell); |
| 188 | + |
| 189 | + expect(item).to.not.be.undefined; |
| 190 | + expect(item?.text).to.equal('INPUT TEXT'); |
| 191 | + }); |
| 192 | + |
| 193 | + test('Should handle mixed case block type', () => { |
| 194 | + const cell = createMockCell({ __deepnotePocket: { type: 'Input-Text' } }); |
| 195 | + const item = provider.provideCellStatusBarItems(cell); |
| 196 | + |
| 197 | + expect(item).to.not.be.undefined; |
| 198 | + expect(item?.text).to.equal('Input Text'); |
| 199 | + }); |
| 200 | + }); |
| 201 | +}); |
0 commit comments