# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1496144337 -19800
#      Tue May 30 17:08:57 2017 +0530
# Node ID 46519d00f9327538068fa3821f89d8ae7e0527c1
# Parent  46eab94d419af1ab92ab1475c494dea468bdb885
Verifies issue 35830 : Added automated test 'I35830_VerifyPreValidationPaymentProvider'

diff -r 46eab94d419a -r 46519d00f932 src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/receipts/I35830_VerifyPreValidationPaymentProvider.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/receipts/I35830_VerifyPreValidationPaymentProvider.java	Tue May 30 17:08:57 2017 +0530
@@ -0,0 +1,109 @@
+/*
+ *************************************************************************
+ * 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) 2017 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ *
+ * @author RAN
+ *
+ */
+
+package org.openbravo.test.mobile.retail.pack.selenium.tests.receipts;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.core.selenium.SeleniumHelper;
+import org.openbravo.test.mobile.retail.mobilecore.annotations.TestClassAnnotations;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.retail.pack.database.WebPOSDatabaseConstants;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+import org.openbravo.test.mobile.retail.pack.selenium.terminals.WebPOSTerminalHelper;
+
+@TestClassAnnotations(isHighVolumeCompatible = true)
+public class I35830_VerifyPreValidationPaymentProvider extends WebPOSTerminalHelper {
+
+  final String modalpayment = "terminal_containerWindow_pointOfSale_modalpayment";
+
+  @Test
+  public void test() {
+    tap(TestIdPack.BUTTON_SEARCH);
+    write(TestIdPack.FIELD_SEARCH_TEXT,
+        TestIdPack.BUTTON_SEARCHPRODUCT_HEADLAMPULTRALIGHT.getRowName());
+    tap(TestIdPack.BUTTON_SEARCH_EXECUTE);
+    tap(TestIdPack.BUTTON_SEARCHPRODUCT_HEADLAMPULTRALIGHT);
+    verify(TestIdPack.LABEL_TOTALTOPAY, "18.90");
+    tap(TestIdPack.BUTTON_PAY);
+    isVisible(TestIdPack.BUTTON_PAY_EXACT, true);
+    isVisible(TestIdPack.BUTTON_PAY_DONE, false);
+
+    // Do Card Overpayment
+    tap(TestIdPack.BUTTON_CARD);
+    tap(TestIdPack.BUTTON_KEYPAD_3);
+    tap(TestIdPack.BUTTON_KEYPAD_3);
+    tap(TestIdPack.BUTTON_KEYPAD_ENTER);
+    isVisible(TestIdPack.CONFIRMATION_POPUP, true);
+    final String errorMsg = (String) SeleniumHelper
+        .executeScriptWithReturn("OB.I18N.getLabel('OBPOS_ErrorInProviderAddPayment', [OB.I18N.getLabel('OBPOS_OverpaymentNotAvailable'), "
+            + "33, OB.MobileApp.model.paymentnames[OB.MobileApp.model.receipt.get('selectedPayment')].payment.commercialName])");
+    verify(TestIdPack.LABEL_POPUP_CONFIRMATION_TITLE, errorMsg);
+    tap(TestIdPack.BUTTON_POPUP_CONFIRMATION_OK);
+
+    // Do Card Exact Payment
+    tap(TestIdPack.BUTTON_PAY_EXACT);
+    TestIdPack.POPUP_MODALPAYMENT.enyoNode().waitUntilIsReady();
+    verify(TestIdPack.POPUP_MODALPAYMENT_TITLE, "Process payment: 18.90");
+    isVisibleDom(modalpayment, true);
+    tap(TestIdPack.POPUP_MODALPAYMENT_OKBUTTON);
+
+    verify(TestIdPack.LABEL_RECEIPT_PAY_EXACT, "Exact amount paid.");
+    isVisible(TestIdPack.LABEL_RECEIPT_PAY_EXACT, true);
+    verify(TestIdPack.LABEL_RECEIPT_ADDEDPAYMENT_ROW1_NAME, "Card");
+    verify(TestIdPack.LABEL_RECEIPT_ADDEDPAYMENT_ROW1_AMOUNT, "18.90");
+    tap(TestIdPack.BUTTON_PAY_DONE);
+    verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
+  }
+
+  private void isVisibleDom(final String idDom, final boolean isVisibleExpected) {
+    logger.info(String.format("Verifying that the button '%s' is %svisible", idDom,
+        isVisibleExpected ? "" : "not "));
+    final String isVisibleScript = String.format(
+        "document.getElementById('%s').style.display === 'none'", idDom);
+    final boolean isVisible = !(Boolean) SeleniumHelper.executeScriptWithReturn(isVisibleScript);
+    assertThat(
+        String.format("'%s' was expected %sto be visible", idDom, isVisibleExpected ? "" : "not "),
+        isVisible, equalTo(isVisibleExpected));
+  }
+
+  @Override
+  public void beforeWithReload() {
+    updatePaymentType(true);
+  }
+
+  @Override
+  public void afterWithReload() {
+    updatePaymentType(false);
+  }
+
+  private void updatePaymentType(final boolean isForTest) {
+    final String sql = String.format("update obpos_app_payment_type "
+        + "set paymentprovider = %s, overpayment_limit = %s "
+        + "where obpos_app_payment_type_id = '%s'", isForTest ? "'OB.UI.MockPayment'" : null,
+        isForTest ? "'0'" : null, WebPOSDatabaseConstants.VBS_OBPOS_APP_PAYMENT_TYPE_CARD);
+
+    new DatabaseHelperInsertUpdateOrDelete().execute(sql, 1);
+  }
+}
diff -r 46eab94d419a -r 46519d00f932 src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/reversepayments/NoCashWhenReverse.java
--- a/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/reversepayments/NoCashWhenReverse.java	Tue May 30 11:29:48 2017 +0200
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/reversepayments/NoCashWhenReverse.java	Tue May 30 17:08:57 2017 +0530
@@ -54,8 +54,8 @@
     tap(TestIdPack.BUTTON_SEARCH_EXECUTE);
     tap(TestIdPack.BUTTON_SEARCHPRODUCT_AVALANCHETRANSCEIVER);
 
-    String receiptNo = BackboneHelper.getDocumentNo();
-    String customer = get(TestIdPack.BUTTON_RECEIPT_CUSTOMER);
+    final String receiptNo = BackboneHelper.getDocumentNo();
+    final String customer = get(TestIdPack.BUTTON_RECEIPT_CUSTOMER);
 
     // Finish the receipt
     tap(TestIdPack.BUTTON_PAY);
@@ -98,10 +98,10 @@
     // Check is not cash available
     tap(TestIdPack.BUTTON_CARD);
     isVisible(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, true);
-    verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available.");
+    verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available");
     isDisabled(TestIdPack.BUTTON_PAY_EXACT, true);
     tap(TestIdPack.BUTTON_CASHUSA);
-    verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available.");
+    verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available");
     isDisabled(TestIdPack.BUTTON_PAY_EXACT, true);
     tap(TestIdPack.BUTTON_CASH);
     isVisible(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, false);
@@ -226,10 +226,10 @@
     // Check is not cash available
     tap(TestIdPack.BUTTON_CASH);
     isVisible(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, true);
-    verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available.");
+    verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available");
     isDisabled(TestIdPack.BUTTON_PAY_EXACT, true);
     tap(TestIdPack.BUTTON_CASHUSA);
-    verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available.");
+    verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available");
     isDisabled(TestIdPack.BUTTON_PAY_EXACT, true);
     tap(TestIdPack.BUTTON_CASH);
 
@@ -250,8 +250,8 @@
     tap(TestIdPack.BUTTON_SEARCH_EXECUTE);
     tap(TestIdPack.BUTTON_SEARCHPRODUCT_AVALANCHETRANSCEIVER);
 
-    String receiptNo = BackboneHelper.getDocumentNo();
-    String customer = get(TestIdPack.BUTTON_RECEIPT_CUSTOMER);
+    final String receiptNo = BackboneHelper.getDocumentNo();
+    final String customer = get(TestIdPack.BUTTON_RECEIPT_CUSTOMER);
 
     // Finish the receipt
     tap(TestIdPack.BUTTON_MENU);
@@ -292,11 +292,11 @@
     // Check is not cash available
     tap(TestIdPack.BUTTON_CARD);
     isVisible(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, true);
-    verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available.");
+    verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available");
     isDisabled(TestIdPack.BUTTON_PAY_EXACT, true);
     isDisabled(TestIdPack.BUTTON_LAYAWAY, true);
     tap(TestIdPack.BUTTON_CASHUSA);
-    verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available.");
+    verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available");
     isDisabled(TestIdPack.BUTTON_PAY_EXACT, true);
     isDisabled(TestIdPack.BUTTON_LAYAWAY, true);
     tap(TestIdPack.BUTTON_CASH);
@@ -336,8 +336,8 @@
       tap(TestIdPack.BUTTON_SEARCH_EXECUTE);
       tap(TestIdPack.BUTTON_SEARCHPRODUCT_AVALANCHETRANSCEIVER);
 
-      String receiptNo = BackboneHelper.getDocumentNo();
-      String customer = get(TestIdPack.BUTTON_RECEIPT_CUSTOMER);
+      final String receiptNo = BackboneHelper.getDocumentNo();
+      final String customer = get(TestIdPack.BUTTON_RECEIPT_CUSTOMER);
 
       // Finish the receipt
       tap(TestIdPack.BUTTON_PAY);
@@ -380,11 +380,11 @@
       // Check is not cash available
       tap(TestIdPack.BUTTON_CARD);
       isVisible(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, true);
-      verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available.");
+      verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available");
       isDisabled(TestIdPack.BUTTON_PAY_EXACT, true);
       isDisabled(TestIdPack.BUTTON_PAY_USECREDIT, true);
       tap(TestIdPack.BUTTON_CASHUSA);
-      verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available.");
+      verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available");
       isDisabled(TestIdPack.BUTTON_PAY_EXACT, true);
       isDisabled(TestIdPack.BUTTON_PAY_USECREDIT, true);
       tap(TestIdPack.BUTTON_CASH);
@@ -539,11 +539,11 @@
       // Check is not cash available
       tap(TestIdPack.BUTTON_CASH);
       isVisible(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, true);
-      verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available.");
+      verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available");
       isDisabled(TestIdPack.BUTTON_PAY_EXACT, true);
       isDisabled(TestIdPack.BUTTON_PAY_USECREDIT, true);
       tap(TestIdPack.BUTTON_CASHUSA);
-      verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available.");
+      verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available");
       isDisabled(TestIdPack.BUTTON_PAY_EXACT, true);
       isDisabled(TestIdPack.BUTTON_PAY_USECREDIT, true);
       tap(TestIdPack.BUTTON_CASH);
@@ -592,8 +592,8 @@
       tap(TestIdPack.BUTTON_SEARCH_EXECUTE);
       tap(TestIdPack.BUTTON_SEARCHPRODUCT_AVALANCHETRANSCEIVER);
 
-      String receiptNo = BackboneHelper.getDocumentNo();
-      String customer = get(TestIdPack.BUTTON_RECEIPT_CUSTOMER);
+      final String receiptNo = BackboneHelper.getDocumentNo();
+      final String customer = get(TestIdPack.BUTTON_RECEIPT_CUSTOMER);
 
       // Finish the receipt
       tap(TestIdPack.BUTTON_MENU);
@@ -634,12 +634,12 @@
       // Check is not cash available
       tap(TestIdPack.BUTTON_CARD);
       isVisible(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, true);
-      verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available.");
+      verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available");
       isDisabled(TestIdPack.BUTTON_PAY_EXACT, true);
       isDisabled(TestIdPack.BUTTON_LAYAWAY, true);
       isDisabled(TestIdPack.BUTTON_PAY_USECREDIT, true);
       tap(TestIdPack.BUTTON_CASHUSA);
-      verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available.");
+      verify(TestIdPack.LABEL_RECEIPT_PAY_NOTENOUGHCASH, "There is not enough cash available");
       isDisabled(TestIdPack.BUTTON_PAY_EXACT, true);
       isDisabled(TestIdPack.BUTTON_LAYAWAY, true);
       isDisabled(TestIdPack.BUTTON_PAY_USECREDIT, true);
