package guitests;

import org.junit.Test;

import seedu.taskitty.commons.core.Messages;
import seedu.taskitty.testutil.TestTask;

import static org.junit.Assert.assertTrue;

public class FindCommandTest extends TaskManagerGuiTest {

    @Test
    public void find_nonEmptyList() {
        assertFindResult("find task", new TestTask[0], new TestTask[0], new TestTask[0]); //no results
        
        TestTask[] expectedEventHits = { td.shop, td.dinner };
        assertFindResult("find xmas", new TestTask[0], new TestTask[0], expectedEventHits); //multiple results

        //find after deleting one result
        commandBox.runCommand("delete e1");
        TestTask[] expectedEventHitsAfterDelete = { td.dinner };
        assertFindResult("find xmas", new TestTask[0], new TestTask[0], expectedEventHitsAfterDelete);
    }

    @Test
    public void find_emptyList(){
        commandBox.runCommand("clear");
        assertFindResult("find todo", new TestTask[0], new TestTask[0], new TestTask[0]); //no results
    }

    @Test
    public void find_invalidCommand_fail() {
        commandBox.runCommand("findevent");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
    }

    private void assertFindResult(String command, TestTask[] expectedTodoHits,
            TestTask[] expectedDeadlineHits, TestTask[] expectedEventHits) {
        commandBox.runCommand(command);
        assertTodoListSize(expectedTodoHits.length);
        assertDeadlineListSize(expectedDeadlineHits.length);
        assertEventListSize(expectedEventHits.length);
        assertResultMessage(expectedTodoHits.length + expectedDeadlineHits.length + expectedEventHits.length + " tasks listed!");
        
        assertTrue(taskListPanel.isTodoListMatching(expectedTodoHits));
        assertTrue(taskListPanel.isDeadlineListMatching(expectedDeadlineHits));
        assertTrue(taskListPanel.isEventListMatching(expectedEventHits));
    }
}

@@ -226,16 +226,41 @@
 Test %7B%0A%0A
+    //@@author A0139930B%0A
     @Tes
@@ -295,24 +295,50 @@
 ptyList() %7B%0A
+        //find no results%0A
         asse
@@ -418,30 +418,290 @@
 0%5D);
- //no results%0A        
+%0A        %0A        //find by tag%0A        TestTask%5B%5D expectedTagTodoHits = %7B td.read %7D;%0A        TestTask%5B%5D expectedTagEventHits = %7B td.dinner %7D;%0A        assertFindResult(%22find #important%22, expectedTagTodoHits, new TestTask%5B0%5D, expectedTagEventHits);%0A        %0A        //find by keyword
 %0A   
@@ -855,27 +855,8 @@
 ts);
- //multiple results
 %0A%0A  
@@ -1105,32 +1105,47 @@
 Delete);%0A    %7D%0A%0A
+    //@@author%0A
     @Test%0A    pu

Update find command test