# HG changeset patch
# User Mario Castello <mario.castello@peoplewalking.com>
# Date 1475612498 21600
#      mar oct 04 14:21:38 2016 -0600
# Node ID 51b22728f5a5400ac9c39878a5dcc2ad96f45577
# Parent  5509f70516ab3ca0288b2786426107fb1eca915b
Related to issue 34092: Added automated test

diff --git a/src-test/org/openbravo/test/mobile/quarantine/extmodules/MCA/stockvalidation/I34092_OrderStockValidationMultiReceipt.java b/src-test/org/openbravo/test/mobile/quarantine/extmodules/MCA/stockvalidation/I34092_OrderStockValidationMultiReceipt.java
new file mode 100644
--- /dev/null
+++ b/src-test/org/openbravo/test/mobile/quarantine/extmodules/MCA/stockvalidation/I34092_OrderStockValidationMultiReceipt.java
@@ -0,0 +1,103 @@
+/*
+ *************************************************************************
+ * 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 = MCA
+ *
+ */
+
+package org.openbravo.test.mobile.quarantine.extmodules.MCA.stockvalidation;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.common.selenium.SeleniumHelper;
+import org.openbravo.test.mobile.retail.extmodules.selenium.TestIdExtModules;
+import org.openbravo.test.mobile.retail.extmodules.selenium.terminals.WebPOSExtModulesTerminalHelper;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+
+public class I34092_OrderStockValidationMultiReceipt extends WebPOSExtModulesTerminalHelper {
+
+  public I34092_OrderStockValidationMultiReceipt() {
+    super("VBS1001", "vallblanca", "openbravo");
+  }
+
+  @Test
+  public void test() {
+    boolean isTestSuccessful = false;
+    try {
+      enablePermission(true);
+      enableProperty(false);
+      // first ticket
+      addProduct();
+      changeQuantity();
+      verify(TestIdExtModules.LABEL_RECEIPT_ROW1_QTY, "50");
+      verify(TestIdExtModules.LABEL_RECEIPT_TOTAL_QTY, "50");
+      verify(TestIdExtModules.LABEL_TOTALTOPAY, "7,525.00");
+
+      // second ticket
+      tap(TestIdExtModules.BUTTON_NEWRECEIPT);
+      addProduct();
+      changeQuantity();
+      TestIdExtModules.CONFIRMATION_POPUP.enyoNode().waitUntilIsReady();
+      verify(TestIdExtModules.LABEL_POPUP_TITLE, "Not enough stock");
+      tap(TestIdExtModules.BUTTON_POPUP_CONFIRMATION_OK);
+      verify(TestIdExtModules.LABEL_RECEIPT_ROW1_QTY, "1");
+      verify(TestIdExtModules.LABEL_RECEIPT_TOTAL_QTY, "1");
+      verify(TestIdExtModules.LABEL_TOTALTOPAY, "150.50");
+
+      tap(TestIdExtModules.BUTTON_DELETERECEIPT);
+      tap(TestIdExtModules.BUTTON_DELETERECEIPT_CONFIRM);
+
+      tap(TestIdExtModules.BUTTON_DELETERECEIPT);
+      tap(TestIdExtModules.BUTTON_DELETERECEIPT_CONFIRM);
+      verify(TestIdExtModules.LABEL_TOTALTOPAY, "0.00");
+      enablePermission(false);
+      enableProperty(true);
+      isTestSuccessful = true;
+    } finally {
+      if (!isTestSuccessful) {
+        // Restore changes
+        enablePermission(false);
+        enableProperty(true);
+      }
+    }
+  }
+
+  private void addProduct() {
+    tap(TestIdExtModules.BUTTON_SEARCH);
+    write(TestIdExtModules.FIELD_SEARCH_TEXT, "Avalanche transceiver");
+    tap(TestIdExtModules.BUTTON_SEARCH_EXECUTE);
+    tap(TestIdExtModules.BUTTON_SEARCHPRODUCT_AVALANCHETRANSCEIVEREXT);
+    verify(TestIdExtModules.LABEL_TOTALTOPAY, "150.50");
+  }
+
+  private void changeQuantity() {
+    tap(TestIdPack.BUTTON_KEYPAD_5);
+    tap(TestIdPack.BUTTON_KEYPAD_0);
+    tap(TestIdPack.BUTTON_KEYPAD_QUANTITY);
+  }
+
+  private void enablePermission(final boolean isActive) {
+    SeleniumHelper.executeScript(String
+        .format("OB.MobileApp.model.attributes.permissions['OBPOSSV_EnableStockValidation'] = %s",
+            isActive));
+  }
+
+  private void enableProperty(final boolean isActive) {
+    SeleniumHelper.executeScript(String.format(
+        "OB.MobileApp.model.attributes.obpossv_negativeStockAllowed = %s", isActive));
+  }
+}
