package guitests;

import org.junit.Test;

import javafx.scene.input.KeyCode;
import seedu.doist.ui.CommandBox;

public class ModeTest extends DoistGUITest {

    @Test
    public void testEditingModeAfterLaunch() {
        assertInEditingMode();
    }

    @Test
    public void testTurnOnNavigationMode() {
        typeEsc();
        assertInNavigationMode();
    }

    @Test
    public void testTurnOnEditingMode() {
        typeEsc();
        assertInNavigationMode();

        typeEsc();
        assert getMessageBoxContent().equals(CommandBox.EDITING_MODE_MESSAGE);
        assertInEditingMode();
    }

    private void typeEsc() {
        GuiRobot bot = new GuiRobot();
        bot.press(KeyCode.ESCAPE);
        bot.release(KeyCode.ESCAPE);
    }

    private String getInputBoxContent() {
        return commandBox.getCommandInput();
    }

    private String getMessageBoxContent() {
        return resultDisplay.getText();
    }

    private void assertInNavigationMode() {
        assert getMessageBoxContent().equals(CommandBox.NAVIGATION_MODE_MESSAGE);
        commandBox.enterCommand("some random input");
        System.out.println(getInputBoxContent());
        assert getInputBoxContent().length() == 0;
    }

    private void assertInEditingMode() {
        assert !getMessageBoxContent().equals(CommandBox.NAVIGATION_MODE_MESSAGE);
        String input = "some randome input";
        commandBox.enterCommand(input);
        assert getInputBoxContent().equals(input);
    }
}











@@ -12,16 +12,62 @@
 tests;%0A%0A
+import static org.junit.Assert.assertEquals;%0A%0A
 import o
@@ -117,16 +117,60 @@
 eyCode;%0A
+import seedu.doist.model.task.ReadOnlyTask;%0A
 import s
@@ -196,16 +196,37 @@
 ndBox;%0A%0A
+//@@author A0147980U%0A
 public c
@@ -509,16 +509,40 @@
 stTurnOn
+NavigationModeThenTurnOn
 EditingM
@@ -747,242 +747,635 @@
     
-private void typeEsc() %7B%0A        GuiRobot bot = new GuiRobot(
+@Test%0A    public void testStartingFromIndexZero() %7B%0A        typeEsc();  // turn on navigation mode%0A        typeJ();%0A        assertTaskSelected(1
 );%0A    
+%7D%0A%0A
     
-bot.press(KeyCode.ESCAPE);%0A        bot.release(KeyCode.ESCAPE);%0A
+@Test%0A    public void testPressJToScrollDown() %7B%0A        typeEsc();%0A        int count = taskListPanel.getNumberOfTasks();%0A        for (int i = 0; i %3C count; i++) %7B%0A            typeJ();%0A            assertTaskSelected(i + 1);%0A   
     
+ 
 %7D%0A%0A    
-private String getInputBoxContent() %7B%0A        return commandBox.getCommandInput
+    // scroll to the bottom%0A        typeJ();%0A        assertTaskSelected(count);%0A    %7D%0A%0A    @Test%0A    public void testPressKToScrollUp() %7B%0A        testPressJToScrollDown();%0A        int count = taskListPanel.getNumberOfTasks
 ();%0A    
 %7D%0A%0A 
@@ -1374,101 +1374,234 @@
     
-%7D%0A%0A
     
-private String getMessageBoxContent() %7B%0A        return resultDisplay.getText();%0A    %7D%0A
+for (int i = count - 1; i %3E= 1; i--) %7B%0A            typeK();%0A            assertTaskSelected(i);%0A        %7D%0A%0A        // scroll to the top%0A        typeK();%0A        assertTaskSelected(1);%0A    %7D%0A%0A    // helper method for testing
 %0A   
@@ -2150,16 +2150,887 @@
 );%0A    %7D
+%0A%0A    private String getInputBoxContent() %7B%0A        return commandBox.getCommandInput();%0A    %7D%0A%0A    private String getMessageBoxContent() %7B%0A        return resultDisplay.getText();%0A    %7D%0A%0A    private void typeEsc() %7B%0A        GuiRobot bot = new GuiRobot();%0A        bot.press(KeyCode.ESCAPE);%0A        bot.release(KeyCode.ESCAPE);%0A    %7D%0A%0A    private void typeJ() %7B%0A        GuiRobot bot = new GuiRobot();%0A        bot.press(KeyCode.J);%0A        bot.release(KeyCode.J);%0A    %7D%0A%0A    private void typeK() %7B%0A        GuiRobot bot = new GuiRobot();%0A        bot.press(KeyCode.K);%0A        bot.release(KeyCode.K);%0A    %7D%0A%0A    private void assertTaskSelected(int index) %7B%0A        assertEquals(taskListPanel.getSelectedTasks().size(), 1);%0A        ReadOnlyTask selectedTask = taskListPanel.getSelectedTasks().get(0);%0A        assertEquals(taskListPanel.getTask(index - 1), selectedTask);%0A    %7D
 %0A%7D%0A%0A%0A%0A%0A%0A

add test cases for use J and K to navigate task list up and down