QuickInput Proposed API (#49340)

This commit is contained in:
Christof Marti
2018-06-12 18:21:35 +02:00
parent e0ac369bb2
commit 965c1862b5
13 changed files with 1428 additions and 504 deletions

View File

@@ -0,0 +1,53 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import { window, commands } from 'vscode';
import { closeAllEditors } from '../utils';
suite('window namespace tests', function () {
suite('QuickInput tests', function () {
teardown(closeAllEditors);
test('createQuickPick, select second', function (_done) {
let done = (err?: any) => {
done = () => {};
_done(err);
};
const quickPick = window.createQuickPick();
const expectedFocusChanges = [['eins'], ['zwei']];
quickPick.onDidChangeActive(items => {
try {
assert.deepEqual(items.map(item => item.label), expectedFocusChanges.shift());
} catch (err) {
done(err);
}
});
quickPick.onDidAccept(() => {
try {
const items = quickPick.activeItems;
quickPick.dispose();
assert.equal(items.length, 1);
assert.equal(items[0].label, 'zwei');
assert.equal(expectedFocusChanges.length, 0);
done();
} catch (err) {
done(err);
}
});
quickPick.items = ['eins', 'zwei', 'drei'].map(label => ({ label }));
quickPick.show();
(async () => {
await commands.executeCommand('workbench.action.quickOpenSelectNext');
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
})()
.catch(err => done(err));
});
});
});

View File

@@ -417,7 +417,7 @@ suite('window namespace tests', () => {
});
});
test('Default value for showInput Box accepted even if fails validateInput, #33691', function () {
test('Default value for showInput Box not accepted when it fails validateInput, reversing #33691', async function () {
const result = window.showInputBox({
validateInput: (value: string) => {
if (!value || value.trim().length === 0) {
@@ -427,19 +427,9 @@ suite('window namespace tests', () => {
}
});
const accept = commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
return Promise.race([
result.then(() => assert.ok(false)),
accept.then(() => assert.ok(false), err => assert.ok(err))
.then(() => new Promise(resolve => setTimeout(resolve, 10)))
])
.then(() => {
const close = commands.executeCommand('workbench.action.closeQuickOpen');
return Promise.all([result, close])
.then(([value]) => {
assert.equal(value, undefined);
});
});
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
await commands.executeCommand('workbench.action.closeQuickOpen');
assert.equal(await result, undefined);
});