Enable basic wizard API (#1450)

This commit is contained in:
Matt Irvine
2018-05-21 15:19:21 -07:00
committed by GitHub
parent 70819252a9
commit 8e234d9b2d
16 changed files with 1247 additions and 157 deletions

View File

@@ -7,9 +7,9 @@ import * as assert from 'assert';
import { Mock, It, Times } from 'typemoq';
import { MainThreadModelViewDialog } from 'sql/workbench/api/node/mainThreadModelViewDialog';
import { IExtHostContext } from 'vs/workbench/api/node/extHost.protocol';
import { IModelViewButtonDetails, IModelViewTabDetails, IModelViewDialogDetails } from 'sql/workbench/api/common/sqlExtHostTypes';
import { IModelViewButtonDetails, IModelViewTabDetails, IModelViewDialogDetails, IModelViewWizardPageDetails, IModelViewWizardDetails } from 'sql/workbench/api/common/sqlExtHostTypes';
import { CustomDialogService } from 'sql/platform/dialog/customDialogService';
import { Dialog, DialogTab } from 'sql/platform/dialog/dialogTypes';
import { Dialog, DialogTab, Wizard } from 'sql/platform/dialog/dialogTypes';
import { ExtHostModelViewDialogShape } from 'sql/workbench/api/node/sqlExtHost.protocol';
import { Emitter } from 'vs/base/common/event';
@@ -20,6 +20,7 @@ suite('MainThreadModelViewDialog Tests', () => {
let mockExtHostModelViewDialog: Mock<ExtHostModelViewDialogShape>;
let mockDialogService: Mock<CustomDialogService>;
let openedDialog: Dialog;
let openedWizard: Wizard;
// Dialog details
let button1Details: IModelViewButtonDetails;
@@ -37,9 +38,28 @@ suite('MainThreadModelViewDialog Tests', () => {
let tab2Handle = 6;
let dialogHandle = 7;
// Wizard details
let nextButtonDetails: IModelViewButtonDetails;
let backButtonDetails: IModelViewButtonDetails;
let generateScriptButtonDetails: IModelViewButtonDetails;
let page1Details: IModelViewWizardPageDetails;
let page2Details: IModelViewWizardPageDetails;
let page3Details: IModelViewWizardPageDetails;
let wizardDetails: IModelViewWizardDetails;
let nextButtonHandle = 8;
let backButtonHandle = 9;
let generateScriptButtonHandle = 10;
let page1Handle = 11;
let page2Handle = 12;
let wizardHandle = 13;
let page3Handle = 14;
setup(() => {
mockExtHostModelViewDialog = Mock.ofInstance(<ExtHostModelViewDialogShape>{
$onButtonClick: handle => undefined
$onButtonClick: handle => undefined,
$onPanelValidityChanged: (handle, valid) => undefined,
$onWizardPageChanged: (handle, info) => undefined,
$updateWizardPageInfo: (wizardHandle, pageHandles, currentPageIndex) => undefined
});
let extHostContext = <IExtHostContext>{
getProxy: proxyType => mockExtHostModelViewDialog.object
@@ -50,6 +70,11 @@ suite('MainThreadModelViewDialog Tests', () => {
mockDialogService = Mock.ofType(CustomDialogService, undefined, undefined);
openedDialog = undefined;
mockDialogService.setup(x => x.showDialog(It.isAny())).callback(dialog => openedDialog = dialog);
mockDialogService.setup(x => x.showWizard(It.isAny())).callback(wizard => {
openedWizard = wizard;
// The actual service will set the page to 0 when it opens the wizard
openedWizard.setCurrentPage(0);
});
(mainThreadModelViewDialog as any)._dialogService = mockDialogService.object;
// Set up the dialog details
@@ -89,6 +114,46 @@ suite('MainThreadModelViewDialog Tests', () => {
customButtons: [button1Handle, button2Handle]
};
// Set up the wizard details
nextButtonDetails = {
label: 'next_label',
enabled: true,
hidden: false
};
backButtonDetails = {
label: 'back_label',
enabled: true,
hidden: false
};
generateScriptButtonDetails = {
label: 'generate_script_label',
enabled: true,
hidden: false
};
page1Details = {
title: 'page1',
content: 'content1',
enabled: true,
customButtons: []
};
page2Details = {
title: 'page2',
content: 'content2',
enabled: true,
customButtons: [button1Handle, button2Handle]
};
wizardDetails = {
backButton: backButtonHandle,
nextButton: nextButtonHandle,
generateScriptButton: generateScriptButtonHandle,
cancelButton: cancelButtonHandle,
doneButton: okButtonHandle,
currentPage: undefined,
title: 'wizard_title',
customButtons: [],
pages: [page1Handle, page2Handle]
};
// Register the buttons, tabs, and dialog
mainThreadModelViewDialog.$setButtonDetails(button1Handle, button1Details);
mainThreadModelViewDialog.$setButtonDetails(button2Handle, button2Details);
@@ -97,11 +162,19 @@ suite('MainThreadModelViewDialog Tests', () => {
mainThreadModelViewDialog.$setTabDetails(tab1Handle, tab1Details);
mainThreadModelViewDialog.$setTabDetails(tab2Handle, tab2Details);
mainThreadModelViewDialog.$setDialogDetails(dialogHandle, dialogDetails);
// Register the wizard and its pages and buttons
mainThreadModelViewDialog.$setButtonDetails(nextButtonHandle, nextButtonDetails);
mainThreadModelViewDialog.$setButtonDetails(backButtonHandle, backButtonDetails);
mainThreadModelViewDialog.$setButtonDetails(generateScriptButtonHandle, generateScriptButtonDetails);
mainThreadModelViewDialog.$setWizardPageDetails(page1Handle, page1Details);
mainThreadModelViewDialog.$setWizardPageDetails(page2Handle, page2Details);
mainThreadModelViewDialog.$setWizardDetails(wizardHandle, wizardDetails);
});
test('Creating a dialog and calling open on it causes a dialog with correct content and buttons to open', () => {
// If I open the dialog
mainThreadModelViewDialog.$open(dialogHandle);
mainThreadModelViewDialog.$openDialog(dialogHandle);
// Then the opened dialog's content and buttons match what was set
mockDialogService.verify(x => x.showDialog(It.isAny()), Times.once());
@@ -129,7 +202,7 @@ suite('MainThreadModelViewDialog Tests', () => {
mockExtHostModelViewDialog.setup(x => x.$onButtonClick(It.isAny())).callback(handle => pressedHandles.push(handle));
// Open the dialog so that its buttons can be accessed
mainThreadModelViewDialog.$open(dialogHandle);
mainThreadModelViewDialog.$openDialog(dialogHandle);
// Set up click emitters for each button
let okEmitter = new Emitter<void>();
@@ -154,4 +227,93 @@ suite('MainThreadModelViewDialog Tests', () => {
// Verify that the correct button click notifications were sent to the proxy
assert.deepEqual(pressedHandles, [button1Handle, button2Handle, okButtonHandle, cancelButtonHandle, button2Handle, cancelButtonHandle, button1Handle, okButtonHandle]);
});
test('Creating a wizard and calling open on it causes a wizard with correct pages and buttons to open', () => {
// If I open the wizard
mainThreadModelViewDialog.$openWizard(wizardHandle);
// Then the opened wizard's content and buttons match what was set
mockDialogService.verify(x => x.showWizard(It.isAny()), Times.once());
assert.notEqual(openedWizard, undefined);
assert.equal(openedWizard.title, wizardDetails.title);
assert.equal(openedWizard.doneButton.label, okButtonDetails.label);
assert.equal(openedWizard.doneButton.enabled, okButtonDetails.enabled);
assert.equal(openedWizard.cancelButton.label, cancelButtonDetails.label);
assert.equal(openedWizard.cancelButton.enabled, cancelButtonDetails.enabled);
assert.equal(openedWizard.customButtons.length, 0);
assert.equal(openedWizard.pages.length, 2);
assert.equal(openedWizard.currentPage, 0);
let page1 = openedWizard.pages[0];
assert.equal(page1.title, page1Details.title);
assert.equal(page1.content, page1Details.content);
assert.equal(page1.enabled, page1Details.enabled);
assert.equal(page1.valid, true);
assert.equal(page1.customButtons.length, 0);
let page2 = openedWizard.pages[1];
assert.equal(page2.title, page2Details.title);
assert.equal(page2.content, page2Details.content);
assert.equal(page2.enabled, page2Details.enabled);
assert.equal(page2.valid, true);
assert.equal(page2.customButtons.length, 2);
});
test('The extension host gets notified when wizard page change events occur', () => {
mockExtHostModelViewDialog.setup(x => x.$onWizardPageChanged(It.isAny(), It.isAny()));
// If I open the wizard and change the page to index 1
mainThreadModelViewDialog.$openWizard(wizardHandle);
openedWizard.setCurrentPage(1);
// Then a page changed event gets sent to the extension host
mockExtHostModelViewDialog.verify(x => x.$onWizardPageChanged(It.is(handle => handle === wizardHandle),
It.is(pageChangeInfo => pageChangeInfo.lastPage === 0 && pageChangeInfo.newPage === 1)), Times.once());
});
test('Validity changed events are forwarded to the extension host', () => {
mockExtHostModelViewDialog.setup(x => x.$onPanelValidityChanged(It.isAny(), It.isAny()));
// If I open the dialog and set its validity and its 2nd tab's validity to false
mainThreadModelViewDialog.$openDialog(dialogHandle);
(openedDialog.content[1] as DialogTab).notifyValidityChanged(false);
openedDialog.notifyValidityChanged(false);
// Then a validity changed event gets sent to the extension host for the tab and the dialog
mockExtHostModelViewDialog.verify(x => x.$onPanelValidityChanged(It.is(handle => handle === dialogHandle), It.is(valid => valid === false)), Times.once());
mockExtHostModelViewDialog.verify(x => x.$onPanelValidityChanged(It.is(handle => handle === tab2Handle), It.is(valid => valid === false)), Times.once());
});
test('addWizardPage method inserts pages at the correct spot and notifies the extension host', () => {
mockExtHostModelViewDialog.setup(x => x.$updateWizardPageInfo(It.isAny(), It.isAny(), It.isAny()));
page3Details = {
title: 'page_3',
content: 'content_3',
customButtons: [],
enabled: true
};
// If I open the wizard and then add a page
mainThreadModelViewDialog.$openWizard(wizardHandle);
mainThreadModelViewDialog.$setWizardPageDetails(page3Handle, page3Details);
mainThreadModelViewDialog.$addWizardPage(wizardHandle, page3Handle, 0);
// Then the updated page info gets sent to the extension host
mockExtHostModelViewDialog.verify(x => x.$updateWizardPageInfo(
It.is(handle => handle === wizardHandle),
It.is(pageHandles => pageHandles.length === 3 && pageHandles[0] === page3Handle),
It.is(currentPage => currentPage === 1)), Times.once());
});
test('removeWizardPage method removes pages at the correct spot and notifies the extension host', () => {
mockExtHostModelViewDialog.setup(x => x.$updateWizardPageInfo(It.isAny(), It.isAny(), It.isAny()));
// If I open the wizard and then remove a page
mainThreadModelViewDialog.$openWizard(wizardHandle);
mainThreadModelViewDialog.$removeWizardPage(wizardHandle, 0);
// Then the updated page info gets sent to the extension host
mockExtHostModelViewDialog.verify(x => x.$updateWizardPageInfo(
It.is(handle => handle === wizardHandle),
It.is(pageHandles => pageHandles.length === 1 && pageHandles[0] === page2Handle),
It.is(currentPage => currentPage === 0)), Times.once());
});
});