-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/microsoft/powerplatform-vscode
- Loading branch information
Showing
20 changed files
with
372 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
import * as vscode from 'vscode'; | ||
import { ITelemetry } from '../../common/OneDSLoggerTelemetry/telemetry/ITelemetry'; | ||
|
||
export interface ICliAcquisitionContext { | ||
readonly extensionPath: string; | ||
readonly globalStorageLocalPath: string; | ||
readonly telemetry: ITelemetry; | ||
showInformationMessage(message: string, ...items: string[]): void; | ||
showErrorMessage(message: string, ...items: string[]): void; | ||
showCliPreparingMessage(version: string): void; | ||
showCliReadyMessage(): void; | ||
showCliInstallFailedError(err: string): void; | ||
locDotnetNotInstalledOrInsufficient(): string; | ||
} | ||
|
||
// allow for DI without direct reference to vscode's d.ts file: that definintions file is being generated at VS Code runtime | ||
export class CliAcquisitionContext implements ICliAcquisitionContext { | ||
public constructor( | ||
private readonly _context: vscode.ExtensionContext, | ||
private readonly _telemetry: ITelemetry | ||
) { } | ||
|
||
public get extensionPath(): string { | ||
return this._context.extensionPath; | ||
} | ||
public get globalStorageLocalPath(): string { | ||
return this._context.globalStorageUri.fsPath; | ||
} | ||
public get telemetry(): ITelemetry { | ||
return this._telemetry; | ||
} | ||
|
||
showInformationMessage(message: string, ...items: string[]): void { | ||
vscode.window.showInformationMessage(message, ...items); | ||
} | ||
|
||
showErrorMessage(message: string, ...items: string[]): void { | ||
vscode.window.showErrorMessage(message, ...items); | ||
} | ||
|
||
showCliPreparingMessage(version: string): void { | ||
vscode.window.showInformationMessage( | ||
vscode.l10n.t({ | ||
message: "Preparing pac CLI (v{0})...", | ||
args: [version], | ||
comment: ["{0} represents the version number"] | ||
}) | ||
); | ||
} | ||
|
||
showCliReadyMessage(): void { | ||
vscode.window.showInformationMessage( | ||
vscode.l10n.t('The pac CLI is ready for use in your VS Code terminal!')); | ||
} | ||
|
||
showCliInstallFailedError(err: string): void { | ||
vscode.window.showErrorMessage( | ||
vscode.l10n.t({ | ||
message: "Cannot install pac CLI: {0}", | ||
args: [err], | ||
comment: ["{0} represents the error message returned from the exception"] | ||
}) | ||
); | ||
} | ||
|
||
showGeneratorInstallingMessage(version: string): void { | ||
vscode.window.showInformationMessage( | ||
vscode.l10n.t({ | ||
message: "Installing Power Pages generator(v{0})...", | ||
args: [version], | ||
comment: ["{0} represents the version number"] | ||
})) | ||
} | ||
|
||
locDotnetNotInstalledOrInsufficient(): string { | ||
return vscode.l10n.t({ | ||
message: "dotnet sdk 6.0 or greater must be installed", | ||
comment: ["Do not translate 'dotnet' or 'sdk'"] | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
src/client/test/Integration/CliAcquisitionContext.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
import * as vscode from 'vscode'; | ||
import { ITelemetry } from '../../../common/OneDSLoggerTelemetry/telemetry/ITelemetry'; | ||
import { CliAcquisitionContext } from '../../lib/CliAcquisitionContext'; | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
|
||
describe('CliAcquisitionContext', () => { | ||
let context: vscode.ExtensionContext; | ||
let telemetry: ITelemetry; | ||
let showInformationMessageSpy: sinon.SinonSpy; | ||
let showErrorMessageSpy: sinon.SinonSpy; | ||
|
||
beforeEach(() => { | ||
context = { | ||
extensionPath: 'testExtensionPath', | ||
globalStorageUri: { | ||
fsPath: 'testGlobalStorageUri' | ||
} | ||
} as vscode.ExtensionContext; | ||
|
||
telemetry = {} as ITelemetry; | ||
|
||
showInformationMessageSpy = sinon.spy(vscode.window, "showInformationMessage"); | ||
showErrorMessageSpy = sinon.spy(vscode.window, "showErrorMessage"); | ||
}); | ||
|
||
afterEach(() => { | ||
showInformationMessageSpy.restore(); | ||
showErrorMessageSpy.restore(); | ||
}); | ||
|
||
it('should return the extension path', () => { | ||
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry); | ||
|
||
expect(cliAcquisitionContext.extensionPath).to.equal('testExtensionPath'); | ||
}); | ||
|
||
it('should return the global storage local path', () => { | ||
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry); | ||
|
||
expect(cliAcquisitionContext.globalStorageLocalPath).to.equal('testGlobalStorageUri'); | ||
}); | ||
|
||
it('should return the telemetry', () => { | ||
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry); | ||
|
||
expect(cliAcquisitionContext.telemetry).to.equal(telemetry); | ||
}); | ||
|
||
it('should show information message', () => { | ||
const message = 'testMessage'; | ||
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry); | ||
|
||
cliAcquisitionContext.showInformationMessage(message); | ||
|
||
const showInformationMessageArgs = showInformationMessageSpy.getCalls()[0].args; | ||
|
||
expect(showInformationMessageArgs[0]).eq("testMessage"); | ||
}); | ||
|
||
it('should show error message', () => { | ||
const message = 'testMessage'; | ||
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry); | ||
|
||
cliAcquisitionContext.showErrorMessage(message); | ||
|
||
const showErrorMessageArgs = showErrorMessageSpy.getCalls()[0].args; | ||
|
||
expect(showErrorMessageArgs[0]).eq("testMessage"); | ||
}); | ||
|
||
it('should show cli preparing message', () => { | ||
const version = 'testVersion'; | ||
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry); | ||
|
||
cliAcquisitionContext.showCliPreparingMessage(version); | ||
|
||
const showInformationMessageArgs = showInformationMessageSpy.getCalls()[0].args; | ||
|
||
expect(showInformationMessageArgs[0]).eq("Preparing pac CLI (vtestVersion)..."); | ||
}); | ||
|
||
it('should show cli ready message', () => { | ||
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry); | ||
|
||
cliAcquisitionContext.showCliReadyMessage(); | ||
|
||
const showInformationMessageArgs = showInformationMessageSpy.getCalls()[0].args; | ||
|
||
expect(showInformationMessageArgs[0]).eq("The pac CLI is ready for use in your VS Code terminal!"); | ||
}); | ||
|
||
it('should show cli install failed error', () => { | ||
const err = 'testError'; | ||
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry); | ||
|
||
cliAcquisitionContext.showCliInstallFailedError(err); | ||
|
||
const showErrorMessageArgs = showErrorMessageSpy.getCalls()[0].args; | ||
|
||
expect(showErrorMessageArgs[0]).eq("Cannot install pac CLI: testError"); | ||
}); | ||
|
||
it('should show generator installing message', () => { | ||
const version = 'testVersion'; | ||
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry); | ||
|
||
cliAcquisitionContext.showGeneratorInstallingMessage(version); | ||
|
||
const showInformationMessageArgs = showInformationMessageSpy.getCalls()[0].args; | ||
|
||
expect(showInformationMessageArgs[0]).eq("Installing Power Pages generator(vtestVersion)..."); | ||
}); | ||
|
||
it('should return loc dotnet not installed or insufficient', () => { | ||
const cliAcquisitionContext = new CliAcquisitionContext(context, telemetry); | ||
|
||
expect(cliAcquisitionContext.locDotnetNotInstalledOrInsufficient()).eq("dotnet sdk 6.0 or greater must be installed"); | ||
}); | ||
}); |
Oops, something went wrong.