Related to issue 39600: added automated test
authorAlejandro <alekosmp86@gmail.com>
Wed, 03 Apr 2019 15:12:14 -0400
changeset 8460 8527935dbfc5
parent 8459 71f8d16e049a
child 8461 8b5182cb2813
Related to issue 39600: added automated test
src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/retailconnector/I39600_VerifyNegativeStockInStorageBinWithNoOverissue.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/retailconnector/I39600_VerifyNegativeStockInStorageBinWithNoOverissue.java	Wed Apr 03 15:12:14 2019 -0400
@@ -0,0 +1,111 @@
+/*
+ *************************************************************************
+ * 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 alekosmp86@gmail.com
+ *
+ */
+
+package org.openbravo.test.mobile.retail.extmodules.selenium.tests.retailconnector;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.core.selenium.SeleniumHelper;
+import org.openbravo.test.mobile.retail.extmodules.selenium.terminals.WebPOSExtModulesTerminalHelper;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperSelect;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+
+public class I39600_VerifyNegativeStockInStorageBinWithNoOverissue
+    extends WebPOSExtModulesTerminalHelper {
+  final String AMS1001_POSTERMINAL_ID = "2694D5D99689476AABC5E3494D9191D5";
+  final String IRA_STGPublic = "6123C45A1E7743B784E1A6A9DDE3D43F";
+  final String LOCATOR_RCT001 = "6D5E05F285AC4235AB7ED925D671A63F";
+
+  // Product Info
+  final String PRODUCT_NAME = "Digital Watch Battery";
+
+  // default values
+  private String defaultIRAforPOS;
+  private String ERROR_MESSAGE = "The stock level for this product is 0. You cannot sell 1 unit(s) of this product because your system doesn't allow negative stocks.";
+
+  public I39600_VerifyNegativeStockInStorageBinWithNoOverissue() {
+    super("AMS1001", "vallblanca", "openbravo");
+  }
+
+  @Test
+  public void test() {
+    Boolean stockValidationStatus = (Boolean) SeleniumHelper.executeScriptWithReturn(
+        "OB.MobileApp.model.get('permissions').OBPOSSV_EnableStockValidation;");
+    try {
+      SeleniumHelper.executeScriptWithReturn(
+          "OB.MobileApp.model.attributes.permissions.OBPOSSV_EnableStockValidation = true");
+
+      addProduct(PRODUCT_NAME);
+      verify(TestIdPack.LABEL_POPUP_CONFIRMATION_TITLE, ERROR_MESSAGE);
+      tap(TestIdPack.BUTTON_POPUP_CONFIRMATION_OK);
+    } finally {
+      SeleniumHelper.executeScriptWithReturn(
+          "OB.MobileApp.model.attributes.permissions.OBPOSSV_EnableStockValidation = "
+              + stockValidationStatus);
+    }
+  }
+
+  @Override
+  public void beforeWithReload() {
+    saveDefaultIRAforPOS();
+    setIRAforPOS(IRA_STGPublic);
+  }
+
+  @Override
+  public void afterWithReload() {
+    setIRAforPOS(defaultIRAforPOS);
+  }
+
+  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 saveDefaultIRAforPOS() {
+    String sql = String.format(
+        "select em_obaworc_irarea from obpos_applications where obpos_applications_id = '%s'",
+        AMS1001_POSTERMINAL_ID);
+
+    new DatabaseHelperSelect() {
+      @Override
+      protected void yieldResultSet(ResultSet rs) throws SQLException {
+        defaultIRAforPOS = rs.getString(1);
+      }
+    }.execute(sql, 1);
+  }
+
+  private void setIRAforPOS(String iraId) {
+    String sql = String.format(
+        "update obpos_applications set em_obaworc_irarea = '%s' where obpos_applications_id = '%s'",
+        iraId, AMS1001_POSTERMINAL_ID);
+
+    new DatabaseHelperInsertUpdateOrDelete() {
+    }.execute(sql, 1);
+  }
+}