Add dialog close validation (#1704)

This commit is contained in:
Matt Irvine
2018-06-21 16:55:47 -07:00
committed by GitHub
parent 1871fd383e
commit 6c5fac997f
8 changed files with 84 additions and 5 deletions

View File

@@ -307,4 +307,23 @@ suite('ExtHostModelViewDialog Tests', () => {
// Then the main thread gets notified of the new details
mockProxy.verify(x => x.$setWizardDetails(It.isAny(), It.is(x => x.message === newMessage)), Times.once());
});
test('Main thread can execute dialog close validation', () => {
// Set up the main thread mock to record the dialog handle
let dialogHandle: number;
mockProxy.setup(x => x.$setDialogDetails(It.isAny(), It.isAny())).callback((handle, details) => dialogHandle = handle);
// Create the dialog and add a validation that records that it has been called
let dialog = extHostModelViewDialog.createDialog('dialog_1');
extHostModelViewDialog.updateDialogContent(dialog);
let callCount = 0;
dialog.registerCloseValidator(() => {
callCount++;
return true;
});
// If I call the validation from the main thread then it should run
extHostModelViewDialog.$validateDialogClose(dialogHandle);
assert.equal(callCount, 1);
});
});

View File

@@ -60,7 +60,8 @@ suite('MainThreadModelViewDialog Tests', () => {
$onPanelValidityChanged: (handle, valid) => undefined,
$onWizardPageChanged: (handle, info) => undefined,
$updateWizardPageInfo: (wizardHandle, pageHandles, currentPageIndex) => undefined,
$validateNavigation: (handle, info) => undefined
$validateNavigation: (handle, info) => undefined,
$validateDialogClose: handle => undefined
});
let extHostContext = <IExtHostContext>{
getProxy: proxyType => mockExtHostModelViewDialog.object
@@ -347,4 +348,15 @@ suite('MainThreadModelViewDialog Tests', () => {
assert.equal(newMessage, wizardDetails.message, 'New message was not included in the fired event');
assert.equal(openedWizard.message, wizardDetails.message, 'New message was not set on the wizard');
});
test('Creating a dialog adds a close validation that calls the extension host', () => {
mockExtHostModelViewDialog.setup(x => x.$validateDialogClose(It.isAny()));
// If I call validateClose on the dialog that gets created
mainThreadModelViewDialog.$openDialog(dialogHandle);
openedDialog.validateClose();
// Then the call gets forwarded to the extension host
mockExtHostModelViewDialog.verify(x => x.$validateDialogClose(It.is(handle => handle === dialogHandle)), Times.once());
});
});