Related to issue 40767: added automated test
authorAlejandro <alekosmp86@gmail.com>
Thu, 16 May 2019 17:12:28 -0400
changeset 8541 e1ba59106b45
parent 8540 e50c96d4dd40
child 8542 6ca36b6d0d18
Related to issue 40767: added automated test
src-test/org/openbravo/test/mobile/retail/pack/selenium/TestIdPack.java
src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/services/I40767_VerifyNoJSErrorWhenRemovingServiceAtFirstTry.java
--- a/src-test/org/openbravo/test/mobile/retail/pack/selenium/TestIdPack.java	Thu May 16 17:02:35 2019 +0200
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/TestIdPack.java	Thu May 16 17:12:28 2019 -0400
@@ -1088,8 +1088,8 @@
       "Descender 8", EnyoKind.SEARCHPRODUCT); //
   public static TestIdConstructor BUTTON_SEARCHPRODUCT_MINILINTERN = new TestIdConstructor(
       "Minilintern solar dynamo", EnyoKind.SEARCHPRODUCT); //
-  public static TestIdConstructor BUTTON_SEARCHPRODUCT_BPSET1 = new TestIdConstructor(
-      "BPSET1", EnyoKind.SEARCHPRODUCT); //
+  public static TestIdConstructor BUTTON_SEARCHPRODUCT_BPSET1 = new TestIdConstructor("BPSET1",
+      EnyoKind.SEARCHPRODUCT); //
   public static TestIdConstructor BUTTON_SEARCHPRODUCT_AVALANCHETRANSCEIVER = new TestIdConstructor(
       "Avalanche transceiver", EnyoKind.SEARCHPRODUCT); //
   public static TestIdConstructor BUTTON_SEARCHPRODUCT_INSECTREPELLENT = new TestIdConstructor(
@@ -1302,7 +1302,9 @@
   public static TestIdConstructor BUTTON_REMOVETHIRDLINE = new TestIdConstructor(
       "line2_checkboxButtonRemoveAssociations", EnyoKind.BUTTON);
   public static TestIdConstructor BUTTON_APPLYREMOVEASSOCIATIONS = new TestIdConstructor(
-      "modalRemoveAssociations_btnApply", EnyoKind.BUTTON);
+      "modalRemoveAssociations_btnApply", EnyoKind.BUTTON); //
+  public static TestIdConstructor BUTTON_CANCELREMOVEASSOCIATIONS = new TestIdConstructor(
+      "modalRemoveAssociations_btnCancel", EnyoKind.BUTTON); //
   public static TestIdConstructor ADD_ASSOC_LABEL_NO_RESULTS = new TestIdConstructor(
       "orderSelector_renderEmpty");
   public static TestIdConstructor BUTTON_CLOSE_ASSOCIATIONS = new TestIdConstructor(
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/services/I40767_VerifyNoJSErrorWhenRemovingServiceAtFirstTry.java	Thu May 16 17:12:28 2019 -0400
@@ -0,0 +1,110 @@
+/*
+ *************************************************************************
+ * 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) 2019 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ *
+ * @author alekosmp86
+ *
+ */
+
+package org.openbravo.test.mobile.retail.pack.selenium.tests.services;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.apache.commons.codec.binary.StringUtils;
+import org.junit.Test;
+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.javascript.SynchronizationMonitor;
+import org.openbravo.test.mobile.retail.mobilecore.selenium.TestIdCore;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+import org.openbravo.test.mobile.retail.pack.selenium.terminals.WebPOSTerminalHelper;
+
+public class I40767_VerifyNoJSErrorWhenRemovingServiceAtFirstTry extends WebPOSTerminalHelper {
+  private final String PRODUCT_SERVICE_ID = "73D4BE4D913A4526A363E1DACD919D48";
+  private final String PRODUCT_SERVICE_NAME = "Customize Coat";
+  private final String PRODUCT_NAME = "Blue Coat";
+
+  @Test
+  public void test() {
+    String docNo = BackboneHelper.getDocumentNo();
+    addProduct(PRODUCT_NAME);
+    tap(TestIdPack.BUTTON_EDIT);
+    verify(TestIdPack.LABEL_RECEIPT_TOTAL_GROSS, "100.00");
+    tap(TestIdPack.BUTTON_PAY);
+    tap(TestIdPack.BUTTON_PAY_EXACT);
+    tap(TestIdPack.BUTTON_PAY_DONE);
+    SynchronizationMonitor.waitUntilDataIsInTheServer();
+
+    openTicket(docNo);
+    tap(TestIdPack.BUTTON_RECEIPT_ROW1_SHOWRELATEDSERVICES);
+    write(TestIdPack.FIELD_SEARCH_TEXT, PRODUCT_SERVICE_NAME);
+    tap(TestIdPack.BUTTON_SEARCH_EXECUTE);
+    isVisible(TestIdPack.BUTTON_SEARCHPRODUCT_FIRSTROW, true);
+    tap(TestIdPack.BUTTON_SEARCHPRODUCT_FIRSTROW);
+    verify(TestIdPack.LABEL_POPUP_OPENEDRECEIPT_TITLE, "Not Editable Receipt");
+    tap(TestIdPack.BUTTON_POPUP_OPENEDRECEIPT_CREATE_NEW_RECEIPT);
+    isDisabled(TestIdPack.BUTTON_POPUP_OPENEDRECEIPT_APPLY, false);
+    tap(TestIdPack.BUTTON_POPUP_OPENEDRECEIPT_APPLY);
+
+    startListeningBubbleErrors();
+    tap(TestIdPack.BUTTON_RECEIPT_ROW1);
+    tap(TestIdPack.BUTTON_OPENREMOVEASOCIATIONSPOPUP);
+    String error = getLastBubbleError();
+    assertThat("No errors should have been shown", StringUtils.equals(error, null));
+    tap(TestIdPack.BUTTON_CANCELREMOVEASSOCIATIONS);
+    tap(TestIdPack.BUTTON_DELETERECEIPT);
+    tap(TestIdPack.BUTTON_DELETERECEIPT_CONFIRM);
+    tap(TestIdPack.BUTTON_DELETERECEIPT);
+  }
+
+  @Override
+  public void beforeWithReload() {
+    setAllowDeferredSalesForService(PRODUCT_SERVICE_ID, true);
+  }
+
+  @Override
+  public void afterWithReload() {
+    setAllowDeferredSalesForService(PRODUCT_SERVICE_ID, false);
+  }
+
+  private void setAllowDeferredSalesForService(String serviceId, boolean isDeferredSale) {
+    String sql = String.format(
+        "update m_product set allow_deferred_sell = '%s' where m_product_id = '%s'",
+        isDeferredSale ? "Y" : "N", serviceId);
+
+    new DatabaseHelperInsertUpdateOrDelete() {
+    }.execute(sql, 1);
+  }
+
+  private void addProduct(String productName) {
+    // add a product
+    tap(TestIdPack.BUTTON_SEARCH);
+    write(TestIdPack.FIELD_SEARCH_TEXT, productName);
+    TestIdPack.FIELD_SEARCH_TEXT.enyoNode().executeExtension(".waterfall('onchange')");
+    tap(TestIdPack.BUTTON_SEARCH_EXECUTE);
+    tap(TestIdPack.BUTTON_SEARCHPRODUCT_FIRSTROW);
+  }
+
+  private void openTicket(String docNo) {
+    tap(TestIdCore.BUTTON_MENU);
+    tap(TestIdPack.BUTTON_MENU_OPENRECEIPT);
+    write(TestIdPack.FIELD_OPEN_RECEIPT_FILTER_TXT, docNo);
+    TestIdPack.FIELD_OPEN_RECEIPT_FILTER_TXT.enyoNode().executeExtension(".waterfall('onchange')");
+    tap(TestIdPack.BUTTON_OPEN_RECEIPT_SEARCH);
+    tap(TestIdPack.BUTTON_OPEN_RECEIPT_ROW1);
+  }
+}