package ru.stqa.pft.addressbook.tests;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import ru.stqa.pft.addressbook.model.ContactData;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;

/**
 * Created by Alex on 19.06.2016.
 */
public class ContactPhoneTests extends TestBase {
    @BeforeMethod
    public void ensurePreconditions()
    {
        app.goTo().homePage();
        if (app.contact().getAll().size()==0) {
            app.contact().create(new ContactData().withName("name").withMiddleName("maname").withLastName("last name")
                    .withNickname("nickname").withTitle("title").withCompany("company").withAddress("address").withMobilePhone("33333")
                    .withEmail("mail@company.com").withHomepage("www.homepage.com").withWorkPhone("1111").withHomePhone("2222"));
        }
    }

    @Test
    public void testContactPhones()
    {
        app.goTo().homePage();
        ContactData contact = app.contact().getAll().iterator().next();
        ContactData contactInfoFromEditForm = app.contact().infoFromEditForm(contact);

        assertThat(contact.getMobilePhone(),equalTo(contactInfoFromEditForm.getMobilePhone()));
        assertThat(contact.getHomePhone(),equalTo(contactInfoFromEditForm.getHomePhone()));
        assertThat(contact.getWorkPhone(),equalTo(contactInfoFromEditForm.getWorkPhone()));
    }

}

@@ -751,13 +751,19 @@
 ne(%22
++
 33
+-
 333
+-988
 %22)%0A 
@@ -862,18 +862,23 @@
 hone(%2211
+ 
 11
+ 977
 %22).withH
@@ -888,19 +888,32 @@
 Phone(%222
+ (
 222
+) 765-12-34
 %22));%0A   
@@ -1213,32 +1213,40 @@
 Phone(),equalTo(
+cleaned(
 contactInfoFromE
@@ -1263,32 +1263,33 @@
 tMobilePhone()))
+)
 ;%0A        assert
@@ -1316,32 +1316,40 @@
 Phone(),equalTo(
+cleaned(
 contactInfoFromE
@@ -1368,24 +1368,25 @@
 omePhone()))
+)
 ;%0A        as
@@ -1425,16 +1425,24 @@
 equalTo(
+cleaned(
 contactI
@@ -1473,16 +1473,112 @@
 hone()))
+);%0A    %7D%0A%0A    public String cleaned(String phone)%7B%0A        return phone.replaceAll(%22%5B%5E+%5C%5Cd%5D%22,%22%22)
 ;%0A    %7D%0A

Test Contact Phone updated