package guitests;

import org.junit.Test;

import guitests.guihandles.TaskCardHandle;
import seedu.tasklist.commons.core.Messages;
import seedu.tasklist.logic.commands.UnmarkCommand;
import seedu.tasklist.testutil.TestTask;

//@@author A0146840E
public class UnmarkCommandTest extends TaskListGuiTest {

    @Test
    public void unmark() {
        TestTask[] currentList = td.getTypicalTasks();
        commandBox.runCommand("list");
        
        //mark tasks
        commandBox.runCommand("mark " + 1);
        commandBox.runCommand("mark " + 1);
        
        //unmark first task
        assertUnmarkSuccess(currentList.length, currentList[0], currentList);
        
        //unmark next task
        assertUnmarkSuccess(currentList.length, currentList[1], currentList);
        
        //unmark task that don't exist
        commandBox.runCommand("unmark -10");
        assertResultMessage(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, UnmarkCommand.MESSAGE_USAGE));
        commandBox.runCommand("unmark -1");
        assertResultMessage(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, UnmarkCommand.MESSAGE_USAGE));
        commandBox.runCommand("unmark " + (currentList.length + 1));
        assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        commandBox.runCommand("unmark " + (currentList.length + 10));
        assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        
        //unmark duplicate task
        commandBox.runCommand("unmark 1");
        assertResultMessage(UnmarkCommand.MESSAGE_UNMARKED_TASK);
        commandBox.runCommand("unmark " + currentList.length);
        assertResultMessage(UnmarkCommand.MESSAGE_UNMARKED_TASK);
        
        //invalid command
        commandBox.runCommand("unmarks 1");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
        commandBox.runCommand("unmark index");
        assertResultMessage(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, UnmarkCommand.MESSAGE_USAGE));
    }

    private void assertUnmarkSuccess(int index, TestTask taskToUnmark, TestTask... currentList) {
        commandBox.runCommand("unmark " + index);
        taskToUnmark.setCompleted(false);
        
        //confirm the new card contains the right data
        TaskCardHandle markedCard = taskListPanel.navigateToTask(taskToUnmark.getTitle().fullTitle);
        assertUnmarked(taskToUnmark, markedCard);
        assertResultMessage("Task unmarked: " + taskToUnmark.getAsText());
    }
}

@@ -329,16 +329,54 @@
 d unmark
+Task_nonEmptyList_successResultMessage
 () %7B%0A   
@@ -470,38 +470,8 @@
 %22);%0A
-        %0A        //mark tasks%0A
     
@@ -567,36 +567,8 @@
    %0A
-        //unmark first task%0A
     
@@ -645,44 +645,8 @@
 t);%0A
-        %0A        //unmark next task%0A
     
@@ -727,208 +727,147 @@
     
+%7D%0A%0A
     
-%0A        //
+@Test%0A    public void 
 unmark
- task that don't exist%0A        commandBox.runCommand(%22unmark -10%22);%0A        assertResultMessage(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, UnmarkCommand.MESSAGE_USAGE)
+Task_nonEmptyList_invalidTaskIndexResultMessage() %7B%0A        TestTask%5B%5D currentList = td.getTypicalTasks(
 );%0A 
@@ -900,17 +900,12 @@
 nd(%22
-unmark -1
+list
 %22);%0A
@@ -916,113 +916,8 @@
     
-assertResultMessage(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, UnmarkCommand.MESSAGE_USAGE));
 %0A   
@@ -1204,24 +1204,26 @@
 INDEX);%0A    
+%7D%0A
     %0A       
@@ -1223,35 +1223,186 @@
     
-    //unmark duplicate task
+@Test%0A    public void unmarkTask_nonEmptyList_unmarkedTaskResultMessage() %7B%0A        TestTask%5B%5D currentList = td.getTypicalTasks();%0A        commandBox.runCommand(%22list%22);%0A        
 %0A   
@@ -1636,24 +1636,26 @@
 _TASK);%0A    
+%7D%0A
     %0A       
@@ -1655,29 +1655,402 @@
     
-    //invalid command
+@Test%0A    public void unmarkTask_nonEmptyList_invalidCommandResultMessage() %7B%0A        commandBox.runCommand(%22unmark -10%22);%0A        assertResultMessage(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, UnmarkCommand.MESSAGE_USAGE));%0A        commandBox.runCommand(%22unmark -1%22);%0A        assertResultMessage(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, UnmarkCommand.MESSAGE_USAGE));
 %0A   
@@ -2316,24 +2316,239 @@
 GE));%0A    %7D%0A
+    %0A    @Test%0A    public void unmarkTask_emptyList_invalidTaskIndexResultMessage() %7B%0A        commandBox.runCommand(%22unmark 1%22);%0A        assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);%0A    %7D%0A    
 %0A    private

refactor UnmarkCommandTest