package ru.stqa.pft.addressbook.tests;

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

import java.util.Arrays;
import java.util.stream.Collectors;

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

public class ContactDetailsTests extends TestBase {

    @BeforeMethod
    public void ensurePreconditions() {
        //app.goTo().homePage();
        app.goTo().goToDetailsPage();
        if (app.contact().allDetails().size() == 0) {
            app.contact().create(new ContactData().withFirstname("myTestName").withLastname("myTestlastname")
                    .withEmail("alena@yandex.com").withEmail2("ASFDSJDJN@gdfg.dg").withEmail3("12312@sdf.ru")
                    .withHomePhone("849580324").withWorkPhone("8800456512").withMobilePhone("88007006050")
                    .withAddress("New Zealand,Auckland, New World St. 15"));
        }
    }

    @Test
    public void testContactDetails() {
        ContactData  contactDetails = app.contact().allDetails().iterator().next();
        ContactData infoFromEditFormWithoutId = app.contact().infoFromEditFormWithoutId(contactDetails);

        assertThat(contactDetails.getAllDetails(), equalTo(mergeDetails(infoFromEditFormWithoutId)));
    }

        private String  mergeDetails(ContactData contact) {
            return Arrays.asList(contact.getFirstname(), contact.getLastname(), contact.getAddress(),
                    contact.getHomePhone(), contact.getMobilePhone(), contact.getWorkPhone(),
                    contact.getEmail(), contact.getEmail2(), contact.getEmail3())
                    .stream().filter((s)->!(s == null || s.equals("")))
                    .map(ContactDetailsTests::cleaned)
                    .collect(Collectors.joining("\n\n"));
    }

    private static String cleaned(String phone) {
        return phone.replaceAll("[M: H: W:]", ""); //регулярные выражения (пробельный символ)
    }
} //.replaceAll("\\s", "")




@@ -1472,33 +1472,40 @@
 t.getFirstname()
-,
+ + %22 %22 +
  contact.getLast
@@ -1545,32 +1545,41 @@
                 
+%22%5CnH: %22 +
  contact.getHome
@@ -1578,32 +1578,39 @@
 .getHomePhone(),
+%22M: %22 +
  contact.getMobi
@@ -1615,24 +1615,31 @@
 bilePhone(),
+%22W: %22 +
  contact.get
@@ -1670,16 +1670,22 @@
         
+%22%5Cn%22 +
  contact
@@ -1815,63 +1815,8 @@
 )))%0A
-                    .map(ContactDetailsTests::cleaned)%0A
     
@@ -1862,18 +1862,16 @@
 ning(%22%5Cn
-%5Cn
 %22));%0A   
@@ -1878,184 +1878,9 @@
  %7D%0A%0A
-    private static String cleaned(String phone) %7B%0A        return phone.replaceAll(%22%5BM: H: W:%5D%22, %22%22); //%D1%80%D0%B5%D0%B3%D1%83%D0%BB%D1%8F%D1%80%D0%BD%D1%8B%D0%B5 %D0%B2%D1%8B%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D1%8F (%D0%BF%D1%80%D0%BE%D0%B1%D0%B5%D0%BB%D1%8C%D0%BD%D1%8B%D0%B9 %D1%81%D0%B8%D0%BC%D0%B2%D0%BE%D0%BB)%0A    %7D%0A%7D //.replaceAll(%22%5C%5Cs%22, %22%22)
+%7D
 %0A%0A%0A%0A

ошибка исправлена.