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

@@ -18,17 +18,21 @@ suite('ExtHostModelViewDialog Tests', () => {
setup(() => {
mockProxy = Mock.ofInstance(<MainThreadModelViewDialogShape>{
$open: handle => undefined,
$close: handle => undefined,
$openDialog: handle => undefined,
$closeDialog: handle => undefined,
$setDialogDetails: (handle, details) => undefined,
$setTabDetails: (handle, details) => undefined,
$setButtonDetails: (handle, details) => undefined
$setButtonDetails: (handle, details) => undefined,
$openWizard: handle => undefined,
$closeWizard: handle => undefined,
$setWizardPageDetails: (handle, details) => undefined,
$setWizardDetails: (handle, details) => undefined
});
let mainContext = <IMainContext>{
getProxy: proxyType => mockProxy.object
};
extHostModelView = Mock.ofInstance(<ExtHostModelViewShape> {
extHostModelView = Mock.ofInstance(<ExtHostModelViewShape>{
$registerProvider: (widget, handler) => undefined
});
extHostModelViewDialog = new ExtHostModelViewDialog(mainContext, extHostModelView.object);
@@ -59,7 +63,7 @@ suite('ExtHostModelViewDialog Tests', () => {
});
test('Opening a dialog updates its tabs and buttons on the main thread', () => {
mockProxy.setup(x => x.$open(It.isAny()));
mockProxy.setup(x => x.$openDialog(It.isAny()));
mockProxy.setup(x => x.$setDialogDetails(It.isAny(), It.isAny()));
mockProxy.setup(x => x.$setTabDetails(It.isAny(), It.isAny()));
mockProxy.setup(x => x.$setButtonDetails(It.isAny(), It.isAny()));
@@ -77,25 +81,26 @@ suite('ExtHostModelViewDialog Tests', () => {
button1.enabled = false;
let button2Label = 'button_2';
let button2 = extHostModelViewDialog.createButton(button2Label);
dialog.customButtons = [button1, button2];
// Open the dialog and verify that the correct main thread methods were called
extHostModelViewDialog.open(dialog);
extHostModelViewDialog.openDialog(dialog);
mockProxy.verify(x => x.$setButtonDetails(It.isAny(), It.is(details => {
return details.enabled === false && details.label === button1Label;
})), Times.once());
})), Times.atLeastOnce());
mockProxy.verify(x => x.$setButtonDetails(It.isAny(), It.is(details => {
return details.enabled === true && details.label === button2Label;
})), Times.once());
})), Times.atLeastOnce());
mockProxy.verify(x => x.$setTabDetails(It.isAny(), It.is(details => {
return details.title === tab1Title;
})), Times.once());
})), Times.atLeastOnce());
mockProxy.verify(x => x.$setTabDetails(It.isAny(), It.is(details => {
return details.title === tab2Title;
})), Times.once());
})), Times.atLeastOnce());
mockProxy.verify(x => x.$setDialogDetails(It.isAny(), It.is(details => {
return details.title === dialogTitle;
})), Times.once());
mockProxy.verify(x => x.$open(It.isAny()), Times.once());
return details.title === dialogTitle && details.content.length === 2 && details.customButtons.length === 2;
})), Times.atLeastOnce());
mockProxy.verify(x => x.$openDialog(It.isAny()), Times.once());
});
test('Button clicks are forwarded to the correct button', () => {
@@ -123,4 +128,139 @@ suite('ExtHostModelViewDialog Tests', () => {
// Then the clicks should have been handled by the expected handlers
assert.deepEqual(clickEvents, [1, 2, 2, 1]);
});
test('Creating a wizard returns a wizard with initialized buttons and the given title', () => {
let title = 'wizard_title';
let wizard = extHostModelViewDialog.createWizard(title);
assert.equal(wizard.title, title);
assert.equal(wizard.doneButton.enabled, true);
assert.equal(wizard.cancelButton.enabled, true);
assert.equal(wizard.nextButton.enabled, true);
assert.equal(wizard.backButton.enabled, true);
assert.deepEqual(wizard.pages, []);
});
test('Opening a wizard updates its pages and buttons on the main thread', () => {
mockProxy.setup(x => x.$openWizard(It.isAny()));
mockProxy.setup(x => x.$setWizardDetails(It.isAny(), It.isAny()));
mockProxy.setup(x => x.$setWizardPageDetails(It.isAny(), It.isAny()));
mockProxy.setup(x => x.$setButtonDetails(It.isAny(), It.isAny()));
// Create a wizard with 2 pages and 2 custom buttons
let wizardTitle = 'wizard_title';
let wizard = extHostModelViewDialog.createWizard(wizardTitle);
let page1Title = 'page_1';
let page1 = extHostModelViewDialog.createWizardPage(page1Title);
let page2Title = 'page_2';
let page2 = extHostModelViewDialog.createWizardPage(page2Title);
wizard.pages = [page1, page2];
let button1Label = 'button_1';
let button1 = extHostModelViewDialog.createButton(button1Label);
button1.enabled = false;
let button2Label = 'button_2';
let button2 = extHostModelViewDialog.createButton(button2Label);
wizard.customButtons = [button1, button2];
// Open the wizard and verify that the correct main thread methods were called
extHostModelViewDialog.openWizard(wizard);
mockProxy.verify(x => x.$setButtonDetails(It.isAny(), It.is(details => {
return details.enabled === false && details.label === button1Label;
})), Times.atLeastOnce());
mockProxy.verify(x => x.$setButtonDetails(It.isAny(), It.is(details => {
return details.enabled === true && details.label === button2Label;
})), Times.atLeastOnce());
mockProxy.verify(x => x.$setWizardPageDetails(It.isAny(), It.is(details => {
return details.title === page1Title;
})), Times.atLeastOnce());
mockProxy.verify(x => x.$setWizardPageDetails(It.isAny(), It.is(details => {
return details.title === page2Title;
})), Times.atLeastOnce());
mockProxy.verify(x => x.$setWizardDetails(It.isAny(), It.is(details => {
return details.title === wizardTitle && details.pages.length === 2 && details.customButtons.length === 2;
})), Times.atLeastOnce());
mockProxy.verify(x => x.$openWizard(It.isAny()), Times.once());
});
test('Wizard page changed events are handled correctly', () => {
// Set up the main thread mock to record the handle assigned to the wizard
let wizardHandle: number;
mockProxy.setup(x => x.$setWizardDetails(It.isAny(), It.isAny())).callback((handle, details) => wizardHandle = handle);
// Set up the wizard with 2 pages
let wizard = extHostModelViewDialog.createWizard('test_wizard');
let page1 = extHostModelViewDialog.createWizardPage('page_1');
let page2 = extHostModelViewDialog.createWizardPage('page_2');
wizard.pages = [page1, page2];
extHostModelViewDialog.updateWizard(wizard);
// Record page changed events
let actualPageChangeInfo = [];
wizard.onPageChanged(pageChangeInfo => {
actualPageChangeInfo.push(pageChangeInfo);
});
// Call the page changed event and verify that it was handled
let expectedPageChangeInfo = {
lastPage: 0,
newPage: 1
};
extHostModelViewDialog.$onWizardPageChanged(wizardHandle, expectedPageChangeInfo);
assert.equal(actualPageChangeInfo.length, 1);
assert.equal(actualPageChangeInfo[0], expectedPageChangeInfo);
assert.equal(wizard.currentPage, expectedPageChangeInfo.newPage);
});
test('Validity changed events are handled correctly', () => {
// Set up the main thread mock to record handles assigned to tabs
let tabHandles = [];
mockProxy.setup(x => x.$setTabDetails(It.isAny(), It.isAny())).callback((handle, details) => tabHandles.push(handle));
// Set up the dialog with 2 tabs
let dialog = extHostModelViewDialog.createDialog('test_dialog');
let tab1 = extHostModelViewDialog.createTab('tab_1');
let tab2 = extHostModelViewDialog.createTab('tab_2');
dialog.content = [tab1, tab2];
extHostModelViewDialog.updateDialogContent(dialog);
// Record tab validity changed events
let tab1ValidityChangedEvents = [];
let tab2ValidityChangedEvents = [];
tab1.onValidityChanged(valid => tab1ValidityChangedEvents.push(valid));
tab2.onValidityChanged(valid => tab2ValidityChangedEvents.push(valid));
// Call the validity changed event on tab 2 and verify that it was handled but tab 1 is still not valid
extHostModelViewDialog.$onPanelValidityChanged(tabHandles[1], false);
assert.equal(tab1ValidityChangedEvents.length, 0);
assert.equal(tab1.valid, true);
assert.equal(tab2ValidityChangedEvents.length, 1);
assert.equal(tab2ValidityChangedEvents[0], false);
assert.equal(tab2.valid, false);
});
test('Verify validity changed events update validity for all panel types', () => {
// Set up the main thread mock to record handles for the tab, dialog, and page
let tabHandle: number;
let dialogHandle: number;
let pageHandle: number;
mockProxy.setup(x => x.$setTabDetails(It.isAny(), It.isAny())).callback((handle, details) => tabHandle = handle);
mockProxy.setup(x => x.$setDialogDetails(It.isAny(), It.isAny())).callback((handle, details) => dialogHandle = handle);
mockProxy.setup(x => x.$setWizardPageDetails(It.isAny(), It.isAny())).callback((handle, details) => pageHandle = handle);
// Initialize a tab, dialog, and page
let tab = extHostModelViewDialog.createTab('tab_1');
extHostModelViewDialog.updateTabContent(tab);
let dialog = extHostModelViewDialog.createDialog('dialog_1');
extHostModelViewDialog.updateDialogContent(dialog);
let page = extHostModelViewDialog.createWizardPage('page_1');
extHostModelViewDialog.updateWizardPage(page);
// Call the validity changed event on each object and verify that the object's validity was updated
extHostModelViewDialog.$onPanelValidityChanged(tabHandle, false);
assert.equal(tab.valid, false);
extHostModelViewDialog.$onPanelValidityChanged(dialogHandle, false);
assert.equal(dialog.valid, false);
extHostModelViewDialog.$onPanelValidityChanged(pageHandle, false);
assert.equal(page.valid, false);
});
});

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());
});
});