Skip to content

Commit

Permalink
test: add apimsg with microsoft entra auth test cases (#11997)
Browse files Browse the repository at this point in the history
  • Loading branch information
Annefch authored Jul 11, 2024
1 parent e08ff04 commit 9b35225
Show file tree
Hide file tree
Showing 9 changed files with 326 additions and 18 deletions.
8 changes: 6 additions & 2 deletions packages/tests/scripts/pvt.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
"remotedebug-spfxreact-import-multiple",
"remotedebug-spfx-none",
"remotedebug-spfx-minimal",
"remotedebug-spfx-react"
"remotedebug-spfx-react",
"remotedebug-msg-newapi-microsoftentra-ts-win-only",
"remotedebug-msg-newapi-microsoftentra-win-only"
],
"node-20": [
"localdebug-obo-tab"
Expand Down Expand Up @@ -119,7 +121,9 @@
"localdebug-spfx-none",
"localdebug-spfx",
"localdebug-msg-newapi-apikey-ts",
"localdebug-msg-newapi-apikey"
"localdebug-msg-newapi-apikey",
"localdebug-msg-newapi-microsoftentra-ts",
"localdebug-msg-newapi-microsoftentra"
],
"node-20": [
"localdebug-obo-tab"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

/**
* @author Anne Fu <v-annefu@microsoft.com>
*/
import * as path from "path";
import { startDebugging, waitForTerminal } from "../../utils/vscodeOperation";
import {
initNoAddappPage,
validateApiMeResult,
} from "../../utils/playwrightOperation";
import { LocalDebugTestContext } from "./localdebugContext";
import { Timeout, LocalDebugTaskLabel } from "../../utils/constants";
import { Env } from "../../utils/env";
import { it } from "../../utils/it";
import { validateFileExist } from "../../utils/commonUtils";

describe("Local Debug Tests", function () {
this.timeout(Timeout.testCase);
let localDebugTestContext: LocalDebugTestContext;

beforeEach(async function () {
// ensure workbench is ready
this.timeout(Timeout.prepareTestCase);
localDebugTestContext = new LocalDebugTestContext("msgmicroentra", {
lang: "typescript",
});
await localDebugTestContext.before();
});

afterEach(async function () {
this.timeout(Timeout.finishTestCase);
await localDebugTestContext.after(false, true);
});

it(
"[Typescript] Local debug for API Message Extension with none auth",
{
testPlanCaseId: 28665898,
author: "v-annefu@microsoft.com",
},
async function () {
const projectPath = path.resolve(
localDebugTestContext.testRootFolder,
localDebugTestContext.appName
);
validateFileExist(projectPath, "src/functions/repair.ts");
await startDebugging("Debug in Teams (Chrome)");
await waitForTerminal(LocalDebugTaskLabel.StartLocalTunnel);
await waitForTerminal(
LocalDebugTaskLabel.StartBackend,
"Worker process started and initialized"
);
const teamsAppId = await localDebugTestContext.getTeamsAppId();
const page = await initNoAddappPage(
localDebugTestContext.context!,
teamsAppId,
Env.username,
Env.password
);
await validateApiMeResult(page, localDebugTestContext.appName);
}
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

/**
* @author Anne Fu <v-annefu@microsoft.com>
*/
import * as path from "path";
import * as fs from "fs-extra";
import { startDebugging, waitForTerminal } from "../../utils/vscodeOperation";
import {
initNoAddappPage,
validateApiMeResult,
} from "../../utils/playwrightOperation";
import { LocalDebugTestContext } from "./localdebugContext";
import { Timeout, LocalDebugTaskLabel } from "../../utils/constants";
import { Env } from "../../utils/env";
import { it } from "../../utils/it";
import { validateFileExist } from "../../utils/commonUtils";

describe("Local Debug Tests", function () {
this.timeout(Timeout.testCase);
let localDebugTestContext: LocalDebugTestContext;

beforeEach(async function () {
// ensure workbench is ready
this.timeout(Timeout.prepareTestCase);
localDebugTestContext = new LocalDebugTestContext("msgmicroentra");
await localDebugTestContext.before();
});

afterEach(async function () {
this.timeout(Timeout.finishTestCase);
await localDebugTestContext.after(false, true);
});

it(
"[Javascript] Local debug for API Message Extension with Microsoft Entra auth",
{
testPlanCaseId: 28665871,
author: "v-annefu@microsoft.com",
},
async function () {
const projectPath = path.resolve(
localDebugTestContext.testRootFolder,
localDebugTestContext.appName
);
validateFileExist(projectPath, "src/functions/repair.js");
await startDebugging("Debug in Teams (Chrome)");
await waitForTerminal(LocalDebugTaskLabel.StartLocalTunnel);
await waitForTerminal(
LocalDebugTaskLabel.StartBackend,
"Worker process started and initialized"
);
const teamsAppId = await localDebugTestContext.getTeamsAppId();
const page = await initNoAddappPage(
localDebugTestContext.context!,
teamsAppId,
Env.username,
Env.password
);
await validateApiMeResult(page, localDebugTestContext.appName);
}
);
});
9 changes: 8 additions & 1 deletion packages/tests/src/ui-test/localdebug/localdebugContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export type LocalDebugTestName =
| "aichat"
| "aiassist"
| "msgnewapi"
| "msgapikey";
| "msgapikey"
| "msgmicroentra";

export class LocalDebugTestContext extends TestContext {
public testName: LocalDebugTestName;
Expand Down Expand Up @@ -279,6 +280,12 @@ export class LocalDebugTestContext extends TestContext {
`teamsapp new --app-name ${this.appName} --interactive false --capability search-app --me-architecture new-api --api-auth api-key --programming-language ${this.lang} --telemetry false`
);
break;
case "msgmicroentra":
await execCommand(
this.testRootFolder,
`teamsapp new --app-name ${this.appName} --interactive false --capability search-app --me-architecture new-api --api-auth microsoft-entra --programming-language ${this.lang} --telemetry false`
);
break;
}
if (this.needMigrate) {
await execCommand(this.testRootFolder, `set TEAMSFX_V3=true`);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

/**
* @author Anne Fu <v-annefu@microsoft.com>
*/
import * as path from "path";
import { VSBrowser } from "vscode-extension-tester";
import { Timeout } from "../../utils/constants";
import {
RemoteDebugTestContext,
provisionProject,
deployProject,
} from "./remotedebugContext";
import {
execCommandIfExist,
createNewProject,
} from "../../utils/vscodeOperation";
import { it } from "../../utils/it";
import {
initNoAddappPage,
validateApiMeResult,
} from "../../utils/playwrightOperation";
import { Env } from "../../utils/env";

describe("Remote debug Tests", function () {
this.timeout(Timeout.testAzureCase);
let remoteDebugTestContext: RemoteDebugTestContext;
let testRootFolder: string;
let appName: string;
const appNameCopySuffix = "copy";
let newAppFolderName: string;
let projectPath: string;

beforeEach(async function () {
// ensure workbench is ready
this.timeout(Timeout.prepareTestCase);
remoteDebugTestContext = new RemoteDebugTestContext("msgmicroentra");
testRootFolder = remoteDebugTestContext.testRootFolder;
appName = remoteDebugTestContext.appName;
newAppFolderName = appName + appNameCopySuffix;
projectPath = path.resolve(testRootFolder, newAppFolderName);
await remoteDebugTestContext.before();
});

afterEach(async function () {
this.timeout(Timeout.finishAzureTestCase);
await remoteDebugTestContext.after();

//Close the folder and cleanup local sample project

await execCommandIfExist("Workspaces: Close Workspace", Timeout.webView);
console.log(`[Successfully] start to clean up for ${projectPath}`);
await remoteDebugTestContext.cleanUp(
appName,
projectPath,
false,
true,
false
);
});

it(
"[auto] [Typescript] Remote debug for API Message Extension with Microsoft Entra auth",
{
testPlanCaseId: 28665924,
author: "v-annefu@microsoft.com",
},
async function () {
const driver = VSBrowser.instance.driver;
await createNewProject("msgmicroentra", appName, { lang: "TypeScript" });
await provisionProject(appName, projectPath);
await deployProject(projectPath, Timeout.botDeploy);
const teamsAppId = await remoteDebugTestContext.getTeamsAppId(
projectPath
);
const page = await initNoAddappPage(
remoteDebugTestContext.context!,
teamsAppId,
Env.username,
Env.password
);
await validateApiMeResult(page, remoteDebugTestContext.appName);
}
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

/**
* @author Anne Fu <v-annefu@microsoft.com>
*/
import * as path from "path";
import { VSBrowser } from "vscode-extension-tester";
import { Timeout } from "../../utils/constants";
import {
RemoteDebugTestContext,
provisionProject,
deployProject,
} from "./remotedebugContext";
import {
execCommandIfExist,
createNewProject,
} from "../../utils/vscodeOperation";
import { it } from "../../utils/it";
import {
initNoAddappPage,
validateApiMeResult,
} from "../../utils/playwrightOperation";
import { Env } from "../../utils/env";

describe("Remote debug Tests", function () {
this.timeout(Timeout.testAzureCase);
let remoteDebugTestContext: RemoteDebugTestContext;
let testRootFolder: string;
let appName: string;
const appNameCopySuffix = "copy";
let newAppFolderName: string;
let projectPath: string;

beforeEach(async function () {
// ensure workbench is ready
this.timeout(Timeout.prepareTestCase);
remoteDebugTestContext = new RemoteDebugTestContext("msgmicroentra");
testRootFolder = remoteDebugTestContext.testRootFolder;
appName = remoteDebugTestContext.appName;
newAppFolderName = appName + appNameCopySuffix;
projectPath = path.resolve(testRootFolder, newAppFolderName);
await remoteDebugTestContext.before();
});

afterEach(async function () {
this.timeout(Timeout.finishAzureTestCase);
await remoteDebugTestContext.after();

//Close the folder and cleanup local sample project

await execCommandIfExist("Workspaces: Close Workspace", Timeout.webView);
console.log(`[Successfully] start to clean up for ${projectPath}`);
await remoteDebugTestContext.cleanUp(
appName,
projectPath,
false,
true,
false
);
});

it(
"[auto] [Javascript] Remote debug for API Message Extension with Microsoft Entra auth",
{
testPlanCaseId: 28665898,
author: "v-annefu@microsoft.com",
},
async function () {
const driver = VSBrowser.instance.driver;
await createNewProject("msgmicroentra", appName);
await provisionProject(appName, projectPath);
await deployProject(projectPath, Timeout.botDeploy);
const teamsAppId = await remoteDebugTestContext.getTeamsAppId(
projectPath
);
const page = await initNoAddappPage(
remoteDebugTestContext.context!,
teamsAppId,
Env.username,
Env.password
);
await validateApiMeResult(page, remoteDebugTestContext.appName);
}
);
});
1 change: 1 addition & 0 deletions packages/tests/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ export type AppType =
| "msgnewapi"
| "msgopenapi"
| "msgapikey"
| "msgmicroentra"
| "importspfx";

export class FeatureFlagName {
Expand Down
16 changes: 1 addition & 15 deletions packages/tests/src/utils/playwrightOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,22 +735,8 @@ export async function initNoAddappPage(
page.waitForNavigation(),
]);
await page.waitForTimeout(Timeout.shortTimeLoading);
const chatTab = await page?.waitForSelector(
".app-bar-items span:has-text('Chat')"
);
const chatTab = await page?.waitForSelector("button span:has-text('Chat')");
await chatTab?.click();
try {
console.log("close dialog");
await page?.click("button[data-tid='closeModelDialogBtn']");
} catch (error) {
console.log("no dialog to close");
}
try {
console.log("dismiss message");
await page.click('button:has-text("Dismiss")');
} catch (error) {
console.log("no message to dismiss");
}
return page;
}

Expand Down
9 changes: 9 additions & 0 deletions packages/tests/src/utils/vscodeOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,15 @@ export async function createNewProject(
await input.selectQuickPick(lang);
break;
}
case "msgmicroentra": {
await input.selectQuickPick(CreateProjectQuestion.MessageExtension);
await input.selectQuickPick("Custom Search Results");
await input.selectQuickPick("Start with a new API");
await input.selectQuickPick("Microsoft Entra");
// Choose programming language
await input.selectQuickPick(lang);
break;
}
default:
break;
}
Expand Down

0 comments on commit 9b35225

Please sign in to comment.