# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1477569206 -19800
#      Thu Oct 27 17:23:26 2016 +0530
# Node ID 000e211d43b93b297c8c472ed9e16872420a76e3
# Parent  e59ae827dabebdc1a79fe6ac41b48b318ef42128
Verifies issue 34285 : Added automated test 'I34285_VerifyCustomerSaveAction'

diff -r e59ae827dabe -r 000e211d43b9 src-test/org/openbravo/test/mobile/retail/pack/selenium/TestIdPack.java
--- a/src-test/org/openbravo/test/mobile/retail/pack/selenium/TestIdPack.java	Wed Oct 26 15:49:03 2016 -0600
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/TestIdPack.java	Thu Oct 27 17:23:26 2016 +0530
@@ -570,6 +570,8 @@
       "bodyheader_newcustomersave", EnyoKind.BUTTON); //
   public static TestIdConstructor FIELD_CUSTOMER_NAME = new TestIdConstructor(
       "newAttribute_firstName"); //
+  public static TestIdConstructor FIELD_CUSTOMER_STATICNAME = new TestIdConstructor(
+      "newAttribute_customerName"); //
   public static TestIdConstructor FIELD_CUSTOMER_LASTNAME = new TestIdConstructor(
       "createcustomers_impl_customerAttributes_line_lastName_newAttribute_lastName"); //
   public static TestIdConstructor FIELD_CUSTOMER_ADDRES = new TestIdConstructor(
diff -r e59ae827dabe -r 000e211d43b9 src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I34285_VerifyCustomerSaveAction.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I34285_VerifyCustomerSaveAction.java	Thu Oct 27 17:23:26 2016 +0530
@@ -0,0 +1,100 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo Public License
+ * Version 1.0 (the "License"), being the Mozilla Public License
+ * Version 1.1 with a permitted attribution clause; you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo S.L.U.
+ * All portions are Copyright (C) 2016 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ *
+ * @author RAN
+ *
+ */
+
+package org.openbravo.test.mobile.retail.pack.selenium.tests.system;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.retail.mobilecore.annotations.TestClassAnnotations;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.retail.mobilecore.javascript.BackboneHelper;
+import org.openbravo.test.mobile.retail.mobilecore.utils.RetailUtils;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+import org.openbravo.test.mobile.retail.pack.selenium.terminals.WebPOSTerminalHelper;
+
+@TestClassAnnotations(isHighVolumeCompatible = true)
+public class I34285_VerifyCustomerSaveAction extends WebPOSTerminalHelper {
+
+  private final String prefSynchronizedMode = "OBMOBC_SynchronizedMode";
+  private final String prefRemoteCustomer = "OBPOS_remote.customer";
+  private String preferenceId1 = null;
+  private String preferenceId2 = null;
+
+  @Test
+  public void test() {
+    logOut();
+    logIn("demouser");
+
+    // Create Customer
+    tap(TestIdPack.BUTTON_RECEIPT_CUSTOMER);
+    tap(TestIdPack.BUTTON_CUSTOMER_NEW);
+    write(TestIdPack.FIELD_CUSTOMER_NAME, "Xavier R");
+    write(TestIdPack.FIELD_CUSTOMER_LASTNAME, "Does");
+    write(TestIdPack.FIELD_CUSTOMER_ADDRES, "Some place");
+    tap(TestIdPack.BUTTON_CUSTOMER_SAVE);
+
+    // Edit Customer
+    tap(TestIdPack.BUTTON_CUSTOMER_EDIT_CUSTOMER);
+    write(TestIdPack.FIELD_CUSTOMER_NAME, "Xavier");
+    tap(TestIdPack.BUTTON_CUSTOMER_SAVE);
+    verify(TestIdPack.FIELD_CUSTOMER_STATICNAME, "Xavier");
+    tap(TestIdPack.BUTTON_CUSTOMER_ASSIGNTOCUSTOMER);
+    assertThat("New Customer not assigned to receipt", "Xavier Does",
+        equalTo(get(TestIdPack.BUTTON_RECEIPT_CUSTOMER)));
+
+    // Delete Receipt
+    tap(TestIdPack.BUTTON_DELETERECEIPT);
+    tap(TestIdPack.BUTTON_DELETERECEIPT_CONFIRM);
+    verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
+
+    logOut();
+    logIn();
+  }
+
+  @Override
+  public void beforeWithReload() {
+    preferenceId1 = RetailUtils.getRandomUUID();
+    preferenceId2 = RetailUtils.getRandomUUID();
+    final String clientId = BackboneHelper.getTerminalValue("client");
+    final String sqlInsertPreference = "INSERT INTO ad_preference(ad_preference_id, ad_client_id, ad_org_id, createdby, updatedby, value, property, "
+        + "ispropertylist, selected, ad_user_id, visibleat_role_id) "
+        + "VALUES ('%s', '%s', '0', '100', '100', 'Y', '%s', to_char('Y'), to_char('Y'), 'E49545E7D0A2413E90C31C2CDC2153B1', null)";
+    // Add Preference 1 - WebPOS Synchronized Mode
+    new DatabaseHelperInsertUpdateOrDelete().execute(
+        String.format(sqlInsertPreference, preferenceId1, clientId, prefSynchronizedMode), 1);
+    // Add Preference 2 - Remote Customer
+    new DatabaseHelperInsertUpdateOrDelete().execute(
+        String.format(sqlInsertPreference, preferenceId2, clientId, prefRemoteCustomer), 1);
+  }
+
+  @Override
+  public void afterWithReload() {
+    // Delete Preference 1
+    new DatabaseHelperInsertUpdateOrDelete().execute(String.format("delete from ad_preference "
+        + "where ad_preference_id = '%s'", preferenceId1), 1);
+    // Delete Preference 2
+    new DatabaseHelperInsertUpdateOrDelete().execute(String.format("delete from ad_preference "
+        + "where ad_preference_id = '%s'", preferenceId2), 1);
+  }
+}
\ No newline at end of file
