package seedu.address.ui;

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

import org.junit.Test;

import guitests.guihandles.PersonCardHandle;
import seedu.address.model.person.Person;
import seedu.address.model.person.ReadOnlyPerson;
import seedu.address.testutil.PersonBuilder;

public class PersonCardTest extends GuiUnitTest {

    @Test
    public void display() throws Exception {
        // no tags
        Person personWithNoTags = new PersonBuilder().withTags(new String[0]).build();
        assertCardDisplay(personWithNoTags, 1);

        // with tags
        Person personWithTags = new PersonBuilder().build();
        assertCardDisplay(personWithTags, 2);
    }

    @Test
    public void equals() throws Exception {
        Person person = new PersonBuilder().build();
        PersonCard personCard = new PersonCard(person, 0);

        // same person, same index -> returns true
        PersonCard copy = new PersonCard(person, 0);
        assertTrue(personCard.equals(copy));

        // same object -> returns true
        assertTrue(personCard.equals(personCard));

        // null -> returns false
        assertFalse(personCard.equals(null));

        // different types -> returns false
        assertFalse(personCard.equals(0));

        // different person, same index -> returns false
        Person differentPerson = new PersonBuilder().withName("differentName").build();
        assertFalse(personCard.equals(new PersonCard(differentPerson, 0)));

        // same person, different index -> returns false
        assertFalse(personCard.equals(new PersonCard(person, 1)));
    }

    /**
     * Asserts that the card in {@code validId} in the card list displays the contact
     * details of {@code validPerson}.
     */
    private void assertCardDisplay(ReadOnlyPerson validPerson, int validId) throws Exception {

        PersonCard personCard = new PersonCard(validPerson, validId);

        uiPartRule.setUiPart(personCard);
        guiRobot.pauseForHuman();

        PersonCardHandle personCardHandle = new PersonCardHandle(personCard.getRoot());

        // verify id is displayed correctly
        assertEquals(Integer.toString(validId) + ". ", personCardHandle.getId());

        // verify person details are displayed correctly
        assertTrue(personCardHandle.isSamePerson(validPerson));
    }
}

@@ -358,16 +358,62 @@
 Builder;
+%0Aimport seedu.address.testutil.TypicalPersons;
 %0A%0Apublic
@@ -610,32 +610,143 @@
 ng%5B0%5D).build();%0A
+        PersonCard personCard = new PersonCard(personWithNoTags, 1);%0A        uiPartRule.setUiPart(personCard);%0A
         assertCa
@@ -747,32 +747,44 @@
 sertCardDisplay(
+personCard, 
 personWithNoTags
@@ -880,34 +880,626 @@
         
-assertCardDisplay(
+personCard = new PersonCard(personWithTags, 2);%0A        uiPartRule.setUiPart(personCard);%0A        assertCardDisplay(personCard, personWithTags, 2);%0A%0A        // changes made to Person reflects on card%0A        Person alice = new TypicalPersons().alice;%0A        guiRobot.interact(() -%3E %7B%0A            personWithTags.setName(alice.getName());%0A            personWithTags.setAddress(alice.getAddress());%0A            personWithTags.setEmail(alice.getEmail());%0A            personWithTags.setPhone(alice.getPhone());%0A            personWithTags.setTags(alice.getTags());%0A        %7D);%0A        assertCardDisplay(personCard, 
 personWi
@@ -2478,80 +2478,39 @@
 hat 
-the card in %7B@code validId%7D in the card list displays the contact%0A     *
+%7B@code personCard%7D displays the
  det
@@ -2528,20 +2528,23 @@
 ode 
-vali
+expecte
 dPerson%7D
 .%0A  
@@ -2543,184 +2543,170 @@
 son%7D
-.%0A     */%0A    private void assertCardDisplay(ReadOnlyPerson validPerson, int validId) throws Exception %7B%0A%0A        PersonCard personCard = new PersonCard(validPerson, vali
+ correctly and matches%0A     * %7B@code expectedId%7D.%0A     */%0A    private void assertCardDisplay(PersonCard personCard, ReadOnlyPerson expectedPerson, int expecte
 dId)
-;%0A
 %0A   
@@ -2714,41 +2714,30 @@
     
-uiPartRule.setUiPart(personCard);
+    throws Exception %7B
 %0A   
@@ -2939,20 +2939,23 @@
 oString(
-vali
+expecte
 dId) + %22
@@ -3097,12 +3097,15 @@
 son(
-vali
+expecte
 dPer

Add test case for subsequent changes to Person