Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the prompt again if user clicks on more info #11664

Merged
merged 3 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/client/application/diagnostics/checks/pythonPathDeprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,17 @@ export class PythonPathDeprecatedDiagnosticService extends BaseDiagnosticsServic
},
{
prompt: Common.moreInfo(),
command: commandFactory.createCommand(diagnostic, {
type: 'launch',
options: learnMoreOnInterpreterSecurityURI
})
command: {
diagnostic,
invoke: async (): Promise<void> => {
const launchCommand = commandFactory.createCommand(diagnostic, {
type: 'launch',
options: learnMoreOnInterpreterSecurityURI
});
await launchCommand.invoke();
return this.messageService.handle(diagnostic, { commandPrompts: options });
}
}
},
{
prompt: Common.doNotShowAgain(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ suite('Application Diagnostics - Python Path Deprecated', () => {
});
test('Python Path Deprecated Diagnostic is handled as expected', async () => {
const diagnostic = new PythonPathDeprecatedDiagnostic('message', resource);
const launchCmd = ({ cmd: 'launchCmd' } as any) as IDiagnosticCommand;
const ignoreCmd = ({ cmd: 'ignoreCmd' } as any) as IDiagnosticCommand;
filterService
.setup((f) =>
Expand All @@ -155,15 +154,6 @@ suite('Application Diagnostics - Python Path Deprecated', () => {
.callback((_d, p: MessageCommandPrompt) => (messagePrompt = p))
.returns(() => Promise.resolve())
.verifiable(typemoq.Times.once());
commandFactory
.setup((f) =>
f.createCommand(
typemoq.It.isAny(),
typemoq.It.isObjectWith<CommandOption<'launch', string>>({ type: 'launch' })
)
)
.returns(() => launchCmd)
.verifiable(typemoq.Times.once());

commandFactory
.setup((f) =>
Expand All @@ -185,10 +175,8 @@ suite('Application Diagnostics - Python Path Deprecated', () => {
expect(messagePrompt!.commandPrompts[0].command!.diagnostic).to.be.deep.equal(diagnostic);
expect(messagePrompt!.commandPrompts[0].prompt).to.be.deep.equal(Common.yesPlease());
expect(messagePrompt!.commandPrompts[1]).to.be.deep.equal({ prompt: Common.noIWillDoItLater() });
expect(messagePrompt!.commandPrompts[2]).to.be.deep.equal({
prompt: Common.moreInfo(),
command: launchCmd
});
expect(messagePrompt!.commandPrompts[2].prompt).to.be.deep.equal(Common.moreInfo());
expect(messagePrompt!.commandPrompts[2].command!.diagnostic).to.be.deep.equal(diagnostic);
expect(messagePrompt!.commandPrompts[3]).to.be.deep.equal({
prompt: Common.doNotShowAgain(),
command: ignoreCmd
Expand All @@ -202,6 +190,69 @@ suite('Application Diagnostics - Python Path Deprecated', () => {
await messagePrompt!.commandPrompts[0].command!.invoke();
assert(_removePythonPathFromWorkspaceSettings.calledOnceWith(resource));
});
test('More info should show the prompt again', async () => {
const diagnostic = new PythonPathDeprecatedDiagnostic('message', resource);
const launchCmd: typemoq.IMock<IDiagnosticCommand> = typemoq.Mock.ofType<IDiagnosticCommand>();
const ignoreCmd = ({ cmd: 'ignoreCmd' } as any) as IDiagnosticCommand;

launchCmd
.setup((f) => f.invoke())
.returns(() => Promise.resolve())
.verifiable(typemoq.Times.once());
filterService
.setup((f) =>
f.shouldIgnoreDiagnostic(typemoq.It.isValue(DiagnosticCodes.PythonPathDeprecatedDiagnostic))
)
.returns(() => Promise.resolve(false));

// This will be invoked twice, first time to show the message
// Next time when more info is clicked.
let messagePrompt: MessageCommandPrompt | undefined;
messageHandler
.setup((i) => i.handle(typemoq.It.isValue(diagnostic), typemoq.It.isAny()))
.callback((_d, p: MessageCommandPrompt) => (messagePrompt = p))
.returns(() => Promise.resolve())
.verifiable(typemoq.Times.exactly(2));

commandFactory
.setup((f) =>
f.createCommand(
typemoq.It.isAny(),
typemoq.It.isObjectWith<CommandOption<'launch', string>>({ type: 'launch' })
)
)
.returns(() => launchCmd.object)
.verifiable(typemoq.Times.once());

commandFactory
.setup((f) =>
f.createCommand(
typemoq.It.isAny(),
typemoq.It.isObjectWith<CommandOption<'ignore', DiagnosticScope>>({ type: 'ignore' })
)
)
.returns(() => ignoreCmd)
.verifiable(typemoq.Times.once());

await diagnosticService.handle([diagnostic]);

expect(messagePrompt).not.be.equal(undefined, 'Message prompt not set');
expect(messagePrompt!.commandPrompts.length).to.equal(4, 'Incorrect length');
expect(messagePrompt!.commandPrompts[0].command).not.be.equal(undefined, 'Command not set');
expect(messagePrompt!.commandPrompts[0].command!.diagnostic).to.be.deep.equal(diagnostic);
expect(messagePrompt!.commandPrompts[0].prompt).to.be.deep.equal(Common.yesPlease());
expect(messagePrompt!.commandPrompts[1]).to.be.deep.equal({ prompt: Common.noIWillDoItLater() });
expect(messagePrompt!.commandPrompts[2].prompt).to.be.deep.equal(Common.moreInfo());
expect(messagePrompt!.commandPrompts[2].command!.diagnostic).to.be.deep.equal(diagnostic);
expect(messagePrompt!.commandPrompts[3]).to.be.deep.equal({
prompt: Common.doNotShowAgain(),
command: ignoreCmd
});

await messagePrompt!.commandPrompts[2].command!.invoke();
messageHandler.verifyAll();
commandFactory.verifyAll();
});
test('Handling an empty diagnostic should not show a message nor return a command', async () => {
const diagnostics: IDiagnostic[] = [];

Expand Down