package guitests;

import guitests.guihandles.PersonListPanelHandle;
import org.junit.Test;
import seedu.address.exceptions.IllegalValueException;
import seedu.address.model.person.ReadOnlyPerson;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class PersonDeleteCommandTest extends GuiTestBase {

    @Test
    public void testDeletePerson_firstPerson_successful() throws IllegalValueException {
        int numberOfPeopleBefore = personListPanel.getNumberOfPeople();
        ReadOnlyPerson secondPersonBefore = personListPanel.getPerson(1);
        ReadOnlyPerson targetPerson = personListPanel.getPerson(0);

        personListPanel.enterCommandAndApply("delete 1");

        int numberOfPeopleAfter = personListPanel.getNumberOfPeople();
        ReadOnlyPerson firstPersonAfter = personListPanel.getPerson(0);
        assertEquals(PersonListPanelHandle.NOT_FOUND, personListPanel.getPersonIndex(targetPerson));
        assertEquals(numberOfPeopleBefore - 1, numberOfPeopleAfter);
        assertTrue(secondPersonBefore.isSameStateAs(firstPersonAfter));
    }

    @Test
    public void testDeletePerson_lastPerson_successful() throws IllegalValueException {
        int numberOfPeopleBefore = personListPanel.getNumberOfPeople();
        ReadOnlyPerson secondLastPersonBefore = personListPanel.getPerson(numberOfPeopleBefore - 2);
        ReadOnlyPerson targetPerson = personListPanel.getPerson(numberOfPeopleBefore - 1);

        personListPanel.enterCommandAndApply("delete " + numberOfPeopleBefore);

        int numberOfPeopleAfter = personListPanel.getNumberOfPeople();
        ReadOnlyPerson lastPersonAfter = personListPanel.getPerson(numberOfPeopleAfter - 1);
        assertEquals(PersonListPanelHandle.NOT_FOUND, personListPanel.getPersonIndex(targetPerson));
        assertEquals(numberOfPeopleBefore - 1, numberOfPeopleAfter);
        assertTrue(secondLastPersonBefore.isSameStateAs(lastPersonAfter));
    }

    @Test
    public void testDeletePerson_middlePerson_successful() throws IllegalValueException {
        int numberOfPeopleBefore = personListPanel.getNumberOfPeople();
        ReadOnlyPerson secondPersonBefore = personListPanel.getPerson(1);
        ReadOnlyPerson fourthPersonBefore = personListPanel.getPerson(3);
        ReadOnlyPerson targetPerson = personListPanel.getPerson(2);

        personListPanel.enterCommandAndApply("delete 3");

        int numberOfPeopleAfter = personListPanel.getNumberOfPeople();
        ReadOnlyPerson secondPersonAfter = personListPanel.getPerson(1);
        ReadOnlyPerson thirdPersonAfter = personListPanel.getPerson(2);
        assertEquals(PersonListPanelHandle.NOT_FOUND, personListPanel.getPersonIndex(targetPerson));
        assertEquals(numberOfPeopleBefore - 1, numberOfPeopleAfter);
        assertTrue(secondPersonBefore.isSameStateAs(secondPersonAfter));
        assertTrue(fourthPersonBefore.isSameStateAs(thirdPersonAfter));
    }

    @Test
    public void testDeletePerson_invalidIndex_fail() {
        personListPanel.enterCommandAndApply("delete " + (personListPanel.getNumberOfPeople() + 1));
        assertEquals("The person index provided is invalid", headerStatusBar.getText());
    }
}

@@ -358,37 +358,33 @@
     public void 
-testD
+d
 eletePerson_firs
@@ -1119,37 +1119,33 @@
     public void 
-testD
+d
 eletePerson_last
@@ -1975,37 +1975,33 @@
     public void 
-testD
+d
 eletePerson_midd
@@ -2969,13 +2969,9 @@
 oid 
-testD
+d
 elet
@@ -2978,22 +2978,25 @@
 ePerson_
-invali
+outOfBoun
 dIndex_f
@@ -3198,11 +3198,440 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void deletePerson_zeroIndex_fail() %7B%0A        personListPanel.enterCommandAndApply(%22delete 0%22);%0A        assertEquals(%22The person index provided is invalid%22, headerStatusBar.getText());%0A    %7D%0A%0A    @Test%0A    public void deletePerson_negativeIndex_fail() %7B%0A        personListPanel.enterCommandAndApply(%22delete -1%22);%0A        assertEquals(%22The person index provided is invalid%22, headerStatusBar.getText());%0A    %7D
 %0A%7D%0A

Rename delete test cases