Related to issue 39841: added automated test
authorAlejandro <alekosmp86@gmail.com>
Thu, 10 Jan 2019 13:00:34 -0500
changeset 8047 b8fa1964c3b4
parent 8046 693d74e30a3c
child 8048 f56706bc6bab
Related to issue 39841: added automated test
src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/discountsandpromotions/I39841_VerifyTicketPaymentIfApprovalForDiscretionaryDiscount.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/discountsandpromotions/I39841_VerifyTicketPaymentIfApprovalForDiscretionaryDiscount.java	Thu Jan 10 13:00:34 2019 -0500
@@ -0,0 +1,114 @@
+/*
+ *************************************************************************
+ * 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@gmail.com
+ *
+ */
+
+package org.openbravo.test.mobile.retail.pack.selenium.tests.discountsandpromotions;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.retail.mobilecore.javascript.SynchronizationMonitor;
+import org.openbravo.test.mobile.retail.mobilecore.utils.RetailUtils;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+import org.openbravo.test.mobile.retail.pack.selenium.terminals.WebPOSTerminalHelper;
+
+public class I39841_VerifyTicketPaymentIfApprovalForDiscretionaryDiscount extends
+    WebPOSTerminalHelper {
+  final static String DISCOUNT_APPROVAL_OB_PREF_ID = RetailUtils.getRandomUUID();
+  final static String DISCOUNT_APPROVAL_VB_PREF_ID = RetailUtils.getRandomUUID();
+  final static String DISCRETIONARY_DISCOUNT_APPROVAL_PREF_NAME = "OBPOS_approval.discounts";
+  final static String NORTH_EAST_ZONE_ORG_ID = "14B1927026BE471E9B85FE699BCA61C2";
+  final static String OPENBRAVO_USER_ID = "100";
+  final static String VALLBLANCA_STORE_USER_ID = "3073EDF96A3C42CC86C7069E379522D2";
+  final static String PRODUCT_NAME = "Avalanche transceiver";
+  final static String DISCOUNT_ID = "0C681EECD8974D56921D47DBFFF5A22C";
+  final static String DISCOUNT_NAME = "-- Employee Discount - 40%";
+
+  @Test
+  public void test() {
+    addProduct(PRODUCT_NAME);
+    tap(TestIdPack.BUTTON_RECEIPT_ROW1);
+    tap(TestIdPack.BUTTON_KEYPAD_DISCOUNT);
+    tap(TestIdPack.BUTTON_RECEIPTDISCOUNTS_OVERRIDE);
+    tap(TestIdPack.BUTTON_RECEIPTDISCOUNTS_CHECKAPPLYALL);
+    tap(TestIdPack.BUTTON_RECEIPTDISCOUNTS_APPLY);
+    verify(TestIdPack.LABEL_RECEIPT_ROW1_DISCOUNTNAME, DISCOUNT_NAME);
+    tap(TestIdPack.BUTTON_PAY);
+    isVisible(TestIdPack.LABEL_APPROVAL_POPUP_TITLE, true);
+    verify(TestIdPack.LABEL_APPROVAL_POPUP_TITLE, "Approval Required");
+    write(TestIdPack.FIELD_APPROVAL_POPUP_USERNAME, "Openbravo");
+    write(TestIdPack.FIELD_APPROVAL_POPUP_PASSWORD, "openbravo");
+    tap(TestIdPack.BUTTON_APPROVAL_POPUP_APPROVE);
+    isVisible(TestIdPack.LABEL_RECEIPT_PAY_REMAINING, true);
+    verify(TestIdPack.LABEL_RECEIPT_PAY_REMAINING, "90.30€");
+    tap(TestIdPack.BUTTON_PAY_EXACT);
+    tap(TestIdPack.BUTTON_PAY_DONE);
+    SynchronizationMonitor.waitUntilDataIsInTheServer();
+  }
+
+  public void beforeWithReload() {
+    setActiveDiscount(true);
+    setPreferenceValue(DISCOUNT_APPROVAL_OB_PREF_ID, DISCRETIONARY_DISCOUNT_APPROVAL_PREF_NAME,
+        NORTH_EAST_ZONE_ORG_ID, OPENBRAVO_USER_ID, true, true);
+    setPreferenceValue(DISCOUNT_APPROVAL_VB_PREF_ID, DISCRETIONARY_DISCOUNT_APPROVAL_PREF_NAME,
+        null, VALLBLANCA_STORE_USER_ID, false, true);
+  }
+
+  public void afterWithReload() {
+    setActiveDiscount(false);
+    setPreferenceValue(DISCOUNT_APPROVAL_OB_PREF_ID, DISCRETIONARY_DISCOUNT_APPROVAL_PREF_NAME,
+        NORTH_EAST_ZONE_ORG_ID, OPENBRAVO_USER_ID, true, false);
+    setPreferenceValue(DISCOUNT_APPROVAL_VB_PREF_ID, DISCRETIONARY_DISCOUNT_APPROVAL_PREF_NAME,
+        null, VALLBLANCA_STORE_USER_ID, false, false);
+  }
+
+  private void setPreferenceValue(String preferenceId, String preferenceName,
+      String visibleAtOrgId, String visibleAtUserId, boolean value, boolean active) {
+    String sql;
+    if (active) {
+      sql = String
+          .format(
+              "INSERT INTO ad_preference(ad_preference_id, ad_client_id, ad_org_id, isactive, createdby, updatedby, value, property, ispropertylist, selected, "
+                  + "visibleat_org_id, ad_user_id) VALUES ('%s', '0', '0', to_char('Y'),'100', '100', '%s', '%s', to_char('Y'), to_char('Y'), %s, '%s')",
+              preferenceId, value ? "Y" : "N", preferenceName, visibleAtOrgId == null ? "NULL"
+                  : "'" + visibleAtOrgId + "'", visibleAtUserId);
+    } else {
+      sql = String.format("DELETE FROM ad_preference where ad_preference_id = '%s'", preferenceId);
+    }
+    new DatabaseHelperInsertUpdateOrDelete().execute(sql, 1);
+  }
+
+  private void setActiveDiscount(boolean active) {
+    String sql = String.format("update m_offer set isactive = '%s' where m_offer_id = '%s'",
+        active ? "Y" : "N", DISCOUNT_ID);
+
+    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);
+  }
+}
\ No newline at end of file