Skip to content

Commit

Permalink
Add tests for jumping to tag
Browse files Browse the repository at this point in the history
  • Loading branch information
varung97 committed Oct 28, 2016
1 parent 87cc10e commit 19f3862
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/manager/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public CommandResult execute() {
try {
model.addTask(toAdd);
if (toAdd.getTag().isPresent()) {
model.addTag((Tag)toAdd.getTag().get());
model.addTag((Tag) toAdd.getTag().get());
}
int addedIndex = model.getIndexOfTask(toAdd);
assert addedIndex != -1;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/manager/model/task/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
*/
public class Tag extends TaskProperty {

public static final String MESSAGE_TAG_CONSTRAINTS = "Tags names should be alphanumeric";
public static final String TAG_VALIDATION_REGEX = "\\p{Alnum}+";
public static final String MESSAGE_TAG_CONSTRAINTS = "Tags names can have anything";
public static final String TAG_VALIDATION_REGEX = ".+";

public String tagName;

Expand Down
46 changes: 28 additions & 18 deletions src/test/java/seedu/manager/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import seedu.manager.commons.core.EventsCenter;
import seedu.manager.commons.core.Messages;
import seedu.manager.commons.events.model.TaskManagerChangedEvent;
import seedu.manager.commons.events.ui.JumpToTagListRequestEvent;
import seedu.manager.commons.events.ui.JumpToTaskListRequestEvent;
import seedu.manager.commons.events.ui.ShowHelpRequestEvent;
import seedu.manager.logic.Logic;
Expand Down Expand Up @@ -51,7 +52,8 @@ public class LogicManagerTest {
//These are for checking the correctness of the events raised
private ReadOnlyTaskManager latestSavedTaskManager;
private boolean helpShown;
private int targetedJumpIndex;
private int targetedTaskJumpIndex;
private int targetedTagJumpIndex;

@Subscribe
private void handleLocalModelChangedEvent(TaskManagerChangedEvent abce) {
Expand All @@ -65,7 +67,12 @@ private void handleShowHelpRequestEvent(ShowHelpRequestEvent she) {

@Subscribe
private void handleJumpToTaskListRequestEvent(JumpToTaskListRequestEvent je) {
targetedJumpIndex = je.targetIndex;
targetedTaskJumpIndex = je.targetIndex;
}

@Subscribe
private void handleJumpToTagListRequestEvent(JumpToTagListRequestEvent je) {
targetedTagJumpIndex = je.targetIndex;
}

@Before
Expand Down Expand Up @@ -207,7 +214,7 @@ public void execute_add_desc_contains_keyword_successful() throws Exception {
String.format(AddCommand.MESSAGE_SUCCESS, toBeAdded),
expectedTM,
expectedTM.getTaskList());
assertEquals(0, targetedJumpIndex);
assertEquals(0, targetedTaskJumpIndex);
}

// @@author
Expand All @@ -224,7 +231,7 @@ public void execute_add_successful() throws Exception {
String.format(AddCommand.MESSAGE_SUCCESS, toBeAdded.getAsPrettyText()),
expectedTM,
expectedTM.getTaskList());
assertEquals(0, targetedJumpIndex);
assertEquals(0, targetedTaskJumpIndex);


toBeAdded = helper.guinevere();
Expand All @@ -234,7 +241,7 @@ public void execute_add_successful() throws Exception {
String.format(AddCommand.MESSAGE_SUCCESS, toBeAdded.getAsPrettyText()),
expectedTM,
expectedTM.getTaskList());
assertEquals(1, targetedJumpIndex);
assertEquals(1, targetedTaskJumpIndex);
}

@Test
Expand Down Expand Up @@ -284,7 +291,7 @@ public void execute_addAfterSorting_successful() throws Exception {
expectedTM,
expectedList);

assertEquals(expectedList.indexOf(toBeAdded), targetedJumpIndex);
assertEquals(expectedList.indexOf(toBeAdded), targetedTaskJumpIndex);
}

// @@author
Expand Down Expand Up @@ -334,7 +341,7 @@ public void execute_edit_successful() throws Exception {
expectedTM.getTaskList()
);

assertEquals(1, targetedJumpIndex);
assertEquals(1, targetedTaskJumpIndex);


HashMap<TaskProperties, Optional<String>> newProps1 =
Expand All @@ -356,7 +363,7 @@ public void execute_edit_successful() throws Exception {
expectedTM.getTaskList()
);

assertEquals(1, targetedJumpIndex);
assertEquals(1, targetedTaskJumpIndex);

assertCommandBehavior(
editCommand1,
Expand Down Expand Up @@ -386,7 +393,7 @@ public void execute_edit_successful() throws Exception {
expectedTM.getTaskList()
);

assertEquals(1, targetedJumpIndex);
assertEquals(1, targetedTaskJumpIndex);
}

@Test
Expand Down Expand Up @@ -422,7 +429,7 @@ public void execute_editAfterSorting_successful() throws Exception {
expectedList
);

assertEquals(expectedList.indexOf(newTask), targetedJumpIndex);
assertEquals(expectedList.indexOf(newTask), targetedTaskJumpIndex);
}


Expand Down Expand Up @@ -687,22 +694,25 @@ public void execute_find_invalidExtension() throws Exception {
@Test
public void execute_findTag_successful() throws Exception {
TestDataHelper helper = new TestDataHelper();
Task p1 = helper.generateTaskWithTag("Violent");
Task p1 = helper.generateTaskWithTagAndDesc("Kill Mordred", "Violent");
Task p2 = helper.guinevere();
Task p3 = helper.lancelot();
Task p4 = helper.morgana();
Task p5 = helper.generateTaskWithTagAndDesc("Elope with Guinevere", "Home-wrecking");

List<Task> fourTasks = helper.generateTaskList(p3, p1, p4, p2);
TaskManager expectedTM = helper.generateTaskManager(fourTasks);
helper.addToModel(model, fourTasks);

List<Task> fiveTasks = helper.generateTaskList(p5, p3, p1, p4, p2);
TaskManager expectedTM = helper.generateTaskManager(fiveTasks);
helper.addToModel(model, fiveTasks);
model.addTag(new Tag("Home-wrecking"));
model.addTag(new Tag("Violent"));

List<Task> expectedList = helper.generateTaskList(p1);

assertCommandBehavior("find tag Violent",
Command.getMessageForTaskListShownSummary(expectedList.size()),
expectedTM,
expectedList);
assertEquals(1, targetedTagJumpIndex);
}

@Test
Expand Down Expand Up @@ -864,7 +874,7 @@ public void execute_alias_successful() throws Exception {
String.format(AddCommand.MESSAGE_SUCCESS, toBeAdded.getAsPrettyText()),
expectedTM,
expectedTM.getTaskList());
assertEquals(0, targetedJumpIndex);
assertEquals(0, targetedTaskJumpIndex);

assertCommandBehavior("alias delete -",
String.format(AliasCommand.MESSAGE_SUCCESS, "delete", "-"),
Expand Down Expand Up @@ -1122,9 +1132,9 @@ Task generateTaskWithDescAndVenue(String desc, String venue) throws Exception {
/**
* Generates a Task object with given tag. Other fields will have some dummy values.
*/
Task generateTaskWithTag(String tag) throws Exception {
Task generateTaskWithTagAndDesc(String desc, String tag) throws Exception {
return new Task(
"Kill Mordred",
desc,
"Camelot",
"med",
"4.30am",
Expand Down

0 comments on commit 19f3862

Please sign in to comment.