mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-25 17:23:10 -05:00
Query editor tests (#9689)
* tests * add tests for query editor input creation
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as sinon from 'sinon';
|
||||
import { TestEditorService } from 'vs/workbench/test/browser/workbenchTestServices';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
@@ -22,6 +23,8 @@ import { UntitledQueryEditorInput } from 'sql/workbench/common/editor/query/unti
|
||||
import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput';
|
||||
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
|
||||
import { isThenable } from 'vs/base/common/async';
|
||||
import { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/queryEditorService';
|
||||
import { QueryResultsInput } from 'sql/workbench/common/editor/query/queryResultsInput';
|
||||
|
||||
suite('Query Input Factory', () => {
|
||||
|
||||
@@ -81,6 +84,30 @@ suite('Query Input Factory', () => {
|
||||
assert(connectionManagementService.numberConnects === 1, 'Convert input should have called connect when active editor connection exists');
|
||||
});
|
||||
|
||||
test('untitled query editor input is connected if global connection exists (Editor)', async () => {
|
||||
const instantiationService = workbenchInstantiationService();
|
||||
const editorService = new MockEditorService(instantiationService);
|
||||
const connectionManagementService = new MockConnectionManagementService();
|
||||
instantiationService.stub(IObjectExplorerService, new MockObjectExplorerService());
|
||||
instantiationService.stub(IConnectionManagementService, connectionManagementService);
|
||||
instantiationService.stub(IEditorService, editorService);
|
||||
const queryEditorLanguageAssociation = instantiationService.createInstance(QueryEditorLanguageAssociation);
|
||||
const untitledService = instantiationService.invokeFunction(accessor => accessor.get(IUntitledTextEditorService));
|
||||
const queryeditorservice = instantiationService.invokeFunction(accessor => accessor.get(IQueryEditorService));
|
||||
const newsqlEditorStub = sinon.stub(queryeditorservice, 'newSqlEditor', () => {
|
||||
const untitledInput = instantiationService.createInstance(UntitledTextEditorInput, untitledService.create());
|
||||
const queryResultsInput: QueryResultsInput = instantiationService.createInstance(QueryResultsInput, untitledInput.resource.toString());
|
||||
let queryInput = instantiationService.createInstance(UntitledQueryEditorInput, '', untitledInput, queryResultsInput);
|
||||
return queryInput;
|
||||
});
|
||||
const input = instantiationService.createInstance(UntitledTextEditorInput, untitledService.create());
|
||||
const response = queryEditorLanguageAssociation.convertInput(input);
|
||||
assert(isThenable(response));
|
||||
await response;
|
||||
assert(newsqlEditorStub.calledWithExactly({ open: false, initalContent: '' }));
|
||||
assert(connectionManagementService.numberConnects === 1, 'Convert input should have called connect when active editor connection exists');
|
||||
});
|
||||
|
||||
test('sync query editor input is not connected if no global connection exists', () => {
|
||||
const instantiationService = workbenchInstantiationService();
|
||||
const editorService = new MockEditorService();
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as sinon from 'sinon';
|
||||
import * as assert from 'assert';
|
||||
import { QueryEditorService } from 'sql/workbench/services/queryEditor/browser/queryEditorService';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
|
||||
import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput';
|
||||
import { workbenchInstantiationService } from 'sql/workbench/test/workbenchTestServices';
|
||||
|
||||
suite('Query Editor Service', () => {
|
||||
test('does open input when requested', async () => {
|
||||
const instantiationService = workbenchInstantiationService();
|
||||
const editorService = instantiationService.invokeFunction(accessor => accessor.get(IEditorService));
|
||||
const untitledService = instantiationService.invokeFunction(accessor => accessor.get(IUntitledTextEditorService));
|
||||
const openStub = sinon.stub(editorService, 'openEditor', () => Promise.resolve());
|
||||
sinon.stub(editorService, 'createEditorInput', () => instantiationService.createInstance(UntitledTextEditorInput, untitledService.create()));
|
||||
const queryEditorService = instantiationService.createInstance(QueryEditorService);
|
||||
|
||||
await queryEditorService.newSqlEditor({ open: true });
|
||||
|
||||
assert(openStub.calledOnce);
|
||||
});
|
||||
|
||||
test('does open input by default', async () => {
|
||||
const instantiationService = workbenchInstantiationService();
|
||||
const editorService = instantiationService.invokeFunction(accessor => accessor.get(IEditorService));
|
||||
const untitledService = instantiationService.invokeFunction(accessor => accessor.get(IUntitledTextEditorService));
|
||||
const openStub = sinon.stub(editorService, 'openEditor', () => Promise.resolve());
|
||||
sinon.stub(editorService, 'createEditorInput', () => instantiationService.createInstance(UntitledTextEditorInput, untitledService.create()));
|
||||
const queryEditorService = instantiationService.createInstance(QueryEditorService);
|
||||
|
||||
await queryEditorService.newSqlEditor();
|
||||
|
||||
assert(openStub.calledOnce);
|
||||
});
|
||||
|
||||
test('doesnt open input when requested', async () => {
|
||||
const instantiationService = workbenchInstantiationService();
|
||||
const editorService = instantiationService.invokeFunction(accessor => accessor.get(IEditorService));
|
||||
const untitledService = instantiationService.invokeFunction(accessor => accessor.get(IUntitledTextEditorService));
|
||||
const openStub = sinon.stub(editorService, 'openEditor', () => Promise.resolve());
|
||||
sinon.stub(editorService, 'createEditorInput', () => instantiationService.createInstance(UntitledTextEditorInput, untitledService.create()));
|
||||
const queryEditorService = instantiationService.createInstance(QueryEditorService);
|
||||
|
||||
await queryEditorService.newSqlEditor({ open: false });
|
||||
|
||||
assert(openStub.notCalled);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user