package guitests;

import org.junit.Test;

import seedu.taskmanager.model.item.ReadOnlyItem;

import static org.junit.Assert.assertEquals;
import static seedu.taskmanager.commons.core.Messages.MESSAGE_INVALID_ITEM_DISPLAYED_INDEX;


public class SelectCommandTest extends TaskManagerGuiTest {


    @Test
    public void selectPerson_nonEmptyList() {

        assertSelectionInvalid(11); //invalid index
        assertNoPersonSelected();

        assertSelectionSuccess(1); //first person in the list
        int personCount = td.getTypicalItems().length;
        assertSelectionSuccess(personCount); //last person in the list
        int middleIndex = personCount / 2;
        assertSelectionSuccess(middleIndex); //a person in the middle of the list

        assertSelectionInvalid(personCount + 1); //invalid index
        assertPersonSelected(middleIndex); //assert previous selection remains

        /* Testing other invalid indexes such as -1 should be done when testing the SelectCommand */
    }

    @Test
    public void selectPerson_emptyList(){
        commandBox.runCommand("clear");
        assertListSize(0);
        assertSelectionInvalid(1); //invalid index
    }

    private void assertSelectionInvalid(int index) {
        commandBox.runCommand("select " + index);
        assertResultMessage(MESSAGE_INVALID_ITEM_DISPLAYED_INDEX);
    }

    private void assertSelectionSuccess(int index) {
        commandBox.runCommand("select " + index);
        assertResultMessage("Selected " + index);
        assertPersonSelected(index);
    }

    private void assertPersonSelected(int index) {
        assertEquals(itemListPanel.getSelectedPersons().size(), 1);
        ReadOnlyItem selectedPerson = itemListPanel.getSelectedPersons().get(0);
        assertEquals(itemListPanel.getPerson(index-1), selectedPerson);
        //TODO: confirm the correct page is loaded in the Browser Panel
    }

    private void assertNoPersonSelected() {
        assertEquals(itemListPanel.getSelectedPersons().size(), 0);
    }

}

@@ -36,16 +36,125 @@
 .Test;%0A%0A
+import seedu.taskmanager.logic.commands.ClearCommand;%0Aimport seedu.taskmanager.logic.commands.SelectCommand;%0A
 import s
@@ -576,239 +576,640 @@
 ess(
-1); //first person in the list%0A        int personCount = td.getTypicalItems().length;%0A        assertSelectionSuccess(personCount); //last person in the list%0A        int middleIndex = personCount / 2;%0A        assertSelectionSuccess(
+SelectCommand.COMMAND_WORD, 1); //first person in the list%0A        assertSelectionSuccess(SelectCommand.SHORT_COMMAND_WORD, 1); //first person in the list%0A        int personCount = td.getTypicalItems().length;%0A        assertSelectionSuccess(SelectCommand.COMMAND_WORD, personCount); //last person in the list%0A        assertSelectionSuccess(SelectCommand.SHORT_COMMAND_WORD, personCount); //last person in the list%0A        int middleIndex = personCount / 2;%0A        assertSelectionSuccess(SelectCommand.COMMAND_WORD, middleIndex); //a person in the middle of the list%0A        assertSelectionSuccess(SelectCommand.SHORT_COMMAND_WORD, 
 midd
@@ -1595,15 +1595,33 @@
 and(
-%22c
+C
 lear
-%22
+Command.COMMAND_WORD
 );%0A 
@@ -1779,39 +1779,62 @@
 dBox.runCommand(
-%22s
+S
 elect
+Command.COMMAND_WORD + %22
  %22 + index);%0A   
@@ -1944,16 +1944,36 @@
 Success(
+String commandWord, 
 int inde
@@ -2011,15 +2011,23 @@
 and(
-%22select
+commandWord + %22
  %22 +

Update SelectCommandTest to cover SHORT_COMMAND_WORD