Skip to content

Commit 8b4d340

Browse files
benbrowngabog
authored andcommitted
Expand TestBot + Add tests (#1022)
* port over CoreBot dialogs into testBot write unit tests for testbot using botbuilder-testing * update package log * update * add testbot to package update stuff * adjust package * restore mybot url and class * updates per comments * add more tests * add all tests for parity with c# * test outcome of booking dialog * new tests for dateresolver * add spoken output to booking dialog * remove unused paramter * Update mainDialog constructor, add inputhint, replace dialog, airpot not found warning * Fix unsupportedCities array length check * Refactor luisHelper / FlightBookingRecognizer, update tests * Update test * Refactoring of MainDialog, flightBookingRecognizer and tests * Add luis config check in mainDialog actStep function * Renamed test files from tests.js to test.js to match naming pattern in botbuilder. Renamed some test cases to use the same capitalization as bot builder. Added empty .env file. Added general .gitignore. Added TSConfig * Renamed test * Updated instantiation of DialogTestClient to match the latest changes from master. Removed unnecesary tests for creating DialogTestClient instance. Renamed dialog variables as sut (systemt under test) to match the documentation. Fixed some tests (need to fix others) * Updated MainDialog to handle LUIS intents, show warnings for unsupported cities and work the same as the dotnet one. Added helper methods to extract LUIS values for composite entities and datetime to FlightBookingRecognizer. Added luis result json captures to testdata so we can write tests for entity extraction based on serialized results. Updated BookingDialog to use proper text, speak and inputhints. Updated DateResolverDialog to use proper text, speak and inputhints. Removed onBeginDialog from cancelAndHelpDialog to avoid handling interruptions on turn 0. Removed myBot. * Formatting and comments in MaindDialog Updated deployment template to point to messages instead of mybot. * trying to fix the build by removing testbo from package.json * reverted changes * Updated bookingDialog logic and test data to match dotnet. * updated tests to use testCases.map instead of for loop. updated dateResolveDialog tests to use strictEquals. * Touched file to kick off build. * Changed flightBookingRecognizer so it caches the instance of the recognizer rather than creating one on each call. Implemented 3 of for test scenarios for mainDialog (with mock dialogs and mock recognizer). deleted unused mainDialogTestCases. Updated other tests to use => instead of function(). Changed the oreder of constructor params for mainDialog. * Implemented showWarningMessage tests for MainDialog. Added placeholder for cancelAndHelpDialog.tests. * Implemented CancelAndHelpDialog tests. * Moved dialog tests into a dialogs folder. * Implemented DialogAndWelcomeBot tests * Added some comments to the code * Updated comments. * Updated confirm prompt to say "is this correct" Moved MockBookingDialogWithPrompt outside the test case for clarity.
1 parent a5386b2 commit 8b4d340

28 files changed

+1932
-66
lines changed

libraries/testbot/.env

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
MicrosoftAppId=
2-
MicrosoftAppPassword=
2+
MicrosoftAppPassword=
3+
LuisAppId=
4+
LuisAPIKey=
5+
LuisAPIHostName=

libraries/testbot/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**/node_modules
2+
/**/.vscode
3+
/**/lib
4+
coverage
5+
.nyc_output
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
const { CardFactory } = require('botbuilder-core');
5+
const { DialogBot } = require('./dialogBot');
6+
const WelcomeCard = require('./resources/welcomeCard.json');
7+
8+
class DialogAndWelcomeBot extends DialogBot {
9+
constructor(conversationState, userState, dialog, logger) {
10+
super(conversationState, userState, dialog, logger);
11+
12+
this.onMembersAdded(async (context, next) => {
13+
const membersAdded = context.activity.membersAdded;
14+
for (let cnt = 0; cnt < membersAdded.length; cnt++) {
15+
if (membersAdded[cnt].id !== context.activity.recipient.id) {
16+
const welcomeCard = CardFactory.adaptiveCard(WelcomeCard);
17+
await context.sendActivity({ attachments: [welcomeCard] });
18+
await dialog.run(context, conversationState.createProperty('DialogState'));
19+
}
20+
}
21+
22+
// By calling next() you ensure that the next BotHandler is run.
23+
await next();
24+
});
25+
}
26+
}
27+
28+
module.exports.DialogAndWelcomeBot = DialogAndWelcomeBot;

libraries/testbot/bots/dialogBot.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
const { ActivityHandler } = require('botbuilder');
5+
6+
class DialogBot extends ActivityHandler {
7+
/**
8+
*
9+
* @param {ConversationState} conversationState
10+
* @param {UserState} userState
11+
* @param {Dialog} dialog
12+
* @param {any} logger object for logging events, defaults to console if none is provided
13+
*/
14+
constructor(conversationState, userState, dialog, logger) {
15+
super();
16+
if (!conversationState) throw new Error('[DialogBot]: Missing parameter. conversationState is required');
17+
if (!userState) throw new Error('[DialogBot]: Missing parameter. userState is required');
18+
if (!dialog) throw new Error('[DialogBot]: Missing parameter. dialog is required');
19+
if (!logger) {
20+
logger = console;
21+
logger.log('[DialogBot]: logger not passed in, defaulting to console');
22+
}
23+
24+
this.conversationState = conversationState;
25+
this.userState = userState;
26+
this.dialog = dialog;
27+
this.logger = logger;
28+
this.dialogState = this.conversationState.createProperty('DialogState');
29+
30+
this.onMessage(async (context, next) => {
31+
this.logger.log('Running dialog with Message Activity.');
32+
33+
// Run the Dialog with the new message Activity.
34+
await this.dialog.run(context, this.dialogState);
35+
36+
// By calling next() you ensure that the next BotHandler is run.
37+
await next();
38+
});
39+
40+
this.onDialog(async (context, next) => {
41+
// Save any state changes. The load happened during the execution of the Dialog.
42+
await this.conversationState.saveChanges(context, false);
43+
await this.userState.saveChanges(context, false);
44+
45+
// By calling next() you ensure that the next BotHandler is run.
46+
await next();
47+
});
48+
}
49+
}
50+
51+
module.exports.DialogBot = DialogBot;

libraries/testbot/bots/myBot.js

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
3+
"type": "AdaptiveCard",
4+
"version": "1.0",
5+
"body": [
6+
{
7+
"type": "Image",
8+
"url": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQtB3AwMUeNoq4gUBGe6Ocj8kyh3bXa9ZbV7u1fVKQoyKFHdkqU",
9+
"size": "stretch"
10+
},
11+
{
12+
"type": "TextBlock",
13+
"spacing": "medium",
14+
"size": "default",
15+
"weight": "bolder",
16+
"text": "Welcome to Bot Framework!",
17+
"wrap": true,
18+
"maxLines": 0
19+
},
20+
{
21+
"type": "TextBlock",
22+
"size": "default",
23+
"isSubtle": "yes",
24+
"text": "Now that you have successfully run your bot, follow the links in this Adaptive Card to expand your knowledge of Bot Framework.",
25+
"wrap": true,
26+
"maxLines": 0
27+
}
28+
],
29+
"actions": [
30+
{
31+
"type": "Action.OpenUrl",
32+
"title": "Get an overview",
33+
"url": "https://docs.microsoft.com/en-us/azure/bot-service/?view=azure-bot-service-4.0"
34+
},
35+
{
36+
"type": "Action.OpenUrl",
37+
"title": "Ask a question",
38+
"url": "https://stackoverflow.com/questions/tagged/botframework"
39+
},
40+
{
41+
"type": "Action.OpenUrl",
42+
"title": "Learn how to deploy",
43+
"url": "https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-deploy-azure?view=azure-bot-service-4.0"
44+
}
45+
]
46+
}

0 commit comments

Comments
 (0)