79suite(
'Query Test Suite',
function () {
100 (
vscode.window as any).showInputBox = async (options?:
vscode.InputBoxOptions) => {
106 (
vscode.window as any).showQuickPick = async (items:
string[], options?:
vscode.QuickPickOptions) => {
128 suite(
'Singleton Pattern', () => {
133 test(
'should return the same instance when accessing Query.instance multiple times', () => {
134 const instance1 =
Query.instance;
135 const instance2 =
Query.instance;
137 assert.strictEqual(instance1, instance2,
'Query.instance should return the same instance');
138 assert.ok(instance1 instanceof
Query,
'Instance should be of type Query');
145 test(
'exported query constant should be the same as Query.instance', () => {
146 const queryInstance =
Query.instance;
148 assert.strictEqual(
query, queryInstance,
'Exported query should be the same as Query.instance');
155 test(
'should create instance on first access', () => {
157 assert.ok(
instance,
'Instance should be created on first access');
158 assert.ok(typeof
instance.input ===
'function',
'Instance should have input method');
159 assert.ok(typeof
instance.quickPick ===
'function',
'Instance should have quickPick method');
160 assert.ok(typeof
instance.confirm ===
'function',
'Instance should have confirm method');
168 suite(
'Input Dialog Tests', () => {
173 test(
'should successfully return user input', async () => {
174 const expectedInput =
'Test user input';
175 const promptText =
'Enter your input:';
179 const result = await
query.input(promptText);
181 assert.strictEqual(result, expectedInput,
'Should return the user input');
190 test(
'should handle user cancellation', async () => {
193 const result = await
query.input(
'Test prompt');
195 assert.strictEqual(result, undefined,
'Should return undefined when user cancels');
203 test(
'should pass through InputBoxOptions correctly', async () => {
204 const promptText =
'Enter password:';
205 const options:
vscode.InputBoxOptions = {
207 placeHolder:
'Your password here'
212 const result = await
query.input(promptText, options);
214 assert.strictEqual(result,
'secret123',
'Should return input value');
224 test(
'should handle empty string input', async () => {
227 const result = await
query.input(
'Enter something:');
229 assert.strictEqual(result,
'',
'Should return empty string if user enters empty string');
237 suite(
'Quick Pick Dialog Tests', () => {
242 test(
'should successfully return selected item', async () => {
243 const items = [
'Option 1',
'Option 2',
'Option 3'];
244 const placeholder =
'Select an option:';
245 const selectedItem =
'Option 2';
249 const result = await
query.quickPick(items, placeholder);
251 assert.strictEqual(result, selectedItem,
'Should return the selected item');
261 test(
'should handle user cancellation in quick pick', async () => {
264 const result = await
query.quickPick([
'Option 1'],
'Select:');
266 assert.strictEqual(result, undefined,
'Should return undefined when user cancels');
274 test(
'should handle empty items array', async () => {
275 const emptyItems:
string[] = [];
278 const result = await
query.quickPick(emptyItems,
'No options:');
280 assert.strictEqual(result, undefined,
'Should handle empty items gracefully');
288 test(
'should handle single item array', async () => {
289 const singleItem = [
'Only Option'];
292 const result = await
query.quickPick(singleItem,
'Only choice:');
294 assert.strictEqual(result,
'Only Option',
'Should handle single item selection');
302 suite(
'Confirmation Dialog Tests', () => {
307 test(
'should return true when user selects Yes', async () => {
309 const messageModule = require(
'../modules/messageProvider');
310 const originalGetMessage = messageModule.getMessage;
311 messageModule.getMessage = (key:
string) => {
312 if (key ===
'quickPickYes') {
315 if (key ===
'quickPickNo') {
324 const result = await
query.confirm(
'Do you want to proceed?');
326 assert.strictEqual(result,
true,
'Should return true for Yes selection');
331 messageModule.getMessage = originalGetMessage;
339 test(
'should return false when user selects No', async () => {
340 const messageModule = require(
'../modules/messageProvider');
341 const originalGetMessage = messageModule.getMessage;
342 messageModule.getMessage = (key:
string) => {
343 if (key ===
'quickPickYes') {
346 if (key ===
'quickPickNo') {
355 const result = await
query.confirm(
'Are you sure?');
357 assert.strictEqual(result,
false,
'Should return false for No selection');
359 messageModule.getMessage = originalGetMessage;
367 test(
'should return false when user cancels confirmation', async () => {
368 const messageModule = require(
'../modules/messageProvider');
369 const originalGetMessage = messageModule.getMessage;
370 messageModule.getMessage = (key:
string) => {
371 if (key ===
'quickPickYes') {
374 if (key ===
'quickPickNo') {
383 const result = await
query.confirm(
'Confirm action?');
385 assert.strictEqual(result,
false,
'Should return false for cancellation');
387 messageModule.getMessage = originalGetMessage;
396 suite(
'Integration Tests', () => {
401 test(
'should handle complex input options', async () => {
402 const complexOptions:
vscode.InputBoxOptions = {
403 value:
'default value',
404 prompt:
'Override prompt',
405 placeHolder:
'Type here...',
412 const result = await
query.input(
'Enter email:', complexOptions);
414 assert.strictEqual(result,
'test@example.com',
'Should handle complex options');
424 test(
'should merge prompt with options correctly', async () => {
425 const options:
vscode.InputBoxOptions = {
426 prompt:
'Original prompt'
431 await
query.input(
'Override prompt', options);
441 test(
'should handle special characters in items', async () => {
442 const mixedItems = [
'string',
'123',
'',
'special@chars!'];
445 const result = await
query.quickPick(mixedItems,
'Pick one:');
447 assert.strictEqual(result,
'123',
'Should handle mixed string items');
Singleton user interaction manager for VS Code UI components.
const instance
Singleton logger instance for application-wide use.
export const Record< string,(...args:any[])=> string
import *as vscode from vscode
let originalShowQuickPick
Original showQuickPick implementation.
let mockInputBoxResponse
Mock state variables for VS Code UI testing.
let originalShowInputBox
Storage for original VS Code API methods.
let mockQuickPickCallCount
Counter for quick pick method calls.
let mockLastInputOptions
Last captured input box options for validation.
import *as assert from assert
let mockLastQuickPickItems
Last captured quick pick items for validation.
let mockInputBoxCallCount
Counter for input box method calls.
let mockLastQuickPickOptions
Last captured quick pick options for validation.
let mockQuickPickResponse
Mock response for quick pick dialogs.
export const query
Convenience singleton export for direct access to Query functionality @export Primary interface for u...