mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-27 17:23:21 -05:00
Insert local/online images using image call out (#15238)
* changes from Chris's branch and cell model updates * get base64 value * handle spaces in image names * add comments * add tests for imageCallOut dialog * format document for hygiene errors * address comments * check base64 validity using regex * replace space with regex * add parameter and return type * split into two functions * move functions to fileUtilities * correct import * fix for layering issue * revert file function changes
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
import * as assert from 'assert';
|
||||
|
||||
import { TestFileDialogService, TestLayoutService, TestPathService } from 'vs/workbench/test/browser/workbenchTestServices';
|
||||
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
|
||||
import { IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
|
||||
import { NullAdsTelemetryService } from 'sql/platform/telemetry/common/adsTelemetryService';
|
||||
import { IAdsTelemetryService } from 'sql/platform/telemetry/common/telemetry';
|
||||
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
|
||||
import { Deferred } from 'sql/base/common/promise';
|
||||
import { IDialogProperties } from 'sql/workbench/browser/modal/modal';
|
||||
import { IImageCalloutDialogOptions, ImageCalloutDialog } from 'sql/workbench/contrib/notebook/browser/calloutDialog/imageCalloutDialog';
|
||||
import { IPathService } from 'vs/workbench/services/path/common/pathService';
|
||||
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
|
||||
import * as path from 'vs/base/common/path';
|
||||
|
||||
suite('Image Callout Dialog', function (): void {
|
||||
let pathService: IPathService;
|
||||
let fileDialogService: IFileDialogService;
|
||||
let layoutService: ILayoutService;
|
||||
let themeService: IThemeService;
|
||||
let telemetryService: IAdsTelemetryService;
|
||||
let contextKeyService: IContextKeyService;
|
||||
|
||||
const defaultDialogProperties: IDialogProperties = { xPos: 0, yPos: 0, height: 250, width: 100 };
|
||||
|
||||
setup(() => {
|
||||
pathService = new TestPathService();
|
||||
fileDialogService = new TestFileDialogService(pathService);
|
||||
layoutService = new TestLayoutService();
|
||||
themeService = new TestThemeService();
|
||||
telemetryService = new NullAdsTelemetryService();
|
||||
contextKeyService = new MockContextKeyService();
|
||||
});
|
||||
|
||||
test('Should return empty markdown on cancel', async function (): Promise<void> {
|
||||
let imageCalloutDialog = new ImageCalloutDialog('Title', 'below', defaultDialogProperties, pathService, fileDialogService,
|
||||
undefined, themeService, layoutService, telemetryService, contextKeyService, undefined, undefined, undefined);
|
||||
imageCalloutDialog.render();
|
||||
|
||||
let deferred = new Deferred<IImageCalloutDialogOptions>();
|
||||
// When I first open the callout dialog
|
||||
imageCalloutDialog.open().then(value => {
|
||||
deferred.resolve(value);
|
||||
});
|
||||
// And cancel the dialog
|
||||
imageCalloutDialog.cancel();
|
||||
let result = await deferred.promise;
|
||||
|
||||
assert.equal(result.imagePath, undefined, 'ImagePath must be undefined');
|
||||
assert.equal(result.embedImage, undefined, 'EmbedImage must be undefined');
|
||||
assert.equal(result.insertEscapedMarkdown, '', 'Markdown not returned correctly');
|
||||
});
|
||||
|
||||
test('Should return expected values on insert', async function (): Promise<void> {
|
||||
const sampleImageFileUrl = await pathService.fileURI('../resources/extension.png');
|
||||
let imageCalloutDialog = new ImageCalloutDialog('Title', 'below', defaultDialogProperties, pathService, fileDialogService,
|
||||
undefined, themeService, layoutService, telemetryService, contextKeyService, undefined, undefined, undefined);
|
||||
imageCalloutDialog.render();
|
||||
|
||||
let deferred = new Deferred<IImageCalloutDialogOptions>();
|
||||
// When I first open the callout dialog
|
||||
imageCalloutDialog.open().then(value => {
|
||||
deferred.resolve(value);
|
||||
});
|
||||
|
||||
imageCalloutDialog.imagePath = sampleImageFileUrl.fsPath;
|
||||
// And insert the dialog
|
||||
imageCalloutDialog.insert();
|
||||
let result = await deferred.promise;
|
||||
assert.equal(result.imagePath, sampleImageFileUrl.fsPath, 'ImagePath not returned correctly');
|
||||
assert.equal(result.embedImage, false, 'EmbedImage not returned correctly');
|
||||
assert.equal(result.insertEscapedMarkdown, ``, 'Markdown not returned correctly');
|
||||
});
|
||||
|
||||
test('Should return expected values on insert when imageName has space', async function (): Promise<void> {
|
||||
const sampleImageFileUrl = await pathService.fileURI('../resources/extension 2.png');
|
||||
let imageCalloutDialog = new ImageCalloutDialog('Title', 'below', defaultDialogProperties, pathService, fileDialogService,
|
||||
undefined, themeService, layoutService, telemetryService, contextKeyService, undefined, undefined, undefined);
|
||||
imageCalloutDialog.render();
|
||||
|
||||
let deferred = new Deferred<IImageCalloutDialogOptions>();
|
||||
// When I first open the callout dialog
|
||||
imageCalloutDialog.open().then(value => {
|
||||
deferred.resolve(value);
|
||||
});
|
||||
|
||||
imageCalloutDialog.imagePath = sampleImageFileUrl.fsPath;
|
||||
|
||||
// And insert the dialog
|
||||
imageCalloutDialog.insert();
|
||||
let result = await deferred.promise;
|
||||
assert.equal(result.imagePath, sampleImageFileUrl.fsPath, 'imagePath not returned correctly');
|
||||
assert.equal(result.embedImage, false, 'embedImage not returned correctly');
|
||||
assert.equal(result.insertEscapedMarkdown, `})`, 'Markdown not returned correctly');
|
||||
});
|
||||
|
||||
test('Should return expected values on insert when add as attachment is set', async function (): Promise<void> {
|
||||
const sampleImageFileUrl = await pathService.fileURI('../resources/extension.png');
|
||||
let imageCalloutDialog = new ImageCalloutDialog('Title', 'below', defaultDialogProperties, pathService, fileDialogService,
|
||||
undefined, themeService, layoutService, telemetryService, contextKeyService, undefined, undefined, undefined);
|
||||
imageCalloutDialog.render();
|
||||
|
||||
let deferred = new Deferred<IImageCalloutDialogOptions>();
|
||||
// When I first open the callout dialog
|
||||
imageCalloutDialog.open().then(value => {
|
||||
deferred.resolve(value);
|
||||
});
|
||||
|
||||
imageCalloutDialog.imagePath = sampleImageFileUrl.fsPath;
|
||||
imageCalloutDialog.embedImage = true;
|
||||
let imageName = path.basename(sampleImageFileUrl.fsPath);
|
||||
|
||||
// And insert the dialog
|
||||
imageCalloutDialog.insert();
|
||||
let result = await deferred.promise;
|
||||
assert.equal(result.imagePath, sampleImageFileUrl.fsPath, 'imagePath not returned correctly');
|
||||
assert.equal(result.embedImage, true, 'embedImage not returned correctly');
|
||||
assert.equal(result.insertEscapedMarkdown, ``, 'Markdown not returned correctly');
|
||||
});
|
||||
|
||||
test('Should return expected values on insert when imageName has space and add attachment is set', async function (): Promise<void> {
|
||||
const sampleImageFileUrl = await pathService.fileURI('../resources/extension 2.png');
|
||||
let imageCalloutDialog = new ImageCalloutDialog('Title', 'below', defaultDialogProperties, pathService, fileDialogService,
|
||||
undefined, themeService, layoutService, telemetryService, contextKeyService, undefined, undefined, undefined);
|
||||
imageCalloutDialog.render();
|
||||
|
||||
let deferred = new Deferred<IImageCalloutDialogOptions>();
|
||||
// When I first open the callout dialog
|
||||
imageCalloutDialog.open().then(value => {
|
||||
deferred.resolve(value);
|
||||
});
|
||||
|
||||
imageCalloutDialog.imagePath = sampleImageFileUrl.fsPath;
|
||||
imageCalloutDialog.embedImage = true;
|
||||
let imageName = path.basename(sampleImageFileUrl.fsPath);
|
||||
|
||||
// And insert the dialog
|
||||
imageCalloutDialog.insert();
|
||||
let result = await deferred.promise;
|
||||
assert.equal(result.imagePath, sampleImageFileUrl.fsPath, 'imagePath not returned correctly');
|
||||
assert.equal(result.embedImage, true, 'embedImage not returned correctly');
|
||||
assert.equal(result.insertEscapedMarkdown, `})`, 'Markdown not returned correctly');
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user