* Replaces createInputBox() with a deterministic scripted input box. * * This lets each test navigate through the real prompt/settings loop without needing * UI interaction (but still exercising the event handlers).
(actions: InputBoxAction[])
| 291 | * UI interaction (but still exercising the event handlers). |
| 292 | */ |
| 293 | function stubCreateInputBoxActions(actions: InputBoxAction[]): void { |
| 294 | const createInputBox = sb.stub(vs.window, "createInputBox"); |
| 295 | createInputBox.callsFake(() => { |
| 296 | let acceptHandler: () => void; |
| 297 | let changeHandler: (value: string) => void; |
| 298 | let hideHandler: () => void; |
| 299 | let triggerHandler: () => void; |
| 300 | const input = { |
| 301 | buttons: [] as vs.QuickInputButton[], |
| 302 | dispose: sb.stub(), |
| 303 | hide: () => hideHandler?.(), |
| 304 | ignoreFocusOut: false, |
| 305 | onDidAccept: (handler: () => void) => { |
| 306 | acceptHandler = handler; |
| 307 | return { dispose: () => undefined }; |
| 308 | }, |
| 309 | onDidChangeValue: (handler: (value: string) => void) => { |
| 310 | changeHandler = handler; |
| 311 | return { dispose: () => undefined }; |
| 312 | }, |
| 313 | onDidHide: (handler: () => void) => { |
| 314 | hideHandler = handler; |
| 315 | return { dispose: () => undefined }; |
| 316 | }, |
| 317 | onDidTriggerButton: (handler: () => void) => { |
| 318 | triggerHandler = handler; |
| 319 | return { dispose: () => undefined }; |
| 320 | }, |
| 321 | placeholder: undefined as string | undefined, |
| 322 | prompt: undefined as string | undefined, |
| 323 | show: () => { |
| 324 | const action = actions.shift(); |
| 325 | if (!action) |
| 326 | throw new Error("No more input box actions were available"); |
| 327 | |
| 328 | // Defer callbacks until after the implementation code has finished wiring up |
| 329 | // all event handlers. |
| 330 | setImmediate(() => { |
| 331 | if (action.kind === "settings") { |
| 332 | triggerHandler?.(); |
| 333 | } else { |
| 334 | input.value = action.value; |
| 335 | changeHandler?.(action.value); |
| 336 | acceptHandler?.(); |
| 337 | } |
| 338 | }); |
| 339 | }, |
| 340 | title: undefined as string | undefined, |
| 341 | validationMessage: undefined as string | undefined, |
| 342 | value: "", |
| 343 | }; |
| 344 | |
| 345 | return input; |
| 346 | }); |
| 347 | } |