Skip to content

Commit

Permalink
Added edit event GUI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daredevil999 committed Oct 24, 2016
1 parent 4e4672a commit e457081
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 4 deletions.
43 changes: 39 additions & 4 deletions src/test/java/guitests/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,31 @@

import org.junit.Test;

import guitests.guihandles.EventCardHandle;
import guitests.guihandles.TaskCardHandle;
import seedu.task.logic.commands.AddTaskCommand;
import seedu.task.logic.commands.EditCommand;
import seedu.task.logic.commands.EditEventCommand;
import seedu.task.logic.commands.EditTaskCommand;
import seedu.task.testutil.TestEvent;
import seedu.task.testutil.TestTask;
import seedu.task.testutil.TestUtil;
import seedu.taskcommons.core.Messages;

public class EditCommandTest extends TaskBookGuiTest{

@Test
public void edit() {
public void editTask() {
//edit one task
TestTask[] currentList = td.getTypicalTasks();
TestTask taskToEdit = td.arts;
currentList = TestUtil.editTasksToList(currentList, 0 , taskToEdit);
assertEditSuccess(taskToEdit, 1, currentList);
assertEditTaskSuccess(taskToEdit, 1, currentList);

//edit another task
taskToEdit = td.socSciences;
currentList = TestUtil.editTasksToList(currentList, 3, taskToEdit);
assertEditSuccess(taskToEdit, 4 ,currentList);
assertEditTaskSuccess(taskToEdit, 4 ,currentList);

//edit to a duplicate task
commandBox.runCommand(td.arts.getEditFloatTaskCommand(3));
Expand All @@ -42,7 +45,27 @@ public void edit() {
assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE));
}

private void assertEditSuccess(TestTask taskToEdit, int index, TestTask... currentList) {
@Test
public void editEvent() {
//edit one event
TestEvent[] currentList = te.getTypicalNotCompletedEvents();
TestEvent taskToEdit = te.addedEvent;
currentList = TestUtil.editEventsToList(currentList, 0 , taskToEdit);
assertEditEventSuccess(taskToEdit, 1, currentList);

//edit another event
taskToEdit = te.addedEvent2;
currentList = TestUtil.editEventsToList(currentList, 1, taskToEdit);
assertEditEventSuccess(taskToEdit, 2 ,currentList);

//edit to a duplicate event
commandBox.runCommand(te.addedEvent.getEditCommand(2));
assertResultMessage(EditEventCommand.MESSAGE_DUPLICATE_EVENT);
assertTrue(eventListPanel.isListMatching(currentList));

}

private void assertEditTaskSuccess(TestTask taskToEdit, int index, TestTask... currentList) {
commandBox.runCommand(taskToEdit.getEditFloatTaskCommand(index));

//confirm the new card contains the right data
Expand All @@ -53,4 +76,16 @@ private void assertEditSuccess(TestTask taskToEdit, int index, TestTask... curre
TestTask[] expectedList = TestUtil.addTasksToListAtIndex(currentList, index -1);
assertTrue(taskListPanel.isListMatching(expectedList));
}

private void assertEditEventSuccess(TestEvent eventToEdit, int index, TestEvent... currentList) {
commandBox.runCommand(eventToEdit.getEditCommand(index));

//confirm the new card contains the right data
EventCardHandle editedCard = eventListPanel.navigateToEvent(eventToEdit.getEvent().fullName);
assertMatching(eventToEdit, editedCard);

//confirm the list now contains all previous events plus the new edited event
TestEvent[] expectedList = TestUtil.addEventsToListAtIndex(currentList, index -1);
assertTrue(eventListPanel.isListMatching(expectedList));
}
}
9 changes: 9 additions & 0 deletions src/test/java/seedu/task/testutil/TestTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ public String getEditFloatTaskCommand(int index) {
sb.append("/desc " + this.getDescriptionValue() + " ");
return sb.toString();
}

public String getFullEditCommand(int index) {
StringBuilder sb = new StringBuilder();
sb.append("edit /t " + index + " ");
sb.append("/name " + this.getTask().fullName + " ");
sb.append("/desc " + this.getDescriptionValue() + " ");
sb.append("/by " + this.getDeadlineValue() + " ");
return sb.toString();
}

@Override
public Optional<Deadline> getDeadline() {
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/seedu/task/testutil/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,18 @@ public static TestTask[] addTasksToListAtIndex(final TestTask[] tasks,int index,
return listOfTasks.toArray(new TestTask[listOfTasks.size()]);
}

/**
* Replaces a task in the array of tasks at certain index.
* @param tasks A array of tasks.
* @param taskToEdit The tasks that are to be edited.
* @return The modified array of tasks.
*/
public static TestTask[] editTasksToListAtIndex(final TestTask[] tasks,int index, TestTask taskToEdit) {
List<TestTask> listOfTasks = asList(tasks);
listOfTasks.set(index, taskToEdit);
return listOfTasks.toArray(new TestTask[listOfTasks.size()]);
}

/**
* Appends events to the array of events.
* @param events A array of events.
Expand Down Expand Up @@ -388,6 +400,19 @@ public static TestTask[] editTasksToList(final TestTask[] tasks, int index, Test
listOfTasks.set(index, taskToEdit);
return listOfTasks.toArray(new TestTask[listOfTasks.size()]);
}

/**
* Edits events according to index in the array of events.
* @param events A array of events.
* @param eventsToEdit The events that are to be edited in the original array.
* @param index Integer of event index to edit
* @return The modified array of events.
*/
public static TestEvent[] editEventsToList(final TestEvent[] events, int index, TestEvent eventToEdit) {
List<TestEvent> listOfEvents = asList(events);
listOfEvents.set(index, eventToEdit);
return listOfEvents.toArray(new TestEvent[listOfEvents.size()]);
}

private static <T> List<T> asList(T[] objs) {
List<T> list = new ArrayList<>();
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/seedu/task/testutil/TypicalTestEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public TypicalTestEvents() {
.withDuration("tomorrow 1pm /to next Friday")
.build();

addedEvent2 = new EventBuilder()
.withName("manual event 2")
.withDescription("for manual testing")
.withDuration("tomorrow 1pm /to next Friday")
.build();

} catch (IllegalValueException e) {
e.printStackTrace();
assert false : "not possible";
Expand Down

0 comments on commit e457081

Please sign in to comment.