package seedu.todo.guitests;

import java.time.LocalDateTime;

import org.junit.Before;
import org.junit.Test;

import seedu.todo.commons.util.DateUtil;
import seedu.todo.models.Event;
import seedu.todo.models.Task;

/**
 * @@author A0093907W
 */
public class FindCommandTest extends GuiTest {
    
    private final LocalDateTime oneDayFromNow = LocalDateTime.now().plusDays(1);
    private final String oneDayFromNowString = DateUtil.formatDate(oneDayFromNow);
    private final String oneDayFromNowIsoString = DateUtil.formatIsoDate(oneDayFromNow);
    private final LocalDateTime twoDaysFromNow = LocalDateTime.now().plusDays(2);
    private final String twoDaysFromNowString = DateUtil.formatDate(twoDaysFromNow);
    private final String twoDaysFromNowIsoString = DateUtil.formatIsoDate(twoDaysFromNow);
    private final LocalDateTime oneDayToNow = LocalDateTime.now().minusDays(1);
    private final String oneDayToNowString = DateUtil.formatDate(oneDayToNow);
    private final String oneDayToNowIsoString = DateUtil.formatIsoDate(oneDayToNow);
    
    String commandAdd1 = String.format("add task Buy KOI by \"%s 8pm\"", oneDayToNowString);
    Task task1 = new Task();
    String commandAdd2 = String.format("add task Buy Milk by \"%s 9pm\"", oneDayFromNowString);
    Task task2 = new Task();
    String commandAdd3 = String.format("add event Some Milk from \"%s 4pm\" to \"%s 5pm\"",
            twoDaysFromNowString, twoDaysFromNowString);
    Event event3 = new Event();
    
    public FindCommandTest() {
        task1.setName("Buy KOI");
        task1.setDueDate(DateUtil.parseDateTime(
                String.format("%s 20:00:00", oneDayToNowIsoString)));
        task2.setName("Buy Milk");
        task2.setDueDate(DateUtil.parseDateTime(
                String.format("%s 21:00:00", oneDayFromNowIsoString)));
        event3.setName("Some Milk");
        event3.setStartDate(DateUtil.parseDateTime(
                String.format("%s 16:00:00", twoDaysFromNowIsoString)));
        event3.setEndDate(DateUtil.parseDateTime(
                String.format("%s 17:00:00", twoDaysFromNowIsoString)));
    }
    
    @Before
    public void fixtures() {
        console.runCommand("clear");
        console.runCommand(commandAdd1);
        console.runCommand(commandAdd2);
        console.runCommand(commandAdd3);
    }
    
    @Test
    public void find_unique_success() {
        console.runCommand("find KOI");
        assertTaskVisible(task1);
        assertTaskNotVisible(task2);
    }
    
    @Test
    public void find_uniqueCaseInsensitive_success() {
        console.runCommand("find koi");
        assertTaskVisible(task1);
        assertTaskNotVisible(task2);
    }

}

@@ -23,16 +23,62 @@
 tests;%0A%0A
+import static org.junit.Assert.assertEquals;%0A%0A
 import j
@@ -192,16 +192,62 @@
 teUtil;%0A
+import seedu.todo.controllers.FindController;%0A
 import s
@@ -2779,11 +2779,497 @@
 ;%0A    %7D%0A
+    %0A    @Test%0A    public void find_uniquePartialMatch_success() %7B%0A        console.runCommand(%22find KO%22);%0A        assertTaskVisible(task1);%0A        assertTaskNotVisible(task2);%0A    %7D%0A    %0A    @Test%0A    public void find_uniqueEndingMatch_fail() %7B%0A        console.runCommand(%22find OI%22);%0A        assertEquals(FindController.MESSAGE_LISTING_FAILURE, console.getConsoleTextArea());%0A        assertTaskVisible(task1);%0A        assertTaskVisible(task2);%0A        assertEventVisible(event3);%0A    %7D
 %0A%7D%0A

Test for partial starting matches and ending matches