Skip to content

Commit

Permalink
fix: remove auto popup install dependency (#11905)
Browse files Browse the repository at this point in the history
* fix: remove auto popup install dependency

* fix: modfiy UT for remove auto install dependency

* fix: remove no needed import

* fix: remove code no longer used

* fix: remove auto install in officedev

---------

Co-authored-by: Ruiqi Yang (from Dev Box) <[email protected]>
  • Loading branch information
richard6094 and Ruiqi Yang (from Dev Box) authored Jul 2, 2024
1 parent c472584 commit bb88a80
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 120 deletions.
46 changes: 1 addition & 45 deletions packages/vscode-extension/src/handlers/officeDevHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
"use strict";

import { FxError, Result, ok } from "@microsoft/teamsfx-api";
import {
globalStateGet,
globalStateUpdate,
isManifestOnlyOfficeAddinProject,
} from "@microsoft/teamsfx-core";
import * as fs from "fs-extra";
import * as path from "path";
import { globalStateGet, globalStateUpdate } from "@microsoft/teamsfx-core";
import * as vscode from "vscode";
import { GlobalKey } from "../constants";
import { OfficeDevTerminal, TriggerCmdType } from "../debug/taskTerminal/officeDevTerminal";
Expand Down Expand Up @@ -167,26 +161,6 @@ export function installOfficeAddInDependencies(args?: any[]): Promise<Result<nul
return Promise.resolve(ok(null));
}

export async function popupOfficeAddInDependenciesMessage() {
const buttonOptions = ["Yes", "No"];
const notificationMessage = localize("teamstoolkit.handlers.askInstallOfficeAddinDependency");

const result = await vscode.window.showInformationMessage(notificationMessage, ...buttonOptions);

if (result === "Yes") {
// Handle Yes button click
await autoInstallDependencyHandler();
} else if (result === "No") {
// Handle No button click
void vscode.window.showInformationMessage(
localize("teamstoolkit.handlers.installOfficeAddinDependencyCancelled")
);
} else {
// Handle case where pop-up was dismissed without clicking a button
// No action.
}
}

export function stopOfficeAddInDebug(args?: any[]): Promise<Result<null, FxError>> {
ExtTelemetry.sendTelemetryEvent(TelemetryEvent.stopAddInDebug, getTriggerFromProperty(args));
const terminal = OfficeDevTerminal.getInstance(TriggerCmdType.triggerStopDebug);
Expand All @@ -208,7 +182,6 @@ export async function autoOpenOfficeDevProjectHandler(): Promise<void> {
const isOpenReadMe = (await globalStateGet(GlobalKey.OpenReadMe, "")) as string;
const isOpenSampleReadMe = (await globalStateGet(GlobalKey.OpenSampleReadMe, false)) as boolean;
const createWarnings = (await globalStateGet(GlobalKey.CreateWarnings, "")) as string;
const autoInstallDependency = (await globalStateGet(GlobalKey.AutoInstallDependency)) as boolean;
if (isOpenWalkThrough) {
// current the welcome walkthrough is not supported for wxp add in
await globalStateUpdate(GlobalKey.OpenWalkThrough, false);
Expand All @@ -225,21 +198,4 @@ export async function autoOpenOfficeDevProjectHandler(): Promise<void> {
await openSampleReadmeHandler([TelemetryTriggerFrom.Auto]);
await globalStateUpdate(GlobalKey.OpenSampleReadMe, false);
}
if (autoInstallDependency) {
if (!isManifestOnlyOfficeAddinProject(globalVariables.workspaceUri?.fsPath ?? ""))
void popupOfficeAddInDependenciesMessage();
await globalStateUpdate(GlobalKey.AutoInstallDependency, false);
}
if (
globalVariables.isOfficeAddInProject &&
!checkOfficeAddInInstalled(globalVariables.workspaceUri?.fsPath ?? "") &&
!isManifestOnlyOfficeAddinProject(globalVariables.workspaceUri?.fsPath ?? "")
) {
void popupOfficeAddInDependenciesMessage();
}
}

export function checkOfficeAddInInstalled(directory: string): boolean {
const nodeModulesExists = fs.existsSync(path.join(directory, "node_modules"));
return nodeModulesExists;
}
75 changes: 0 additions & 75 deletions packages/vscode-extension/test/handlers/officeDevHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,29 +121,6 @@ describe("officeDevHandler", () => {
"https://aka.ms/OfficeAddinsPromptLibrary"
);
});

it("popupOfficeAddInDependenciesMessage", async () => {
const autoInstallDependencyHandlerStub = sandbox.stub(
autoOpenHelper,
"autoInstallDependencyHandler"
);
sandbox.stub(localizeUtils, "localize").returns("installPopUp");
sandbox
.stub(vscode.window, "showInformationMessage")
.callsFake((_message: string, option: any, ...items: vscode.MessageItem[]) => {
return Promise.resolve(option);
});
await officeDevHandlers.popupOfficeAddInDependenciesMessage();
chai.assert(autoInstallDependencyHandlerStub.calledOnce);
});

it("checkOfficeAddInInstalled", async () => {
mockfs({
"/test/node_modules/test": "",
});
const node_modulesExists = officeDevHandlers.checkOfficeAddInInstalled("/test");
chai.assert.isTrue(node_modulesExists);
});
});

describe("autoOpenOfficeDevProjectHandler", () => {
Expand Down Expand Up @@ -216,58 +193,6 @@ describe("autoOpenOfficeDevProjectHandler", () => {
chai.assert.isTrue(executeCommandStub.calledOnce);
});

it("autoInstallDependency", async () => {
sandbox.stub(globalVariables, "workspaceUri").value(vscode.Uri.file("test"));
sandbox.stub(globalState, "globalStateGet").callsFake(async (key: string) => {
if (key === "teamsToolkit:autoInstallDependency") {
return true;
} else {
return "";
}
});
sandbox.stub(localizeUtils, "localize").returns("installPopUp");
const showInformationMessageStub = sandbox
.stub(vscode.window, "showInformationMessage")
.callsFake((_message: string, option: any, ...items: vscode.MessageItem[]) => {
return Promise.resolve("No" as any);
});
const globalStateUpdateStub = sandbox.stub(globalState, "globalStateUpdate");
const isManifestOnlyOfficeAddinProjectStub = sandbox
.stub(projectSettingsHelper, "isManifestOnlyOfficeAddinProject")
.returns(false);

await officeDevHandlers.autoOpenOfficeDevProjectHandler();

chai.assert(showInformationMessageStub.callCount == 2);
chai.assert(globalStateUpdateStub.calledOnce);
});

it("autoInstallDependency when extension launch", async () => {
sandbox.stub(globalVariables, "workspaceUri").value({ fsPath: "/test" });
sandbox.stub(globalState, "globalStateGet").resolves("");
sandbox.stub(globalVariables, "isOfficeAddInProject").value(true);

sandbox.stub(localizeUtils, "localize").returns("ask install window pop up");
const autoInstallDependencyHandlerStub = sandbox.stub(
autoOpenHelper,
"autoInstallDependencyHandler"
);

const showInformationMessageStub = sandbox
.stub(vscode.window, "showInformationMessage")
.callsFake((_message: string, option: any, ...items: vscode.MessageItem[]) => {
return Promise.resolve(option);
});

const isManifestOnlyOfficeAddinProjectStub = sandbox
.stub(projectSettingsHelper, "isManifestOnlyOfficeAddinProject")
.returns(false);

await officeDevHandlers.autoOpenOfficeDevProjectHandler();

chai.assert(autoInstallDependencyHandlerStub.calledOnce);
});

it("openOfficeDevFolder", async () => {
const folderPath = vscode.Uri.file("/test");
const executeCommandStub = sandbox.stub(vscode.commands, "executeCommand");
Expand Down

0 comments on commit bb88a80

Please sign in to comment.