Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
[ToDo] Fix as designer's suggestion (#2548)
Browse files Browse the repository at this point in the history
* change markToDo reply

* hotfix: luis and responses

* cover tests

* luis issue

* modify wordings as designer's suggustions
  • Loading branch information
ssss141414 committed Oct 23, 2019
1 parent 7384638 commit 9d7fa04
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ private Action<IActivity> ShowUpdatedCard()
return activity =>
{
var messageActivity = activity.AsMessageActivity();
Assert.AreEqual(messageActivity.Attachments.Count, 1);
CollectionAssert.Contains(
this.ParseReplies(MarkToDoResponses.AfterAllTasksCompleted, new StringDictionary() { { MockData.ListType, MockData.ToDo } }),
Expand Down
58 changes: 37 additions & 21 deletions skills/csharp/tests/todoskill.tests/Flow/MarkToDoFlowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ await this.GetTestFlow()
.AssertReplyOneOf(this.AfterSettingUpOneNote())
.AssertReplyOneOf(this.CollectTaskIndex())
.Send(MarkToDoFlowTestUtterances.TaskContent)
.AssertReply(this.ShowUpdatedToDoCard(0))
.AssertReplyOneOf(this.CompleteAnotherTask())
.Send(MockData.ConfirmNo)
.AssertReplyOneOf(this.ActionEndMessage())
.AssertReply(this.ShowCompleteMessage(0))
.AssertReply(this.ShowSummary())
.StartTestAsync();
}

Expand All @@ -49,10 +47,8 @@ await this.GetTestFlow()
.Send(MarkToDoFlowTestUtterances.ConfirmListType)
.AssertReplyOneOf(this.SettingUpOneNote())
.AssertReplyOneOf(this.AfterSettingUpOneNote())
.AssertReply(this.ShowUpdatedToDoCard(1))
.AssertReplyOneOf(this.CompleteAnotherTask())
.Send(MockData.ConfirmNo)
.AssertReplyOneOf(this.ActionEndMessage())
.AssertReply(this.ShowCompleteMessage(1))
.AssertReply(this.ShowSummary())
.StartTestAsync();
}

Expand All @@ -66,10 +62,8 @@ await this.GetTestFlow()
.Send(this.GetAuthResponse())
.AssertReplyOneOf(this.SettingUpOneNote())
.AssertReplyOneOf(this.AfterSettingUpOneNote())
.AssertReply(this.ShowUpdatedGroceryCard(2))
.AssertReplyOneOf(this.CompleteAnotherTask())
.Send(MockData.ConfirmNo)
.AssertReplyOneOf(this.ActionEndMessage())
.AssertReply(this.ShowGroceryCompleteMessage(2))
.AssertReply(this.ShowGrocerySummary())
.StartTestAsync();
}

Expand All @@ -85,20 +79,16 @@ await this.GetTestFlow()
.Send(MarkToDoFlowTestUtterances.ConfirmListType)
.AssertReplyOneOf(this.SettingUpOneNote())
.AssertReplyOneOf(this.AfterSettingUpOneNote())
.AssertReply(this.ShowUpdatedToDoCard(0))
.AssertReplyOneOf(this.CompleteAnotherTask())
.Send(MockData.ConfirmNo)
.AssertReplyOneOf(this.ActionEndMessage())
.AssertReply(this.ShowCompleteMessage(0))
.AssertReply(this.ShowSummary())
.StartTestAsync();
}

private Action<IActivity> ShowUpdatedToDoCard(int index)
private Action<IActivity> ShowCompleteMessage(int index)
{
return activity =>
{
var messageActivity = activity.AsMessageActivity();
Assert.AreEqual(messageActivity.Attachments.Count, 1);
CollectionAssert.Contains(
this.ParseReplies(MarkToDoResponses.AfterTaskCompleted, new StringDictionary()
{
Expand All @@ -108,13 +98,39 @@ private Action<IActivity> ShowUpdatedToDoCard(int index)
};
}

private Action<IActivity> ShowUpdatedGroceryCard(int index)
private Action<IActivity> ShowSummary()
{
return activity =>
{
var messageActivity = activity.AsMessageActivity();
CollectionAssert.Contains(
this.ParseReplies(MarkToDoResponses.AfterCompleteCardSummaryMessageForMultipleTasks, new StringDictionary()
{
{ MockData.TaskCount, (MockData.MockTaskItems.Count - 1).ToString() },
{ MockData.ListType, MockData.ToDo }
}), messageActivity.Speak);
};
}

private Action<IActivity> ShowGrocerySummary()
{
return activity =>
{
var messageActivity = activity.AsMessageActivity();
Assert.AreEqual(messageActivity.Attachments.Count, 1);
CollectionAssert.Contains(
this.ParseReplies(MarkToDoResponses.AfterCompleteCardSummaryMessageForMultipleTasks, new StringDictionary()
{
{ MockData.TaskCount, (MockData.MockGroceryItems.Count - 1).ToString() },
{ MockData.ListType, MockData.Grocery }
}), messageActivity.Speak);
};
}

private Action<IActivity> ShowGroceryCompleteMessage(int index)
{
return activity =>
{
var messageActivity = activity.AsMessageActivity();
CollectionAssert.Contains(
this.ParseReplies(MarkToDoResponses.AfterTaskCompleted, new StringDictionary()
{
Expand Down
2 changes: 2 additions & 0 deletions skills/csharp/todoskill/Deployment/Resources/LU/en/ToDo.lu
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
> # Intent definitions

## AddToDo
- add {TaskContent=schedule car maintenance} to my {ListType=to do} list
- add {TaskContent=get a perm} to my {ListType=to do} list
- add a few items to the {ListType=grocery} list
- add a {ListType=grocery} item to {TaskContent=buy fish}
- add a {ListType=grocery} item to {TaskContent=buy fruit and vegetables}
Expand Down
45 changes: 26 additions & 19 deletions skills/csharp/todoskill/Dialogs/MarkToDoItemDialog.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -118,30 +119,36 @@ public MarkToDoItemDialog(
state.ShowTaskPageIndex = state.TaskIndexes[0] / state.PageSize;
}

var allTasksCount = state.AllTasks.Count;
var currentTaskIndex = state.ShowTaskPageIndex * state.PageSize;
state.Tasks = state.AllTasks.GetRange(currentTaskIndex, Math.Min(state.PageSize, allTasksCount - currentTaskIndex));
var markToDoCard = ToAdaptiveCardForTaskCompletedFlow(
sc.Context,
state.Tasks,
state.AllTasks.Count,
taskTopicToBeMarked,
state.ListType,
state.MarkOrDeleteAllTasksFlag);

var uncompletedTaskIndex = state.AllTasks.FindIndex(t => t.IsCompleted == false);
if (state.MarkOrDeleteAllTasksFlag || uncompletedTaskIndex < 0)
ResponseTemplate response = null;
if (state.MarkOrDeleteAllTasksFlag)
{
markToDoCard.InputHint = InputHints.AcceptingInput;
await sc.Context.SendActivityAsync(markToDoCard);
return await sc.EndDialogAsync(true);
response = ResponseManager.GetResponseTemplate(MarkToDoResponses.AfterAllTasksCompleted);
var completeSummary = ResponseManager.Format(response.Reply.Speak, new StringDictionary() { { "listType", state.ListType } });
await sc.Context.SendActivityAsync(completeSummary, speak: completeSummary);
}
else
{
markToDoCard.InputHint = InputHints.IgnoringInput;
await sc.Context.SendActivityAsync(markToDoCard);
return await sc.NextAsync();
var completedTaskIndex = state.AllTasks.FindIndex(t => t.IsCompleted == true);
var taskContent = state.AllTasks[completedTaskIndex].Topic;
response = ResponseManager.GetResponseTemplate(MarkToDoResponses.AfterTaskCompleted);
var completeSummary = ResponseManager.Format(response.Reply.Speak, new StringDictionary() { { "taskContent", taskContent }, { "listType", state.ListType } });
await sc.Context.SendActivityAsync(completeSummary, speak: completeSummary);

int uncompletedTaskCount = state.AllTasks.Where(t => t.IsCompleted == false).Count();
if (uncompletedTaskCount == 1)
{
response = ResponseManager.GetResponseTemplate(MarkToDoResponses.AfterCompleteCardSummaryMessageForSingleTask);
}
else
{
response = ResponseManager.GetResponseTemplate(MarkToDoResponses.AfterCompleteCardSummaryMessageForMultipleTasks);
}

var taskSummary = ResponseManager.Format(response.Reply.Speak, new StringDictionary() { { "taskCount", uncompletedTaskCount.ToString() }, { "listType", state.ListType } });
await sc.Context.SendActivityAsync(taskSummary, speak: taskSummary);
}

return await sc.EndDialogAsync(true);
}
catch (SkillException ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public class MarkToDoResponses : IResponseIdCollection
public const string AskTaskIndexRetryForComplete = "AskTaskIndexRetryForComplete";
public const string CompleteAnotherTaskPrompt = "CompleteAnotherTaskPrompt";
public const string CompleteAnotherTaskConfirmFailed = "CompleteAnotherTaskConfirmFailed";
public const string AfterCompleteCardSummaryMessageForMultipleTasks = "AfterCompleteCardSummaryMessageForMultipleTasks";
public const string AfterCompleteCardSummaryMessageForSingleTask = "AfterCompleteCardSummaryMessageForSingleTask";
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
22 changes: 20 additions & 2 deletions skills/csharp/todoskill/Responses/MarkToDo/MarkToDoResponses.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"AfterTaskCompleted": {
"replies": [
{
"text": "I have completed {taskContent} on your {listType} list.",
"speak": "I have completed {taskContent} on your {listType} list."
"text": "OK, I have marked '{taskContent}' on your {listType} list as complete.",
"speak": "OK, I have marked '{taskContent}' on your {listType} list as complete."
}
],
"inputHint": "ignoringInput"
Expand Down Expand Up @@ -61,5 +61,23 @@
}
],
"inputHint": "expectingInput"
},
"AfterCompleteCardSummaryMessageForMultipleTasks": {
"replies": [
{
"text": "You now have {taskCount} items on your {listType} list.",
"speak": "You now have {taskCount} items on your {listType} list."
}
],
"inputHint": "ignoringInput"
},
"AfterCompleteCardSummaryMessageForSingleTask": {
"replies": [
{
"text": "You now have 1 item on your {listType} list.",
"speak": "You now have 1 item on your {listType} list."
}
],
"inputHint": "ignoringInput"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"AfterTaskCompleted": {
"replies": [
{
"text": "已经为你完成{listType}列表上的{taskContent}任务",
"speak": "已经为你完成{listType}列表上的{taskContent}任务"
"speak": "好的,我已经在您的{listType}列表上将“ {taskContent}”标记为完成",
"text": "好的,我已经在您的{listType}列表上将“ {taskContent}”标记为完成"
}
],
"inputHint": "ignoringInput"
Expand Down Expand Up @@ -61,5 +61,23 @@
}
],
"inputHint": "expectingInput"
},
"AfterCompleteCardSummaryMessageForMultipleTasks": {
"replies": [
{
"speak": "现在 {listType} 列表中有 {taskCount} 个项目。",
"text": "现在 {listType} 列表中有 {taskCount} 个项目。"
}
],
"inputHint": "ignoringInput"
},
"AfterCompleteCardSummaryMessageForSingleTask": {
"replies": [
{
"speak": "现在 {listType} 列表中有 1 个项目。",
"text": "现在 {listType} 列表中有 1 个项目。"
}
],
"inputHint": "ignoringInput"
}
}

0 comments on commit 9d7fa04

Please sign in to comment.