Related to issue 38724: Added tests for Price Modification Reason
authorGuillermo Gil <guillermo.gil@openbravo.com>
Wed, 17 Oct 2018 06:58:59 +0200
changeset 7793 d70601a764f2
parent 7792 95789e4486a4
child 7794 3c651b4a3772
Related to issue 38724: Added tests for Price Modification Reason
src-test/org/openbravo/test/mobile/core/utils/AllowedErrorsHelper.java
src-test/org/openbravo/test/mobile/retail/pack/selenium/TestIdPack.java
src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/receipts/I38724_AllowPriceModificationVerifiedReturns.java
src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/receipts/I38724_PriceModificationReason.java
--- a/src-test/org/openbravo/test/mobile/core/utils/AllowedErrorsHelper.java	Mon Sep 10 16:06:12 2018 -0400
+++ b/src-test/org/openbravo/test/mobile/core/utils/AllowedErrorsHelper.java	Wed Oct 17 06:58:59 2018 +0200
@@ -458,6 +458,9 @@
     // Forgot Password
     testsAllowedToHaveJavascriptErrors.add("FP090_ForgotPasswordOffline");
 
+    // Price Modification Reason
+    testsAllowedToHaveJavascriptErrors.add("I38724_AllowPriceModificationVerifiedReturns");
+
     return testsAllowedToHaveJavascriptErrors;
   }
 
@@ -502,6 +505,8 @@
     javascriptAllowedErrors
         .add("Failed to load resource: the server responded with a status of 500 (Server Error)");
 
+    javascriptAllowedErrors.add("You cannot change the price of a line from original receipt");
+
     // ServiceWorkers may trigger this message when a resource fails:
     javascriptAllowedErrors.add("Error in fetching the application sources");
     return javascriptAllowedErrors;
@@ -611,6 +616,9 @@
     // Forgot Password
     testsAllowedToHaveLogclientErrors.add("FP090_ForgotPasswordOffline");
 
+    // Price Modification Reason
+    testsAllowedToHaveLogclientErrors.add("I38724_AllowPriceModificationVerifiedReturns");
+
     return testsAllowedToHaveLogclientErrors;
   }
 
--- a/src-test/org/openbravo/test/mobile/retail/pack/selenium/TestIdPack.java	Mon Sep 10 16:06:12 2018 -0400
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/TestIdPack.java	Wed Oct 17 06:58:59 2018 +0200
@@ -87,6 +87,10 @@
       "theButton_buttonDelete", EnyoKind.BUTTON); //
   public static TestIdConstructor BUTTON_DELETERECEIPT_CONFIRM = new TestIdConstructor(
       "bodyButtons_btnModalApplyDelete", EnyoKind.BUTTON); //
+  public static TestIdConstructor BUTTON_PRICEREASON_CONFIRM = new TestIdConstructor(
+      "bodyButtons_btnModalPriceModificationAccept", EnyoKind.BUTTON); //
+  public static TestIdConstructor SELECT_PRICEMODIFICATION_REASON = new TestIdConstructor(
+      "bodyContent_priceModificationReason", EnyoKind.BUTTON); //
   public static TestIdConstructor BUTTON_PAY = new TestIdConstructor("theButton_btnTotalToPay",
       EnyoKind.BUTTON); //
   public static TestIdConstructor BUTTON_PAY_AMOUNT = new TestIdConstructor(
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/receipts/I38724_AllowPriceModificationVerifiedReturns.java	Wed Oct 17 06:58:59 2018 +0200
@@ -0,0 +1,107 @@
+/*
+ *************************************************************************
+ * 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) 2018 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ *
+ * @author GIG
+ *
+ */
+
+package org.openbravo.test.mobile.retail.pack.selenium.tests.receipts;
+
+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.API.WebPOSAPI;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+import org.openbravo.test.mobile.retail.pack.selenium.terminals.WebPOSTerminalHelper;
+
+@TestClassAnnotations(isHighVolumeCompatible = true)
+public class I38724_AllowPriceModificationVerifiedReturns extends WebPOSTerminalHelper {
+
+  String receiptNo;
+  private final String preferenceId = RetailUtils.getRandomUUID();
+
+  @Test
+  public void test() {
+    try {
+      createPriceModificationPreference();
+
+      reload();
+
+      final String receiptNo1 = BackboneHelper.getDocumentNo();
+      final String customer = get(TestIdPack.BUTTON_RECEIPT_CUSTOMER);
+      tap(TestIdPack.BUTTON_SEARCH);
+      write(TestIdPack.FIELD_SEARCH_TEXT,
+          TestIdPack.BUTTON_SEARCHPRODUCT_BASECAMPLANTERN.getRowName());
+      tap(TestIdPack.BUTTON_SEARCH_EXECUTE);
+      tap(TestIdPack.BUTTON_SEARCHPRODUCT_BASECAMPLANTERN);
+      verify(TestIdPack.LABEL_TOTALTOPAY, "55.50");
+      tap(TestIdPack.BUTTON_PAY);
+      tap(TestIdPack.BUTTON_PAY_EXACT);
+      tap(TestIdPack.BUTTON_PAY_DONE);
+      verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
+      tap(TestIdPack.BUTTON_MENU);
+      tap(TestIdPack.BUTTON_MENU_VERIFIEDRETURN);
+      write(TestIdPack.FIELD_VERIFIED_RETURNS_FILTER_TXT, receiptNo1);
+      tap(TestIdPack.BUTTON_VERIFIEDRETURNS_SEARCH);
+      verify(TestIdPack.LABEL_VERIFIED_RETURNS_SEARCH_RESULT_ROW1_DOCUMENTNO, receiptNo1);
+      verify(TestIdPack.LABEL_VERIFIED_RETURNS_SEARCH_RESULT_ROW1_CUSTOMER, customer);
+      tap(TestIdPack.BUTTON_VERIFIEDRETURNS_ROW1);
+      verify(TestIdPack.LABEL_POPUP_DOCUMENTNO, receiptNo1);
+      tap(TestIdPack.BUTTON_VERIFIEDRETURNS_LINES_CHECKROW1);
+      tap(TestIdPack.BUTTON_POPUP_APPLY);
+      verify(TestIdPack.LABEL_TOTALTOPAY, "-55.50");
+      tap(TestIdPack.BUTTON_EDIT);
+      WebPOSAPI.tapKeypad(this, 60);
+      tap(TestIdPack.BUTTON_KEYPAD_PRICE);
+      verify(TestIdPack.LABEL_TOTALTOPAY, "-55.50");
+      tap(TestIdPack.BUTTON_EDIT);
+      WebPOSAPI.tapKeypad(this, 50);
+      tap(TestIdPack.BUTTON_KEYPAD_PRICE);
+      verify(TestIdPack.LABEL_TOTALTOPAY, "-50.00");
+      tap(TestIdPack.BUTTON_PAY);
+      tap(TestIdPack.BUTTON_PAY_EXACT);
+      tap(TestIdPack.BUTTON_PAY_DONE);
+      verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
+    } finally {
+      deletePriceModificationPreference();
+      reload();
+    }
+  }
+
+  private void createPriceModificationPreference() {
+    final String clientId = BackboneHelper.getTerminalValue("client");
+    final String prefereceName = "OBPOS_ModifyPriceVerifiedReturns";
+    final String adUserId = "3073EDF96A3C42CC86C7069E379522D2";
+
+    final String SQL = String
+        .format(
+            "insert into ad_preference(ad_preference_id, ad_client_id, ad_org_id, createdby, updatedby, value, property, ispropertylist, ad_user_id) "
+                + "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", preferenceId,
+            clientId, "0", "100", "100", "Y", prefereceName, "Y", adUserId);
+
+    new DatabaseHelperInsertUpdateOrDelete().execute(SQL, 1);
+  }
+
+  private void deletePriceModificationPreference() {
+    new DatabaseHelperInsertUpdateOrDelete().execute(
+        String.format("delete from ad_preference where ad_preference_id = '%s'", preferenceId), 1);
+  }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/receipts/I38724_PriceModificationReason.java	Wed Oct 17 06:58:59 2018 +0200
@@ -0,0 +1,118 @@
+/*
+ *************************************************************************
+ * 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) 2018 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ *
+ * @author GIG
+ *
+ */
+
+package org.openbravo.test.mobile.retail.pack.selenium.tests.receipts;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.retail.extmodules.selenium.TestIdExtModules;
+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.database.DatabaseHelperSelect;
+import org.openbravo.test.mobile.retail.mobilecore.javascript.BackboneHelper;
+import org.openbravo.test.mobile.retail.pack.API.WebPOSAPI;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+import org.openbravo.test.mobile.retail.pack.selenium.terminals.WebPOSTerminalHelper;
+
+@TestClassAnnotations(isHighVolumeCompatible = true)
+public class I38724_PriceModificationReason extends WebPOSTerminalHelper {
+
+  String receiptNo;
+  String avalancheKey = "WVG/M0019";
+  String cramponsKey = "WVG/M0003";
+
+  @Test
+  public void test() {
+    try {
+      new DatabaseHelperInsertUpdateOrDelete().execute(
+          String.format("update obpos_pricereason set isactive = '%s'", "Y"), 2);
+
+      reload();
+
+      receiptNo = BackboneHelper.getDocumentNo();
+
+      tap(TestIdExtModules.BUTTON_SEARCH);
+      write(TestIdExtModules.FIELD_SEARCH_TEXT, avalancheKey);
+      tap(TestIdExtModules.BUTTON_SEARCH_EXECUTE);
+      tap(TestIdExtModules.BUTTON_SEARCHPRODUCT_FIRSTROW);
+      tap(TestIdPack.BUTTON_EDIT);
+      WebPOSAPI.tapKeypad(this, 50);
+      tap(TestIdPack.BUTTON_KEYPAD_PRICE);
+      TestIdPack.SELECT_PRICEMODIFICATION_REASON.enyoNode().executeExtension(".setSelected(0)");
+      tap(TestIdPack.BUTTON_PRICEREASON_CONFIRM);
+      verify(TestIdPack.LABEL_TOTALTOPAY, "50.00");
+
+      tap(TestIdExtModules.BUTTON_SEARCH);
+      write(TestIdExtModules.FIELD_SEARCH_TEXT, cramponsKey);
+      tap(TestIdExtModules.BUTTON_SEARCH_EXECUTE);
+      tap(TestIdExtModules.BUTTON_SEARCHPRODUCT_FIRSTROW);
+      tap(TestIdPack.BUTTON_EDIT);
+      WebPOSAPI.tapKeypad(this, 20);
+      tap(TestIdPack.BUTTON_KEYPAD_PRICE);
+      TestIdPack.SELECT_PRICEMODIFICATION_REASON.enyoNode().executeExtension(".setSelected(1)");
+      tap(TestIdPack.BUTTON_PRICEREASON_CONFIRM);
+      verify(TestIdPack.LABEL_TOTALTOPAY, "70.00");
+
+      tap(TestIdPack.BUTTON_PAY);
+      tap(TestIdPack.BUTTON_PAY_EXACT);
+      tap(TestIdPack.BUTTON_PAY_DONE);
+      verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
+
+      // Verify in Backend
+      final String sql = String
+          .format(
+              "SELECT cl.em_obpos_PriceReason_id FROM c_orderline cl "
+                  + "join c_order co on co.c_order_id = cl.c_order_id WHERE co.documentno = '%s' order by line asc",
+              receiptNo);
+      new DatabaseHelperSelect() {
+        private int count = 0;
+
+        @Override
+        protected void yieldResultSet(final ResultSet rs) throws SQLException {
+          count++;
+          final String priceReason = rs.getString("em_obpos_PriceReason_id");
+          switch (count) {
+          case 1:
+            assertThat(priceReason, equalTo("8279708139F143B8ACAEA907B43E84BA"));
+            break;
+          case 2:
+            assertThat(priceReason, equalTo("96440397D4914547874393CB982B64E0"));
+            break;
+          default:
+            throw new IllegalArgumentException("The returned resulset is missing the assertions");
+          }
+        }
+      }.execute(sql, 2);
+
+    } finally {
+      new DatabaseHelperInsertUpdateOrDelete().execute(
+          String.format("update obpos_pricereason set isactive = '%s'", "N"), 2);
+      reload();
+    }
+  }
+
+}