package jfdi.test.ui;

import static org.junit.Assert.assertEquals;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import jfdi.ui.Constants;

import org.testfx.util.WaitForAsyncUtils;

public class TestAdd extends UiTest {

    TestAdd(TestMain main) {
        super(main);
    }

    @Override
    void run() {
        testAddTaskDone();
        testAddDuplicateTask();
        testAddEmptyTask();
    }


    /*
     * Test a simple "add testing1" command and check if the task is added to
     * the incomplete list as an item, and check if the feedback displayed
     * matches the expected lines.
     */
    public void testAddTaskDone() {
        String taskName = "testing1";
        int listSize = main.controller.importantList.size();
        StringProperty notiSize = new SimpleStringProperty(Integer.toString(listSize + 1));

        main.addTask(taskName);

        WaitForAsyncUtils.waitForFxEvents();

        main.assertResponseMessage(String.format(Constants.CMD_SUCCESS_ADDED, taskName));
        assertEquals(listSize + 1, main.controller.importantList.size());
        assertEquals(notiSize.getValue(), main.controller.incompletePlaceHdr.getValue());
    }

    /*
     * Test the "add testing1" command again to check if error for duplicated
     * task can be detected and reflected correctly
     */
    public void testAddDuplicateTask() {
        int listSize = main.controller.importantList.size();
        StringProperty notiSize = new SimpleStringProperty(Integer.toString(listSize));

        String taskName = "testing1";
        main.addTask(taskName);

        WaitForAsyncUtils.waitForFxEvents();

        main.assertErrorMessage(Constants.CMD_ERROR_CANT_ADD_DUPLICATE);
        assertEquals(listSize, main.controller.importantList.size());
        assertEquals(notiSize.getValue(), main.controller.incompletePlaceHdr.getValue());
    }

    /*
     * Test an "add " command with empty description and check if the error is
     * correctly detected and reflected.
     */
    public void testAddEmptyTask() {
        int listSize = main.controller.importantList.size();
        StringProperty notiSize = new SimpleStringProperty(Integer.toString(listSize));

        main.addTask("\" \"");

        WaitForAsyncUtils.waitForFxEvents();
        main.assertErrorMessage(Constants.CMD_ERROR_CANT_ADD_EMPTY);
        assertEquals(listSize, main.controller.importantList.size());
        assertEquals(notiSize.getValue(), main.controller.incompletePlaceHdr.getValue());
    }

}

@@ -188,51 +188,8 @@
 s;%0A%0A
-import org.testfx.util.WaitForAsyncUtils;%0A%0A
 publ
@@ -394,24 +394,51 @@
 mptyTask();%0A
+        testAddUpcoming();%0A
     %7D%0A%0A%0A    
@@ -901,54 +901,8 @@
 );%0A%0A
-        WaitForAsyncUtils.waitForFxEvents();%0A%0A
     
@@ -1150,32 +1150,560 @@
 alue());%0A    %7D%0A%0A
+    public void testAddUpcoming() %7B%0A        main.execute(%22list upcoming%22);%0A        int originalListSize = main.getImportantListSize();%0A        int originalNotiSize = Integer.parseInt(main.controller.upcomingPlaceHdr.getValueSafe());%0A%0A        main.addTask(%22something 2 hours later%22);%0A        main.addTask(%22something 1 hour later%22);%0A%0A        assertEquals(originalListSize + 2, main.controller.importantList.size());%0A        assertEquals(originalNotiSize + 2, Integer.parseInt(main.controller.upcomingPlaceHdr.getValue()));%0A    %7D%0A%0A
     /*%0A     * Te
@@ -2097,54 +2097,8 @@
 );%0A%0A
-        WaitForAsyncUtils.waitForFxEvents();%0A%0A
     
@@ -2691,53 +2691,8 @@
 );%0A%0A
-        WaitForAsyncUtils.waitForFxEvents();%0A
     

Add more tests