|
5 | 5 |
|
6 | 6 | // tslint:disable:insecure-random max-func-body-length no-any |
7 | 7 |
|
| 8 | +import { expect } from 'chai'; |
8 | 9 | import * as typemoq from 'typemoq'; |
9 | 10 | import { DiagnosticSeverity } from 'vscode'; |
10 | 11 | import { |
@@ -69,6 +70,70 @@ suite('Application Diagnostics - PromptHandler', () => { |
69 | 70 | await promptHandler.handle(diagnostic); |
70 | 71 | appShell.verifyAll(); |
71 | 72 | }); |
| 73 | + test(`Handling a diagnositic of severity '${severity.name}' should invoke the onClose handler`, async () => { |
| 74 | + const diagnostic: IDiagnostic = { |
| 75 | + code: '1' as any, |
| 76 | + message: 'one', |
| 77 | + scope: DiagnosticScope.Global, |
| 78 | + severity: severity.value, |
| 79 | + resource: undefined, |
| 80 | + invokeHandler: 'default' |
| 81 | + }; |
| 82 | + let onCloseHandlerInvoked = false; |
| 83 | + const options: MessageCommandPrompt = { |
| 84 | + commandPrompts: [{ prompt: 'Yes' }, { prompt: 'No' }], |
| 85 | + message: 'Custom Message', |
| 86 | + onClose: () => { |
| 87 | + onCloseHandlerInvoked = true; |
| 88 | + } |
| 89 | + }; |
| 90 | + |
| 91 | + switch (severity.value) { |
| 92 | + case DiagnosticSeverity.Error: { |
| 93 | + appShell |
| 94 | + .setup((a) => |
| 95 | + a.showErrorMessage( |
| 96 | + typemoq.It.isValue(options.message!), |
| 97 | + typemoq.It.isValue('Yes'), |
| 98 | + typemoq.It.isValue('No') |
| 99 | + ) |
| 100 | + ) |
| 101 | + .returns(() => Promise.resolve('Yes')) |
| 102 | + .verifiable(typemoq.Times.once()); |
| 103 | + break; |
| 104 | + } |
| 105 | + case DiagnosticSeverity.Warning: { |
| 106 | + appShell |
| 107 | + .setup((a) => |
| 108 | + a.showWarningMessage( |
| 109 | + typemoq.It.isValue(options.message!), |
| 110 | + typemoq.It.isValue('Yes'), |
| 111 | + typemoq.It.isValue('No') |
| 112 | + ) |
| 113 | + ) |
| 114 | + .returns(() => Promise.resolve('Yes')) |
| 115 | + .verifiable(typemoq.Times.once()); |
| 116 | + break; |
| 117 | + } |
| 118 | + default: { |
| 119 | + appShell |
| 120 | + .setup((a) => |
| 121 | + a.showInformationMessage( |
| 122 | + typemoq.It.isValue(options.message!), |
| 123 | + typemoq.It.isValue('Yes'), |
| 124 | + typemoq.It.isValue('No') |
| 125 | + ) |
| 126 | + ) |
| 127 | + .returns(() => Promise.resolve('Yes')) |
| 128 | + .verifiable(typemoq.Times.once()); |
| 129 | + break; |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + await promptHandler.handle(diagnostic, options); |
| 134 | + appShell.verifyAll(); |
| 135 | + expect(onCloseHandlerInvoked).to.equal(true, 'onClose handler should be called.'); |
| 136 | + }); |
72 | 137 | test(`Handling a diagnositic of severity '${severity.name}' should display a custom message with buttons`, async () => { |
73 | 138 | const diagnostic: IDiagnostic = { |
74 | 139 | code: '1' as any, |
|
0 commit comments