package guitests;

import org.junit.Test;
import seedu.address.commons.core.Messages;
import seedu.address.logic.commands.ListCommand;
import seedu.address.testutil.TestTask;

import static org.junit.Assert.assertTrue;

//@@author A0142325R
public class ListCommandTest extends TaskManagerGuiTest {

    @Test
    public void list_all_Tasks_Events() {
    	TestTask[] currentList = td.getTypicalTasks();
        //list all tasks
        assertListResult("list tasks",td.friend,td.friendEvent,td.lunch,
        		td.book,td.work,td.movie);
        assertResultMessage(String.format(ListCommand.MESSAGE_TASK_SUCCESS));
        
        //list all events
        assertListResult("list events", td.meeting,td.travel);
        assertResultMessage(String.format(ListCommand.MESSAGE_EVENT_SUCCESS));

        //list all items
        assertListResult("list",currentList);
        assertResultMessage(String.format(ListCommand.MESSAGE_SUCCESS));
        
        //list all done items
        commandBox.runCommand("done 1");
        td.friend.markAsDone();
        assertListResult("list done", td.friend);
        assertResultMessage(String.format(ListCommand.MESSAGE_LIST_DONE_TASK_SUCCESS));
        
        // list all undone items
        assertListResult("list undone", td.friendEvent, td.lunch, td.book, td.work, td.movie, td.meeting, td.travel);
        assertResultMessage(String.format(ListCommand.MESSAGE_LIST_UNDONE_TASK_SUCCESS));
        
        //list empty lists
        commandBox.runCommand("clear");
        assertListResult("list");
        
        //invalid command
        commandBox.runCommand("lists");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
        commandBox.runCommand("list unknown");
        assertResultMessage(ListCommand.MESSAGE_INVALID_LIST_COMMAND);
        
    }

    private void assertListResult(String command, TestTask... expectedHits ) {
        commandBox.runCommand(command);
        assertListSize(expectedHits.length);
        assertTrue(taskListPanel.isListMatching(expectedHits));
    }

}

@@ -217,28 +217,264 @@
 e;%0A%0A
-//@@author A0142325R
+import org.junit.Before;%0A%0A//@@author A0142325R%0A/**%0A * Test GUI for list command%0A * @author LiXiaowei%0A * Command format: list, list tasks/events/done/undone%0A * %0A * Equivalence partitions: emply parameter, tasks, events, done, undone, otherInvalidData%0A *%0A */
 %0Apub
@@ -532,76 +532,98 @@
 t %7B%0A
-%0A
     
-@Test%0A    public void list_all_Tasks_Even
+private TestTask%5B%5D currentList;%0A    %0A    @Before%0A    public void setUpLis
 ts()
- 
 %7B%0A    
-%09TestTask%5B%5D
+   
  cur
@@ -634,11 +634,9 @@
 List
- = 
+=
 td.g
@@ -661,28 +661,187 @@
     
-    //list all tasks
+%7D%0A    %0A    //----------------------------valid cases-----------------------------------------------%0A    %0A    //list all tasks%0A%0A    @Test%0A    public void listAllTasks_successful()%7B
 %0A   
@@ -922,10 +922,16 @@
     
-%09%09
+        
 td.b
@@ -1036,32 +1036,39 @@
 );%0A        %0A    
+%7D%0A    %0A
     //list all e
@@ -1073,16 +1073,75 @@
  events%0A
+    %0A    @Test%0A    public void listAllEvents_successful()%7B%0A
         
@@ -1278,33 +1278,126 @@
 ));%0A
-%0A        //list all items
+        %0A    %7D%0A    %0A    //list all tasks and events%0A    %0A    @Test%0A    public void listAllTasksAndEvents_successful()%7B
 %0A   
@@ -1525,24 +1525,40 @@
    %0A        
+%0A    %7D%0A    %0A    
 //list all d
@@ -1559,32 +1559,103 @@
  all done items%0A
+    %0A    @Test%0A    public void listAllDoneTasksAndEvents_successful()%7B%0A
         commandB
@@ -1866,15 +1866,21 @@
     
+%7D%0A    %0A
     //
- 
 list
@@ -1893,24 +1893,106 @@
 ndone items%0A
+    %0A    @Test%0A    public void listAllUndoneTasksAndEvents_successful()%7B%0A        %0A
         asse
@@ -2187,33 +2187,31 @@
 CESS));%0A    
-    
+%7D
 %0A    
+%0A
     //list e
@@ -2219,17 +2219,76 @@
 pty list
-s
+%0A    %0A    @Test%0A    public void listEmptyLists_successful()%7B
 %0A       
@@ -2375,25 +2375,197 @@
     
-//invalid command
+%0A    %7D%0A    %0A    //----------------------------invalid cases-------------------------------------------%0A    %0A    //invalid command%0A    %0A    @Test%0A    public void listInvalidDataField_fail()%7B
 %0A   
@@ -2791,22 +2791,34 @@
        %0A
+        %0A
     %7D%0A
+   
 %0A    pri

refactor listCommandTest in guitest