|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import * as assert from 'assert'; |
| 7 | +import { IListRenderer, IListVirtualDelegate } from 'vs/base/browser/ui/list/list'; |
| 8 | +import { List } from 'vs/base/browser/ui/list/listWidget'; |
| 9 | +import { QuickInputController } from 'vs/base/parts/quickinput/browser/quickInput'; |
| 10 | +import { IWorkbenchListOptions } from 'vs/platform/list/browser/listService'; |
| 11 | + |
| 12 | +// Simple promisify of setTimeout |
| 13 | +function wait(delayMS: number) { |
| 14 | + return new Promise(function (resolve) { |
| 15 | + setTimeout(resolve, delayMS); |
| 16 | + }); |
| 17 | +} |
| 18 | + |
| 19 | +suite('QuickInput', () => { |
| 20 | + let fixture: HTMLElement, controller: QuickInputController; |
| 21 | + |
| 22 | + setup(() => { |
| 23 | + fixture = document.createElement('div'); |
| 24 | + document.body.appendChild(fixture); |
| 25 | + |
| 26 | + controller = new QuickInputController({ |
| 27 | + container: fixture, |
| 28 | + idPrefix: 'testQuickInput', |
| 29 | + ignoreFocusOut() { return false; }, |
| 30 | + isScreenReaderOptimized() { return false; }, |
| 31 | + returnFocus() { }, |
| 32 | + backKeybindingLabel() { return undefined; }, |
| 33 | + setContextKey() { return undefined; }, |
| 34 | + createList: <T>( |
| 35 | + user: string, |
| 36 | + container: HTMLElement, |
| 37 | + delegate: IListVirtualDelegate<T>, |
| 38 | + renderers: IListRenderer<T, any>[], |
| 39 | + options: IWorkbenchListOptions<T>, |
| 40 | + ) => new List<T>(user, container, delegate, renderers, options), |
| 41 | + styles: { |
| 42 | + button: {}, |
| 43 | + countBadge: {}, |
| 44 | + inputBox: {}, |
| 45 | + keybindingLabel: {}, |
| 46 | + list: {}, |
| 47 | + progressBar: {}, |
| 48 | + widget: {} |
| 49 | + } |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + teardown(() => { |
| 54 | + controller.dispose(); |
| 55 | + document.body.removeChild(fixture); |
| 56 | + }); |
| 57 | + |
| 58 | + test('onDidChangeValue gets triggered when .value is set', async () => { |
| 59 | + const quickpick = controller.createQuickPick(); |
| 60 | + |
| 61 | + let value: string | undefined = undefined; |
| 62 | + quickpick.onDidChangeValue((e) => value = e); |
| 63 | + |
| 64 | + // Trigger a change |
| 65 | + quickpick.value = 'changed'; |
| 66 | + |
| 67 | + try { |
| 68 | + // wait a bit to let the event play out. |
| 69 | + await wait(200); |
| 70 | + assert.strictEqual(value, quickpick.value); |
| 71 | + } finally { |
| 72 | + quickpick.dispose(); |
| 73 | + } |
| 74 | + }); |
| 75 | +}); |
0 commit comments