Add wizard navigation validator (#1587)

This commit is contained in:
Matt Irvine
2018-06-08 15:32:37 -07:00
committed by GitHub
parent 20c4f085c8
commit e3a2ed95d4
8 changed files with 104 additions and 8 deletions

View File

@@ -3,6 +3,7 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as sqlops from 'sqlops';
import * as assert from 'assert';
import { Mock, It, Times } from 'typemoq';
import { ExtHostModelViewDialog } from 'sql/workbench/api/node/extHostModelViewDialog';
@@ -263,4 +264,30 @@ suite('ExtHostModelViewDialog Tests', () => {
extHostModelViewDialog.$onPanelValidityChanged(pageHandle, false);
assert.equal(page.valid, false);
});
test('Main thread can execute wizard navigation validation', () => {
// Set up the main thread mock to record the wizard handle
let wizardHandle: number;
mockProxy.setup(x => x.$setWizardDetails(It.isAny(), It.isAny())).callback((handle, details) => wizardHandle = handle);
// Create the wizard and add a validation that records that it has been called
let wizard = extHostModelViewDialog.createWizard('wizard_1');
extHostModelViewDialog.updateWizard(wizard);
let validationInfo: sqlops.window.modelviewdialog.WizardPageChangeInfo;
wizard.registerNavigationValidator(info => {
validationInfo = info;
return true;
});
// If I call the validation from the main thread then it should run and record the correct page change info
let lastPage = 0;
let newPage = 1;
extHostModelViewDialog.$validateNavigation(wizardHandle, {
lastPage: lastPage,
newPage: newPage
});
assert.notEqual(validationInfo, undefined);
assert.equal(validationInfo.lastPage, lastPage);
assert.equal(validationInfo.newPage, newPage);
});
});

View File

@@ -59,7 +59,8 @@ suite('MainThreadModelViewDialog Tests', () => {
$onButtonClick: handle => undefined,
$onPanelValidityChanged: (handle, valid) => undefined,
$onWizardPageChanged: (handle, info) => undefined,
$updateWizardPageInfo: (wizardHandle, pageHandles, currentPageIndex) => undefined
$updateWizardPageInfo: (wizardHandle, pageHandles, currentPageIndex) => undefined,
$validateNavigation: (handle, info) => undefined
});
let extHostContext = <IExtHostContext>{
getProxy: proxyType => mockExtHostModelViewDialog.object
@@ -316,4 +317,15 @@ suite('MainThreadModelViewDialog Tests', () => {
It.is(pageHandles => pageHandles.length === 1 && pageHandles[0] === page2Handle),
It.is(currentPage => currentPage === 0)), Times.once());
});
test('Creating a wizard adds a navigation validation that calls the extension host', () => {
mockExtHostModelViewDialog.setup(x => x.$validateNavigation(It.isAny(), It.isAny()));
// If I call validateNavigation on the wizard that gets created
let wizard: Wizard = (mainThreadModelViewDialog as any).getWizard(wizardHandle);
wizard.validateNavigation(1);
// Then the call gets forwarded to the extension host
mockExtHostModelViewDialog.verify(x => x.$validateNavigation(It.is(handle => handle === wizardHandle), It.is(info => info.newPage === 1)), Times.once());
});
});