package guitests;


import static seedu.doit.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import java.util.Arrays;

import org.junit.Test;

import seedu.doit.logic.commands.DoneCommand;
import seedu.doit.model.item.TaskNameComparator;
import seedu.doit.testutil.TaskBuilder;
import seedu.doit.testutil.TestTask;

public class DoneCommandTest extends TaskManagerGuiTest {

    // The list of tasks in the task list panel is expected to match this list.
    // This list is updated with every successful call to assertEditSuccess().
    private TestTask[] expectedTasksList = this.td.getTypicalTasks();

    @Test
    public void mark_task_success() throws Exception {
        int taskManagerIndex = 2;

        TestTask taskToMark = this.expectedTasksList[taskManagerIndex - 1];
        TestTask markedTask = new TaskBuilder(taskToMark).withIsDone(true).build();

        assertDoneSuccess(taskManagerIndex, taskManagerIndex, markedTask);
    }

    @Test
    public void mark_task_failure() throws Exception {
        int taskManagerIndex = -2;
        this.commandBox.runCommand("done " + taskManagerIndex);

        assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, DoneCommand.MESSAGE_USAGE));
    }

    @Test
    public void edit_findThenEdit_success() throws Exception {
        this.commandBox.runCommand("find Elle");

        int filteredTaskListIndex = 1;

        int taskManagerIndex = 5;

        TestTask taskToMark = this.expectedTasksList[taskManagerIndex - 1];
        TestTask markedTask = new TaskBuilder(taskToMark).withIsDone(true).build();

        assertDoneSuccess(filteredTaskListIndex, taskManagerIndex, markedTask);
    }



    private void assertDoneSuccess(int filteredTaskListIndex, int taskManagerIndex,
                                   TestTask markedTask) {

        this.commandBox.runCommand("done " + filteredTaskListIndex);


        // confirm the list now contains all previous tasks plus the task with
        // updated isDone variable
        this.expectedTasksList[taskManagerIndex - 1] = markedTask;
        Arrays.sort(this.expectedTasksList, new TaskNameComparator());

        assertAllPanelsMatch(this.expectedTasksList);
        assertResultMessage(String.format(DoneCommand.MESSAGE_DONE_TASK_SUCCESS, markedTask));

    }

}

@@ -12,17 +12,16 @@
 tests;%0A%0A
-%0A
 import s
@@ -142,16 +142,57 @@
 .Test;%0A%0A
+import seedu.doit.commons.core.Messages;%0A
 import s
@@ -356,16 +356,37 @@
 tTask;%0A%0A
+//@@author A0139399J%0A
 public c
@@ -1446,17 +1446,16 @@
 ex = 1;%0A
-%0A
         
@@ -1480,17 +1480,16 @@
 ex = 5;%0A
-%0A
         
@@ -1721,23 +1721,340 @@
 dTask);%0A
-
     %7D%0A%0A
+    @Test%0A    public void edit_findThenEdit_failure() throws Exception %7B%0A        this.commandBox.runCommand(%22find Elle%22);%0A        int filteredTaskListIndex = 5;%0A        this.commandBox.runCommand(%22done %22 + filteredTaskListIndex);%0A%0A        assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);%0A%0A    %7D%0A%0A%0A%0A
 %0A%0A    pr

Update DoneTest