# HG changeset patch
# User Silambarasan Sekar <silambarasan@qualiantech.com>
# Date 1458134165 -19800
#      Wed Mar 16 18:46:05 2016 +0530
# Node ID d2c63e03f1429147c234243d39e5c597c81272de
# Parent  a1278c755b89281f896354a6d5cc93090b504b36
Added Automated test for CrossStore

diff -r a1278c755b89 -r d2c63e03f142 src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/sales/I31592_LayawayInCrossStore.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/sales/I31592_LayawayInCrossStore.java	Wed Mar 16 18:46:05 2016 +0530
@@ -0,0 +1,171 @@
+/*
+ *************************************************************************
+ * 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.BUTTON_RECEIPTLIST_ROW1
+ * 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):  Silambarasan.
+ ************************************************************************
+ */
+
+package org.openbravo.test.mobile.retail.pack.selenium.tests.sales;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.common.selenium.SeleniumHelper;
+import org.openbravo.test.mobile.common.selenium.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.common.selenium.database.DatabaseHelperSelect;
+import org.openbravo.test.mobile.common.selenium.javascript.BackboneHelper;
+import org.openbravo.test.mobile.common.selenium.javascript.TestId;
+import org.openbravo.test.mobile.common.selenium.javascript.APIs.MobileCoreAPI;
+import org.openbravo.test.mobile.common.selenium.terminals.WebPOSTerminalHelper;
+import org.openbravo.test.mobile.common.selenium.utils.ApplicationWindow;
+import org.openbravo.test.mobile.common.selenium.utils.OBConstants;
+import org.openbravo.test.mobile.common.selenium.utils.OBUtils;
+
+public class I31592_LayawayInCrossStore extends WebPOSTerminalHelper {
+
+  private static String orgId;
+  private static String receiptNo;
+
+  @Test
+  public void test() {
+
+    final String VBS1Uri = OBUtils.getCurrentHref();
+    final String PS1Uri = VBS1Uri.replace("VBS1001", "PS-1");
+
+    boolean isTestSuccessful = true;
+
+    try {
+      final String selectSQL = "select ad_org_id from ad_org where name='White Valley Spain S.A'";
+      new DatabaseHelperSelect() {
+        @Override
+        protected void yieldResultSet(final ResultSet rs) throws SQLException {
+          orgId = rs.getString("ad_org_id");
+        }
+      }.execute(selectSQL, 1);
+      logger.info(String.format("Verifying that the database record '%s' is one of the expected",
+          orgId));
+
+      // Create database changes
+      createDatabaseChanges();
+      isTestSuccessful = false;
+
+      // Update Terminal with Database Changes
+      updateTerminalAfterDatabaseChange();
+
+      createLayaway();
+      MobileCoreAPI.localStorageClear();
+
+      logOut();
+
+      // Navigating to PS-1
+      OBUtils.navigate(PS1Uri, ApplicationWindow.LOGIN);
+      login("posets");
+
+      // Setting permission
+
+      setCrossStorePermission("OBPOS_CrossStore_LayawaySel", true);
+
+      completeLayaway();
+
+      OBUtils.navigate(VBS1Uri, ApplicationWindow.LOGIN);
+      logIn();
+
+      restoreDatabaseChanges();
+
+      // Update Terminal with Database Changes
+      updateTerminalAfterDatabaseChange();
+
+      isTestSuccessful = true;
+    } finally {
+      if (!isTestSuccessful) {
+        restoreDatabaseChanges();
+      }
+    }
+
+  }
+
+  private void createDatabaseChanges() {
+    new DatabaseHelperInsertUpdateOrDelete()
+        .execute(
+            String
+                .format(
+                    "Update ad_org Set em_obpos_crossstore_id='%s' where name='Posets Store' or name='Vall Blanca Store'",
+                    orgId), 2);
+
+  }
+
+  private void restoreDatabaseChanges() {
+    // Delete Preference
+    final String restoreSQL = "update ad_org set em_obpos_crossstore_id=NULL where name='Posets Store' or name='Vall Blanca Store'";
+    new DatabaseHelperInsertUpdateOrDelete().execute(restoreSQL, 2);
+
+  }
+
+  private void createLayaway() {
+
+    // 1. Simple layaway
+
+    tap(TestId.BUTTON_RECEIPT_CUSTOMER);
+    write(TestId.FIELD_CUSTOMER_MODAL, "Arturo Montoro");
+    tap(TestId.BUTTON_CUSTOMER_MODAL_SEARCH);
+    tap(TestId.BUTTON_CUSTOMER_SEARCH_ROW1);
+    verify(TestId.BUTTON_RECEIPT_CUSTOMER, "Arturo Montoro");
+
+    tap(TestId.BUTTON_MENU);
+    tap(TestId.BUTTON_MENU_LAYAWAYTHISRECEIPT);
+    verify(TestId.LABEL_RECEIPT_TYPE, "To be laid away");
+    tap(TestId.BUTTON_BROWSE);
+    tap(TestId.BUTTON_CATEGORY_BACKPACKSANDTRAVEL);
+    tap(TestId.BUTTON_PRODUCT_BACKPACKSANDTRAVEL_WHISTLE);
+    receiptNo = BackboneHelper.getDocumentNo();
+
+    verify(TestId.LABEL_TOTALTOPAY, "2.90");
+    tap(TestId.BUTTON_PAY);
+    tap(TestId.BUTTON_LAYAWAY);
+    verify(TestId.LABEL_TOTALTOPAY, "0.00");
+
+  }
+
+  private void completeLayaway() {
+
+    tap(TestId.BUTTON_MENU);
+    tap(TestId.BUTTON_MENU_LAYAWAYS);
+    write(TestId.FIELD_SEARCH_RECEIPT, receiptNo);
+    tap(TestId.BUTTON_RECEIPTS_SEARCH);
+    tap(TestId.BUTTON_VERIFIEDRETURNS_ROW1);
+    tap(TestId.BUTTON_PAY);
+    tap(TestId.BUTTON_PAY_EXACT);
+    tap(TestId.BUTTON_PAY_DONE);
+    verify(TestId.LABEL_TOTALTOPAY, "0.00");
+
+  }
+
+  private void setCrossStorePermission(String selector, Boolean value) {
+    SeleniumHelper.executeScript("OB.MobileApp.model.attributes.permissions." + selector + "="
+        + value + "");
+  }
+
+  private void login(final String newUsername) {
+    TestId.LABEL_LOGIN_OPENBRAVOMOBILE.enyoNode().waitUntilIsReady();
+    OBUtils.pause(OBConstants.WAIT_AFTERWEBPOSLOGO);
+    write(TestId.FIELD_LOGIN_USERNAME, newUsername);
+    write(TestId.FIELD_LOGIN_PASSWORD, "openbravo");
+    tap(TestId.BUTTON_LOGIN);
+    OBUtils.pause(OBConstants.WAIT_AFTERSUCCESSFULLOGIN);
+    TestId.TABLE_PRODUCTS.enyoNode().waitUntilIsReady();
+  }
+
+}
diff -r a1278c755b89 -r d2c63e03f142 src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/sales/I31592_PayOpenTicketsInCrossStore.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/sales/I31592_PayOpenTicketsInCrossStore.java	Wed Mar 16 18:46:05 2016 +0530
@@ -0,0 +1,171 @@
+/*
+ *************************************************************************
+ * 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.BUTTON_RECEIPTLIST_ROW1
+ * 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):  Silambarasan.
+ ************************************************************************
+ */
+
+package org.openbravo.test.mobile.retail.pack.selenium.tests.sales;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.common.selenium.SeleniumHelper;
+import org.openbravo.test.mobile.common.selenium.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.common.selenium.database.DatabaseHelperSelect;
+import org.openbravo.test.mobile.common.selenium.javascript.BackboneHelper;
+import org.openbravo.test.mobile.common.selenium.javascript.TestId;
+import org.openbravo.test.mobile.common.selenium.javascript.APIs.MobileCoreAPI;
+import org.openbravo.test.mobile.common.selenium.terminals.WebPOSTerminalHelper;
+import org.openbravo.test.mobile.common.selenium.utils.ApplicationWindow;
+import org.openbravo.test.mobile.common.selenium.utils.OBConstants;
+import org.openbravo.test.mobile.common.selenium.utils.OBUtils;
+
+public class I31592_PayOpenTicketsInCrossStore extends WebPOSTerminalHelper {
+
+  private static String orgId;
+  private static String receiptNo;
+
+  @Test
+  public void test() {
+
+    final String VBS1Uri = OBUtils.getCurrentHref();
+    final String PS1Uri = VBS1Uri.replace("VBS1001", "PS-1");
+
+    boolean isTestSuccessful = true;
+
+    try {
+      final String selectSQL = "select ad_org_id from ad_org where name='White Valley Spain S.A'";
+      new DatabaseHelperSelect() {
+        @Override
+        protected void yieldResultSet(final ResultSet rs) throws SQLException {
+          orgId = rs.getString("ad_org_id");
+        }
+      }.execute(selectSQL, 1);
+      logger.info(String.format("Verifying that the database record '%s' is one of the expected",
+          orgId));
+
+      // Create database changes
+      createDatabaseChanges();
+      isTestSuccessful = false;
+
+      // Update Terminal with Database Changes
+      updateTerminalAfterDatabaseChange();
+
+      createLayaway();
+      MobileCoreAPI.localStorageClear();
+
+      logOut();
+
+      // Navigating to PS-1
+      OBUtils.navigate(PS1Uri, ApplicationWindow.LOGIN);
+      login("posets");
+
+      // Setting permission
+
+      setCrossStorePermission("OBPOS_CrossStore_PayopenSel", true);
+
+      completePayOpen();
+
+      OBUtils.navigate(VBS1Uri, ApplicationWindow.LOGIN);
+      logIn();
+
+      restoreDatabaseChanges();
+
+      // Update Terminal with Database Changes
+      updateTerminalAfterDatabaseChange();
+
+      isTestSuccessful = true;
+    } finally {
+      if (!isTestSuccessful) {
+        restoreDatabaseChanges();
+      }
+    }
+
+  }
+
+  private void createDatabaseChanges() {
+    new DatabaseHelperInsertUpdateOrDelete()
+        .execute(
+            String
+                .format(
+                    "Update ad_org Set em_obpos_crossstore_id='%s' where name='Posets Store' or name='Vall Blanca Store'",
+                    orgId), 2);
+
+  }
+
+  private void restoreDatabaseChanges() {
+    // Delete Preference
+    final String restoreSQL = "update ad_org set em_obpos_crossstore_id=NULL where name='Posets Store' or name='Vall Blanca Store'";
+    new DatabaseHelperInsertUpdateOrDelete().execute(restoreSQL, 2);
+
+  }
+
+  private void createLayaway() {
+
+    // 1. Simple layaway
+
+    tap(TestId.BUTTON_RECEIPT_CUSTOMER);
+    write(TestId.FIELD_CUSTOMER_MODAL, "Arturo Montoro");
+    tap(TestId.BUTTON_CUSTOMER_MODAL_SEARCH);
+    tap(TestId.BUTTON_CUSTOMER_SEARCH_ROW1);
+    verify(TestId.BUTTON_RECEIPT_CUSTOMER, "Arturo Montoro");
+
+    tap(TestId.BUTTON_MENU);
+    tap(TestId.BUTTON_MENU_LAYAWAYTHISRECEIPT);
+    verify(TestId.LABEL_RECEIPT_TYPE, "To be laid away");
+    tap(TestId.BUTTON_BROWSE);
+    tap(TestId.BUTTON_CATEGORY_BACKPACKSANDTRAVEL);
+    tap(TestId.BUTTON_PRODUCT_BACKPACKSANDTRAVEL_WHISTLE);
+    receiptNo = BackboneHelper.getDocumentNo();
+
+    verify(TestId.LABEL_TOTALTOPAY, "2.90");
+    tap(TestId.BUTTON_PAY);
+    tap(TestId.BUTTON_LAYAWAY);
+    verify(TestId.LABEL_TOTALTOPAY, "0.00");
+
+  }
+
+  private void completePayOpen() {
+
+    tap(TestId.BUTTON_MENU);
+    tap(TestId.BUTTON_MENU_PAYOPENTICKETS);
+    write(TestId.FIELD_SEARCH_MULTIORDERS_TEXT, receiptNo);
+    tap(TestId.BUTTON_POPUP_OPENTICKETS_SEARCH);
+    tap(TestId.BUTTON_POPUP_OPENTICKETS_ROW1);
+    tap(TestId.BUTTON_POPUP_OPENTICKETS_DONE);
+    tap(TestId.BUTTON_PAY_EXACT);
+    tap(TestId.BUTTON_PAY_DONE);
+    verify(TestId.LABEL_TOTALTOPAY, "0.00");
+
+  }
+
+  private void setCrossStorePermission(String selector, Boolean value) {
+    SeleniumHelper.executeScript("OB.MobileApp.model.attributes.permissions." + selector + "="
+        + value + "");
+  }
+
+  private void login(final String newUsername) {
+    TestId.LABEL_LOGIN_OPENBRAVOMOBILE.enyoNode().waitUntilIsReady();
+    OBUtils.pause(OBConstants.WAIT_AFTERWEBPOSLOGO);
+    write(TestId.FIELD_LOGIN_USERNAME, newUsername);
+    write(TestId.FIELD_LOGIN_PASSWORD, "openbravo");
+    tap(TestId.BUTTON_LOGIN);
+    OBUtils.pause(OBConstants.WAIT_AFTERSUCCESSFULLOGIN);
+    TestId.TABLE_PRODUCTS.enyoNode().waitUntilIsReady();
+  }
+
+}
diff -r a1278c755b89 -r d2c63e03f142 src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/sales/I31592_ReceiptsInCrossStore.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/sales/I31592_ReceiptsInCrossStore.java	Wed Mar 16 18:46:05 2016 +0530
@@ -0,0 +1,166 @@
+/*
+ *************************************************************************
+ * 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.BUTTON_RECEIPTLIST_ROW1
+ * 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):  Silambarasan.
+ ************************************************************************
+ */
+
+package org.openbravo.test.mobile.retail.pack.selenium.tests.sales;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.common.selenium.SeleniumHelper;
+import org.openbravo.test.mobile.common.selenium.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.common.selenium.database.DatabaseHelperSelect;
+import org.openbravo.test.mobile.common.selenium.javascript.BackboneHelper;
+import org.openbravo.test.mobile.common.selenium.javascript.TestId;
+import org.openbravo.test.mobile.common.selenium.javascript.APIs.MobileCoreAPI;
+import org.openbravo.test.mobile.common.selenium.terminals.WebPOSTerminalHelper;
+import org.openbravo.test.mobile.common.selenium.utils.ApplicationWindow;
+import org.openbravo.test.mobile.common.selenium.utils.OBConstants;
+import org.openbravo.test.mobile.common.selenium.utils.OBUtils;
+
+public class I31592_ReceiptsInCrossStore extends WebPOSTerminalHelper {
+
+  private static String orgId;
+  private static String receiptNo;
+
+  @Test
+  public void test() {
+
+    final String VBS1Uri = OBUtils.getCurrentHref();
+    final String PS1Uri = VBS1Uri.replace("VBS1001", "PS-1");
+
+    boolean isTestSuccessful = true;
+
+    try {
+      final String selectSQL = "select ad_org_id from ad_org where name='White Valley Spain S.A'";
+      new DatabaseHelperSelect() {
+        @Override
+        protected void yieldResultSet(final ResultSet rs) throws SQLException {
+          orgId = rs.getString("ad_org_id");
+        }
+      }.execute(selectSQL, 1);
+      logger.info(String.format("Verifying that the database record '%s' is one of the expected",
+          orgId));
+
+      // Create database changes
+      createDatabaseChanges();
+
+      isTestSuccessful = false;
+
+      // Update Terminal with Database Changes
+      updateTerminalAfterDatabaseChange();
+
+      createLayaway();
+      MobileCoreAPI.localStorageClear();
+
+      logOut();
+
+      // Navigating to PS-1
+      OBUtils.navigate(PS1Uri, ApplicationWindow.LOGIN);
+      login("posets");
+
+      // Setting permission
+
+      setCrossStorePermission("OBPOS_CrossStore_ReceiptSel", true);
+
+      completeLayaway();
+
+      OBUtils.navigate(VBS1Uri, ApplicationWindow.LOGIN);
+      logIn();
+
+      restoreDatabaseChanges();
+
+      // Update Terminal with Database Changes
+      updateTerminalAfterDatabaseChange();
+
+      isTestSuccessful = true;
+    } finally {
+      if (!isTestSuccessful) {
+        restoreDatabaseChanges();
+      }
+    }
+
+  }
+
+  private void createDatabaseChanges() {
+    new DatabaseHelperInsertUpdateOrDelete()
+        .execute(
+            String
+                .format(
+                    "Update ad_org Set em_obpos_crossstore_id='%s' where name='Posets Store' or name='Vall Blanca Store'",
+                    orgId), 2);
+
+  }
+
+  private void restoreDatabaseChanges() {
+    // Delete Preference
+    final String restoreSQL = "update ad_org set em_obpos_crossstore_id=NULL where name='Posets Store' or name='Vall Blanca Store'";
+    new DatabaseHelperInsertUpdateOrDelete().execute(restoreSQL, 2);
+
+  }
+
+  private void createLayaway() {
+
+    // 1. Simple layaway
+
+    tap(TestId.BUTTON_RECEIPT_CUSTOMER);
+    write(TestId.FIELD_CUSTOMER_MODAL, "Arturo Montoro");
+    tap(TestId.BUTTON_CUSTOMER_MODAL_SEARCH);
+    tap(TestId.BUTTON_CUSTOMER_SEARCH_ROW1);
+    verify(TestId.BUTTON_RECEIPT_CUSTOMER, "Arturo Montoro");
+    tap(TestId.BUTTON_BROWSE);
+    tap(TestId.BUTTON_CATEGORY_BACKPACKSANDTRAVEL);
+    tap(TestId.BUTTON_PRODUCT_BACKPACKSANDTRAVEL_WHISTLE);
+    receiptNo = BackboneHelper.getDocumentNo();
+
+    verify(TestId.LABEL_TOTALTOPAY, "2.90");
+    tap(TestId.BUTTON_PAY);
+    tap(TestId.BUTTON_PAY_EXACT);
+    tap(TestId.BUTTON_PAY_DONE);
+
+    verify(TestId.LABEL_TOTALTOPAY, "0.00");
+
+  }
+
+  private void completeLayaway() {
+
+    tap(TestId.BUTTON_MENU);
+    tap(TestId.BUTTON_MENU_RECEIPTS);
+    write(TestId.FIELD_SEARCH_RECEIPT, receiptNo);
+    tap(TestId.BUTTON_RECEIPTS_SEARCH);
+    verify(TestId.LABEL_VERIFIEDRETURNS_ROW1_TITLE, receiptNo + " - Arturo Montoro");
+
+  }
+
+  private void setCrossStorePermission(String selector, Boolean value) {
+    SeleniumHelper.executeScript("OB.MobileApp.model.attributes.permissions." + selector + "="
+        + value + "");
+  }
+
+  private void login(final String newUsername) {
+    TestId.LABEL_LOGIN_OPENBRAVOMOBILE.enyoNode().waitUntilIsReady();
+    OBUtils.pause(OBConstants.WAIT_AFTERWEBPOSLOGO);
+    write(TestId.FIELD_LOGIN_USERNAME, newUsername);
+    write(TestId.FIELD_LOGIN_PASSWORD, "openbravo");
+    tap(TestId.BUTTON_LOGIN);
+    OBUtils.pause(OBConstants.WAIT_AFTERSUCCESSFULLOGIN);
+    TestId.TABLE_PRODUCTS.enyoNode().waitUntilIsReady();
+  }
+
+}
