Related to issue 40490: added automated test
authorAlejandro <alekosmp86@gmail.com>
Thu, 11 Apr 2019 15:22:43 -0400
changeset 8459 71f8d16e049a
parent 8458 799596a77295
child 8460 8527935dbfc5
Related to issue 40490: added automated test
src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/sessions/openstoretill/I40490_VerifyTillDifferenceNotDeletedWhenCacheIsCleared.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/extmodules/selenium/tests/sessions/openstoretill/I40490_VerifyTillDifferenceNotDeletedWhenCacheIsCleared.java	Thu Apr 11 15:22:43 2019 -0400
@@ -0,0 +1,141 @@
+/*
+ *************************************************************************
+ * 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.extmodules.selenium.tests.sessions.openstoretill;
+
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.core.selenium.SeleniumHelper;
+import org.openbravo.test.mobile.core.utils.OBWait;
+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.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.retail.mobilecore.javascript.MobileCoreAPI;
+import org.openbravo.test.mobile.retail.mobilecore.javascript.SynchronizationMonitor;
+import org.openbravo.test.mobile.retail.mobilecore.selenium.TestIdCore;
+import org.openbravo.test.mobile.retail.mobilecore.utils.ApplicationWindow;
+import org.openbravo.test.mobile.retail.pack.API.WebPOSAPI;
+import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
+
+public class I40490_VerifyTillDifferenceNotDeletedWhenCacheIsCleared
+    extends WebPOSExtModulesTerminalHelper {
+  private final String YS_CASH_DIFFERENCES = "806798E644E34262B78E7E1B6CEBF93F";
+  private final String GL_ITEM_CASH_DIFFERENCES = "28494DB26CD54D95A19A66B4EE571D96";
+  private final String YS_POSTERMINAL_TYPE_ID = "C06D12232C024E0FAB5FBD6049C7F020";
+  private final String CASH_PAYMENT_TYPE_ID = "BD225CB17C674DAB81D8D86FD6A574CB";
+
+  private String PRODUCT_NAME = "Hiking boots";
+
+  @Test
+  public void test() {
+    WebPOSAPI.cleanCashup(this);
+    waitUntilCertainWindowIsReached(ApplicationWindow.LOGIN);
+
+    write(TestIdExtModules.FIELD_LOGIN_USERNAME, "vallblanca");
+    write(TestIdExtModules.FIELD_LOGIN_PASSWORD, "openbravo");
+    tap(TestIdExtModules.BUTTON_LOGIN);
+
+    waitUntilCertainWindowIsReached(ApplicationWindow.OPENTILLCOUNTCASH);
+    tap(TestIdExtModules.BUTTON_CASHUP_COUNTCASH_50);
+    verify(TestIdExtModules.BUTTON_SESSIONS_OPENTILL_DONE, "Approve difference");
+    tap(TestIdExtModules.BUTTON_SESSIONS_OPENTILL_DONE);
+    verify(TestIdExtModules.LABEL_POPUP_TITLE, "Good job!");
+    tap(TestIdExtModules.BUTTON_POPUP_OK);
+    verify(TestIdExtModules.LABEL_TOTALTOPAY, "0.00");
+
+    addProduct(PRODUCT_NAME);
+    tap(TestIdPack.BUTTON_PAY);
+    tap(TestIdPack.BUTTON_PAY_EXACT);
+    tap(TestIdPack.BUTTON_PAY_DONE);
+    SynchronizationMonitor.waitUntilDataIsInTheServer();
+
+    tap(TestIdCore.BUTTON_MENU);
+    tap(TestIdPack.BUTTON_MENU_CASHMANAGEMENT);
+    isVisible(TestIdPack.BUTTON_CASHMANAGEMENT_CASHDEPOSITBUTTON, true);
+    write(TestIdPack.INPUT_KEYPAD_CASHMGMT_EDITBOX, "50");
+    tap(TestIdPack.BUTTON_CASHMANAGEMENT_CASHDEPOSITBUTTON);
+    isVisible(TestIdPack.BUTTON_SELECTDEPOSIT_BACOFFICEVBS, true);
+    tap(TestIdPack.BUTTON_SELECTDEPOSIT_BACOFFICEVBS);
+    tap(TestIdPack.BUTTON_CASHMANAGEMENT_DONE);
+    tap(TestIdPack.BUTTON_POPUP_OK);
+    SynchronizationMonitor.waitUntilDataIsInTheServer();
+
+    verifyLocalDatabase();
+
+    // clear cache and reload
+    MobileCoreAPI.localStorageClear();
+    reload();
+    SynchronizationMonitor.waitUntilDataIsInTheServer();
+
+    verifyLocalDatabase();
+  }
+
+  @Override
+  public void beforeWithReload() {
+    setGLItemForTillDifferences(GL_ITEM_CASH_DIFFERENCES);
+  }
+
+  @Override
+  public void afterWithReload() {
+    setGLItemForTillDifferences(YS_CASH_DIFFERENCES);
+  }
+
+  private void verifyLocalDatabase() {
+    // verify the local database has 2 records in cashmanagement table
+    StringBuilder queryFunction = new StringBuilder();
+    queryFunction.append("OB.Dal.find(OB.Model.CashManagement, ");
+    queryFunction.append("{}, function success(r){OB.UTIL.Test40490 = r.length;}, ");
+    queryFunction.append("function e(){})");
+    SeleniumHelper.executeScriptWithReturn(queryFunction.toString());
+    new OBWait() {
+      @Override
+      protected boolean until(int currentIteration) {
+        Long recordsCount = (Long) SeleniumHelper.executeScriptWithReturn("OB.UTIL.Test40490");
+        return recordsCount == 2L;
+      }
+
+      @Override
+      protected void timeout() {
+        fail("There should have been 2 records in CashManagement local table");
+      }
+    };
+  }
+
+  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 setGLItemForTillDifferences(String glItemDiff) {
+    String sql = String.format(
+        "update obpos_app_payment_type set em_poss_glitem_tilldiff = '%s' where obpos_app_payment_type_id = '%s' and obpos_terminaltype_id = '%s'",
+        glItemDiff, CASH_PAYMENT_TYPE_ID, YS_POSTERMINAL_TYPE_ID);
+
+    new DatabaseHelperInsertUpdateOrDelete() {
+    }.execute(sql, 1);
+  }
+}