teamsfx-extension
Version:
Create, debug, and deploy Teams apps with Teams Toolkit
211 lines • 12.6 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
};
Object.defineProperty(exports, "__esModule", { value: true });
const chai = require("chai");
const vscode_1 = require("vscode");
const teamsfx_api_1 = require("@microsoft/teamsfx-api");
const extensionVariables_1 = require("../../../src/extensionVariables");
const userInterface_1 = require("../../../src/userInterface");
const globalVaribles_1 = require("../../globalVaribles");
const testUserInput_1 = require("../../testUserInput");
const commonUtils_1 = require("../../../src/utils/commonUtils");
suite("UI Unit Tests", () => __awaiter(void 0, void 0, void 0, function* () {
suiteSetup(() => {
// Mock user input.
extensionVariables_1.ext.ui = new testUserInput_1.TestUserInput();
});
suite("Manually", () => {
suite("Show Message Immediately", () => {
test("Infomation", function () {
return __awaiter(this, void 0, void 0, function* () {
yield userInterface_1.default["showMessage"]({
description: "Info",
level: teamsfx_api_1.MsgLevel.Info,
});
for (let i = 0; i < 1e9; ++i) { } // simulate the large calculated work.
});
});
test("Warning", function () {
return __awaiter(this, void 0, void 0, function* () {
yield userInterface_1.default["showMessage"]({
description: "Warning",
level: teamsfx_api_1.MsgLevel.Warning,
});
for (let i = 0; i < 1e9; ++i) { } // simulate the large calculated work.
});
});
test("Error", function () {
return __awaiter(this, void 0, void 0, function* () {
yield userInterface_1.default["showMessage"]({
description: "Error",
level: teamsfx_api_1.MsgLevel.Error,
});
for (let i = 0; i < 1e9; ++i) { } // simulate the large calculated work.
});
});
});
test("Show Progress", function () {
return __awaiter(this, void 0, void 0, function* () {
this.timeout(0);
const progressIterGenerator = function () {
return __asyncGenerator(this, arguments, function* () {
for (let i = 0; i < 1e9; ++i) { }
yield yield __await({ increment: 0, message: "Start" });
for (let i = 0; i < 1e9; ++i) { }
yield yield __await({ increment: 50, message: "Run" });
for (let i = 0; i < 1e9; ++i) { }
yield yield __await({ increment: 100, message: "Finish" });
return yield __await(teamsfx_api_1.ok(null));
});
};
yield userInterface_1.default["showProgress"]({
progressIter: progressIterGenerator(),
title: "Test",
});
yield userInterface_1.default.communicate(new teamsfx_api_1.DialogMsg(teamsfx_api_1.DialogType.ShowProgress, {
progressIter: progressIterGenerator(),
title: "Test",
}));
});
});
test("Show Progress 2", function () {
return __awaiter(this, void 0, void 0, function* () {
this.timeout(0);
const handler = userInterface_1.default.createProgressBar("Test Progress Bar", 3);
yield handler.start("Prepare");
yield commonUtils_1.sleep(2 * 1000);
yield handler.next("First step");
yield commonUtils_1.sleep(2 * 1000);
yield handler.next("Second step");
yield commonUtils_1.sleep(2 * 1000);
yield handler.next("Third step");
yield commonUtils_1.sleep(2 * 1000);
yield handler.end();
});
});
test("Execute Command", () => __awaiter(void 0, void 0, void 0, function* () {
yield userInterface_1.default["askQuestion"]({
type: teamsfx_api_1.QuestionType.ExecuteCmd,
terminalName: "test",
description: "cd ../../../..",
});
// TODO: do some special command and check it.
}));
test("Communicate", () => __awaiter(void 0, void 0, void 0, function* () {
chai.assert.deepEqual(yield userInterface_1.default.communicate(new teamsfx_api_1.DialogMsg(teamsfx_api_1.DialogType.Show, {
description: "test",
level: teamsfx_api_1.MsgLevel.Info,
})), new teamsfx_api_1.DialogMsg(teamsfx_api_1.DialogType.Answer, "Show Successfully"));
chai.assert.deepEqual(yield userInterface_1.default.communicate(new teamsfx_api_1.DialogMsg(teamsfx_api_1.DialogType.Output, {
description: "test",
level: teamsfx_api_1.MsgLevel.Info,
})), new teamsfx_api_1.DialogMsg(teamsfx_api_1.DialogType.Show, {
description: "",
level: teamsfx_api_1.MsgLevel.Info,
}));
}));
});
suite("Automation", () => {
suite("Ask Question", () => {
test("Radio", () => __awaiter(void 0, void 0, void 0, function* () {
const items = [...Array(9).keys()].map((num) => {
return { type: testUserInput_1.EInputType.specifiedItem, index: num % 3 };
});
extensionVariables_1.ext.ui.addInputItems(items);
extensionVariables_1.ext.ui.addInputItems([{ type: testUserInput_1.EInputType.specifiedItem, index: 3 }]);
const question = {
type: teamsfx_api_1.QuestionType.Radio,
description: "test",
defaultAnswer: "a",
options: ["a", "b", "c"],
};
chai.assert.ok((yield userInterface_1.default["askQuestion"](question)) === "a");
chai.assert.ok((yield userInterface_1.default["askQuestion"](question)) === "b");
chai.assert.ok((yield userInterface_1.default["askQuestion"](question)) === "c");
question.defaultAnswer = "b";
chai.assert.ok((yield userInterface_1.default["askQuestion"](question)) === "b");
chai.assert.ok((yield userInterface_1.default["askQuestion"](question)) === "a");
chai.assert.ok((yield userInterface_1.default["askQuestion"](question)) === "c");
question.defaultAnswer = "d";
chai.assert.ok((yield userInterface_1.default["askQuestion"](question)) === "d");
chai.assert.ok((yield userInterface_1.default["askQuestion"](question)) === "a");
chai.assert.ok((yield userInterface_1.default["askQuestion"](question)) === "b");
chai.assert.ok((yield userInterface_1.default["askQuestion"](question)) === "c");
}));
test("Text", () => __awaiter(void 0, void 0, void 0, function* () {
extensionVariables_1.ext.ui.addInputItems([
{ type: testUserInput_1.EInputType.defaultValue },
{ type: testUserInput_1.EInputType.specifiedItem, index: "placeHolder" },
{ type: testUserInput_1.EInputType.defaultValue },
{ type: testUserInput_1.EInputType.specifiedItem, index: "placeHolder" },
{ type: testUserInput_1.EInputType.specifiedValue, value: undefined },
]);
const question = {
type: teamsfx_api_1.QuestionType.Text,
description: "test",
defaultAnswer: "abcd",
};
chai.assert.ok((yield userInterface_1.default["askQuestion"](question)) === "abcd");
chai.assert.ok((yield userInterface_1.default["askQuestion"](question)) === "test");
question.defaultAnswer = undefined;
chai.assert.ok((yield userInterface_1.default["askQuestion"](question)) === "");
chai.assert.ok((yield userInterface_1.default["askQuestion"](question)) === "test");
chai.assert.ok((yield userInterface_1.default["askQuestion"](question)) === undefined);
}));
test("Select Folder", () => __awaiter(void 0, void 0, void 0, function* () {
extensionVariables_1.ext.ui.addInputItems([
{ type: testUserInput_1.EInputType.specifiedValue, value: globalVaribles_1.testFolder },
{ type: testUserInput_1.EInputType.specifiedValue, value: undefined },
]);
const question = {
type: teamsfx_api_1.QuestionType.SelectFolder,
description: "lalala",
};
chai.assert.ok((yield userInterface_1.default["askQuestion"](question)) === vscode_1.Uri.file(globalVaribles_1.testFolder).fsPath);
chai.assert.ok((yield userInterface_1.default["askQuestion"](question)) === undefined);
}));
test("Open Folder", () => __awaiter(void 0, void 0, void 0, function* () {
chai.assert.ok((yield userInterface_1.default["askQuestion"]({
type: teamsfx_api_1.QuestionType.OpenFolder,
description: vscode_1.Uri.file(globalVaribles_1.testFolder).fsPath,
})) === vscode_1.Uri.file(globalVaribles_1.testFolder).fsPath);
}));
});
test("Communicate", () => __awaiter(void 0, void 0, void 0, function* () {
extensionVariables_1.ext.ui.addInputItems([{ type: testUserInput_1.EInputType.defaultValue }]);
chai.assert.deepEqual(yield userInterface_1.default.communicate(new teamsfx_api_1.DialogMsg(teamsfx_api_1.DialogType.Ask, {
type: teamsfx_api_1.QuestionType.Radio,
description: "test",
defaultAnswer: "a",
options: ["a", "b", "c"],
})), new teamsfx_api_1.DialogMsg(teamsfx_api_1.DialogType.Answer, "a"));
chai.assert.deepEqual(yield userInterface_1.default.communicate(new teamsfx_api_1.DialogMsg(teamsfx_api_1.DialogType.Answer, "abc")), new teamsfx_api_1.DialogMsg(teamsfx_api_1.DialogType.Show, {
description: "",
level: teamsfx_api_1.MsgLevel.Error,
}));
}));
});
}));
//# sourceMappingURL=userInterface.noFolder.test.js.map