package guitests;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

import guitests.guihandles.TaskCardHandle;
import seedu.bulletjournal.commons.core.Messages;
import seedu.bulletjournal.logic.commands.AddCommand;
import seedu.bulletjournal.testutil.TestTask;
import seedu.bulletjournal.testutil.TestUtil;

public class AddCommandTest extends AddressBookGuiTest {

    @Test
    public void add() {
        //add one person
        TestTask[] currentList = td.getTypicalPersons();
        TestTask personToAdd = td.hoon;
        assertAddSuccess(personToAdd, currentList);
        currentList = TestUtil.addPersonsToList(currentList, personToAdd);

        //add another person
        personToAdd = td.ida;
        assertAddSuccess(personToAdd, currentList);
        currentList = TestUtil.addPersonsToList(currentList, personToAdd);

        //add duplicate person
        commandBox.runCommand(td.hoon.getAddCommand());
        assertResultMessage(AddCommand.MESSAGE_DUPLICATE_PERSON);
        assertTrue(personListPanel.isListMatching(currentList));

        //add to empty list
        commandBox.runCommand("clear");
        assertAddSuccess(td.assignment);

        //invalid command
        commandBox.runCommand("adds Johnny");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
    }

    private void assertAddSuccess(TestTask personToAdd, TestTask... currentList) {
        commandBox.runCommand(personToAdd.getAddCommand());

        //confirm the new card contains the right data
        TaskCardHandle addedCard = personListPanel.navigateToPerson(personToAdd.getName().fullName);
        assertMatching(personToAdd, addedCard);

        //confirm the list now contains all previous persons plus the new person
        TestTask[] expectedList = TestUtil.addPersonsToList(currentList, personToAdd);
        assertTrue(personListPanel.isListMatching(expectedList));
    }

}

@@ -932,20 +932,986 @@
 Command(
+%22add %22));%0A        assertResultMessage(AddCommand.MESSAGE_DUPLICATE_PERSON);%0A        assertTrue(personListPanel.isListMatching(currentList));%0A%0A        //add duplicate person%0A        commandBox.runCommand(td.hoon.getAddCommand(%22adds %22));%0A        assertResultMessage(AddCommand.MESSAGE_DUPLICATE_PERSON);%0A        assertTrue(personListPanel.isListMatching(currentList));%0A%0A        //add duplicate person with %22a%22 command%0A        commandBox.runCommand(td.hoon.getAddCommand(%22a %22));%0A        assertResultMessage(AddCommand.MESSAGE_DUPLICATE_PERSON);%0A        assertTrue(personListPanel.isListMatching(currentList));%0A%0A        //add duplicate person with %22new%22 command%0A        commandBox.runCommand(td.hoon.getAddCommand(%22new %22));%0A        assertResultMessage(AddCommand.MESSAGE_DUPLICATE_PERSON);%0A        assertTrue(personListPanel.isListMatching(currentList));%0A%0A        //add duplicate person with %22create%22 command%0A        commandBox.runCommand(td.hoon.getAddCommand(%22create %22
 ));%0A
-
         
@@ -2203,18 +2203,16 @@
 mand(%22ad
-ds
  Johnny%22
@@ -2363,24 +2363,24 @@
 rentList) %7B%0A
-
         comm
@@ -2423,16 +2423,22 @@
 Command(
+%22add %22
 ));%0A%0A   

Update AddCommandTest for guitests