package guitests;

import org.junit.Test;

import seedu.malitio.testutil.TestDeadline;
import seedu.malitio.testutil.TestEvent;
import seedu.malitio.testutil.TestFloatingTask;
import seedu.malitio.commons.core.Messages;
import seedu.malitio.commons.exceptions.IllegalValueException;
import seedu.malitio.logic.commands.FindCommand;

import static org.junit.Assert.assertTrue;
import static seedu.malitio.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

//@@author a0126633j
public class FindCommandTest extends MalitioGuiTest {

    @Test
    public void find_nonEmptyList() throws IllegalArgumentException, IllegalValueException {

        assertFindEventResult("find with", td.event1, td.event2); //multiple results
        assertFindEventResult("find hello"); //no result
        
        //find after deleting one result
        commandBox.runCommand("list");
        commandBox.runCommand("delete f1");
        assertFindFloatingTaskResult("find bring",td.floatingTask2);
    }

    @Test
    public void find_emptyList() throws IllegalArgumentException, IllegalValueException {
        commandBox.runCommand("clear");
        assertFindFloatingTaskResult("find eat"); //no results
        assertFindDeadlineResult("find eat");
        assertFindEventResult("find eat");
    }

    @Test
    public void find_invalidCommand_fail() {
        commandBox.runCommand("finddonothing");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
    }
 
    @Test
    public void find_specificTasks() throws IllegalArgumentException, IllegalValueException {  
     assertFindDeadlineResult("find d SOME", td.deadline2);
     assertFindFloatingTaskResult("find f tell", td.floatingTask3);
     
     commandBox.runCommand("find e");
     assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
             FindCommand.MESSAGE_USAGE)); // recognise as finding in event but no keywords
    }
    
    private void assertFindFloatingTaskResult(String command, TestFloatingTask... expectedHits ) {
        commandBox.runCommand(command);
        assertFloatingTaskListSize(expectedHits.length);
        assertResultMessage(expectedHits.length + " tasks found!");
        
        assertTrue(floatingTaskListPanel.isListMatching(expectedHits));
    }
    private void assertFindDeadlineResult(String command, TestDeadline... expectedHits ) {
        commandBox.runCommand(command);
        assertDeadlineListSize(expectedHits.length);
        assertResultMessage(expectedHits.length + " tasks found!");
        
        assertTrue(deadlineListPanel.isListMatching(expectedHits));
    }
    private void assertFindEventResult(String command, TestEvent... expectedHits ) throws IllegalArgumentException, IllegalValueException {
        commandBox.runCommand(command);
        assertEventListSize(expectedHits.length);
        assertResultMessage(expectedHits.length + " tasks found!");
        
        assertTrue(eventListPanel.isListMatching(expectedHits));
    }
}

@@ -524,24 +524,164 @@
 oGuiTest %7B%0A%0A
+    //In the tests below, we assume event,floating task and deadline lists are identical, hence to save resources only work on them equally%0A
     @Test%0A  
@@ -808,16 +808,18 @@
 t(%22find 
+e 
 with%22, t
@@ -877,35 +877,496 @@
 sert
-FindEventResult(%22find hello
+ResultMessage(%222 tasks found!%22);%0A        %0A        assertFindFloatingTaskResult(%22find peN HOMEWORK%22, td.floatingTask2);%0A        assertFindDeadlineResult(%22find peN HOMEWORK%22, td.deadline3, td.deadline5);%0A        assertResultMessage(%223 tasks found!%22);%0A        %0A        assertFindDeadlineResult(%22find 12-25%22, td.deadline4); //find dates%0A        assertFindEventResult(%22find 12-25%22, td.event5);%0A        assertResultMessage(%222 tasks found!%22);%0A        %0A        assertFindEventResult(%22find wedding
 %22); 
@@ -1730,117 +1730,8 @@
 %22);%0A
-        assertFindFloatingTaskResult(%22find eat%22); //no results%0A        assertFindDeadlineResult(%22find eat%22);%0A
     
@@ -1764,24 +1764,36 @@
 %22find eat%22);
+ //no result
 %0A    %7D%0A%0A    
@@ -2068,16 +2068,162 @@
 ion %7B  %0A
+        assertFindEventResult(%22find e with%22, td.event1, td.event2); //multiple results%0A        assertResultMessage(%222 tasks found!%22);%0A        %0A   
      ass
@@ -2256,12 +2256,9 @@
 d d 
-SOME
+H
 %22, t
@@ -2267,20 +2267,107 @@
 deadline
-2);%0A
+1, td.deadline4, td.deadline5);%0A        assertResultMessage(%223 tasks found!%22);%0A        %0A   
      ass
@@ -2427,24 +2427,74 @@
 ask3);%0A     
+   assertResultMessage(%221 tasks found!%22);%0A        
 %0A     comman
@@ -2689,24 +2689,141 @@
 %0A    %7D%0A    %0A
+    /**%0A     * Overload functions to assert result in each floating task, deadline and event list is correct%0A     */%0A
     private 
@@ -3010,76 +3010,8 @@
 h);%0A
-        assertResultMessage(expectedHits.length + %22 tasks found!%22);%0A
     
@@ -3281,76 +3281,8 @@
 h);%0A
-        assertResultMessage(expectedHits.length + %22 tasks found!%22);%0A
     
@@ -3594,76 +3594,8 @@
 h);%0A
-        assertResultMessage(expectedHits.length + %22 tasks found!%22);%0A
     

Update find test cases