diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CenterListFragmentTest.java b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CenterListFragmentTest.kt old mode 100755 new mode 100644 similarity index 55% rename from mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CenterListFragmentTest.java rename to mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CenterListFragmentTest.kt index c3d0c788aa0..f88404bfe8f --- a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CenterListFragmentTest.java +++ b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CenterListFragmentTest.kt @@ -1,79 +1,62 @@ -package com.mifos.mifosxdroid.tests; +package com.mifos.mifosxdroid.tests -import android.test.ActivityInstrumentationTestCase2; -import android.test.ViewAsserts; -import android.test.suitebuilder.annotation.SmallTest; -import android.test.suitebuilder.annotation.Suppress; -import android.util.Log; -import android.view.KeyEvent; -import android.view.View; -import android.widget.ListView; - -import com.mifos.mifosxdroid.online.CentersActivity; +import android.test.ActivityInstrumentationTestCase2 +import android.util.Log +import android.view.KeyEvent +import android.view.View +import android.widget.ListView /** * Created by Gabriel Esteban on 12/12/14. */ @Suppress // TODO: Fix NPE and Rewrite Test with new Documentation -public class CenterListFragmentTest extends ActivityInstrumentationTestCase2 { - - public final String LOG_TAG = getClass().getSimpleName(); - - CentersActivity centersActivity; - - ListView lv_centers_list; - - public CenterListFragmentTest() { - super(CentersActivity.class); - } - @Override - protected void setUp() throws Exception { - super.setUp(); - centersActivity = getActivity(); +class CenterListFragmentTest : ActivityInstrumentationTestCase2( + CentersActivity::class.java +) { + val LOG_TAG: String = javaClass.getSimpleName() + var centersActivity: CentersActivity? = null + var lv_centers_list: ListView? = null + @Throws(Exception::class) + protected fun setUp() { + super.setUp() + centersActivity = getActivity() //API wait for charging all centers - Thread.sleep(6000); + Thread.sleep(6000) //instantiating view objects //lv_centers_list = (ListView) centersActivity.findViewById(R.id.lv_center_list); } @SmallTest - public void testViewsAreNotNull() { - assertNotNull(lv_centers_list); + fun testViewsAreNotNull() { + assertNotNull(lv_centers_list) } @SmallTest - public void testViewsAreOnTheScreen() { - final View decorView = centersActivity.getWindow().getDecorView(); - - ViewAsserts.assertOnScreen(decorView, lv_centers_list); + fun testViewsAreOnTheScreen() { + val decorView: View = centersActivity.getWindow().getDecorView() + ViewAsserts.assertOnScreen(decorView, lv_centers_list) } @SmallTest - public void testOpenClientActivity() throws InterruptedException { + @Throws(InterruptedException::class) + fun testOpenClientActivity() { try { - runTestOnUiThread(new Runnable() { - @Override - public void run() { - lv_centers_list.performItemClick(null, 0, 0); - } - }); - } catch (Throwable throwable) { - Log.d(LOG_TAG, throwable.getMessage()); + runTestOnUiThread(Runnable { lv_centers_list!!.performItemClick(null, 0, 0) }) + } catch (throwable: Throwable) { + Log.d(LOG_TAG, throwable.message!!) } //if something went wrong instantiating the group fragment, performItemClick will throw // and exception //waiting for the API - Thread.sleep(2000); - - this.sendKeys(KeyEvent.KEYCODE_BACK); + Thread.sleep(2000) + this.sendKeys(KeyEvent.KEYCODE_BACK) //waiting again for the API - Thread.sleep(6000); + Thread.sleep(6000) } - /** * - open center list, check title is "Centers" * - open a center and check title is "Groups" @@ -118,4 +101,4 @@ public void testCorrectTitles() throws InterruptedException { }*/ -} +} \ No newline at end of file diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientChargesTest.java b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientChargesTest.java deleted file mode 100644 index e2c6df65caa..00000000000 --- a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientChargesTest.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ - -package com.mifos.mifosxdroid.tests; - -import android.content.Intent; -import androidx.fragment.app.Fragment; -import androidx.appcompat.view.menu.ActionMenuItem; -import android.test.ActivityInstrumentationTestCase2; -import android.test.suitebuilder.annotation.MediumTest; -import android.view.KeyEvent; - -import com.mifos.mifosxdroid.R; -import com.mifos.mifosxdroid.dialogfragments.chargedialog.ChargeDialogFragment; -import com.mifos.mifosxdroid.online.ClientActivity; -import com.mifos.mifosxdroid.online.clientcharge.ClientChargeFragment; -import com.mifos.mifosxdroid.online.clientdetails.ClientDetailsFragment; -import com.mifos.utils.Constants; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.clearText; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.action.ViewActions.typeText; -import static androidx.test.espresso.matcher.ViewMatchers.withId; - -/** - * Created by ahmed fathy on 10/4/16. - */ -public class ClientChargesTest extends ActivityInstrumentationTestCase2 { - - /* fields */ - ClientActivity activity; - - public ClientChargesTest() { - super(ClientActivity.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - // set the intent with the user id - Intent intent = new Intent(); - intent.putExtra(Constants.CLIENT_ID, 1); - setActivityIntent(intent); - activity = getActivity(); - } - - /** - * open client activity - * open charges - * check the charges fragment is there - */ - @MediumTest - public void testChargesFragmentVisible() throws InterruptedException { - - // wait for the API - Thread.sleep(3000); - openCharges(); - Thread.sleep(2000); - - // check the fragment is there - ClientChargeFragment clientChargesFragment = - (ClientChargeFragment) activity - .getSupportFragmentManager() - .findFragmentById(R.id.container); - assertNotNull(clientChargesFragment); - assertTrue(clientChargesFragment.isAdded()); - } - - /** - * opens client activity - * opens charges - * chooses create new charge - * checks the ChargeDialogFragment is there - */ - @MediumTest - public void testCreateChargesVisible() throws InterruptedException { - - // wait for the API - Thread.sleep(3000); - openCreateNewCharge(); - Thread.sleep(2000); - - // check the fragment is there - ChargeDialogFragment chargeDialogFragment = - (ChargeDialogFragment) activity - .getSupportFragmentManager() - .findFragmentByTag("Charge Dialog Fragment"); - assertNotNull(chargeDialogFragment); - assertTrue(chargeDialogFragment.isAdded()); - } - - /** - * opens client activity - * opens charges - * chooses create new charge - * enter the new charge details - * press submit - */ - public void testCreateNewCharge() throws InterruptedException { - - // open the dialog - openCreateNewCharge(); - ChargeDialogFragment chargeDialogFragment = - (ChargeDialogFragment) activity - .getSupportFragmentManager() - .findFragmentByTag("Charge Dialog Fragment"); - - // enter the date - onView(withId(R.id.amount_due_charge)).perform(typeText("12")); - onView(withId(R.id.et_date)).perform(clearText()); - onView(withId(R.id.et_date)).perform(typeText("08-04-2018")); - - // press save - onView(withId(R.id.bt_save_charge)).perform(click()); - Thread.sleep(2000); - - } - - /** - * open charges fragment by choosing the "charges" options menu item - */ - private void openCharges() { - ClientDetailsFragment clientDetailsFragment = - (ClientDetailsFragment) activity - .getSupportFragmentManager() - .findFragmentById(R.id.container); - getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU); - chooseOptionItem(clientDetailsFragment, R.id.charges); - } - - /** - * open charges fragment then choose the "new" options menu item - */ - private void openCreateNewCharge() throws InterruptedException { - openCharges(); - Thread.sleep(2000); - - ClientChargeFragment clientChargeFragment = (ClientChargeFragment) activity - .getSupportFragmentManager() - .findFragmentById(R.id.container); - getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU); - chooseOptionItem(clientChargeFragment, ClientChargeFragment.MENU_ITEM_ADD_NEW_CHARGES); - } - - /** - * a work around to choose from an options menu made from the fragment not the activity - * so getInstrumentation().invokeMenuActionSync(getActivity(), R.id.charges, 0) wont work - */ - public void chooseOptionItem(Fragment fragment, int id) { - ActionMenuItem item = new ActionMenuItem(activity, 0, id, 0, 0, ""); - fragment.onOptionsItemSelected(item); - } - -} diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientChargesTest.kt b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientChargesTest.kt new file mode 100644 index 00000000000..5c0194dabe6 --- /dev/null +++ b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientChargesTest.kt @@ -0,0 +1,137 @@ +/* + * This project is licensed under the open source MPL V2. + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.mifosxdroid.tests + +import android.view.KeyEvent +import androidx.fragment.app.Fragment +import com.mifos.mifosxdroid.R +import com.mifos.utils.Constants + +/** + * Created by ahmed fathy on 10/4/16. + */ +class ClientChargesTest : ActivityInstrumentationTestCase2( + ClientActivity::class.java +) { + /* fields */ + var activity: ClientActivity? = null + @Throws(Exception::class) + protected fun setUp() { + super.setUp() + + // set the intent with the user id + val intent = Intent() + intent.putExtra(Constants.CLIENT_ID, 1) + setActivityIntent(intent) + activity = getActivity() + } + + /** + * open client activity + * open charges + * check the charges fragment is there + */ + @MediumTest + @Throws(InterruptedException::class) + fun testChargesFragmentVisible() { + + // wait for the API + Thread.sleep(3000) + openCharges() + Thread.sleep(2000) + + // check the fragment is there + val clientChargesFragment: ClientChargeFragment = activity + .getSupportFragmentManager() + .findFragmentById(R.id.container) as ClientChargeFragment + assertNotNull(clientChargesFragment) + assertTrue(clientChargesFragment.isAdded()) + } + + /** + * opens client activity + * opens charges + * chooses create new charge + * checks the ChargeDialogFragment is there + */ + @MediumTest + @Throws(InterruptedException::class) + fun testCreateChargesVisible() { + + // wait for the API + Thread.sleep(3000) + openCreateNewCharge() + Thread.sleep(2000) + + // check the fragment is there + val chargeDialogFragment: ChargeDialogFragment = activity + .getSupportFragmentManager() + .findFragmentByTag("Charge Dialog Fragment") as ChargeDialogFragment + assertNotNull(chargeDialogFragment) + assertTrue(chargeDialogFragment.isAdded()) + } + + /** + * opens client activity + * opens charges + * chooses create new charge + * enter the new charge details + * press submit + */ + @Throws(InterruptedException::class) + fun testCreateNewCharge() { + + // open the dialog + openCreateNewCharge() + val chargeDialogFragment: ChargeDialogFragment = activity + .getSupportFragmentManager() + .findFragmentByTag("Charge Dialog Fragment") as ChargeDialogFragment + + // enter the date + Espresso.onView(ViewMatchers.withId(R.id.amount_due_charge)) + .perform(ViewActions.typeText("12")) + Espresso.onView(ViewMatchers.withId(R.id.et_date)).perform(ViewActions.clearText()) + Espresso.onView(ViewMatchers.withId(R.id.et_date)) + .perform(ViewActions.typeText("08-04-2018")) + + // press save + Espresso.onView(ViewMatchers.withId(R.id.bt_save_charge)).perform(ViewActions.click()) + Thread.sleep(2000) + } + + /** + * open charges fragment by choosing the "charges" options menu item + */ + private fun openCharges() { + val clientDetailsFragment: ClientDetailsFragment = activity + .getSupportFragmentManager() + .findFragmentById(R.id.container) as ClientDetailsFragment + getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU) + chooseOptionItem(clientDetailsFragment, R.id.charges) + } + + /** + * open charges fragment then choose the "new" options menu item + */ + @Throws(InterruptedException::class) + private fun openCreateNewCharge() { + openCharges() + Thread.sleep(2000) + val clientChargeFragment: ClientChargeFragment = activity + .getSupportFragmentManager() + .findFragmentById(R.id.container) as ClientChargeFragment + getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU) + chooseOptionItem(clientChargeFragment, ClientChargeFragment.MENU_ITEM_ADD_NEW_CHARGES) + } + + /** + * a work around to choose from an options menu made from the fragment not the activity + * so getInstrumentation().invokeMenuActionSync(getActivity(), R.id.charges, 0) wont work + */ + fun chooseOptionItem(fragment: Fragment, id: Int) { + val item = ActionMenuItem(activity, 0, id, 0, 0, "") + fragment.onOptionsItemSelected(item) + } +} \ No newline at end of file diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientDetailsFragmentTest.java b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientDetailsFragmentTest.java deleted file mode 100755 index dc9003597cc..00000000000 --- a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientDetailsFragmentTest.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.mifos.mifosxdroid.tests; - -import android.content.Intent; -import android.test.ActivityInstrumentationTestCase2; -import android.test.ViewAsserts; -import android.test.suitebuilder.annotation.SmallTest; -import android.test.suitebuilder.annotation.Suppress; -import android.view.KeyEvent; -import android.view.View; -import android.widget.ImageView; -import android.widget.RelativeLayout; -import android.widget.TableLayout; -import android.widget.TextView; - -import com.mifos.mifosxdroid.R; -import com.mifos.mifosxdroid.online.ClientActivity; -import com.mifos.mifosxdroid.online.clientdetails.ClientDetailsFragment; -import com.mifos.utils.Constants; -import com.mifos.utils.FragmentConstants; - -/** - * Created by Gabriel Esteban on 07/12/14. - */ -@Suppress // TODO: Fix NPE -public class ClientDetailsFragmentTest extends ActivityInstrumentationTestCase2 { - - ClientActivity clientActivity; - ClientDetailsFragment detailsFragment; - - ImageView iv_client_image; - TextView tv_full_name; - TableLayout tbl_client_details; - RelativeLayout loans, savings, recurring; - - public ClientDetailsFragmentTest() { - super(ClientActivity.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - Intent clientActivityIntent = new Intent(); - clientActivityIntent.putExtra(Constants.CLIENT_ID, "000000001"); - setActivityIntent(clientActivityIntent); - clientActivity = getActivity(); - //waiting for the API - Thread.sleep(2000); - - detailsFragment = (ClientDetailsFragment) getActivity().getSupportFragmentManager() - .findFragmentByTag(FragmentConstants.FRAG_CLIENT_DETAILS); - - iv_client_image = (ImageView) clientActivity.findViewById(R.id.iv_clientImage); - tv_full_name = (TextView) clientActivity.findViewById(R.id.tv_fullName); - tbl_client_details = (TableLayout) clientActivity.findViewById(R.id.tbl_clientDetails); - loans = (RelativeLayout) clientActivity.findViewById(R.id.account_accordion_section_loans); - savings = (RelativeLayout) clientActivity.findViewById(R.id - .account_accordion_section_savings); - recurring = (RelativeLayout) clientActivity.findViewById(R.id - .account_accordion_section_recurring); - } - - @SmallTest - public void testFragmentIsNotNull() { - assertNotNull(detailsFragment); - } - - @SmallTest - public void testViewsAreNotNull() { - assertNotNull(iv_client_image); - assertNotNull(tv_full_name); - assertNotNull(tbl_client_details); - assertNotNull(loans); - assertNotNull(savings); - assertNotNull(recurring); - } - - @SmallTest - public void testViewsAreOnTheScreen() { - final View decorView = clientActivity.getWindow().getDecorView(); - - ViewAsserts.assertOnScreen(decorView, iv_client_image); - ViewAsserts.assertOnScreen(decorView, tv_full_name); - ViewAsserts.assertOnScreen(decorView, tbl_client_details); - ViewAsserts.assertOnScreen(decorView, loans); - ViewAsserts.assertOnScreen(decorView, savings); - ViewAsserts.assertOnScreen(decorView, recurring); - } - - @SmallTest - public void testClientDocumentsFragmentShowed() throws InterruptedException { - //clicking the button - getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU); -// getInstrumentation().invokeMenuActionSync(clientActivity, ClientDetailsFragment -// .MENU_ITEM_DOCUMENTS, 0); - - //if something is wrong, invokeMenuActionSync will take an exception - - //waiting for the API - Thread.sleep(2000); - - this.sendKeys(KeyEvent.KEYCODE_BACK); - } - - @SmallTest - public void testClientIdentifiersFragmentShowed() throws InterruptedException { - //clicking the button - getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU); -// getInstrumentation().invokeMenuActionSync(clientActivity, ClientDetailsFragment -// .MENU_ITEM_IDENTIFIERS, 0); - - //if something is wrong, invokeMenuActionSync will take an exception - - //waiting for the API - Thread.sleep(2000); - - this.sendKeys(KeyEvent.KEYCODE_BACK); - } -} diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientDetailsFragmentTest.kt b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientDetailsFragmentTest.kt new file mode 100644 index 00000000000..a01c7626e2f --- /dev/null +++ b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientDetailsFragmentTest.kt @@ -0,0 +1,102 @@ +package com.mifos.mifosxdroid.tests + +import android.test.ActivityInstrumentationTestCase2 +import android.view.KeyEvent +import android.view.View +import android.widget.ImageView +import com.mifos.mifosxdroid.R +import com.mifos.utils.Constants + +/** + * Created by Gabriel Esteban on 07/12/14. + */ +@Suppress // TODO: Fix NPE + +class ClientDetailsFragmentTest : ActivityInstrumentationTestCase2( + ClientActivity::class.java +) { + var clientActivity: ClientActivity? = null + var detailsFragment: ClientDetailsFragment? = null + var iv_client_image: ImageView? = null + var tv_full_name: TextView? = null + var tbl_client_details: TableLayout? = null + var loans: RelativeLayout? = null + var savings: RelativeLayout? = null + var recurring: RelativeLayout? = null + @Throws(Exception::class) + protected fun setUp() { + super.setUp() + val clientActivityIntent = Intent() + clientActivityIntent.putExtra(Constants.CLIENT_ID, "000000001") + setActivityIntent(clientActivityIntent) + clientActivity = getActivity() + //waiting for the API + Thread.sleep(2000) + detailsFragment = getActivity().getSupportFragmentManager() + .findFragmentByTag(FragmentConstants.FRAG_CLIENT_DETAILS) as ClientDetailsFragment + iv_client_image = clientActivity.findViewById(R.id.iv_clientImage) + tv_full_name = clientActivity.findViewById(R.id.tv_fullName) as TextView + tbl_client_details = clientActivity.findViewById(R.id.tbl_clientDetails) as TableLayout + loans = clientActivity.findViewById(R.id.account_accordion_section_loans) as RelativeLayout + savings = + clientActivity.findViewById(R.id.account_accordion_section_savings) as RelativeLayout + recurring = + clientActivity.findViewById(R.id.account_accordion_section_recurring) as RelativeLayout + } + + @SmallTest + fun testFragmentIsNotNull() { + assertNotNull(detailsFragment) + } + + @SmallTest + fun testViewsAreNotNull() { + assertNotNull(iv_client_image) + assertNotNull(tv_full_name) + assertNotNull(tbl_client_details) + assertNotNull(loans) + assertNotNull(savings) + assertNotNull(recurring) + } + + @SmallTest + fun testViewsAreOnTheScreen() { + val decorView: View = clientActivity.getWindow().getDecorView() + ViewAsserts.assertOnScreen(decorView, iv_client_image) + ViewAsserts.assertOnScreen(decorView, tv_full_name) + ViewAsserts.assertOnScreen(decorView, tbl_client_details) + ViewAsserts.assertOnScreen(decorView, loans) + ViewAsserts.assertOnScreen(decorView, savings) + ViewAsserts.assertOnScreen(decorView, recurring) + } + + @SmallTest + @Throws(InterruptedException::class) + fun testClientDocumentsFragmentShowed() { + //clicking the button + getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU) + // getInstrumentation().invokeMenuActionSync(clientActivity, ClientDetailsFragment +// .MENU_ITEM_DOCUMENTS, 0); + + //if something is wrong, invokeMenuActionSync will take an exception + + //waiting for the API + Thread.sleep(2000) + this.sendKeys(KeyEvent.KEYCODE_BACK) + } + + @SmallTest + @Throws(InterruptedException::class) + fun testClientIdentifiersFragmentShowed() { + //clicking the button + getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU) + // getInstrumentation().invokeMenuActionSync(clientActivity, ClientDetailsFragment +// .MENU_ITEM_IDENTIFIERS, 0); + + //if something is wrong, invokeMenuActionSync will take an exception + + //waiting for the API + Thread.sleep(2000) + this.sendKeys(KeyEvent.KEYCODE_BACK) + } +} \ No newline at end of file diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientListFragmentTest.java b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientListFragmentTest.java deleted file mode 100755 index 83d6d5365a6..00000000000 --- a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientListFragmentTest.java +++ /dev/null @@ -1,796 +0,0 @@ -package com.mifos.mifosxdroid.tests; - -import androidx.test.espresso.Espresso; -import androidx.test.rule.ActivityTestRule; -import androidx.test.runner.AndroidJUnit4; -import androidx.recyclerview.widget.RecyclerView; -import android.test.suitebuilder.annotation.LargeTest; -import android.text.TextUtils; -import android.util.Log; -import android.view.Gravity; -import android.view.View; - -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.mifos.mifosxdroid.R; -import com.mifos.mifosxdroid.online.DashboardActivity; -import com.mifos.objects.client.Client; - -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.util.ArrayList; -import java.util.List; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.contrib.DrawerActions.open; -import static androidx.test.espresso.contrib.DrawerMatchers.isClosed; -import static androidx.test.espresso.contrib.RecyclerViewActions.scrollTo; -import static androidx.test.espresso.core.deps.guava.base.Preconditions.checkArgument; -import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant; -import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom; -import static androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA; -import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withText; -import static com.mifos.mifosxdroid.tests.action.NavigationViewActions.navigateTo; -import static org.hamcrest.Matchers.allOf; - -/** - * Created by Gabriel Esteban on 12/12/14. - */ -@RunWith(AndroidJUnit4.class) -@LargeTest -public class ClientListFragmentTest { - - public static final String CLIENTLIST_JSON = "[\n" + - " {\n" + - " \"id\": 1,\n" + - " \"accountNo\": \"000000001\",\n" + - " \"status\": {\n" + - " \"id\": 300,\n" + - " \"code\": \"clientStatusType.active\",\n" + - " \"value\": \"Active\"\n" + - " },\n" + - " \"subStatus\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"active\": true,\n" + - " \"activationDate\": [\n" + - " 2016,\n" + - " 3,\n" + - " 28\n" + - " ],\n" + - " \"firstname\": \"Smith\",\n" + - " \"lastname\": \"R\",\n" + - " \"displayName\": \"Smith R\",\n" + - " \"gender\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientType\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientClassification\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"officeId\": 1,\n" + - " \"officeName\": \"Head Office\",\n" + - " \"transferToOfficeId\": 11,\n" + - " \"transferToOfficeName\": \"Pooja_EDI_2015\",\n" + - " \"imageId\": 36,\n" + - " \"imagePresent\": true,\n" + - " \"staffId\": 1,\n" + - " \"staffName\": \"BB, AliyaBhath\",\n" + - " \"timeline\": {\n" + - " \"submittedOnDate\": [\n" + - " 2010,\n" + - " 1,\n" + - " 1\n" + - " ],\n" + - " \"submittedByUsername\": \"mifos\",\n" + - " \"submittedByFirstname\": \"App\",\n" + - " \"submittedByLastname\": \"Administrator\",\n" + - " \"activatedOnDate\": [\n" + - " 2016,\n" + - " 3,\n" + - " 28\n" + - " ],\n" + - " \"activatedByUsername\": \"mifos\",\n" + - " \"activatedByFirstname\": \"App\",\n" + - " \"activatedByLastname\": \"Administrator\"\n" + - " },\n" + - " \"clientNonPersonDetails\": {\n" + - " \"constitution\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"mainBusinessLine\": {\n" + - " \"isActive\": false\n" + - " }\n" + - " }\n" + - " },\n" + - " {\n" + - " \"id\": 9,\n" + - " \"accountNo\": \"000000009\",\n" + - " \"externalId\": \"1700512345\",\n" + - " \"status\": {\n" + - " \"id\": 300,\n" + - " \"code\": \"clientStatusType.active\",\n" + - " \"value\": \"Active\"\n" + - " },\n" + - " \"subStatus\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"active\": true,\n" + - " \"activationDate\": [\n" + - " 2015,\n" + - " 12,\n" + - " 18\n" + - " ],\n" + - " \"firstname\": \"sun\",\n" + - " \"lastname\": \"por\",\n" + - " \"displayName\": \"sun por\",\n" + - " \"mobileNo\": \"123456789\",\n" + - " \"dateOfBirth\": [\n" + - " 1990,\n" + - " 8,\n" + - " 25\n" + - " ],\n" + - " \"gender\": {\n" + - " \"id\": 22,\n" + - " \"name\": \"Male\",\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientType\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientClassification\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"officeId\": 1,\n" + - " \"officeName\": \"Head Office\",\n" + - " \"staffId\": 1,\n" + - " \"staffName\": \"BB, AliyaBhath\",\n" + - " \"timeline\": {\n" + - " \"submittedOnDate\": [\n" + - " 2014,\n" + - " 1,\n" + - " 1\n" + - " ],\n" + - " \"submittedByUsername\": \"mifos\",\n" + - " \"submittedByFirstname\": \"App\",\n" + - " \"submittedByLastname\": \"Administrator\",\n" + - " \"activatedOnDate\": [\n" + - " 2015,\n" + - " 12,\n" + - " 18\n" + - " ],\n" + - " \"activatedByUsername\": \"mifos\",\n" + - " \"activatedByFirstname\": \"App\",\n" + - " \"activatedByLastname\": \"Administrator\"\n" + - " },\n" + - " \"savingsAccountId\": 1,\n" + - " \"clientNonPersonDetails\": {\n" + - " \"constitution\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"mainBusinessLine\": {\n" + - " \"isActive\": false\n" + - " }\n" + - " }\n" + - " },\n" + - " {\n" + - " \"id\": 10,\n" + - " \"accountNo\": \"000000010\",\n" + - " \"status\": {\n" + - " \"id\": 300,\n" + - " \"code\": \"clientStatusType.active\",\n" + - " \"value\": \"Active\"\n" + - " },\n" + - " \"subStatus\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"active\": true,\n" + - " \"activationDate\": [\n" + - " 2015,\n" + - " 11,\n" + - " 2\n" + - " ],\n" + - " \"firstname\": \"JAVA\",\n" + - " \"lastname\": \"BOY\",\n" + - " \"displayName\": \"JAVA BOY\",\n" + - " \"gender\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientType\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientClassification\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"officeId\": 1,\n" + - " \"officeName\": \"Head Office\",\n" + - " \"timeline\": {\n" + - " \"submittedOnDate\": [\n" + - " 2015,\n" + - " 11,\n" + - " 2\n" + - " ],\n" + - " \"submittedByUsername\": \"mifos\",\n" + - " \"submittedByFirstname\": \"App\",\n" + - " \"submittedByLastname\": \"Administrator\",\n" + - " \"activatedOnDate\": [\n" + - " 2015,\n" + - " 11,\n" + - " 2\n" + - " ],\n" + - " \"activatedByUsername\": \"mifos\",\n" + - " \"activatedByFirstname\": \"App\",\n" + - " \"activatedByLastname\": \"Administrator\"\n" + - " },\n" + - " \"clientNonPersonDetails\": {\n" + - " \"constitution\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"mainBusinessLine\": {\n" + - " \"isActive\": false\n" + - " }\n" + - " }\n" + - " },\n" + - " {\n" + - " \"id\": 11,\n" + - " \"accountNo\": \"000000011\",\n" + - " \"status\": {\n" + - " \"id\": 300,\n" + - " \"code\": \"clientStatusType.active\",\n" + - " \"value\": \"Active\"\n" + - " },\n" + - " \"subStatus\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"active\": true,\n" + - " \"activationDate\": [\n" + - " 2015,\n" + - " 12,\n" + - " 18\n" + - " ],\n" + - " \"firstname\": \"KILLER\",\n" + - " \"lastname\": \"ZONE\",\n" + - " \"displayName\": \"KILLER ZONE\",\n" + - " \"gender\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientType\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientClassification\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"officeId\": 1,\n" + - " \"officeName\": \"Head Office\",\n" + - " \"timeline\": {\n" + - " \"submittedOnDate\": [\n" + - " 2015,\n" + - " 12,\n" + - " 18\n" + - " ],\n" + - " \"submittedByUsername\": \"mifos\",\n" + - " \"submittedByFirstname\": \"App\",\n" + - " \"submittedByLastname\": \"Administrator\",\n" + - " \"activatedOnDate\": [\n" + - " 2015,\n" + - " 12,\n" + - " 18\n" + - " ],\n" + - " \"activatedByUsername\": \"mifos\",\n" + - " \"activatedByFirstname\": \"App\",\n" + - " \"activatedByLastname\": \"Administrator\"\n" + - " },\n" + - " \"clientNonPersonDetails\": {\n" + - " \"constitution\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"mainBusinessLine\": {\n" + - " \"isActive\": false\n" + - " }\n" + - " }\n" + - " },\n" + - " {\n" + - " \"id\": 12,\n" + - " \"accountNo\": \"000000012\",\n" + - " \"status\": {\n" + - " \"id\": 300,\n" + - " \"code\": \"clientStatusType.active\",\n" + - " \"value\": \"Active\"\n" + - " },\n" + - " \"subStatus\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"active\": true,\n" + - " \"activationDate\": [\n" + - " 2015,\n" + - " 11,\n" + - " 1\n" + - " ],\n" + - " \"firstname\": \"PERL\",\n" + - " \"lastname\": \"GERM\",\n" + - " \"displayName\": \"PERL GERM\",\n" + - " \"gender\": {\n" + - " \"id\": 22,\n" + - " \"name\": \"Male\",\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientType\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientClassification\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"officeId\": 1,\n" + - " \"officeName\": \"Head Office\",\n" + - " \"timeline\": {\n" + - " \"submittedOnDate\": [\n" + - " 2015,\n" + - " 11,\n" + - " 1\n" + - " ],\n" + - " \"submittedByUsername\": \"mifos\",\n" + - " \"submittedByFirstname\": \"App\",\n" + - " \"submittedByLastname\": \"Administrator\",\n" + - " \"activatedOnDate\": [\n" + - " 2015,\n" + - " 11,\n" + - " 1\n" + - " ],\n" + - " \"activatedByUsername\": \"mifos\",\n" + - " \"activatedByFirstname\": \"App\",\n" + - " \"activatedByLastname\": \"Administrator\"\n" + - " },\n" + - " \"clientNonPersonDetails\": {\n" + - " \"constitution\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"mainBusinessLine\": {\n" + - " \"isActive\": false\n" + - " }\n" + - " }\n" + - " },\n" + - " {\n" + - " \"id\": 13,\n" + - " \"accountNo\": \"000000013\",\n" + - " \"externalId\": \"267777\",\n" + - " \"status\": {\n" + - " \"id\": 300,\n" + - " \"code\": \"clientStatusType.active\",\n" + - " \"value\": \"Active\"\n" + - " },\n" + - " \"subStatus\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"active\": true,\n" + - " \"activationDate\": [\n" + - " 2015,\n" + - " 12,\n" + - " 18\n" + - " ],\n" + - " \"firstname\": \"John\",\n" + - " \"middlename\": \"Olu\",\n" + - " \"lastname\": \"Olu\",\n" + - " \"displayName\": \"John Olu Olu\",\n" + - " \"mobileNo\": \"233264500099\",\n" + - " \"dateOfBirth\": [\n" + - " 2000,\n" + - " 11,\n" + - " 30\n" + - " ],\n" + - " \"gender\": {\n" + - " \"id\": 22,\n" + - " \"name\": \"Male\",\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientType\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientClassification\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"officeId\": 1,\n" + - " \"officeName\": \"Head Office\",\n" + - " \"timeline\": {\n" + - " \"submittedOnDate\": [\n" + - " 2015,\n" + - " 12,\n" + - " 18\n" + - " ],\n" + - " \"submittedByUsername\": \"mifos\",\n" + - " \"submittedByFirstname\": \"App\",\n" + - " \"submittedByLastname\": \"Administrator\",\n" + - " \"activatedOnDate\": [\n" + - " 2015,\n" + - " 12,\n" + - " 18\n" + - " ],\n" + - " \"activatedByUsername\": \"mifos\",\n" + - " \"activatedByFirstname\": \"App\",\n" + - " \"activatedByLastname\": \"Administrator\"\n" + - " },\n" + - " \"savingsAccountId\": 4,\n" + - " \"clientNonPersonDetails\": {\n" + - " \"constitution\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"mainBusinessLine\": {\n" + - " \"isActive\": false\n" + - " }\n" + - " }\n" + - " },\n" + - " {\n" + - " \"id\": 17,\n" + - " \"accountNo\": \"000000017\",\n" + - " \"externalId\": \"515096660\",\n" + - " \"status\": {\n" + - " \"id\": 300,\n" + - " \"code\": \"clientStatusType.active\",\n" + - " \"value\": \"Active\"\n" + - " },\n" + - " \"subStatus\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"active\": true,\n" + - " \"activationDate\": [\n" + - " 2015,\n" + - " 12,\n" + - " 21\n" + - " ],\n" + - " \"firstname\": \"Okeleke\",\n" + - " \"middlename\": \"N\",\n" + - " \"lastname\": \"Mike\",\n" + - " \"displayName\": \"Okeleke N Mike\",\n" + - " \"mobileNo\": \"08035889650\",\n" + - " \"dateOfBirth\": [\n" + - " 1975,\n" + - " 12,\n" + - " 7\n" + - " ],\n" + - " \"gender\": {\n" + - " \"id\": 22,\n" + - " \"name\": \"Male\",\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientType\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientClassification\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"officeId\": 1,\n" + - " \"officeName\": \"Head Office\",\n" + - " \"imageId\": 3,\n" + - " \"imagePresent\": true,\n" + - " \"staffId\": 1,\n" + - " \"staffName\": \"BB, AliyaBhath\",\n" + - " \"timeline\": {\n" + - " \"submittedOnDate\": [\n" + - " 2015,\n" + - " 12,\n" + - " 21\n" + - " ],\n" + - " \"submittedByUsername\": \"mifos\",\n" + - " \"submittedByFirstname\": \"App\",\n" + - " \"submittedByLastname\": \"Administrator\",\n" + - " \"activatedOnDate\": [\n" + - " 2015,\n" + - " 12,\n" + - " 21\n" + - " ],\n" + - " \"activatedByUsername\": \"mifos\",\n" + - " \"activatedByFirstname\": \"App\",\n" + - " \"activatedByLastname\": \"Administrator\"\n" + - " },\n" + - " \"savingsAccountId\": 8,\n" + - " \"clientNonPersonDetails\": {\n" + - " \"constitution\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"mainBusinessLine\": {\n" + - " \"isActive\": false\n" + - " }\n" + - " }\n" + - " },\n" + - " {\n" + - " \"id\": 20,\n" + - " \"accountNo\": \"000000020\",\n" + - " \"status\": {\n" + - " \"id\": 300,\n" + - " \"code\": \"clientStatusType.active\",\n" + - " \"value\": \"Active\"\n" + - " },\n" + - " \"subStatus\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"active\": true,\n" + - " \"activationDate\": [\n" + - " 2016,\n" + - " 3,\n" + - " 28\n" + - " ],\n" + - " \"firstname\": \"Mosha\",\n" + - " \"lastname\": \"Pinto\",\n" + - " \"displayName\": \"Mosha Pinto\",\n" + - " \"dateOfBirth\": [\n" + - " 1988,\n" + - " 1,\n" + - " 8\n" + - " ],\n" + - " \"gender\": {\n" + - " \"id\": 24,\n" + - " \"name\": \"Female\",\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientType\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientClassification\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"officeId\": 1,\n" + - " \"officeName\": \"Head Office\",\n" + - " \"timeline\": {\n" + - " \"submittedOnDate\": [\n" + - " 2015,\n" + - " 12,\n" + - " 21\n" + - " ],\n" + - " \"submittedByUsername\": \"mifos\",\n" + - " \"submittedByFirstname\": \"App\",\n" + - " \"submittedByLastname\": \"Administrator\",\n" + - " \"activatedOnDate\": [\n" + - " 2016,\n" + - " 3,\n" + - " 28\n" + - " ],\n" + - " \"activatedByUsername\": \"mifos\",\n" + - " \"activatedByFirstname\": \"App\",\n" + - " \"activatedByLastname\": \"Administrator\"\n" + - " },\n" + - " \"clientNonPersonDetails\": {\n" + - " \"constitution\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"mainBusinessLine\": {\n" + - " \"isActive\": false\n" + - " }\n" + - " }\n" + - " },\n" + - " {\n" + - " \"id\": 24,\n" + - " \"accountNo\": \"000000024\",\n" + - " \"status\": {\n" + - " \"id\": 304,\n" + - " \"code\": \"clientStatusType.transfer.on.hold\",\n" + - " \"value\": \"Transfer on hold\"\n" + - " },\n" + - " \"subStatus\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"active\": false,\n" + - " \"activationDate\": [\n" + - " 2009,\n" + - " 1,\n" + - " 4\n" + - " ],\n" + - " \"firstname\": \"ADi\",\n" + - " \"lastname\": \"Yst\",\n" + - " \"displayName\": \"ADi Yst\",\n" + - " \"gender\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientType\": {\n" + - " \"id\": 47,\n" + - " \"name\": \"SSB\",\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientClassification\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"officeId\": 1,\n" + - " \"officeName\": \"Head Office\",\n" + - " \"staffId\": 1,\n" + - " \"staffName\": \"BB, AliyaBhath\",\n" + - " \"timeline\": {\n" + - " \"submittedOnDate\": [\n" + - " 2009,\n" + - " 1,\n" + - " 4\n" + - " ],\n" + - " \"submittedByUsername\": \"mifos\",\n" + - " \"submittedByFirstname\": \"App\",\n" + - " \"submittedByLastname\": \"Administrator\",\n" + - " \"activatedOnDate\": [\n" + - " 2009,\n" + - " 1,\n" + - " 4\n" + - " ],\n" + - " \"activatedByUsername\": \"mifos\",\n" + - " \"activatedByFirstname\": \"App\",\n" + - " \"activatedByLastname\": \"Administrator\"\n" + - " },\n" + - " \"savingsAccountId\": 26,\n" + - " \"clientNonPersonDetails\": {\n" + - " \"constitution\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"mainBusinessLine\": {\n" + - " \"isActive\": false\n" + - " }\n" + - " }\n" + - " },\n" + - " {\n" + - " \"id\": 38,\n" + - " \"accountNo\": \"000000038\",\n" + - " \"externalId\": \"HMT0000001\",\n" + - " \"status\": {\n" + - " \"id\": 300,\n" + - " \"code\": \"clientStatusType.active\",\n" + - " \"value\": \"Active\"\n" + - " },\n" + - " \"subStatus\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"active\": true,\n" + - " \"activationDate\": [\n" + - " 2015,\n" + - " 12,\n" + - " 24\n" + - " ],\n" + - " \"firstname\": \"Tejas\",\n" + - " \"middlename\": \"Ram\",\n" + - " \"lastname\": \"Vyas\",\n" + - " \"displayName\": \"Tejas Ram Vyas\",\n" + - " \"mobileNo\": \"7600330857\",\n" + - " \"dateOfBirth\": [\n" + - " 1991,\n" + - " 4,\n" + - " 26\n" + - " ],\n" + - " \"gender\": {\n" + - " \"id\": 22,\n" + - " \"name\": \"Male\",\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientType\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"clientClassification\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"officeId\": 1,\n" + - " \"officeName\": \"Head Office\",\n" + - " \"timeline\": {\n" + - " \"submittedOnDate\": [\n" + - " 2015,\n" + - " 12,\n" + - " 24\n" + - " ],\n" + - " \"submittedByUsername\": \"mifos\",\n" + - " \"submittedByFirstname\": \"App\",\n" + - " \"submittedByLastname\": \"Administrator\",\n" + - " \"activatedOnDate\": [\n" + - " 2015,\n" + - " 12,\n" + - " 24\n" + - " ],\n" + - " \"activatedByUsername\": \"mifos\",\n" + - " \"activatedByFirstname\": \"App\",\n" + - " \"activatedByLastname\": \"Administrator\"\n" + - " },\n" + - " \"savingsAccountId\": 13,\n" + - " \"clientNonPersonDetails\": {\n" + - " \"constitution\": {\n" + - " \"isActive\": false\n" + - " },\n" + - " \"mainBusinessLine\": {\n" + - " \"isActive\": false\n" + - " }\n" + - " }\n" + - " }\n" + - " ]"; - @Rule - public ActivityTestRule mDashboardActivity = - new ActivityTestRule<>(DashboardActivity.class); - private List clientList = new ArrayList<>(); - - /** - * A custom {@link Matcher} which matches an item in a {@link RecyclerView} by its text. - *

- *

- * View constraints: - *

    - *
  • View must be a child of a {@link RecyclerView} - *
      - * - * @param itemText the text to match - * @return Matcher that matches text in the given view - */ - private Matcher withItemText(final String itemText) { - checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty"); - return new TypeSafeMatcher() { - @Override - public boolean matchesSafely(View item) { - return allOf( - isDescendantOfA(isAssignableFrom(RecyclerView.class)), - withText(itemText)).matches(item); - } - - @Override - public void describeTo(Description description) { - description.appendText("is isDescendantOfA RV with text " + itemText); - } - }; - } - - /** - * Convenience method to register an IdlingResources with Espresso. IdlingResource resource is - * a great way to tell Espresso when your app is in an idle state. This helps Espresso to - * synchronize your test actions, which makes tests significantly more reliable. - */ - @Before - public void registerIdlingResource() { - - Gson gson = new Gson(); - clientList = gson.fromJson(CLIENTLIST_JSON, new TypeToken>() { - }.getType()); - Log.d("Clients", clientList.get(5).getDisplayName()); - Espresso.registerIdlingResources( - mDashboardActivity.getActivity().getCountingIdlingResource()); - } - - /** - * When project is successfully enable any architecture, we have to pass - * this fake client list data to the view layer and remain will not to change. - * test case automatically pass. - * - * @throws Exception - */ - @Test - public void testOpenClientListFragment() throws Exception { - // Open Drawer to click on navigation. - onView(withId(R.id.drawer)) - .check(matches(isClosed(Gravity.LEFT))) // Left Drawer should be closed. - .perform(open()); // Open Drawer - - // Start Transaction of ClientListFragment screen. - onView(withId(R.id.navigation_view)) - .perform(navigateTo(R.id.item_clients)); - - // Scroll notes list to added note, by finding its description - onView(withId(R.id.rv_clients)).perform( - scrollTo(hasDescendant(withText(clientList.get(4).getAccountNo())))); - // Verify note is displayed on screen - onView(withItemText(clientList.get(4).getAccountNo())).check(matches(isDisplayed())); - - // Scroll notes list to added note, by finding its description - onView(withId(R.id.rv_clients)).perform( - scrollTo(hasDescendant(withText(clientList.get(9).getAccountNo())))); - // Verify note is displayed on screen - onView(withItemText(clientList.get(9).getAccountNo())).check(matches(isDisplayed())); - - } - - /** - * Unregister your Idling Resource so it can be garbage collected and does not leak any memory. - */ - @After - public void unregisterIdlingResource() { - Espresso.unregisterIdlingResources( - mDashboardActivity.getActivity().getCountingIdlingResource()); - } - - -} diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientListFragmentTest.kt b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientListFragmentTest.kt new file mode 100644 index 00000000000..37cfb99c10a --- /dev/null +++ b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientListFragmentTest.kt @@ -0,0 +1,789 @@ +package com.mifos.mifosxdroid.tests + +import android.util.Log +import android.view.View +import androidx.recyclerview.widget.RecyclerView +import com.mifos.mifosxdroid.R +import com.mifos.objects.client.Client +import org.hamcrest.Description +import org.hamcrest.Matcher +import org.hamcrest.TypeSafeMatcher +import org.junit.After +import org.junit.Rule +import org.junit.Test + +/** + * Created by Gabriel Esteban on 12/12/14. + */ +@RunWith(AndroidJUnit4::class) +@LargeTest +class ClientListFragmentTest constructor() { + @Rule + var mDashboardActivity: ActivityTestRule = + ActivityTestRule( + DashboardActivity::class.java + ) + private var clientList: MutableList = ArrayList() + + /** + * A custom [Matcher] which matches an item in a [RecyclerView] by its text. + * + * + * + * + * View constraints: + * + * * View must be a child of a [RecyclerView] + * + * + * @param itemText the text to match + * @return Matcher that matches text in the given view + */ + private fun withItemText(itemText: String?): Matcher { + checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty") + return object : TypeSafeMatcher() { + public override fun matchesSafely(item: View?): Boolean { + return Matchers.allOf( + ViewMatchers.isDescendantOfA(ViewMatchers.isAssignableFrom(RecyclerView::class.java)), + ViewMatchers.withText(itemText) + ).matches(item) + } + + public override fun describeTo(description: Description) { + description.appendText("is isDescendantOfA RV with text " + itemText) + } + } + } + + /** + * Convenience method to register an IdlingResources with Espresso. IdlingResource resource is + * a great way to tell Espresso when your app is in an idle state. This helps Espresso to + * synchronize your test actions, which makes tests significantly more reliable. + */ + @Before + fun registerIdlingResource() { + val gson: Gson = Gson() + clientList = + gson.fromJson(CLIENTLIST_JSON, object : TypeToken?>() {}.getType()) + Log.d("Clients", clientList.get(5).displayName) + Espresso.registerIdlingResources( + mDashboardActivity.getActivity().getCountingIdlingResource() + ) + } + + /** + * When project is successfully enable any architecture, we have to pass + * this fake client list data to the view layer and remain will not to change. + * test case automatically pass. + * + * @throws Exception + */ + @Test + @Throws(Exception::class) + fun testOpenClientListFragment() { + // Open Drawer to click on navigation. + Espresso.onView(ViewMatchers.withId(R.id.drawer)) + .check(ViewAssertions.matches(DrawerMatchers.isClosed(Gravity.LEFT))) // Left Drawer should be closed. + .perform(DrawerActions.open()) // Open Drawer + + // Start Transaction of ClientListFragment screen. + Espresso.onView(ViewMatchers.withId(R.id.navigation_view)) + .perform(navigateTo(R.id.item_clients)) + + // Scroll notes list to added note, by finding its description + Espresso.onView(ViewMatchers.withId(R.id.rv_clients)).perform( + RecyclerViewActions.scrollTo( + ViewMatchers.hasDescendant( + ViewMatchers.withText( + clientList.get( + 4 + ).accountNo + ) + ) + ) + ) + // Verify note is displayed on screen + Espresso.onView(withItemText(clientList.get(4).accountNo)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + + // Scroll notes list to added note, by finding its description + Espresso.onView(ViewMatchers.withId(R.id.rv_clients)).perform( + RecyclerViewActions.scrollTo( + ViewMatchers.hasDescendant( + ViewMatchers.withText( + clientList.get( + 9 + ).accountNo + ) + ) + ) + ) + // Verify note is displayed on screen + Espresso.onView(withItemText(clientList.get(9).accountNo)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + } + + /** + * Unregister your Idling Resource so it can be garbage collected and does not leak any memory. + */ + @After + fun unregisterIdlingResource() { + Espresso.unregisterIdlingResources( + mDashboardActivity.getActivity().getCountingIdlingResource() + ) + } + + companion object { + val CLIENTLIST_JSON: String = ("[\n" + + " {\n" + + " \"id\": 1,\n" + + " \"accountNo\": \"000000001\",\n" + + " \"status\": {\n" + + " \"id\": 300,\n" + + " \"code\": \"clientStatusType.active\",\n" + + " \"value\": \"Active\"\n" + + " },\n" + + " \"subStatus\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"active\": true,\n" + + " \"activationDate\": [\n" + + " 2016,\n" + + " 3,\n" + + " 28\n" + + " ],\n" + + " \"firstname\": \"Smith\",\n" + + " \"lastname\": \"R\",\n" + + " \"displayName\": \"Smith R\",\n" + + " \"gender\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientType\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientClassification\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"officeId\": 1,\n" + + " \"officeName\": \"Head Office\",\n" + + " \"transferToOfficeId\": 11,\n" + + " \"transferToOfficeName\": \"Pooja_EDI_2015\",\n" + + " \"imageId\": 36,\n" + + " \"imagePresent\": true,\n" + + " \"staffId\": 1,\n" + + " \"staffName\": \"BB, AliyaBhath\",\n" + + " \"timeline\": {\n" + + " \"submittedOnDate\": [\n" + + " 2010,\n" + + " 1,\n" + + " 1\n" + + " ],\n" + + " \"submittedByUsername\": \"mifos\",\n" + + " \"submittedByFirstname\": \"App\",\n" + + " \"submittedByLastname\": \"Administrator\",\n" + + " \"activatedOnDate\": [\n" + + " 2016,\n" + + " 3,\n" + + " 28\n" + + " ],\n" + + " \"activatedByUsername\": \"mifos\",\n" + + " \"activatedByFirstname\": \"App\",\n" + + " \"activatedByLastname\": \"Administrator\"\n" + + " },\n" + + " \"clientNonPersonDetails\": {\n" + + " \"constitution\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"mainBusinessLine\": {\n" + + " \"isActive\": false\n" + + " }\n" + + " }\n" + + " },\n" + + " {\n" + + " \"id\": 9,\n" + + " \"accountNo\": \"000000009\",\n" + + " \"externalId\": \"1700512345\",\n" + + " \"status\": {\n" + + " \"id\": 300,\n" + + " \"code\": \"clientStatusType.active\",\n" + + " \"value\": \"Active\"\n" + + " },\n" + + " \"subStatus\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"active\": true,\n" + + " \"activationDate\": [\n" + + " 2015,\n" + + " 12,\n" + + " 18\n" + + " ],\n" + + " \"firstname\": \"sun\",\n" + + " \"lastname\": \"por\",\n" + + " \"displayName\": \"sun por\",\n" + + " \"mobileNo\": \"123456789\",\n" + + " \"dateOfBirth\": [\n" + + " 1990,\n" + + " 8,\n" + + " 25\n" + + " ],\n" + + " \"gender\": {\n" + + " \"id\": 22,\n" + + " \"name\": \"Male\",\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientType\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientClassification\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"officeId\": 1,\n" + + " \"officeName\": \"Head Office\",\n" + + " \"staffId\": 1,\n" + + " \"staffName\": \"BB, AliyaBhath\",\n" + + " \"timeline\": {\n" + + " \"submittedOnDate\": [\n" + + " 2014,\n" + + " 1,\n" + + " 1\n" + + " ],\n" + + " \"submittedByUsername\": \"mifos\",\n" + + " \"submittedByFirstname\": \"App\",\n" + + " \"submittedByLastname\": \"Administrator\",\n" + + " \"activatedOnDate\": [\n" + + " 2015,\n" + + " 12,\n" + + " 18\n" + + " ],\n" + + " \"activatedByUsername\": \"mifos\",\n" + + " \"activatedByFirstname\": \"App\",\n" + + " \"activatedByLastname\": \"Administrator\"\n" + + " },\n" + + " \"savingsAccountId\": 1,\n" + + " \"clientNonPersonDetails\": {\n" + + " \"constitution\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"mainBusinessLine\": {\n" + + " \"isActive\": false\n" + + " }\n" + + " }\n" + + " },\n" + + " {\n" + + " \"id\": 10,\n" + + " \"accountNo\": \"000000010\",\n" + + " \"status\": {\n" + + " \"id\": 300,\n" + + " \"code\": \"clientStatusType.active\",\n" + + " \"value\": \"Active\"\n" + + " },\n" + + " \"subStatus\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"active\": true,\n" + + " \"activationDate\": [\n" + + " 2015,\n" + + " 11,\n" + + " 2\n" + + " ],\n" + + " \"firstname\": \"JAVA\",\n" + + " \"lastname\": \"BOY\",\n" + + " \"displayName\": \"JAVA BOY\",\n" + + " \"gender\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientType\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientClassification\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"officeId\": 1,\n" + + " \"officeName\": \"Head Office\",\n" + + " \"timeline\": {\n" + + " \"submittedOnDate\": [\n" + + " 2015,\n" + + " 11,\n" + + " 2\n" + + " ],\n" + + " \"submittedByUsername\": \"mifos\",\n" + + " \"submittedByFirstname\": \"App\",\n" + + " \"submittedByLastname\": \"Administrator\",\n" + + " \"activatedOnDate\": [\n" + + " 2015,\n" + + " 11,\n" + + " 2\n" + + " ],\n" + + " \"activatedByUsername\": \"mifos\",\n" + + " \"activatedByFirstname\": \"App\",\n" + + " \"activatedByLastname\": \"Administrator\"\n" + + " },\n" + + " \"clientNonPersonDetails\": {\n" + + " \"constitution\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"mainBusinessLine\": {\n" + + " \"isActive\": false\n" + + " }\n" + + " }\n" + + " },\n" + + " {\n" + + " \"id\": 11,\n" + + " \"accountNo\": \"000000011\",\n" + + " \"status\": {\n" + + " \"id\": 300,\n" + + " \"code\": \"clientStatusType.active\",\n" + + " \"value\": \"Active\"\n" + + " },\n" + + " \"subStatus\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"active\": true,\n" + + " \"activationDate\": [\n" + + " 2015,\n" + + " 12,\n" + + " 18\n" + + " ],\n" + + " \"firstname\": \"KILLER\",\n" + + " \"lastname\": \"ZONE\",\n" + + " \"displayName\": \"KILLER ZONE\",\n" + + " \"gender\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientType\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientClassification\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"officeId\": 1,\n" + + " \"officeName\": \"Head Office\",\n" + + " \"timeline\": {\n" + + " \"submittedOnDate\": [\n" + + " 2015,\n" + + " 12,\n" + + " 18\n" + + " ],\n" + + " \"submittedByUsername\": \"mifos\",\n" + + " \"submittedByFirstname\": \"App\",\n" + + " \"submittedByLastname\": \"Administrator\",\n" + + " \"activatedOnDate\": [\n" + + " 2015,\n" + + " 12,\n" + + " 18\n" + + " ],\n" + + " \"activatedByUsername\": \"mifos\",\n" + + " \"activatedByFirstname\": \"App\",\n" + + " \"activatedByLastname\": \"Administrator\"\n" + + " },\n" + + " \"clientNonPersonDetails\": {\n" + + " \"constitution\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"mainBusinessLine\": {\n" + + " \"isActive\": false\n" + + " }\n" + + " }\n" + + " },\n" + + " {\n" + + " \"id\": 12,\n" + + " \"accountNo\": \"000000012\",\n" + + " \"status\": {\n" + + " \"id\": 300,\n" + + " \"code\": \"clientStatusType.active\",\n" + + " \"value\": \"Active\"\n" + + " },\n" + + " \"subStatus\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"active\": true,\n" + + " \"activationDate\": [\n" + + " 2015,\n" + + " 11,\n" + + " 1\n" + + " ],\n" + + " \"firstname\": \"PERL\",\n" + + " \"lastname\": \"GERM\",\n" + + " \"displayName\": \"PERL GERM\",\n" + + " \"gender\": {\n" + + " \"id\": 22,\n" + + " \"name\": \"Male\",\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientType\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientClassification\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"officeId\": 1,\n" + + " \"officeName\": \"Head Office\",\n" + + " \"timeline\": {\n" + + " \"submittedOnDate\": [\n" + + " 2015,\n" + + " 11,\n" + + " 1\n" + + " ],\n" + + " \"submittedByUsername\": \"mifos\",\n" + + " \"submittedByFirstname\": \"App\",\n" + + " \"submittedByLastname\": \"Administrator\",\n" + + " \"activatedOnDate\": [\n" + + " 2015,\n" + + " 11,\n" + + " 1\n" + + " ],\n" + + " \"activatedByUsername\": \"mifos\",\n" + + " \"activatedByFirstname\": \"App\",\n" + + " \"activatedByLastname\": \"Administrator\"\n" + + " },\n" + + " \"clientNonPersonDetails\": {\n" + + " \"constitution\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"mainBusinessLine\": {\n" + + " \"isActive\": false\n" + + " }\n" + + " }\n" + + " },\n" + + " {\n" + + " \"id\": 13,\n" + + " \"accountNo\": \"000000013\",\n" + + " \"externalId\": \"267777\",\n" + + " \"status\": {\n" + + " \"id\": 300,\n" + + " \"code\": \"clientStatusType.active\",\n" + + " \"value\": \"Active\"\n" + + " },\n" + + " \"subStatus\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"active\": true,\n" + + " \"activationDate\": [\n" + + " 2015,\n" + + " 12,\n" + + " 18\n" + + " ],\n" + + " \"firstname\": \"John\",\n" + + " \"middlename\": \"Olu\",\n" + + " \"lastname\": \"Olu\",\n" + + " \"displayName\": \"John Olu Olu\",\n" + + " \"mobileNo\": \"233264500099\",\n" + + " \"dateOfBirth\": [\n" + + " 2000,\n" + + " 11,\n" + + " 30\n" + + " ],\n" + + " \"gender\": {\n" + + " \"id\": 22,\n" + + " \"name\": \"Male\",\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientType\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientClassification\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"officeId\": 1,\n" + + " \"officeName\": \"Head Office\",\n" + + " \"timeline\": {\n" + + " \"submittedOnDate\": [\n" + + " 2015,\n" + + " 12,\n" + + " 18\n" + + " ],\n" + + " \"submittedByUsername\": \"mifos\",\n" + + " \"submittedByFirstname\": \"App\",\n" + + " \"submittedByLastname\": \"Administrator\",\n" + + " \"activatedOnDate\": [\n" + + " 2015,\n" + + " 12,\n" + + " 18\n" + + " ],\n" + + " \"activatedByUsername\": \"mifos\",\n" + + " \"activatedByFirstname\": \"App\",\n" + + " \"activatedByLastname\": \"Administrator\"\n" + + " },\n" + + " \"savingsAccountId\": 4,\n" + + " \"clientNonPersonDetails\": {\n" + + " \"constitution\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"mainBusinessLine\": {\n" + + " \"isActive\": false\n" + + " }\n" + + " }\n" + + " },\n" + + " {\n" + + " \"id\": 17,\n" + + " \"accountNo\": \"000000017\",\n" + + " \"externalId\": \"515096660\",\n" + + " \"status\": {\n" + + " \"id\": 300,\n" + + " \"code\": \"clientStatusType.active\",\n" + + " \"value\": \"Active\"\n" + + " },\n" + + " \"subStatus\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"active\": true,\n" + + " \"activationDate\": [\n" + + " 2015,\n" + + " 12,\n" + + " 21\n" + + " ],\n" + + " \"firstname\": \"Okeleke\",\n" + + " \"middlename\": \"N\",\n" + + " \"lastname\": \"Mike\",\n" + + " \"displayName\": \"Okeleke N Mike\",\n" + + " \"mobileNo\": \"08035889650\",\n" + + " \"dateOfBirth\": [\n" + + " 1975,\n" + + " 12,\n" + + " 7\n" + + " ],\n" + + " \"gender\": {\n" + + " \"id\": 22,\n" + + " \"name\": \"Male\",\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientType\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientClassification\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"officeId\": 1,\n" + + " \"officeName\": \"Head Office\",\n" + + " \"imageId\": 3,\n" + + " \"imagePresent\": true,\n" + + " \"staffId\": 1,\n" + + " \"staffName\": \"BB, AliyaBhath\",\n" + + " \"timeline\": {\n" + + " \"submittedOnDate\": [\n" + + " 2015,\n" + + " 12,\n" + + " 21\n" + + " ],\n" + + " \"submittedByUsername\": \"mifos\",\n" + + " \"submittedByFirstname\": \"App\",\n" + + " \"submittedByLastname\": \"Administrator\",\n" + + " \"activatedOnDate\": [\n" + + " 2015,\n" + + " 12,\n" + + " 21\n" + + " ],\n" + + " \"activatedByUsername\": \"mifos\",\n" + + " \"activatedByFirstname\": \"App\",\n" + + " \"activatedByLastname\": \"Administrator\"\n" + + " },\n" + + " \"savingsAccountId\": 8,\n" + + " \"clientNonPersonDetails\": {\n" + + " \"constitution\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"mainBusinessLine\": {\n" + + " \"isActive\": false\n" + + " }\n" + + " }\n" + + " },\n" + + " {\n" + + " \"id\": 20,\n" + + " \"accountNo\": \"000000020\",\n" + + " \"status\": {\n" + + " \"id\": 300,\n" + + " \"code\": \"clientStatusType.active\",\n" + + " \"value\": \"Active\"\n" + + " },\n" + + " \"subStatus\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"active\": true,\n" + + " \"activationDate\": [\n" + + " 2016,\n" + + " 3,\n" + + " 28\n" + + " ],\n" + + " \"firstname\": \"Mosha\",\n" + + " \"lastname\": \"Pinto\",\n" + + " \"displayName\": \"Mosha Pinto\",\n" + + " \"dateOfBirth\": [\n" + + " 1988,\n" + + " 1,\n" + + " 8\n" + + " ],\n" + + " \"gender\": {\n" + + " \"id\": 24,\n" + + " \"name\": \"Female\",\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientType\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientClassification\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"officeId\": 1,\n" + + " \"officeName\": \"Head Office\",\n" + + " \"timeline\": {\n" + + " \"submittedOnDate\": [\n" + + " 2015,\n" + + " 12,\n" + + " 21\n" + + " ],\n" + + " \"submittedByUsername\": \"mifos\",\n" + + " \"submittedByFirstname\": \"App\",\n" + + " \"submittedByLastname\": \"Administrator\",\n" + + " \"activatedOnDate\": [\n" + + " 2016,\n" + + " 3,\n" + + " 28\n" + + " ],\n" + + " \"activatedByUsername\": \"mifos\",\n" + + " \"activatedByFirstname\": \"App\",\n" + + " \"activatedByLastname\": \"Administrator\"\n" + + " },\n" + + " \"clientNonPersonDetails\": {\n" + + " \"constitution\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"mainBusinessLine\": {\n" + + " \"isActive\": false\n" + + " }\n" + + " }\n" + + " },\n" + + " {\n" + + " \"id\": 24,\n" + + " \"accountNo\": \"000000024\",\n" + + " \"status\": {\n" + + " \"id\": 304,\n" + + " \"code\": \"clientStatusType.transfer.on.hold\",\n" + + " \"value\": \"Transfer on hold\"\n" + + " },\n" + + " \"subStatus\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"active\": false,\n" + + " \"activationDate\": [\n" + + " 2009,\n" + + " 1,\n" + + " 4\n" + + " ],\n" + + " \"firstname\": \"ADi\",\n" + + " \"lastname\": \"Yst\",\n" + + " \"displayName\": \"ADi Yst\",\n" + + " \"gender\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientType\": {\n" + + " \"id\": 47,\n" + + " \"name\": \"SSB\",\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientClassification\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"officeId\": 1,\n" + + " \"officeName\": \"Head Office\",\n" + + " \"staffId\": 1,\n" + + " \"staffName\": \"BB, AliyaBhath\",\n" + + " \"timeline\": {\n" + + " \"submittedOnDate\": [\n" + + " 2009,\n" + + " 1,\n" + + " 4\n" + + " ],\n" + + " \"submittedByUsername\": \"mifos\",\n" + + " \"submittedByFirstname\": \"App\",\n" + + " \"submittedByLastname\": \"Administrator\",\n" + + " \"activatedOnDate\": [\n" + + " 2009,\n" + + " 1,\n" + + " 4\n" + + " ],\n" + + " \"activatedByUsername\": \"mifos\",\n" + + " \"activatedByFirstname\": \"App\",\n" + + " \"activatedByLastname\": \"Administrator\"\n" + + " },\n" + + " \"savingsAccountId\": 26,\n" + + " \"clientNonPersonDetails\": {\n" + + " \"constitution\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"mainBusinessLine\": {\n" + + " \"isActive\": false\n" + + " }\n" + + " }\n" + + " },\n" + + " {\n" + + " \"id\": 38,\n" + + " \"accountNo\": \"000000038\",\n" + + " \"externalId\": \"HMT0000001\",\n" + + " \"status\": {\n" + + " \"id\": 300,\n" + + " \"code\": \"clientStatusType.active\",\n" + + " \"value\": \"Active\"\n" + + " },\n" + + " \"subStatus\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"active\": true,\n" + + " \"activationDate\": [\n" + + " 2015,\n" + + " 12,\n" + + " 24\n" + + " ],\n" + + " \"firstname\": \"Tejas\",\n" + + " \"middlename\": \"Ram\",\n" + + " \"lastname\": \"Vyas\",\n" + + " \"displayName\": \"Tejas Ram Vyas\",\n" + + " \"mobileNo\": \"7600330857\",\n" + + " \"dateOfBirth\": [\n" + + " 1991,\n" + + " 4,\n" + + " 26\n" + + " ],\n" + + " \"gender\": {\n" + + " \"id\": 22,\n" + + " \"name\": \"Male\",\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientType\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"clientClassification\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"officeId\": 1,\n" + + " \"officeName\": \"Head Office\",\n" + + " \"timeline\": {\n" + + " \"submittedOnDate\": [\n" + + " 2015,\n" + + " 12,\n" + + " 24\n" + + " ],\n" + + " \"submittedByUsername\": \"mifos\",\n" + + " \"submittedByFirstname\": \"App\",\n" + + " \"submittedByLastname\": \"Administrator\",\n" + + " \"activatedOnDate\": [\n" + + " 2015,\n" + + " 12,\n" + + " 24\n" + + " ],\n" + + " \"activatedByUsername\": \"mifos\",\n" + + " \"activatedByFirstname\": \"App\",\n" + + " \"activatedByLastname\": \"Administrator\"\n" + + " },\n" + + " \"savingsAccountId\": 13,\n" + + " \"clientNonPersonDetails\": {\n" + + " \"constitution\": {\n" + + " \"isActive\": false\n" + + " },\n" + + " \"mainBusinessLine\": {\n" + + " \"isActive\": false\n" + + " }\n" + + " }\n" + + " }\n" + + " ]") + } +} \ No newline at end of file diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientSearchFragmentTest.java b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientSearchFragmentTest.java deleted file mode 100644 index da55aa8acc3..00000000000 --- a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientSearchFragmentTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.mifos.mifosxdroid.tests; - -import androidx.test.espresso.Espresso; -import androidx.test.rule.ActivityTestRule; -import androidx.test.runner.AndroidJUnit4; -import android.test.suitebuilder.annotation.LargeTest; - -import com.mifos.mifosxdroid.R; -import com.mifos.mifosxdroid.online.DashboardActivity; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard; -import static androidx.test.espresso.action.ViewActions.typeText; -import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withText; - -/** - * Created by Rajan Maurya on 16/4/16. - */ -@RunWith(AndroidJUnit4.class) -@LargeTest -public class ClientSearchFragmentTest { - - @Rule - public ActivityTestRule mDashboardActivity = - new ActivityTestRule<>(DashboardActivity.class); - - @Before - public void registerIdlingResource() { - Espresso.registerIdlingResources( - mDashboardActivity.getActivity().getCountingIdlingResource()); - } - - @Test - public void testViewsAreOnTheScreen() { - onView(withId(R.id.tv_search)).check(matches(withText(R.string.client_search))); - onView(withId(R.id.et_search_by_id)).check(matches(isDisplayed())); - onView(withId(R.id.bt_searchClient)).check(matches(withText(R.string.search))); - } - - @Test - public void testSearchClient() throws Exception { - - // Add Client Name In EditText - String clientname = "client"; - onView(withId(R.id.et_search_by_id)).perform(typeText(clientname), closeSoftKeyboard()); - - //Search from Rest API - onView(withId(R.id.bt_searchClient)).perform(click()); - - } - - /** - * Unregister your Idling Resource so it can be garbage collected and does not leak any memory. - */ - @After - public void unregisterIdlingResource() { - Espresso.unregisterIdlingResources( - mDashboardActivity.getActivity().getCountingIdlingResource()); - } -} diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientSearchFragmentTest.kt b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientSearchFragmentTest.kt new file mode 100644 index 00000000000..d7e42e053c7 --- /dev/null +++ b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/ClientSearchFragmentTest.kt @@ -0,0 +1,70 @@ +package com.mifos.mifosxdroid.tests + +import android.test.suitebuilder.annotation.LargeTest +import com.mifos.mifosxdroid.R +import org.junit.After +import org.junit.Rule +import org.junit.Test + +/** + * Created by Rajan Maurya on 16/4/16. + */ +@RunWith(AndroidJUnit4::class) +@LargeTest +class ClientSearchFragmentTest { + @Rule + var mDashboardActivity: ActivityTestRule = + ActivityTestRule( + DashboardActivity::class.java + ) + + @Before + fun registerIdlingResource() { + Espresso.registerIdlingResources( + mDashboardActivity.getActivity().getCountingIdlingResource() + ) + } + + @Test + fun testViewsAreOnTheScreen() { + Espresso.onView(ViewMatchers.withId(R.id.tv_search)).check( + ViewAssertions.matches( + ViewMatchers.withText( + R.string.client_search + ) + ) + ) + Espresso.onView(withId(R.id.et_search_by_id)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + Espresso.onView(withId(R.id.bt_searchClient)).check( + ViewAssertions.matches( + ViewMatchers.withText( + R.string.search + ) + ) + ) + } + + @Test + @Throws(Exception::class) + fun testSearchClient() { + + // Add Client Name In EditText + val clientname = "client" + Espresso.onView(withId(R.id.et_search_by_id)) + .perform(ViewActions.typeText(clientname), ViewActions.closeSoftKeyboard()) + + //Search from Rest API + Espresso.onView(withId(R.id.bt_searchClient)).perform(ViewActions.click()) + } + + /** + * Unregister your Idling Resource so it can be garbage collected and does not leak any memory. + */ + @After + fun unregisterIdlingResource() { + Espresso.unregisterIdlingResources( + mDashboardActivity.getActivity().getCountingIdlingResource() + ) + } +} \ No newline at end of file diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CreateNewCenterFragmentTest.java b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CreateNewCenterFragmentTest.java deleted file mode 100644 index 3eaee988339..00000000000 --- a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CreateNewCenterFragmentTest.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ - -package com.mifos.mifosxdroid.tests; - -import android.test.ActivityInstrumentationTestCase2; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.SmallTest; -import android.view.KeyEvent; -import android.view.View; -import android.widget.Spinner; - -import com.mifos.mifosxdroid.R; -import com.mifos.mifosxdroid.online.createnewcenter.CreateNewCenterFragment; -import com.mifos.mifosxdroid.online.DashboardActivity; - -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; - -import java.text.SimpleDateFormat; -import java.util.Date; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard; -import static androidx.test.espresso.action.ViewActions.scrollTo; -import static androidx.test.espresso.action.ViewActions.typeText; -import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.ViewMatchers.isChecked; -import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withText; - -/** - * Created by ahmed fathy on 17/04/16. - */ -public class CreateNewCenterFragmentTest extends - ActivityInstrumentationTestCase2 { - - private DashboardActivity mActivity; - - public CreateNewCenterFragmentTest() { - super(DashboardActivity.class); - } - - /** - * checks that the spinner is loaded with 1 or more items - */ - public static Matcher hasChildren() { - return new TypeSafeMatcher() { - - @Override - public boolean matchesSafely(View view) { - return ((Spinner) view).getAdapter().getCount() > 0; - } - - @Override - public void describeTo(Description description) { - description.appendText("The spinner has no children"); - } - }; - } - - @Override - public void setUp() throws Exception { - super.setUp(); - mActivity = getActivity(); - openCreateCenter(); - } - - /** - * - chooses "Create Center" from options menu - * - checks the CrateNewCenterFragment is added - */ - @SmallTest - public void testOpenCreateCenter() throws InterruptedException { - - openCreateCenter(); - - CreateNewCenterFragment createNewCenterFragment - = (CreateNewCenterFragment) mActivity.getSupportFragmentManager() - .findFragmentById(R.id.container); - - assertNotNull(createNewCenterFragment); - assertTrue(createNewCenterFragment.isAdded()); - } - - @SmallTest - public void testViewsVisible() throws InterruptedException { - - // initially, the center name edit test, office spinner and active checkbox are visible - onView(withId(R.id.et_center_name)) - .perform(scrollTo()) - .check(matches(isDisplayed())); - onView(withId(R.id.sp_center_offices)) - .perform(scrollTo()) - .check(matches(isDisplayed())); - onView(withId(R.id.cb_center_active_status)) - .perform(scrollTo()) - .check(matches(isDisplayed())); - onView(withId(R.id.btn_submit)) - .perform(scrollTo()) - .check(matches(isDisplayed())); - - // initially, the activation date is invisible but shows after checking the active checkbox - onView(withId(R.id.cb_center_active_status)) - .perform(scrollTo(), click()) - .check(matches(isChecked())); - onView(withId(R.id.tv_center_activationDate)) - .perform(scrollTo()) - .check(matches(isDisplayed())); - } - - /** - * checks that the center offcies spinner is loaded with data from the template - */ - @SmallTest - public void testSpinnerPopulated() throws InterruptedException { - Thread.sleep(3000); - onView(withId(R.id.sp_center_offices)) - .check(matches(hasChildren())); - } - - /** - * fills the template and presses submit - */ - @MediumTest - public void testCreateCenter() throws InterruptedException { - Thread.sleep(3000); - - // center name - onView(withId(R.id.et_center_name)) - .perform(scrollTo()) - .perform(typeText("myTestCenter"), closeSoftKeyboard()); - - // office - Spinner spinnerOffice = (Spinner) mActivity.findViewById(R.id.sp_center_offices); - String selectedOffice = (String) spinnerOffice.getAdapter().getItem(2); - onView(withId(R.id.sp_center_offices)) - .perform(scrollTo(), click()); - onView(withText(selectedOffice)) - .check(matches(isDisplayed())) - .perform(click()) - .check(matches(isDisplayed())); - - // activation date - onView(withId(R.id.cb_center_active_status)) - .perform(scrollTo(), click()); - SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy"); - String currentDate = formatter.format(new Date()); - onView(withId(R.id.tv_center_activationDate)) - .check(matches(withText(currentDate))); - - // submit - onView(withId(R.id.btn_submit)) - .perform(scrollTo(), click()); - } - - /** - * chooses "Create Center" from the options menu - */ - private void openCreateCenter() throws InterruptedException { - - getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU); - onView(withText("Create Center")) - .perform(click()); - } - -} \ No newline at end of file diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CreateNewCenterFragmentTest.kt b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CreateNewCenterFragmentTest.kt new file mode 100644 index 00000000000..d365ee96bf3 --- /dev/null +++ b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CreateNewCenterFragmentTest.kt @@ -0,0 +1,145 @@ +/* + * This project is licensed under the open source MPL V2. + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.mifosxdroid.tests + +import android.test.ActivityInstrumentationTestCase2 +import android.view.KeyEvent +import android.view.View +import com.mifos.mifosxdroid.R +import org.hamcrest.Description +import org.hamcrest.Matcher +import org.hamcrest.TypeSafeMatcher +import java.text.SimpleDateFormat +import java.util.Date + +/** + * Created by ahmed fathy on 17/04/16. + */ +class CreateNewCenterFragmentTest : ActivityInstrumentationTestCase2( + DashboardActivity::class.java +) { + private var mActivity: DashboardActivity? = null + @Throws(Exception::class) + fun setUp() { + super.setUp() + mActivity = getActivity() + openCreateCenter() + } + + /** + * - chooses "Create Center" from options menu + * - checks the CrateNewCenterFragment is added + */ + @SmallTest + @Throws(InterruptedException::class) + fun testOpenCreateCenter() { + openCreateCenter() + val createNewCenterFragment: CreateNewCenterFragment = mActivity.getSupportFragmentManager() + .findFragmentById(R.id.container) as CreateNewCenterFragment + assertNotNull(createNewCenterFragment) + assertTrue(createNewCenterFragment.isAdded()) + } + + @SmallTest + @Throws(InterruptedException::class) + fun testViewsVisible() { + + // initially, the center name edit test, office spinner and active checkbox are visible + Espresso.onView(ViewMatchers.withId(R.id.et_center_name)) + .perform(ViewActions.scrollTo()) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + Espresso.onView(ViewMatchers.withId(R.id.sp_center_offices)) + .perform(ViewActions.scrollTo()) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + Espresso.onView(ViewMatchers.withId(R.id.cb_center_active_status)) + .perform(ViewActions.scrollTo()) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + Espresso.onView(ViewMatchers.withId(R.id.btn_submit)) + .perform(ViewActions.scrollTo()) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + + // initially, the activation date is invisible but shows after checking the active checkbox + Espresso.onView(ViewMatchers.withId(R.id.cb_center_active_status)) + .perform(ViewActions.scrollTo(), ViewActions.click()) + .check(ViewAssertions.matches(ViewMatchers.isChecked())) + Espresso.onView(ViewMatchers.withId(R.id.tv_center_activationDate)) + .perform(ViewActions.scrollTo()) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + } + + /** + * checks that the center offcies spinner is loaded with data from the template + */ + @SmallTest + @Throws(InterruptedException::class) + fun testSpinnerPopulated() { + Thread.sleep(3000) + Espresso.onView(ViewMatchers.withId(R.id.sp_center_offices)) + .check(ViewAssertions.matches(hasChildren())) + } + + /** + * fills the template and presses submit + */ + @MediumTest + @Throws(InterruptedException::class) + fun testCreateCenter() { + Thread.sleep(3000) + + // center name + Espresso.onView(ViewMatchers.withId(R.id.et_center_name)) + .perform(ViewActions.scrollTo()) + .perform(ViewActions.typeText("myTestCenter"), ViewActions.closeSoftKeyboard()) + + // office + val spinnerOffice: Spinner = mActivity.findViewById(R.id.sp_center_offices) as Spinner + val selectedOffice = spinnerOffice.getAdapter().getItem(2) as String + Espresso.onView(ViewMatchers.withId(R.id.sp_center_offices)) + .perform(ViewActions.scrollTo(), ViewActions.click()) + Espresso.onView(ViewMatchers.withText(selectedOffice)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + .perform(ViewActions.click()) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + + // activation date + Espresso.onView(ViewMatchers.withId(R.id.cb_center_active_status)) + .perform(ViewActions.scrollTo(), ViewActions.click()) + val formatter = SimpleDateFormat("dd-MM-yyyy") + val currentDate = formatter.format(Date()) + Espresso.onView(ViewMatchers.withId(R.id.tv_center_activationDate)) + .check(ViewAssertions.matches(ViewMatchers.withText(currentDate))) + + // submit + Espresso.onView(ViewMatchers.withId(R.id.btn_submit)) + .perform(ViewActions.scrollTo(), ViewActions.click()) + } + + /** + * chooses "Create Center" from the options menu + */ + @Throws(InterruptedException::class) + private fun openCreateCenter() { + getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU) + Espresso.onView(ViewMatchers.withText("Create Center")) + .perform(ViewActions.click()) + } + + companion object { + /** + * checks that the spinner is loaded with 1 or more items + */ + fun hasChildren(): Matcher { + return object : TypeSafeMatcher() { + public override fun matchesSafely(view: View): Boolean { + return (view as Spinner).getAdapter().getCount() > 0 + } + + override fun describeTo(description: Description) { + description.appendText("The spinner has no children") + } + } + } + } +} \ No newline at end of file diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CreateNewClientFragmentTest.java b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CreateNewClientFragmentTest.java deleted file mode 100644 index dd0e236ce94..00000000000 --- a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CreateNewClientFragmentTest.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ - -package com.mifos.mifosxdroid.tests; - -import android.test.ActivityInstrumentationTestCase2; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.SmallTest; -import android.view.View; -import android.widget.CheckBox; -import android.widget.TextView; - -import com.mifos.mifosxdroid.R; -import com.mifos.mifosxdroid.online.createnewclient.CreateNewClientFragment; -import com.mifos.mifosxdroid.online.DashboardActivity; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.action.ViewActions.scrollTo; -import static androidx.test.espresso.matcher.ViewMatchers.withId; - -/** - * Created by ahmed fathy on 26/03/16. - */ -public class CreateNewClientFragmentTest extends - ActivityInstrumentationTestCase2 { - - /* fields */ - private DashboardActivity dashboardActivity; - private CreateNewClientFragment createNewClientFragment; - - /* views */ - private TextView textViewDateOfBirth; - private TextView textViewSubmissionDate; - private CheckBox checkBoxActive; - - public CreateNewClientFragmentTest() { - super(DashboardActivity.class); - } - - @Override - public void setUp() throws Exception { - super.setUp(); - - // open create client tab - dashboardActivity = getActivity(); - dashboardActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - dashboardActivity.openCreateClient(); - } - }); - Thread.sleep(5000); - - // reference views - createNewClientFragment = (CreateNewClientFragment) dashboardActivity - .getSupportFragmentManager().findFragmentById(R.id.container); - textViewDateOfBirth = (TextView) dashboardActivity.findViewById(R.id.tv_dateofbirth); - textViewSubmissionDate = (TextView) dashboardActivity.findViewById(R.id.tv_submission_date); - checkBoxActive = (CheckBox) dashboardActivity.findViewById(R.id.cb_client_active_status); - } - - @SmallTest - public void testViewsNotNull() { - assertNotNull(textViewDateOfBirth); - assertNotNull(textViewSubmissionDate); - assertNotNull(checkBoxActive); - } - - /** - * - change birth date, check its text view is update - * - change submission date, check its text view is updated and birth date isn't - * - change birth date again, checks its text view is update, submission date isn't - */ - @MediumTest - public void testChangeDates() throws InterruptedException { - - // change birth date - String birthDate = "01-01-1990"; - changeBirthDate(birthDate); - assertEquals(textViewDateOfBirth.getText().toString(), birthDate); - - // check the active checkbox - dashboardActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - checkBoxActive.setChecked(true); - } - }); - Thread.sleep(1000); - assertEquals(View.VISIBLE, textViewSubmissionDate.getVisibility()); - - // change submission date - final String submissionDate = "02-02-2000"; - changeSubmissionDate(submissionDate); - assertEquals(textViewSubmissionDate.getText().toString(), submissionDate); - assertEquals(textViewDateOfBirth.getText().toString(), birthDate); - - // change date of birth again - birthDate = "03-03-1989"; - changeBirthDate(birthDate); - assertEquals(textViewSubmissionDate.getText().toString(), submissionDate); - assertEquals(textViewDateOfBirth.getText().toString(), birthDate); - } - - private void changeBirthDate(final String dateOfBirth) throws InterruptedException { - - // open the date picker - onView(withId(R.id.tv_dateofbirth)).perform(scrollTo()); - onView(withId(R.id.tv_dateofbirth)).perform(click()); - Thread.sleep(1000); - assertTrue(createNewClientFragment.datePickerDateOfBirth.isAdded()); - - // update date and close date picker - dashboardActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - createNewClientFragment.onDatePicked(dateOfBirth); - } - }); - createNewClientFragment.datePickerDateOfBirth.dismiss(); - Thread.sleep(1000); - } - - private void changeSubmissionDate(final String submissionDate) throws InterruptedException { - // open the date picker - onView(withId(R.id.tv_submission_date)).perform(scrollTo()); - onView(withId(R.id.tv_submission_date)).perform(click()); - Thread.sleep(1000); - assertTrue(createNewClientFragment.datePickerSubmissionDate.isAdded()); - - // update date and close date picker - dashboardActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - createNewClientFragment.onDatePicked(submissionDate); - } - }); - createNewClientFragment.datePickerSubmissionDate.dismiss(); - Thread.sleep(1000); - } - - -} \ No newline at end of file diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CreateNewClientFragmentTest.kt b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CreateNewClientFragmentTest.kt new file mode 100644 index 00000000000..8e97ca714fd --- /dev/null +++ b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CreateNewClientFragmentTest.kt @@ -0,0 +1,114 @@ +/* + * This project is licensed under the open source MPL V2. + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.mifosxdroid.tests + +import android.test.ActivityInstrumentationTestCase2 +import android.view.View +import com.mifos.mifosxdroid.R + +/** + * Created by ahmed fathy on 26/03/16. + */ +class CreateNewClientFragmentTest : ActivityInstrumentationTestCase2( + DashboardActivity::class.java +) { + /* fields */ + private var dashboardActivity: DashboardActivity? = null + private var createNewClientFragment: CreateNewClientFragment? = null + + /* views */ + private var textViewDateOfBirth: TextView? = null + private var textViewSubmissionDate: TextView? = null + private var checkBoxActive: CheckBox? = null + @Throws(Exception::class) + fun setUp() { + super.setUp() + + // open create client tab + dashboardActivity = getActivity() + dashboardActivity.runOnUiThread(Runnable { dashboardActivity.openCreateClient() }) + Thread.sleep(5000) + + // reference views + createNewClientFragment = dashboardActivity + .getSupportFragmentManager().findFragmentById(R.id.container) as CreateNewClientFragment + textViewDateOfBirth = dashboardActivity.findViewById(R.id.tv_dateofbirth) as TextView + textViewSubmissionDate = dashboardActivity.findViewById(R.id.tv_submission_date) as TextView + checkBoxActive = dashboardActivity.findViewById(R.id.cb_client_active_status) as CheckBox + } + + @SmallTest + fun testViewsNotNull() { + assertNotNull(textViewDateOfBirth) + assertNotNull(textViewSubmissionDate) + assertNotNull(checkBoxActive) + } + + /** + * - change birth date, check its text view is update + * - change submission date, check its text view is updated and birth date isn't + * - change birth date again, checks its text view is update, submission date isn't + */ + @MediumTest + @Throws(InterruptedException::class) + fun testChangeDates() { + + // change birth date + var birthDate = "01-01-1990" + changeBirthDate(birthDate) + assertEquals(textViewDateOfBirth.getText().toString(), birthDate) + + // check the active checkbox + dashboardActivity.runOnUiThread(Runnable { checkBoxActive.setChecked(true) }) + Thread.sleep(1000) + assertEquals(View.VISIBLE, textViewSubmissionDate.getVisibility()) + + // change submission date + val submissionDate = "02-02-2000" + changeSubmissionDate(submissionDate) + assertEquals(textViewSubmissionDate.getText().toString(), submissionDate) + assertEquals(textViewDateOfBirth.getText().toString(), birthDate) + + // change date of birth again + birthDate = "03-03-1989" + changeBirthDate(birthDate) + assertEquals(textViewSubmissionDate.getText().toString(), submissionDate) + assertEquals(textViewDateOfBirth.getText().toString(), birthDate) + } + + @Throws(InterruptedException::class) + private fun changeBirthDate(dateOfBirth: String) { + + // open the date picker + Espresso.onView(ViewMatchers.withId(R.id.tv_dateofbirth)).perform(ViewActions.scrollTo()) + Espresso.onView(ViewMatchers.withId(R.id.tv_dateofbirth)).perform(ViewActions.click()) + Thread.sleep(1000) + assertTrue(createNewClientFragment.datePickerDateOfBirth.isAdded()) + + // update date and close date picker + dashboardActivity.runOnUiThread(Runnable { createNewClientFragment.onDatePicked(dateOfBirth) }) + createNewClientFragment.datePickerDateOfBirth.dismiss() + Thread.sleep(1000) + } + + @Throws(InterruptedException::class) + private fun changeSubmissionDate(submissionDate: String) { + // open the date picker + Espresso.onView(ViewMatchers.withId(R.id.tv_submission_date)) + .perform(ViewActions.scrollTo()) + Espresso.onView(ViewMatchers.withId(R.id.tv_submission_date)).perform(ViewActions.click()) + Thread.sleep(1000) + assertTrue(createNewClientFragment.datePickerSubmissionDate.isAdded()) + + // update date and close date picker + dashboardActivity.runOnUiThread(Runnable { + createNewClientFragment.onDatePicked( + submissionDate + ) + }) + createNewClientFragment.datePickerSubmissionDate.dismiss() + Thread.sleep(1000) + } +} \ No newline at end of file diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CreateNewGroupFragmentTest.java b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CreateNewGroupFragmentTest.java deleted file mode 100644 index e2aa4c568eb..00000000000 --- a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CreateNewGroupFragmentTest.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ - -package com.mifos.mifosxdroid.tests; - -import android.test.ActivityInstrumentationTestCase2; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.SmallTest; -import android.view.KeyEvent; -import android.view.View; -import android.widget.Spinner; - -import com.mifos.mifosxdroid.R; -import com.mifos.mifosxdroid.online.createnewgroup.CreateNewGroupFragment; -import com.mifos.mifosxdroid.online.DashboardActivity; - -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; - -import java.text.SimpleDateFormat; -import java.util.Date; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard; -import static androidx.test.espresso.action.ViewActions.scrollTo; -import static androidx.test.espresso.action.ViewActions.typeText; -import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.ViewMatchers.isChecked; -import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withText; - -/** - * Created by ahmed fathy on 20/04/16. - */ -public class CreateNewGroupFragmentTest extends - ActivityInstrumentationTestCase2 { - - private DashboardActivity mActivity; - - public CreateNewGroupFragmentTest() { - super(DashboardActivity.class); - } - - /** - * checks that the spinner is loaded with 1 or more items - */ - public static Matcher hasChildren() { - return new TypeSafeMatcher() { - - @Override - public boolean matchesSafely(View view) { - return ((Spinner) view).getAdapter().getCount() > 0; - } - - @Override - public void describeTo(Description description) { - description.appendText("The spinner has no children"); - } - }; - } - - @Override - public void setUp() throws Exception { - super.setUp(); - mActivity = getActivity(); - openCreateGroup(); - } - - /** - * - chooses "Create Group" from options menu - * - checks the CrateNewGroupFragment is added - */ - @SmallTest - public void testOpenCreateGroup() throws InterruptedException { - - CreateNewGroupFragment createNewGroupFragment - = (CreateNewGroupFragment) mActivity.getSupportFragmentManager() - .findFragmentById(R.id.container); - - assertNotNull(createNewGroupFragment); - assertTrue(createNewGroupFragment.isAdded()); - } - - @SmallTest - public void testViewsVisible() throws InterruptedException { - - // initially, the group name, office spinner. submission date, - // external id, active checkbox and submit button are visible - onView(withId(R.id.et_group_name)) - .perform(scrollTo()) - .check(matches(isDisplayed())); - onView(withId(R.id.sp_group_offices)) - .perform(scrollTo()) - .check(matches(isDisplayed())); - onView(withId(R.id.tv_group_submission_date)) - .perform(scrollTo()) - .check(matches(isDisplayed())); - onView(withId(R.id.et_group_external_id)) - .perform(scrollTo()) - .check(matches(isDisplayed())); - onView(withId(R.id.cb_group_active_status)) - .perform(scrollTo()) - .check(matches(isDisplayed())); - onView(withId(R.id.btn_submit)) - .perform(scrollTo()) - .check(matches(isDisplayed())); - - // initially, the activation date is invisible but shows after checking the active checkbox - onView(withId(R.id.cb_group_active_status)) - .perform(scrollTo(), click()) - .check(matches(isChecked())); - onView(withId(R.id.tv_group_activationDate)) - .perform(scrollTo()) - .check(matches(isDisplayed())); - } - - /** - * checks that the office spinner is loaded with data from the template - */ - @SmallTest - public void testSpinnerPopulated() throws InterruptedException { - Thread.sleep(3000); - onView(withId(R.id.sp_group_offices)) - .check(matches(hasChildren())); - } - - /** - * fills the template and presses submit - */ - @MediumTest - public void testCreateGroup() throws InterruptedException { - Thread.sleep(3000); - - // group name - onView(withId(R.id.et_group_name)) - .perform(scrollTo()) - .perform(typeText("myTestGroup"), closeSoftKeyboard()); - - // office - Spinner spinnerOffice = (Spinner) mActivity.findViewById(R.id.sp_group_offices); - if (spinnerOffice.getAdapter().getCount() > 2) { - String selectedOffice = (String) spinnerOffice.getAdapter().getItem(2); - onView(withId(R.id.sp_group_offices)) - .perform(scrollTo(), click()); - onView(withText(selectedOffice)) - .check(matches(isDisplayed())) - .perform(click()) - .check(matches(isDisplayed())); - } - - // submission date - SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy"); - String currentDate = formatter.format(new Date()); - onView(withId(R.id.tv_group_submission_date)) - .perform(scrollTo()) - .check(matches(withText(currentDate))); - - // external id - onView(withId(R.id.et_group_external_id)) - .perform(scrollTo()) - .perform(typeText("123"), closeSoftKeyboard()); - - // activation date - onView(withId(R.id.cb_group_active_status)) - .perform(scrollTo(), click()); - onView(withId(R.id.tv_group_activationDate)) - .check(matches(withText(currentDate))); - - // submit - onView(withId(R.id.btn_submit)) - .perform(scrollTo(), click()); - } - - /** - * chooses "Create Group" from the options menu - */ - private void openCreateGroup() throws InterruptedException { - - getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU); - onView(withText("Create Group")) - .perform(click()); - } - -} \ No newline at end of file diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CreateNewGroupFragmentTest.kt b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CreateNewGroupFragmentTest.kt new file mode 100644 index 00000000000..c98fa5804ab --- /dev/null +++ b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/CreateNewGroupFragmentTest.kt @@ -0,0 +1,163 @@ +/* + * This project is licensed under the open source MPL V2. + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.mifosxdroid.tests + +import android.test.ActivityInstrumentationTestCase2 +import android.view.KeyEvent +import android.view.View +import com.mifos.mifosxdroid.R +import org.hamcrest.Description +import org.hamcrest.Matcher +import org.hamcrest.TypeSafeMatcher +import java.text.SimpleDateFormat +import java.util.Date + +/** + * Created by ahmed fathy on 20/04/16. + */ +class CreateNewGroupFragmentTest : ActivityInstrumentationTestCase2( + DashboardActivity::class.java +) { + private var mActivity: DashboardActivity? = null + @Throws(Exception::class) + fun setUp() { + super.setUp() + mActivity = getActivity() + openCreateGroup() + } + + /** + * - chooses "Create Group" from options menu + * - checks the CrateNewGroupFragment is added + */ + @SmallTest + @Throws(InterruptedException::class) + fun testOpenCreateGroup() { + val createNewGroupFragment: CreateNewGroupFragment = mActivity.getSupportFragmentManager() + .findFragmentById(R.id.container) as CreateNewGroupFragment + assertNotNull(createNewGroupFragment) + assertTrue(createNewGroupFragment.isAdded()) + } + + @SmallTest + @Throws(InterruptedException::class) + fun testViewsVisible() { + + // initially, the group name, office spinner. submission date, + // external id, active checkbox and submit button are visible + Espresso.onView(ViewMatchers.withId(R.id.et_group_name)) + .perform(ViewActions.scrollTo()) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + Espresso.onView(ViewMatchers.withId(R.id.sp_group_offices)) + .perform(ViewActions.scrollTo()) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + Espresso.onView(ViewMatchers.withId(R.id.tv_group_submission_date)) + .perform(ViewActions.scrollTo()) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + Espresso.onView(ViewMatchers.withId(R.id.et_group_external_id)) + .perform(ViewActions.scrollTo()) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + Espresso.onView(ViewMatchers.withId(R.id.cb_group_active_status)) + .perform(ViewActions.scrollTo()) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + Espresso.onView(ViewMatchers.withId(R.id.btn_submit)) + .perform(ViewActions.scrollTo()) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + + // initially, the activation date is invisible but shows after checking the active checkbox + Espresso.onView(ViewMatchers.withId(R.id.cb_group_active_status)) + .perform(ViewActions.scrollTo(), ViewActions.click()) + .check(ViewAssertions.matches(ViewMatchers.isChecked())) + Espresso.onView(ViewMatchers.withId(R.id.tv_group_activationDate)) + .perform(ViewActions.scrollTo()) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + } + + /** + * checks that the office spinner is loaded with data from the template + */ + @SmallTest + @Throws(InterruptedException::class) + fun testSpinnerPopulated() { + Thread.sleep(3000) + Espresso.onView(ViewMatchers.withId(R.id.sp_group_offices)) + .check(ViewAssertions.matches(hasChildren())) + } + + /** + * fills the template and presses submit + */ + @MediumTest + @Throws(InterruptedException::class) + fun testCreateGroup() { + Thread.sleep(3000) + + // group name + Espresso.onView(ViewMatchers.withId(R.id.et_group_name)) + .perform(ViewActions.scrollTo()) + .perform(ViewActions.typeText("myTestGroup"), ViewActions.closeSoftKeyboard()) + + // office + val spinnerOffice: Spinner = mActivity.findViewById(R.id.sp_group_offices) as Spinner + if (spinnerOffice.getAdapter().getCount() > 2) { + val selectedOffice = spinnerOffice.getAdapter().getItem(2) as String + Espresso.onView(ViewMatchers.withId(R.id.sp_group_offices)) + .perform(ViewActions.scrollTo(), ViewActions.click()) + Espresso.onView(ViewMatchers.withText(selectedOffice)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + .perform(ViewActions.click()) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + } + + // submission date + val formatter = SimpleDateFormat("dd-MM-yyyy") + val currentDate = formatter.format(Date()) + Espresso.onView(ViewMatchers.withId(R.id.tv_group_submission_date)) + .perform(ViewActions.scrollTo()) + .check(ViewAssertions.matches(ViewMatchers.withText(currentDate))) + + // external id + Espresso.onView(ViewMatchers.withId(R.id.et_group_external_id)) + .perform(ViewActions.scrollTo()) + .perform(ViewActions.typeText("123"), ViewActions.closeSoftKeyboard()) + + // activation date + Espresso.onView(ViewMatchers.withId(R.id.cb_group_active_status)) + .perform(ViewActions.scrollTo(), ViewActions.click()) + Espresso.onView(ViewMatchers.withId(R.id.tv_group_activationDate)) + .check(ViewAssertions.matches(ViewMatchers.withText(currentDate))) + + // submit + Espresso.onView(ViewMatchers.withId(R.id.btn_submit)) + .perform(ViewActions.scrollTo(), ViewActions.click()) + } + + /** + * chooses "Create Group" from the options menu + */ + @Throws(InterruptedException::class) + private fun openCreateGroup() { + getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU) + Espresso.onView(ViewMatchers.withText("Create Group")) + .perform(ViewActions.click()) + } + + companion object { + /** + * checks that the spinner is loaded with 1 or more items + */ + fun hasChildren(): Matcher { + return object : TypeSafeMatcher() { + public override fun matchesSafely(view: View): Boolean { + return (view as Spinner).getAdapter().getCount() > 0 + } + + override fun describeTo(description: Description) { + description.appendText("The spinner has no children") + } + } + } + } +} \ No newline at end of file diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/DashboardFragmentActivityTest.java b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/DashboardFragmentActivityTest.java deleted file mode 100755 index 79440d26bc4..00000000000 --- a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/DashboardFragmentActivityTest.java +++ /dev/null @@ -1,251 +0,0 @@ -package com.mifos.mifosxdroid.tests; - -import android.app.Activity; -import android.app.Instrumentation; -import com.google.android.material.navigation.NavigationView; -import androidx.test.espresso.UiController; -import androidx.test.espresso.ViewAction; -import androidx.core.view.GravityCompat; -import androidx.drawerlayout.widget.DrawerLayout; -import android.test.ActivityInstrumentationTestCase2; -import android.test.TouchUtils; -import android.test.ViewAsserts; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.SmallTest; -import android.test.suitebuilder.annotation.Suppress; -import android.view.KeyEvent; -import android.view.MenuItem; -import android.view.View; -import android.widget.Button; -import android.widget.EditText; -import android.widget.ListView; -import android.widget.TextView; - -import com.mifos.mifosxdroid.ClientListActivity; -import com.mifos.mifosxdroid.GroupListActivity; -import com.mifos.mifosxdroid.R; -import com.mifos.mifosxdroid.activity.pathtracking.PathTrackingActivity; -import com.mifos.mifosxdroid.offline.offlinedashbarod.OfflineDashboardFragment; -import com.mifos.mifosxdroid.online.CentersActivity; -import com.mifos.mifosxdroid.online.DashboardActivity; -import com.mifos.mifosxdroid.online.search.SearchFragment; -import com.mifos.utils.FragmentConstants; -import com.mifos.utils.PrefManager; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom; -import static androidx.test.espresso.matcher.ViewMatchers.withId; - -/** - * Created by Gabriel Esteban on 06/12/14. - */ -@Suppress // TODO: Fix NPE -public class DashboardFragmentActivityTest extends - ActivityInstrumentationTestCase2 { - - DashboardActivity dashboardActivity; - EditText et_searchById; - Button bt_searchClient; - ListView lv_searchResults; - TextView tv_title_search; - SearchFragment searchFragment; - - public DashboardFragmentActivityTest() { - super(DashboardActivity.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - dashboardActivity = getActivity(); - searchFragment = (SearchFragment) getActivity().getSupportFragmentManager() - .findFragmentByTag(FragmentConstants.FRAG_CLIENT_SEARCH); - et_searchById = (EditText) dashboardActivity.findViewById(R.id.et_search_by_id); - bt_searchClient = (Button) dashboardActivity.findViewById(R.id.bt_searchClient); - lv_searchResults = (ListView) dashboardActivity.findViewById(R.id.lv_searchResults); - tv_title_search = (TextView) dashboardActivity.findViewById(R.id.tv_title_search_results); - } - - - @SmallTest - public void testViewsAreNotNull() { - assertNotNull(et_searchById); - assertNotNull(bt_searchClient); - assertNotNull(lv_searchResults); - assertNotNull(tv_title_search); - } - - @SmallTest - public void testViewsAreOnTheScreen() { - final View decorView = dashboardActivity.getWindow().getDecorView(); - - ViewAsserts.assertOnScreen(decorView, et_searchById); - ViewAsserts.assertOnScreen(decorView, bt_searchClient); - ViewAsserts.assertOnScreen(decorView, lv_searchResults); - ViewAsserts.assertOnScreen(decorView, tv_title_search); - } - - @SmallTest - public void testNullInput() { - //checking if the text field is empty - String expected = ""; - String actual = et_searchById.getText().toString(); - assertEquals(expected, actual); - - //clicking the button - TouchUtils.clickView(this, bt_searchClient); - } - - @MediumTest - public void testClientListActivityStarted() throws InterruptedException { - - Instrumentation.ActivityMonitor monitor = getInstrumentation().addMonitor - (ClientListActivity.class.getName(), null, false); - - // select item from navigation drawer - onView(withId(R.id.drawer)).perform(actionOpenDrawer()); - Thread.sleep(500); - onView(withId(R.id.navigation_view)).perform(actionSelectNavItem(R.id.item_clients)); - - Activity startedActivity = getInstrumentation().waitForMonitorWithTimeout(monitor, 6000); - assertNotNull(startedActivity); - assertEquals(true, getInstrumentation().checkMonitorHit(monitor, 1)); - - this.sendKeys(KeyEvent.KEYCODE_BACK); - } - - @MediumTest - public void testGroupListActivityStarted() throws InterruptedException { - Instrumentation.ActivityMonitor monitor = getInstrumentation().addMonitor - (GroupListActivity.class.getName(), null, false); - - // select item from navigation drawer - onView(withId(R.id.drawer)).perform(actionOpenDrawer()); - Thread.sleep(500); - onView(withId(R.id.navigation_view)).perform(actionSelectNavItem(R.id.item_groups)); - - - Activity startedActivity = getInstrumentation().waitForMonitorWithTimeout(monitor, 6000); - assertNotNull(startedActivity); - assertEquals(true, getInstrumentation().checkMonitorHit(monitor, 1)); - - this.sendKeys(KeyEvent.KEYCODE_BACK); - } - - @MediumTest - public void testCenterListActivityStarted() throws InterruptedException { - Instrumentation.ActivityMonitor monitor = getInstrumentation().addMonitor(CentersActivity - .class.getName(), null, false); - - // select item from navigation drawer - onView(withId(R.id.drawer)).perform(actionOpenDrawer()); - Thread.sleep(500); - onView(withId(R.id.navigation_view)).perform(actionSelectNavItem(R.id.item_centers)); - - - Activity startedActivity = getInstrumentation().waitForMonitorWithTimeout(monitor, 6000); - assertNotNull(startedActivity); - assertEquals(true, getInstrumentation().checkMonitorHit(monitor, 1)); - - this.sendKeys(KeyEvent.KEYCODE_BACK); - } - - @MediumTest - public void testPathTrackingActivityStarted() throws InterruptedException { - Instrumentation.ActivityMonitor monitor = getInstrumentation().addMonitor - (PathTrackingActivity.class.getName(), null, false); - - // select item from navigation drawer - onView(withId(R.id.drawer)).perform(actionOpenDrawer()); - Thread.sleep(500); - onView(withId(R.id.navigation_view)).perform(actionSelectNavItem(R.id.item_path_tracker)); - - - Activity startedActivity = getInstrumentation().waitForMonitorWithTimeout(monitor, 6000); - assertNotNull(startedActivity); - assertEquals(true, getInstrumentation().checkMonitorHit(monitor, 1)); - - this.sendKeys(KeyEvent.KEYCODE_BACK); - } - - - @MediumTest - public void testOfflineActivityStarted() throws InterruptedException { - Instrumentation.ActivityMonitor monitor = getInstrumentation().addMonitor - (OfflineDashboardFragment.class.getName(), null, false); - - // select item from navigation drawer - onView(withId(R.id.drawer)).perform(actionOpenDrawer()); - Thread.sleep(500); - onView(withId(R.id.navigation_view)).perform(actionSelectNavItem(R.id.item_offline)); - - Activity startedActivity = getInstrumentation().waitForMonitorWithTimeout(monitor, 2000); - assertNotNull(startedActivity); - assertEquals(true, getInstrumentation().checkMonitorHit(monitor, 1)); - - this.sendKeys(KeyEvent.KEYCODE_BACK); - } - - /** - * Should be tested once the user is logged in. - */ - @MediumTest - public void testLogOut() throws InterruptedException { - // select log out from options menu - getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU); - getInstrumentation().invokeMenuActionSync(getActivity(), R.id.logout, 0); - - assertEquals("", PrefManager.getToken()); - } - - /** - * a work around to test opening a nav drawer - */ - private ViewAction actionOpenDrawer() { - return new ViewAction() { - - @Override - public org.hamcrest.Matcher getConstraints() { - return isAssignableFrom(DrawerLayout.class); - } - - @Override - public String getDescription() { - return "open drawer"; - } - - @Override - public void perform(UiController uiController, View view) { - ((DrawerLayout) view).openDrawer(GravityCompat.START); - } - }; - } - - /** - * a work around to test selecting an item from a navigation view - */ - private ViewAction actionSelectNavItem(final int id) { - return new ViewAction() { - - @Override - public org.hamcrest.Matcher getConstraints() { - return isAssignableFrom(NavigationView.class); - } - - @Override - public String getDescription() { - return "select item"; - } - - @Override - public void perform(UiController uiController, View view) { - - MenuItem item = ((NavigationView) view).getMenu().findItem(id).setCheckable(true); - NavigationView.OnNavigationItemSelectedListener listener = (NavigationView - .OnNavigationItemSelectedListener) getActivity(); - listener.onNavigationItemSelected(item); - } - }; - } - -} diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/DashboardFragmentActivityTest.kt b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/DashboardFragmentActivityTest.kt new file mode 100644 index 00000000000..9d4c6f576ea --- /dev/null +++ b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/DashboardFragmentActivityTest.kt @@ -0,0 +1,207 @@ +package com.mifos.mifosxdroid.tests + +import android.view.KeyEvent +import android.view.MenuItem +import android.view.View +import android.widget.Button +import android.widget.ListView +import androidx.test.espresso.UiController +import com.google.android.material.navigation.NavigationView +import com.mifos.mifosxdroid.R +import org.hamcrest.Matcher + +/** + * Created by Gabriel Esteban on 06/12/14. + */ +@Suppress // TODO: Fix NPE + +class DashboardFragmentActivityTest : ActivityInstrumentationTestCase2( + DashboardActivity::class.java +) { + var dashboardActivity: DashboardActivity? = null + var et_searchById: EditText? = null + var bt_searchClient: Button? = null + var lv_searchResults: ListView? = null + var tv_title_search: TextView? = null + var searchFragment: SearchFragment? = null + @Throws(Exception::class) + protected fun setUp() { + super.setUp() + dashboardActivity = getActivity() + searchFragment = getActivity().getSupportFragmentManager() + .findFragmentByTag(FragmentConstants.FRAG_CLIENT_SEARCH) as SearchFragment + et_searchById = dashboardActivity.findViewById(R.id.et_search_by_id) as EditText + bt_searchClient = dashboardActivity.findViewById(R.id.bt_searchClient) + lv_searchResults = dashboardActivity.findViewById(R.id.lv_searchResults) + tv_title_search = dashboardActivity.findViewById(R.id.tv_title_search_results) as TextView + } + + @SmallTest + fun testViewsAreNotNull() { + assertNotNull(et_searchById) + assertNotNull(bt_searchClient) + assertNotNull(lv_searchResults) + assertNotNull(tv_title_search) + } + + @SmallTest + fun testViewsAreOnTheScreen() { + val decorView: View = dashboardActivity.getWindow().getDecorView() + ViewAsserts.assertOnScreen(decorView, et_searchById) + ViewAsserts.assertOnScreen(decorView, bt_searchClient) + ViewAsserts.assertOnScreen(decorView, lv_searchResults) + ViewAsserts.assertOnScreen(decorView, tv_title_search) + } + + @SmallTest + fun testNullInput() { + //checking if the text field is empty + val expected = "" + val actual: String = et_searchById.getText().toString() + assertEquals(expected, actual) + + //clicking the button + TouchUtils.clickView(this, bt_searchClient) + } + + @MediumTest + @Throws(InterruptedException::class) + fun testClientListActivityStarted() { + val monitor: ActivityMonitor = + getInstrumentation().addMonitor(ClientListActivity::class.java.getName(), null, false) + + // select item from navigation drawer + Espresso.onView(ViewMatchers.withId(R.id.drawer)).perform(actionOpenDrawer()) + Thread.sleep(500) + Espresso.onView(ViewMatchers.withId(R.id.navigation_view)) + .perform(actionSelectNavItem(R.id.item_clients)) + val startedActivity: Activity = + getInstrumentation().waitForMonitorWithTimeout(monitor, 6000) + assertNotNull(startedActivity) + assertEquals(true, getInstrumentation().checkMonitorHit(monitor, 1)) + this.sendKeys(KeyEvent.KEYCODE_BACK) + } + + @MediumTest + @Throws(InterruptedException::class) + fun testGroupListActivityStarted() { + val monitor: ActivityMonitor = + getInstrumentation().addMonitor(GroupListActivity::class.java.getName(), null, false) + + // select item from navigation drawer + Espresso.onView(ViewMatchers.withId(R.id.drawer)).perform(actionOpenDrawer()) + Thread.sleep(500) + Espresso.onView(ViewMatchers.withId(R.id.navigation_view)) + .perform(actionSelectNavItem(R.id.item_groups)) + val startedActivity: Activity = + getInstrumentation().waitForMonitorWithTimeout(monitor, 6000) + assertNotNull(startedActivity) + assertEquals(true, getInstrumentation().checkMonitorHit(monitor, 1)) + this.sendKeys(KeyEvent.KEYCODE_BACK) + } + + @MediumTest + @Throws(InterruptedException::class) + fun testCenterListActivityStarted() { + val monitor: ActivityMonitor = + getInstrumentation().addMonitor(CentersActivity::class.java.getName(), null, false) + + // select item from navigation drawer + Espresso.onView(ViewMatchers.withId(R.id.drawer)).perform(actionOpenDrawer()) + Thread.sleep(500) + Espresso.onView(ViewMatchers.withId(R.id.navigation_view)) + .perform(actionSelectNavItem(R.id.item_centers)) + val startedActivity: Activity = + getInstrumentation().waitForMonitorWithTimeout(monitor, 6000) + assertNotNull(startedActivity) + assertEquals(true, getInstrumentation().checkMonitorHit(monitor, 1)) + this.sendKeys(KeyEvent.KEYCODE_BACK) + } + + @MediumTest + @Throws(InterruptedException::class) + fun testPathTrackingActivityStarted() { + val monitor: ActivityMonitor = + getInstrumentation().addMonitor(PathTrackingActivity::class.java.getName(), null, false) + + // select item from navigation drawer + Espresso.onView(ViewMatchers.withId(R.id.drawer)).perform(actionOpenDrawer()) + Thread.sleep(500) + Espresso.onView(ViewMatchers.withId(R.id.navigation_view)) + .perform(actionSelectNavItem(R.id.item_path_tracker)) + val startedActivity: Activity = + getInstrumentation().waitForMonitorWithTimeout(monitor, 6000) + assertNotNull(startedActivity) + assertEquals(true, getInstrumentation().checkMonitorHit(monitor, 1)) + this.sendKeys(KeyEvent.KEYCODE_BACK) + } + + @MediumTest + @Throws(InterruptedException::class) + fun testOfflineActivityStarted() { + val monitor: ActivityMonitor = getInstrumentation().addMonitor( + OfflineDashboardFragment::class.java.getName(), + null, + false + ) + + // select item from navigation drawer + Espresso.onView(ViewMatchers.withId(R.id.drawer)).perform(actionOpenDrawer()) + Thread.sleep(500) + Espresso.onView(ViewMatchers.withId(R.id.navigation_view)) + .perform(actionSelectNavItem(R.id.item_offline)) + val startedActivity: Activity = + getInstrumentation().waitForMonitorWithTimeout(monitor, 2000) + assertNotNull(startedActivity) + assertEquals(true, getInstrumentation().checkMonitorHit(monitor, 1)) + this.sendKeys(KeyEvent.KEYCODE_BACK) + } + + /** + * Should be tested once the user is logged in. + */ + @MediumTest + @Throws(InterruptedException::class) + fun testLogOut() { + // select log out from options menu + getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU) + getInstrumentation().invokeMenuActionSync(getActivity(), R.id.logout, 0) + assertEquals("", PrefManager.token) + } + + /** + * a work around to test opening a nav drawer + */ + private fun actionOpenDrawer(): ViewAction { + return object : ViewAction { + val constraints: Matcher + get() = ViewMatchers.isAssignableFrom(DrawerLayout::class.java) + val description: String + get() = "open drawer" + + override fun perform(uiController: UiController, view: View) { + (view as DrawerLayout).openDrawer(GravityCompat.START) + } + } + } + + /** + * a work around to test selecting an item from a navigation view + */ + private fun actionSelectNavItem(id: Int): ViewAction { + return object : ViewAction { + val constraints: Matcher + get() = ViewMatchers.isAssignableFrom(NavigationView::class.java) + val description: String + get() = "select item" + + override fun perform(uiController: UiController, view: View) { + val item: MenuItem = + (view as NavigationView).getMenu().findItem(id).setCheckable(true) + val listener: NavigationView.OnNavigationItemSelectedListener = + getActivity() as NavigationView.OnNavigationItemSelectedListener + listener.onNavigationItemSelected(item) + } + } + } +} \ No newline at end of file diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/LoginActivityTest.java b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/LoginActivityTest.java deleted file mode 100755 index d1f34f6df61..00000000000 --- a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/LoginActivityTest.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ - -package com.mifos.mifosxdroid.tests; - -import android.content.SharedPreferences; -import android.preference.PreferenceManager; -import android.test.ActivityInstrumentationTestCase2; -import android.test.suitebuilder.annotation.MediumTest; -import android.test.suitebuilder.annotation.SmallTest; -import android.test.suitebuilder.annotation.Suppress; -import android.view.View; -import android.widget.EditText; -import android.widget.TextView; - -import com.mifos.mifosxdroid.login.LoginActivity; -import com.mifos.mifosxdroid.R; -import com.mifos.utils.Constants; -import com.mifos.utils.PrefManager; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription; -import static androidx.test.espresso.matcher.ViewMatchers.withText; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.startsWith; - -/** - * Created by ishankhanna on 12/08/14. - */ -public class LoginActivityTest extends ActivityInstrumentationTestCase2 { - - public static final String TEST_URL_1 = "demo.mifos.org"; - public static final String TEST_URL_2 = "www.google.com"; - public static final String TEST_URL_3 = "this.is.valid.url"; - public static final String TEST_URL_4 = "yahoo.in"; - public final String TEST_URL_5 = getActivity().getString(R.string.test_ip); - - LoginActivity loginActivity; - EditText et_mifos_domain; - EditText et_username; - TextView tv_constructed_instance_url; - - public LoginActivityTest() { - super(LoginActivity.class); - } - - @Override - public void setUp() throws Exception { - super.setUp(); - - loginActivity = getActivity(); - et_mifos_domain = (EditText) loginActivity.findViewById(R.id.et_instanceURL); - et_username = (EditText) loginActivity.findViewById(R.id.et_username); - tv_constructed_instance_url = (TextView) loginActivity.findViewById(R.id - .tv_constructed_instance_url); - } - - @SmallTest - public void testEditTextsAreNotNull() { - assertNotNull(et_mifos_domain); - assertNotNull(et_username); - } - - @SmallTest - public void testAllEditTextsAreVisible() { - assertEquals(View.VISIBLE, et_mifos_domain.getVisibility()); - } - - @SuppressWarnings("deprecation") - @SmallTest - public void testURLInstance1() { - //Test if TextView has been instantiated - assertNotNull(tv_constructed_instance_url); - - // Set URL and check the color of the message, it turns green - // only if the URL matches the pattern specified - enterMifosInstanceDomain(TEST_URL_1); - assertEquals(loginActivity.getResources().getColor(R.color.green_light), - tv_constructed_instance_url.getCurrentTextColor()); - } - - @SuppressWarnings("deprecation") - @SmallTest - public void testURLInstance2() { - //Test if TextView has been instantiated - assertNotNull(tv_constructed_instance_url); - enterMifosInstanceDomain(TEST_URL_2); - assertEquals(loginActivity.getResources().getColor(R.color.green_light), - tv_constructed_instance_url.getCurrentTextColor()); - } - - - @SuppressWarnings("deprecation") - @SmallTest - public void testURLInstance3() { - //Test if TextView has been instantiated - assertNotNull(tv_constructed_instance_url); - - enterMifosInstanceDomain(TEST_URL_3); - assertEquals(loginActivity.getResources().getColor(R.color.green_light), - tv_constructed_instance_url.getCurrentTextColor()); - } - - @SuppressWarnings("deprecation") - @SmallTest - public void testURLInstance4() { - //Test if TextView has been instantiated - assertNotNull(tv_constructed_instance_url); - enterMifosInstanceDomain(TEST_URL_4); - assertEquals(loginActivity.getResources().getColor(R.color.green_light), - tv_constructed_instance_url.getCurrentTextColor()); - } - - @SuppressWarnings("deprecation") - @SmallTest - public void testURLInstance5() { - //Test if TextView has been instantiated - assertNotNull(tv_constructed_instance_url); - enterMifosInstanceDomain(TEST_URL_5); - assertEquals(loginActivity.getResources().getColor(R.color.green_light), - tv_constructed_instance_url.getCurrentTextColor()); - } - - @MediumTest - public void testSaveLastAccessedInstanceDomainNameSavesProvidedString() { - PrefManager.setInstanceDomain(TEST_URL_1); - assertEquals(TEST_URL_1, PrefManager.getInstanceDomain()); - - PrefManager.setInstanceDomain(TEST_URL_2); - assertEquals(TEST_URL_2, PrefManager.getInstanceDomain()); - } - - @MediumTest - @Suppress // TODO: Fix ComparisonFailure: expected:<[demo.mifos.org]> but was:<[www.google.com]> - public void testValidateUserInputsSavesValidDomainToSharedProperties() { - saveLastAccessedInstanceDomainName(TEST_URL_2); - enterMifosInstanceDomain(TEST_URL_1); - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - getActivity().validateUserInputs(); - } - }); - getInstrumentation().waitForIdleSync(); - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences - (getInstrumentation().getTargetContext()); - assertEquals(TEST_URL_1, sharedPreferences.getString(Constants.INSTANCE_URL_KEY, "")); - } - - @MediumTest - @Suppress // TODO: Fix expected: - // but was: - public void testValidateUserInputsSetsAPIinstanceUrl() { - saveLastAccessedInstanceDomainName(TEST_URL_2); - enterMifosInstanceDomain(TEST_URL_1); - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - getActivity().validateUserInputs(); - } - }); - getInstrumentation().waitForIdleSync(); - } - - @SmallTest - public void testMoreOptionsDisplaysOfflineMenuItem() { - onView(withContentDescription("More options")).perform(click()); - onView(withText(is(startsWith("Offline")))).check(matches(isDisplayed())); - } - - private void enterMifosInstanceDomain(final String domain) { - clearMifosDomainTextInputField(); - getInstrumentation().sendStringSync(domain); - getInstrumentation().waitForIdleSync(); - } - - private void clearMifosDomainTextInputField() { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - et_mifos_domain.setText(""); - et_mifos_domain.requestFocus(); - } - }); - getInstrumentation().waitForIdleSync(); - } - - private void saveLastAccessedInstanceDomainName(final String domain) { - getInstrumentation().runOnMainSync(new Runnable() { - @Override - public void run() { - PrefManager.setInstanceDomain(domain); - } - }); - getInstrumentation().waitForIdleSync(); - } - -} diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/LoginActivityTest.kt b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/LoginActivityTest.kt new file mode 100644 index 00000000000..1ac2f7f8868 --- /dev/null +++ b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/LoginActivityTest.kt @@ -0,0 +1,166 @@ +/* + * This project is licensed under the open source MPL V2. + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.mifosxdroid.tests + +import android.preference.PreferenceManager +import android.test.ActivityInstrumentationTestCase2 +import android.view.View +import com.mifos.mifosxdroid.R +import com.mifos.utils.Constants + +/** + * Created by ishankhanna on 12/08/14. + */ +class LoginActivityTest : ActivityInstrumentationTestCase2( + LoginActivity::class.java +) { + val TEST_URL_5: String = getActivity().getString(R.string.test_ip) + var loginActivity: LoginActivity? = null + var et_mifos_domain: EditText? = null + var et_username: EditText? = null + var tv_constructed_instance_url: TextView? = null + @Throws(Exception::class) + fun setUp() { + super.setUp() + loginActivity = getActivity() + et_mifos_domain = loginActivity.findViewById(R.id.et_instanceURL) as EditText + et_username = loginActivity.findViewById(R.id.et_username) as EditText + tv_constructed_instance_url = + loginActivity.findViewById(R.id.tv_constructed_instance_url) as TextView + } + + @SmallTest + fun testEditTextsAreNotNull() { + assertNotNull(et_mifos_domain) + assertNotNull(et_username) + } + + @SmallTest + fun testAllEditTextsAreVisible() { + assertEquals(View.VISIBLE, et_mifos_domain.getVisibility()) + } + + @SmallTest + fun testURLInstance1() { + //Test if TextView has been instantiated + assertNotNull(tv_constructed_instance_url) + + // Set URL and check the color of the message, it turns green + // only if the URL matches the pattern specified + enterMifosInstanceDomain(TEST_URL_1) + assertEquals( + loginActivity.getResources().getColor(R.color.green_light), + tv_constructed_instance_url.getCurrentTextColor() + ) + } + + @SmallTest + fun testURLInstance2() { + //Test if TextView has been instantiated + assertNotNull(tv_constructed_instance_url) + enterMifosInstanceDomain(TEST_URL_2) + assertEquals( + loginActivity.getResources().getColor(R.color.green_light), + tv_constructed_instance_url.getCurrentTextColor() + ) + } + + @SmallTest + fun testURLInstance3() { + //Test if TextView has been instantiated + assertNotNull(tv_constructed_instance_url) + enterMifosInstanceDomain(TEST_URL_3) + assertEquals( + loginActivity.getResources().getColor(R.color.green_light), + tv_constructed_instance_url.getCurrentTextColor() + ) + } + + @SmallTest + fun testURLInstance4() { + //Test if TextView has been instantiated + assertNotNull(tv_constructed_instance_url) + enterMifosInstanceDomain(TEST_URL_4) + assertEquals( + loginActivity.getResources().getColor(R.color.green_light), + tv_constructed_instance_url.getCurrentTextColor() + ) + } + + @SmallTest + fun testURLInstance5() { + //Test if TextView has been instantiated + assertNotNull(tv_constructed_instance_url) + enterMifosInstanceDomain(TEST_URL_5) + assertEquals( + loginActivity.getResources().getColor(R.color.green_light), + tv_constructed_instance_url.getCurrentTextColor() + ) + } + + @MediumTest + fun testSaveLastAccessedInstanceDomainNameSavesProvidedString() { + PrefManager.instanceDomain = TEST_URL_1 + assertEquals(TEST_URL_1, PrefManager.instanceDomain) + PrefManager.instanceDomain = TEST_URL_2 + assertEquals(TEST_URL_2, PrefManager.instanceDomain) + } + + @MediumTest + @Suppress // TODO: Fix ComparisonFailure: expected:<[demo.mifos.org]> but was:<[www.google.com]> + fun testValidateUserInputsSavesValidDomainToSharedProperties() { + saveLastAccessedInstanceDomainName(TEST_URL_2) + enterMifosInstanceDomain(TEST_URL_1) + getActivity().runOnUiThread(Runnable { getActivity().validateUserInputs() }) + getInstrumentation().waitForIdleSync() + val sharedPreferences: SharedPreferences = + PreferenceManager.getDefaultSharedPreferences(getInstrumentation().getTargetContext()) + assertEquals(TEST_URL_1, sharedPreferences.getString(Constants.INSTANCE_URL_KEY, "")) + } + + @MediumTest + @Suppress // TODO: Fix expected: + // but was: + fun testValidateUserInputsSetsAPIinstanceUrl() { + saveLastAccessedInstanceDomainName(TEST_URL_2) + enterMifosInstanceDomain(TEST_URL_1) + getActivity().runOnUiThread(Runnable { getActivity().validateUserInputs() }) + getInstrumentation().waitForIdleSync() + } + + @SmallTest + fun testMoreOptionsDisplaysOfflineMenuItem() { + Espresso.onView(ViewMatchers.withContentDescription("More options")) + .perform(ViewActions.click()) + Espresso.onView(ViewMatchers.withText(Matchers.`is`(Matchers.startsWith("Offline")))) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + } + + private fun enterMifosInstanceDomain(domain: String) { + clearMifosDomainTextInputField() + getInstrumentation().sendStringSync(domain) + getInstrumentation().waitForIdleSync() + } + + private fun clearMifosDomainTextInputField() { + getActivity().runOnUiThread(Runnable { + et_mifos_domain.setText("") + et_mifos_domain.requestFocus() + }) + getInstrumentation().waitForIdleSync() + } + + private fun saveLastAccessedInstanceDomainName(domain: String) { + getInstrumentation().runOnMainSync(Runnable { PrefManager.instanceDomain = domain }) + getInstrumentation().waitForIdleSync() + } + + companion object { + const val TEST_URL_1 = "demo.mifos.org" + const val TEST_URL_2 = "www.google.com" + const val TEST_URL_3 = "this.is.valid.url" + const val TEST_URL_4 = "yahoo.in" + } +} \ No newline at end of file diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/SavingsAccountSummaryFragmentTest.java b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/SavingsAccountSummaryFragmentTest.java deleted file mode 100755 index 98b6c9dd162..00000000000 --- a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/SavingsAccountSummaryFragmentTest.java +++ /dev/null @@ -1,208 +0,0 @@ -package com.mifos.mifosxdroid.tests; - -import android.content.Intent; -import androidx.fragment.app.FragmentTransaction; -import android.test.ActivityInstrumentationTestCase2; -import android.test.TouchUtils; -import android.test.ViewAsserts; -import android.test.suitebuilder.annotation.SmallTest; -import android.test.suitebuilder.annotation.Suppress; -import android.view.KeyEvent; -import android.view.View; -import android.widget.Button; -import android.widget.ListView; -import android.widget.QuickContactBadge; -import android.widget.TextView; - -import com.mifos.mifosxdroid.R; -import com.mifos.mifosxdroid.online.ClientActivity; -import com.mifos.mifosxdroid.online.documentlist.DocumentListFragment; -import com.mifos.objects.accounts.savings.DepositType; -import com.mifos.utils.Constants; -import com.mifos.utils.FragmentConstants; - -/** - * Created by Gabriel Esteban on 07/12/14. - */ -@Suppress // TODO: Fix NPE -public class SavingsAccountSummaryFragmentTest extends - ActivityInstrumentationTestCase2 { - - ClientActivity clientActivity; - - TextView tv_clientName; - QuickContactBadge quickContactBadge; - TextView tv_savingsProductName; - TextView tv_savingsAccountNumber; - TextView tv_savingsAccountBalance; - TextView tv_totalDeposits; - TextView tv_totalWithdrawals; - ListView lv_Transactions; - TextView tv_interestEarned; - Button bt_deposit; - Button bt_withdrawal; - - public SavingsAccountSummaryFragmentTest() { - super(ClientActivity.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - //Entering to this client for testing - Intent clientActivityIntent = new Intent(); - clientActivityIntent.putExtra(Constants.CLIENT_ID, "000001026"); - setActivityIntent(clientActivityIntent); - - clientActivity = getActivity(); - /* - Test made with the following constructor on DepositType - - public DepositType(Integer id, String code, String value) { - this.id = id; - this.code = code; - this.value = value; - } - */ - DepositType depositType = null; - //depositType = new DepositType(100, "depositAccountType.savingsDeposit", "Savings"); - - //Moving to SavingsAccountSummaryFragment with the following id and account type - SavingsAccountSummaryFragment savingsAccountSummaryFragment - = SavingsAccountSummaryFragment.newInstance(419, depositType); - FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager() - .beginTransaction(); - fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CLIENT_DETAILS); - fragmentTransaction.replace(R.id.global_container, savingsAccountSummaryFragment).commit(); - - //waiting for the API - Thread.sleep(8000); - - //instantiating the views that we're going to test@BindView(R.id.tv_clientName) - tv_clientName = (TextView) clientActivity.findViewById(R.id.tv_clientName); - quickContactBadge = (QuickContactBadge) clientActivity.findViewById(R.id - .quickContactBadge_client); - tv_savingsProductName = (TextView) clientActivity.findViewById(R.id - .tv_savings_product_short_name); - tv_savingsAccountNumber = (TextView) clientActivity.findViewById(R.id - .tv_savingsAccountNumber); - tv_savingsAccountBalance = (TextView) clientActivity.findViewById(R.id - .tv_savings_account_balance); - tv_totalDeposits = (TextView) clientActivity.findViewById(R.id.tv_total_deposits); - tv_totalWithdrawals = (TextView) clientActivity.findViewById(R.id.tv_total_withdrawals); - lv_Transactions = (ListView) clientActivity.findViewById(R.id.lv_savings_transactions); - tv_interestEarned = (TextView) clientActivity.findViewById(R.id.tv_interest_earned); - bt_deposit = (Button) clientActivity.findViewById(R.id.bt_deposit); - bt_withdrawal = (Button) clientActivity.findViewById(R.id.bt_withdrawal); - } - - //we are not going to test if fragment is null this time, - //because we've started it from this test, so we wouldn't be testing the app - - @SmallTest - public void testViewsAreNotNull() { - assertNotNull(tv_clientName); - assertNotNull(quickContactBadge); - assertNotNull(tv_savingsProductName); - assertNotNull(tv_savingsAccountNumber); - assertNotNull(tv_savingsAccountBalance); - assertNotNull(tv_totalDeposits); - assertNotNull(tv_totalWithdrawals); - assertNotNull(lv_Transactions); - assertNotNull(tv_interestEarned); - assertNotNull(bt_deposit); - assertNotNull(bt_withdrawal); - } - - @SmallTest - public void testViewsAreOnTheScreen() { - final View decorView = clientActivity.getWindow().getDecorView(); - - ViewAsserts.assertOnScreen(decorView, tv_clientName); - ViewAsserts.assertOnScreen(decorView, quickContactBadge); - ViewAsserts.assertOnScreen(decorView, tv_savingsProductName); - ViewAsserts.assertOnScreen(decorView, tv_savingsAccountNumber); - ViewAsserts.assertOnScreen(decorView, tv_savingsAccountBalance); - ViewAsserts.assertOnScreen(decorView, tv_totalDeposits); - ViewAsserts.assertOnScreen(decorView, tv_totalWithdrawals); - ViewAsserts.assertOnScreen(decorView, lv_Transactions); - ViewAsserts.assertOnScreen(decorView, tv_interestEarned); - ViewAsserts.assertOnScreen(decorView, bt_deposit); - ViewAsserts.assertOnScreen(decorView, bt_withdrawal); - } - - /** - * Should be tested alone because sometimes it can cause problems with the Application Context. - *

      - * Maybe it should be reviewed the {@link DocumentListFragment}, - * because is who is throwing out a NullPointerException after closing the fragment. The - * method who - * throws the exception is inflateDocumentList on the API request. - *

      - * Here the logcat output: - * java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context - * android.support.v4.app.FragmentActivity.getApplicationContext()' on a null object reference - * at com.mifos.mifosxdroid.online.savingaccountsummary.SavingsAccountSummaryFragment$1.success - * (SavingsAccountSummaryFragment.java:201) - * at com.mifos.mifosxdroid.online.savingaccountsummary.SavingsAccountSummaryFragment$1.success - * (SavingsAccountSummaryFragment.java:169) - * at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:41) - * at android.os.Handler.handleCallback(Handler.java:739) - * at android.os.Handler.dispatchMessage(Handler.java:95) - * at android.os.Looper.loop(Looper.java:135) - * at android.app.ActivityThread.main(ActivityThread.java:5221) - * at java.lang.reflect.Method.invoke(Native Method) - * at java.lang.reflect.Method.invoke(Method.java:372) - * at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) - * at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) - * - * @throws InterruptedException - */ - @SmallTest - public void testClientDocumentsFragmentShowed() throws InterruptedException { - //clicking the button - getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU); - getInstrumentation().invokeMenuActionSync(clientActivity, SavingsAccountSummaryFragment - .MENU_ITEM_DOCUMENTS, 0); - - //if something is wrong, invokeMenuActionSync will take an exception - - //waiting for the API - Thread.sleep(4000); - - this.sendKeys(KeyEvent.KEYCODE_BACK); - } - - @SmallTest - public void testMakeWithdrawalButton() throws InterruptedException { - TouchUtils.clickView(this, bt_withdrawal); - - //waiting for the API - Thread.sleep(4000); - - //Try if cancel button is onScreen, if true the fragment have started - final View decorView = clientActivity.getWindow().getDecorView(); - final Button cancel = (Button) clientActivity.findViewById(R.id.bt_cancelTransaction); - ViewAsserts.assertOnScreen(decorView, cancel); - - //return to the savings fragment - this.sendKeys(KeyEvent.KEYCODE_BACK); - } - - @SmallTest - public void testMakeDepositButton() throws InterruptedException { - TouchUtils.clickView(this, bt_deposit); - - //waiting for the API - Thread.sleep(4000); - - //Try if cancel button is onScreen, if true the fragment have started - final View decorView = clientActivity.getWindow().getDecorView(); - final Button cancel = (Button) clientActivity.findViewById(R.id.bt_cancelTransaction); - ViewAsserts.assertOnScreen(decorView, cancel); - - //return to the savings fragment - this.sendKeys(KeyEvent.KEYCODE_BACK); - } -} diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/SavingsAccountSummaryFragmentTest.kt b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/SavingsAccountSummaryFragmentTest.kt new file mode 100644 index 00000000000..63210c2ee57 --- /dev/null +++ b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/SavingsAccountSummaryFragmentTest.kt @@ -0,0 +1,194 @@ +package com.mifos.mifosxdroid.tests + +import android.view.KeyEvent +import android.view.View +import android.widget.Button +import android.widget.ListView +import androidx.fragment.app.FragmentTransaction +import com.mifos.mifosxdroid.R +import com.mifos.utils.Constants + +/** + * Created by Gabriel Esteban on 07/12/14. + */ +@Suppress // TODO: Fix NPE + +class SavingsAccountSummaryFragmentTest : ActivityInstrumentationTestCase2( + ClientActivity::class.java +) { + var clientActivity: ClientActivity? = null + var tv_clientName: TextView? = null + var quickContactBadge: QuickContactBadge? = null + var tv_savingsProductName: TextView? = null + var tv_savingsAccountNumber: TextView? = null + var tv_savingsAccountBalance: TextView? = null + var tv_totalDeposits: TextView? = null + var tv_totalWithdrawals: TextView? = null + var lv_Transactions: ListView? = null + var tv_interestEarned: TextView? = null + var bt_deposit: Button? = null + var bt_withdrawal: Button? = null + @Throws(Exception::class) + protected fun setUp() { + super.setUp() + + //Entering to this client for testing + val clientActivityIntent = Intent() + clientActivityIntent.putExtra(Constants.CLIENT_ID, "000001026") + setActivityIntent(clientActivityIntent) + clientActivity = getActivity() + /* + Test made with the following constructor on DepositType + + public DepositType(Integer id, String code, String value) { + this.id = id; + this.code = code; + this.value = value; + } + */ + val depositType: DepositType? = null + //depositType = new DepositType(100, "depositAccountType.savingsDeposit", "Savings"); + + //Moving to SavingsAccountSummaryFragment with the following id and account type + val savingsAccountSummaryFragment: SavingsAccountSummaryFragment = + SavingsAccountSummaryFragment.newInstance(419, depositType) + val fragmentTransaction: FragmentTransaction = getActivity().getSupportFragmentManager() + .beginTransaction() + fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CLIENT_DETAILS) + fragmentTransaction.replace(R.id.global_container, savingsAccountSummaryFragment).commit() + + //waiting for the API + Thread.sleep(8000) + + //instantiating the views that we're going to test@BindView(R.id.tv_clientName) + tv_clientName = clientActivity.findViewById(R.id.tv_clientName) as TextView + quickContactBadge = + clientActivity.findViewById(R.id.quickContactBadge_client) as QuickContactBadge + tv_savingsProductName = + clientActivity.findViewById(R.id.tv_savings_product_short_name) as TextView + tv_savingsAccountNumber = + clientActivity.findViewById(R.id.tv_savingsAccountNumber) as TextView + tv_savingsAccountBalance = + clientActivity.findViewById(R.id.tv_savings_account_balance) as TextView + tv_totalDeposits = clientActivity.findViewById(R.id.tv_total_deposits) as TextView + tv_totalWithdrawals = clientActivity.findViewById(R.id.tv_total_withdrawals) as TextView + lv_Transactions = clientActivity.findViewById(R.id.lv_savings_transactions) + tv_interestEarned = clientActivity.findViewById(R.id.tv_interest_earned) as TextView + bt_deposit = clientActivity.findViewById(R.id.bt_deposit) + bt_withdrawal = clientActivity.findViewById(R.id.bt_withdrawal) + } + + //we are not going to test if fragment is null this time, + //because we've started it from this test, so we wouldn't be testing the app + @SmallTest + fun testViewsAreNotNull() { + assertNotNull(tv_clientName) + assertNotNull(quickContactBadge) + assertNotNull(tv_savingsProductName) + assertNotNull(tv_savingsAccountNumber) + assertNotNull(tv_savingsAccountBalance) + assertNotNull(tv_totalDeposits) + assertNotNull(tv_totalWithdrawals) + assertNotNull(lv_Transactions) + assertNotNull(tv_interestEarned) + assertNotNull(bt_deposit) + assertNotNull(bt_withdrawal) + } + + @SmallTest + fun testViewsAreOnTheScreen() { + val decorView: View = clientActivity.getWindow().getDecorView() + ViewAsserts.assertOnScreen(decorView, tv_clientName) + ViewAsserts.assertOnScreen(decorView, quickContactBadge) + ViewAsserts.assertOnScreen(decorView, tv_savingsProductName) + ViewAsserts.assertOnScreen(decorView, tv_savingsAccountNumber) + ViewAsserts.assertOnScreen(decorView, tv_savingsAccountBalance) + ViewAsserts.assertOnScreen(decorView, tv_totalDeposits) + ViewAsserts.assertOnScreen(decorView, tv_totalWithdrawals) + ViewAsserts.assertOnScreen(decorView, lv_Transactions) + ViewAsserts.assertOnScreen(decorView, tv_interestEarned) + ViewAsserts.assertOnScreen(decorView, bt_deposit) + ViewAsserts.assertOnScreen(decorView, bt_withdrawal) + } + + /** + * Should be tested alone because sometimes it can cause problems with the Application Context. + * + * + * Maybe it should be reviewed the [DocumentListFragment], + * because is who is throwing out a NullPointerException after closing the fragment. The + * method who + * throws the exception is inflateDocumentList on the API request. + * + * + * Here the logcat output: + * java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context + * android.support.v4.app.FragmentActivity.getApplicationContext()' on a null object reference + * at com.mifos.mifosxdroid.online.savingaccountsummary.SavingsAccountSummaryFragment$1.success + * (SavingsAccountSummaryFragment.java:201) + * at com.mifos.mifosxdroid.online.savingaccountsummary.SavingsAccountSummaryFragment$1.success + * (SavingsAccountSummaryFragment.java:169) + * at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:41) + * at android.os.Handler.handleCallback(Handler.java:739) + * at android.os.Handler.dispatchMessage(Handler.java:95) + * at android.os.Looper.loop(Looper.java:135) + * at android.app.ActivityThread.main(ActivityThread.java:5221) + * at java.lang.reflect.Method.invoke(Native Method) + * at java.lang.reflect.Method.invoke(Method.java:372) + * at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) + * at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) + * + * @throws InterruptedException + */ + @SmallTest + @Throws(InterruptedException::class) + fun testClientDocumentsFragmentShowed() { + //clicking the button + getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU) + getInstrumentation().invokeMenuActionSync( + clientActivity, + SavingsAccountSummaryFragment.MENU_ITEM_DOCUMENTS, + 0 + ) + + //if something is wrong, invokeMenuActionSync will take an exception + + //waiting for the API + Thread.sleep(4000) + this.sendKeys(KeyEvent.KEYCODE_BACK) + } + + @SmallTest + @Throws(InterruptedException::class) + fun testMakeWithdrawalButton() { + TouchUtils.clickView(this, bt_withdrawal) + + //waiting for the API + Thread.sleep(4000) + + //Try if cancel button is onScreen, if true the fragment have started + val decorView: View = clientActivity.getWindow().getDecorView() + val cancel = clientActivity.findViewById(R.id.bt_cancelTransaction) as Button + ViewAsserts.assertOnScreen(decorView, cancel) + + //return to the savings fragment + this.sendKeys(KeyEvent.KEYCODE_BACK) + } + + @SmallTest + @Throws(InterruptedException::class) + fun testMakeDepositButton() { + TouchUtils.clickView(this, bt_deposit) + + //waiting for the API + Thread.sleep(4000) + + //Try if cancel button is onScreen, if true the fragment have started + val decorView: View = clientActivity.getWindow().getDecorView() + val cancel = clientActivity.findViewById(R.id.bt_cancelTransaction) as Button + ViewAsserts.assertOnScreen(decorView, cancel) + + //return to the savings fragment + this.sendKeys(KeyEvent.KEYCODE_BACK) + } +} \ No newline at end of file diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/SurveyQuestionViewPagerActivityTest.java b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/SurveyQuestionViewPagerActivityTest.java deleted file mode 100644 index 78fa8d65282..00000000000 --- a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/SurveyQuestionViewPagerActivityTest.java +++ /dev/null @@ -1,306 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ - -package com.mifos.mifosxdroid.tests; - -import android.content.Intent; -import android.test.ActivityInstrumentationTestCase2; -import android.test.suitebuilder.annotation.MediumTest; - -import com.mifos.mifosxdroid.R; - -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.action.ViewActions.swipeLeft; -import static androidx.test.espresso.action.ViewActions.swipeRight; -import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.ViewMatchers.isChecked; -import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withText; - -/** - * Created by ahmed fathy on 11/04/16. - */ -public class SurveyQuestionViewPagerActivityTest extends - ActivityInstrumentationTestCase2 { - - /* mock data */ - public static final int N_QUESTIONS = 3; - public static final String SURVEY_JSON = - "{\n" + - " \"componentDatas\": [\n" + - " {\n" + - " \"id\": 5,\n" + - " \"key\": \"Household\",\n" + - " \"sequenceNo\": 1,\n" + - " \"text\": \"Information about the household.\"\n" + - " }\n" + - " ],\n" + - " \"countryCode\": \"KE\",\n" + - " \"id\": 24,\n" + - " \"key\": \"ppi-kenya-2010\",\n" + - " \"name\": \"PPI Survey for Kenya, version 2010\",\n" + - " \"questionDatas\": [\n" + - " {\n" + - " \"componentKey\": \"CK\",\n" + - " \"id\": 1,\n" + - " \"key\": \"Key1\",\n" + - " \"responseDatas\": [\n" + - " {\n" + - " \"id\": 1,\n" + - " \"sequenceNo\": 1,\n" + - " \"text\": \"Answer 1a\",\n" + - " \"value\": 1\n" + - " },\n" + - " {\n" + - " \"id\": 2,\n" + - " \"sequenceNo\": 2,\n" + - " \"text\": \"Answer 1b\",\n" + - " \"value\": 5\n" + - " },\n" + - " {\n" + - " \"id\": 3,\n" + - " \"sequenceNo\": 3,\n" + - " \"text\": \"Answer 1c\",\n" + - " \"value\": 13\n" + - " }\n" + - " ],\n" + - " \"sequenceNo\": 1,\n" + - " \"text\": \"This is question 1\"\n" + - " },\n" + - " {\n" + - " \"componentKey\": \"CK\",\n" + - " \"id\": 2,\n" + - " \"key\": \"Key2\",\n" + - " \"responseDatas\": [\n" + - " {\n" + - " \"id\": 1,\n" + - " \"sequenceNo\": 1,\n" + - " \"text\": \"Answer 2a\",\n" + - " \"value\": 1\n" + - " },\n" + - " {\n" + - " \"id\": 2,\n" + - " \"sequenceNo\": 2,\n" + - " \"text\": \"Answer 2b\",\n" + - " \"value\": 5\n" + - " },\n" + - " {\n" + - " \"id\": 3,\n" + - " \"sequenceNo\": 3,\n" + - " \"text\": \"Answer 2c\",\n" + - " \"value\": 13\n" + - " }\n" + - " ],\n" + - " \"sequenceNo\": 2,\n" + - " \"text\": \"This is question 2\"\n" + - " },\n" + - " {\n" + - " \"componentKey\": \"CK\",\n" + - " \"id\": 1,\n" + - " \"key\": \"Key3\",\n" + - " \"responseDatas\": [\n" + - " {\n" + - " \"id\": 1,\n" + - " \"sequenceNo\": 1,\n" + - " \"text\": \"Answer 3a\",\n" + - " \"value\": 1\n" + - " },\n" + - " {\n" + - " \"id\": 2,\n" + - " \"sequenceNo\": 2,\n" + - " \"text\": \"Answer 3b\",\n" + - " \"value\": 5\n" + - " },\n" + - " {\n" + - " \"id\": 3,\n" + - " \"sequenceNo\": 3,\n" + - " \"text\": \"Answer 3c\",\n" + - " \"value\": 13\n" + - " }\n" + - " ],\n" + - " \"sequenceNo\": 3,\n" + - " \"text\": \"This is question 3\"\n" + - " }\n" + - " ]\n" + - "}"; - - - public SurveyQuestionViewPagerActivityTest() { - super(SurveyQuestionActivity.class); - } - - /* tests */ - - @Override - public void setUp() throws Exception { - super.setUp(); - - // pass the mock intent - Intent intent = new Intent(); - intent.putExtra("ClientId", "000000001"); - intent.putExtra("Survey", SURVEY_JSON); - setActivityIntent(intent); - - getActivity(); - } - - /** - * checks all th questions and answers are displayed correctly - */ - @MediumTest - public void testQuestionAndAnswersDisplayed() throws InterruptedException { - - for (int i = 1; i <= N_QUESTIONS; i++) { - - // check the numbering in the subtitle - assertEquals(i + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()); - - // check question - onView(withText("This is question " + i)) - .check(matches(isDisplayed())); - - // check answers - onView(withText("Answer " + i + "a")) - .check(matches(isDisplayed())); - onView(withText("Answer " + i + "b")) - .check(matches(isDisplayed())); - onView(withText("Answer " + i + "c")) - .check(matches(isDisplayed())); - - // go to the next question - onView(withId(R.id.btnNext)) - .perform(click()); - } - - } - - /** - * answers each question then press next - * press submit - */ - @MediumTest - public void testAnswerSurvey() throws InterruptedException { - - // answer all questions - for (int i = 1; i <= N_QUESTIONS; i++) { - - // choose an answer - onView(withText("Answer " + i + "a")) - .perform(click()) - .check(matches(isChecked())); - - // go to the next question - onView(withId(R.id.btnNext)) - .check(matches(isDisplayed())) - .perform(click()); - - // check the numbering in the subtitle - if (i < N_QUESTIONS) - assertEquals((i + 1) + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()); - - } - - // check we reached the submission page - assertEquals("Submit Survey", getActivity().getToolbar().getSubtitle()); - onView(withId(R.id.btn_submit)) - .check(matches(isDisplayed())) - .perform(click()); - Thread.sleep(1000); - - } - - /** - * swipe right to go to question 2 - * swipe left to go back to question 1 - * swipe right two times to question 3 - */ - public void testSwipeNavigate() { - - assertEquals(1 + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()); - - // to page 2 - onView(withId(R.id.surveyPager)) - .perform(swipeLeft()); - assertEquals(2 + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()); - - // to page 1 - onView(withId(R.id.surveyPager)) - .perform(swipeRight()); - assertEquals(1 + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()); - - // to page 3 - onView(withId(R.id.surveyPager)) - .perform(swipeLeft()); - onView(withId(R.id.surveyPager)) - .perform(swipeLeft()); - assertEquals(3 + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()); - - } - - /** - * answers all the questions - * goes back to each question and check the answers are still checked - */ - public void testAnswersPersistent() throws InterruptedException { - // answer the first question - assertEquals(1 + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()); - onView(withText("Answer 1a")) - .perform(click()); - - // go to the second question - onView(withId(R.id.surveyPager)) - .perform(swipeLeft()); - assertEquals(2 + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()); - - // answer the second question - Thread.sleep(300); - onView(withText("Answer 2b")) - .perform(click()); - - // go to the third question - onView(withId(R.id.surveyPager)) - .perform(swipeLeft()); - assertEquals(3 + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()); - - // answer the third question - Thread.sleep(300); - onView(withText("Answer 3c")) - .perform(click()); - - // go go back to the first question - onView(withId(R.id.surveyPager)) - .perform(swipeRight()); - onView(withId(R.id.surveyPager)) - .perform(swipeRight()); - assertEquals(1 + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()); - - // check the answer is checked - onView(withText("Answer 1a")) - .check(matches(isChecked())); - - - // go to the second question - onView(withId(R.id.surveyPager)) - .perform(swipeLeft()); - assertEquals(2 + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()); - - // check the answer is checked - onView(withText("Answer 2b")) - .check(matches(isChecked())); - - // go to the third question - onView(withId(R.id.surveyPager)) - .perform(swipeLeft()); - assertEquals(3 + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()); - - // check the answer is checked - onView(withText("Answer 3c")) - .check(matches(isChecked())); - - } - -} diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/SurveyQuestionViewPagerActivityTest.kt b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/SurveyQuestionViewPagerActivityTest.kt new file mode 100644 index 00000000000..2fa0fc3a127 --- /dev/null +++ b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/SurveyQuestionViewPagerActivityTest.kt @@ -0,0 +1,284 @@ +/* + * This project is licensed under the open source MPL V2. + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.mifosxdroid.tests + +import android.test.ActivityInstrumentationTestCase2 +import com.mifos.mifosxdroid.R + +/** + * Created by ahmed fathy on 11/04/16. + */ +class SurveyQuestionViewPagerActivityTest : + ActivityInstrumentationTestCase2( + SurveyQuestionActivity::class.java + ) { + /* tests */ + @Throws(Exception::class) + fun setUp() { + super.setUp() + + // pass the mock intent + val intent = Intent() + intent.putExtra("ClientId", "000000001") + intent.putExtra("Survey", SURVEY_JSON) + setActivityIntent(intent) + getActivity() + } + + /** + * checks all th questions and answers are displayed correctly + */ + @MediumTest + @Throws(InterruptedException::class) + fun testQuestionAndAnswersDisplayed() { + for (i in 1..N_QUESTIONS) { + + // check the numbering in the subtitle + assertEquals(i.toString() + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()) + + // check question + Espresso.onView(ViewMatchers.withText("This is question $i")) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + + // check answers + Espresso.onView(ViewMatchers.withText("Answer " + i + "a")) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + Espresso.onView(ViewMatchers.withText("Answer " + i + "b")) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + Espresso.onView(ViewMatchers.withText("Answer " + i + "c")) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + + // go to the next question + Espresso.onView(ViewMatchers.withId(R.id.btnNext)) + .perform(ViewActions.click()) + } + } + + /** + * answers each question then press next + * press submit + */ + @MediumTest + @Throws(InterruptedException::class) + fun testAnswerSurvey() { + + // answer all questions + for (i in 1..N_QUESTIONS) { + + // choose an answer + Espresso.onView(ViewMatchers.withText("Answer " + i + "a")) + .perform(ViewActions.click()) + .check(ViewAssertions.matches(ViewMatchers.isChecked())) + + // go to the next question + Espresso.onView(ViewMatchers.withId(R.id.btnNext)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + .perform(ViewActions.click()) + + // check the numbering in the subtitle + if (i < N_QUESTIONS) assertEquals( + (i + 1).toString() + "/" + N_QUESTIONS, + getActivity().getToolbar().getSubtitle() + ) + } + + // check we reached the submission page + assertEquals("Submit Survey", getActivity().getToolbar().getSubtitle()) + Espresso.onView(ViewMatchers.withId(R.id.btn_submit)) + .check(ViewAssertions.matches(ViewMatchers.isDisplayed())) + .perform(ViewActions.click()) + Thread.sleep(1000) + } + + /** + * swipe right to go to question 2 + * swipe left to go back to question 1 + * swipe right two times to question 3 + */ + fun testSwipeNavigate() { + assertEquals(1.toString() + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()) + + // to page 2 + Espresso.onView(ViewMatchers.withId(R.id.surveyPager)) + .perform(ViewActions.swipeLeft()) + assertEquals(2.toString() + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()) + + // to page 1 + Espresso.onView(ViewMatchers.withId(R.id.surveyPager)) + .perform(ViewActions.swipeRight()) + assertEquals(1.toString() + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()) + + // to page 3 + Espresso.onView(ViewMatchers.withId(R.id.surveyPager)) + .perform(ViewActions.swipeLeft()) + Espresso.onView(ViewMatchers.withId(R.id.surveyPager)) + .perform(ViewActions.swipeLeft()) + assertEquals(3.toString() + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()) + } + + /** + * answers all the questions + * goes back to each question and check the answers are still checked + */ + @Throws(InterruptedException::class) + fun testAnswersPersistent() { + // answer the first question + assertEquals(1.toString() + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()) + Espresso.onView(ViewMatchers.withText("Answer 1a")) + .perform(ViewActions.click()) + + // go to the second question + Espresso.onView(ViewMatchers.withId(R.id.surveyPager)) + .perform(ViewActions.swipeLeft()) + assertEquals(2.toString() + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()) + + // answer the second question + Thread.sleep(300) + Espresso.onView(ViewMatchers.withText("Answer 2b")) + .perform(ViewActions.click()) + + // go to the third question + Espresso.onView(ViewMatchers.withId(R.id.surveyPager)) + .perform(ViewActions.swipeLeft()) + assertEquals(3.toString() + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()) + + // answer the third question + Thread.sleep(300) + Espresso.onView(ViewMatchers.withText("Answer 3c")) + .perform(ViewActions.click()) + + // go go back to the first question + Espresso.onView(ViewMatchers.withId(R.id.surveyPager)) + .perform(ViewActions.swipeRight()) + Espresso.onView(ViewMatchers.withId(R.id.surveyPager)) + .perform(ViewActions.swipeRight()) + assertEquals(1.toString() + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()) + + // check the answer is checked + Espresso.onView(ViewMatchers.withText("Answer 1a")) + .check(ViewAssertions.matches(ViewMatchers.isChecked())) + + + // go to the second question + Espresso.onView(ViewMatchers.withId(R.id.surveyPager)) + .perform(ViewActions.swipeLeft()) + assertEquals(2.toString() + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()) + + // check the answer is checked + Espresso.onView(ViewMatchers.withText("Answer 2b")) + .check(ViewAssertions.matches(ViewMatchers.isChecked())) + + // go to the third question + Espresso.onView(ViewMatchers.withId(R.id.surveyPager)) + .perform(ViewActions.swipeLeft()) + assertEquals(3.toString() + "/" + N_QUESTIONS, getActivity().getToolbar().getSubtitle()) + + // check the answer is checked + Espresso.onView(ViewMatchers.withText("Answer 3c")) + .check(ViewAssertions.matches(ViewMatchers.isChecked())) + } + + companion object { + /* mock data */ + const val N_QUESTIONS = 3 + const val SURVEY_JSON = "{\n" + + " \"componentDatas\": [\n" + + " {\n" + + " \"id\": 5,\n" + + " \"key\": \"Household\",\n" + + " \"sequenceNo\": 1,\n" + + " \"text\": \"Information about the household.\"\n" + + " }\n" + + " ],\n" + + " \"countryCode\": \"KE\",\n" + + " \"id\": 24,\n" + + " \"key\": \"ppi-kenya-2010\",\n" + + " \"name\": \"PPI Survey for Kenya, version 2010\",\n" + + " \"questionDatas\": [\n" + + " {\n" + + " \"componentKey\": \"CK\",\n" + + " \"id\": 1,\n" + + " \"key\": \"Key1\",\n" + + " \"responseDatas\": [\n" + + " {\n" + + " \"id\": 1,\n" + + " \"sequenceNo\": 1,\n" + + " \"text\": \"Answer 1a\",\n" + + " \"value\": 1\n" + + " },\n" + + " {\n" + + " \"id\": 2,\n" + + " \"sequenceNo\": 2,\n" + + " \"text\": \"Answer 1b\",\n" + + " \"value\": 5\n" + + " },\n" + + " {\n" + + " \"id\": 3,\n" + + " \"sequenceNo\": 3,\n" + + " \"text\": \"Answer 1c\",\n" + + " \"value\": 13\n" + + " }\n" + + " ],\n" + + " \"sequenceNo\": 1,\n" + + " \"text\": \"This is question 1\"\n" + + " },\n" + + " {\n" + + " \"componentKey\": \"CK\",\n" + + " \"id\": 2,\n" + + " \"key\": \"Key2\",\n" + + " \"responseDatas\": [\n" + + " {\n" + + " \"id\": 1,\n" + + " \"sequenceNo\": 1,\n" + + " \"text\": \"Answer 2a\",\n" + + " \"value\": 1\n" + + " },\n" + + " {\n" + + " \"id\": 2,\n" + + " \"sequenceNo\": 2,\n" + + " \"text\": \"Answer 2b\",\n" + + " \"value\": 5\n" + + " },\n" + + " {\n" + + " \"id\": 3,\n" + + " \"sequenceNo\": 3,\n" + + " \"text\": \"Answer 2c\",\n" + + " \"value\": 13\n" + + " }\n" + + " ],\n" + + " \"sequenceNo\": 2,\n" + + " \"text\": \"This is question 2\"\n" + + " },\n" + + " {\n" + + " \"componentKey\": \"CK\",\n" + + " \"id\": 1,\n" + + " \"key\": \"Key3\",\n" + + " \"responseDatas\": [\n" + + " {\n" + + " \"id\": 1,\n" + + " \"sequenceNo\": 1,\n" + + " \"text\": \"Answer 3a\",\n" + + " \"value\": 1\n" + + " },\n" + + " {\n" + + " \"id\": 2,\n" + + " \"sequenceNo\": 2,\n" + + " \"text\": \"Answer 3b\",\n" + + " \"value\": 5\n" + + " },\n" + + " {\n" + + " \"id\": 3,\n" + + " \"sequenceNo\": 3,\n" + + " \"text\": \"Answer 3c\",\n" + + " \"value\": 13\n" + + " }\n" + + " ],\n" + + " \"sequenceNo\": 3,\n" + + " \"text\": \"This is question 3\"\n" + + " }\n" + + " ]\n" + + "}" + } +} \ No newline at end of file diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/action/NavigationViewActions.java b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/action/NavigationViewActions.java deleted file mode 100644 index 0111980d439..00000000000 --- a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/action/NavigationViewActions.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright 2015, The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mifos.mifosxdroid.tests.action; - -import android.content.res.Resources.NotFoundException; -import com.google.android.material.navigation.NavigationView; -import androidx.test.espresso.PerformException; -import androidx.test.espresso.UiController; -import androidx.test.espresso.ViewAction; -import androidx.test.espresso.matcher.ViewMatchers; -import androidx.test.espresso.util.HumanReadables; -import androidx.drawerlayout.widget.DrawerLayout; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; - -import org.hamcrest.Matcher; - -import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom; -import static androidx.test.espresso.matcher.ViewMatchers.isDisplayingAtLeast; -import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility; -import static org.hamcrest.Matchers.allOf; - -/** - * Rajan Maurya - * View actions for interacting with {@link NavigationView} - */ -public final class NavigationViewActions { - - private NavigationViewActions() { - // no Instance - } - - /** - * Returns a {@link ViewAction} that navigates to a menu item in {@link NavigationView} using a - * menu item resource id. - *

      - *

      - * View constraints: - *

        - *
      • View must be a child of a {@link DrawerLayout} - *
      • View must be of type {@link NavigationView} - *
      • View must be visible on screen - *
      • View must be displayed on screen - *
          - * - * @param menuItemId the resource id of the menu item - * @return a {@link ViewAction} that navigates on a menu item - */ - public static ViewAction navigateTo(final int menuItemId) { - - return new ViewAction() { - - @Override - public void perform(UiController uiController, View view) { - NavigationView navigationView = (NavigationView) view; - Menu menu = navigationView.getMenu(); - if (null == menu.findItem(menuItemId)) { - throw new PerformException.Builder() - .withActionDescription(this.getDescription()) - .withViewDescription(HumanReadables.describe(view)) - .withCause(new RuntimeException(getErrorMessage(menu, view))) - .build(); - } - menu.performIdentifierAction(menuItemId, 0); - uiController.loopMainThreadUntilIdle(); - } - - private String getErrorMessage(Menu menu, View view) { - String NEW_LINE = System.getProperty("line.separator"); - StringBuilder errorMessage = new StringBuilder(66) - .append("Menu item was not found, available menu items:") - .append(NEW_LINE); - for (int position = 0; position < menu.size(); position++) { - errorMessage.append("[MenuItem] position=") - .append(position); - MenuItem menuItem = menu.getItem(position); - if (menuItem != null) { - CharSequence itemTitle = menuItem.getTitle(); - if (itemTitle != null) { - errorMessage.append(", title=") - .append(itemTitle); - } - if (view.getResources() != null) { - int itemId = menuItem.getItemId(); - try { - errorMessage.append(", id="); - String menuItemResourceName = view.getResources() - .getResourceName(itemId); - errorMessage.append(menuItemResourceName); - } catch (NotFoundException nfe) { - errorMessage.append("not found"); - } - } - errorMessage.append(NEW_LINE); - } - } - return errorMessage.toString(); - } - - @Override - public String getDescription() { - return "click on menu item with id"; - } - - @Override - public Matcher getConstraints() { - return allOf(isAssignableFrom(NavigationView.class), - withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE), - isDisplayingAtLeast(90) - ); - } - }; - - } -} diff --git a/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/action/NavigationViewActions.kt b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/action/NavigationViewActions.kt new file mode 100644 index 00000000000..ec161e94e93 --- /dev/null +++ b/mifosng-android/src/instrumentTest/java/com/mifos/mifosxdroid/tests/action/NavigationViewActions.kt @@ -0,0 +1,114 @@ +/* + * Copyright 2015, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.mifos.mifosxdroid.tests.action + +import android.content.res.Resources +import android.view.Menu +import android.view.View +import androidx.test.espresso.PerformException +import androidx.test.espresso.UiController +import androidx.test.espresso.ViewAction +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.util.HumanReadables +import com.google.android.material.navigation.NavigationView +import org.hamcrest.Matcher +import org.hamcrest.Matchers + +/** + * Rajan Maurya + * View actions for interacting with [NavigationView] + */ +object NavigationViewActions { + /** + * Returns a [ViewAction] that navigates to a menu item in [NavigationView] using a + * menu item resource id. + * + * + * + * + * View constraints: + * + * * View must be a child of a [DrawerLayout] + * * View must be of type [NavigationView] + * * View must be visible on screen + * * View must be displayed on screen + * + * + * @param menuItemId the resource id of the menu item + * @return a [ViewAction] that navigates on a menu item + */ + @kotlin.jvm.JvmStatic + fun navigateTo(menuItemId: Int): ViewAction { + return object : ViewAction { + override fun perform(uiController: UiController, view: View) { + val navigationView: NavigationView = view as NavigationView + val menu: Menu = navigationView.getMenu() + if (null == menu.findItem(menuItemId)) { + throw PerformException.Builder() + .withActionDescription(description) + .withViewDescription(HumanReadables.describe(view)) + .withCause(RuntimeException(getErrorMessage(menu, view))) + .build() + } + menu.performIdentifierAction(menuItemId, 0) + uiController.loopMainThreadUntilIdle() + } + + private fun getErrorMessage(menu: Menu, view: View): String { + val NEW_LINE = System.getProperty("line.separator") + val errorMessage = StringBuilder(66) + .append("Menu item was not found, available menu items:") + .append(NEW_LINE) + for (position in 0 until menu.size()) { + errorMessage.append("[MenuItem] position=") + .append(position) + val menuItem = menu.getItem(position) + if (menuItem != null) { + val itemTitle = menuItem.title + if (itemTitle != null) { + errorMessage.append(", title=") + .append(itemTitle) + } + if (view.resources != null) { + val itemId = menuItem.itemId + try { + errorMessage.append(", id=") + val menuItemResourceName = view.resources + .getResourceName(itemId) + errorMessage.append(menuItemResourceName) + } catch (nfe: Resources.NotFoundException) { + errorMessage.append("not found") + } + } + errorMessage.append(NEW_LINE) + } + } + return errorMessage.toString() + } + + val description: String + get() = "click on menu item with id" + val constraints: Matcher + get() = Matchers.allOf( + ViewMatchers.isAssignableFrom( + NavigationView::class.java + ), + ViewMatchers.withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE), + ViewMatchers.isDisplayingAtLeast(90) + ) + } + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/core/SelectableAdapter.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/core/SelectableAdapter.java deleted file mode 100644 index c13df937d01..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/core/SelectableAdapter.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.mifos.mifosxdroid.core; - -import androidx.recyclerview.widget.RecyclerView; -import android.util.SparseBooleanArray; - -import java.util.ArrayList; -import java.util.List; - -public abstract class SelectableAdapter - extends RecyclerView.Adapter { - @SuppressWarnings("unused") - private static final String LOG_TAG = SelectableAdapter.class.getSimpleName(); - - private SparseBooleanArray selectedItems; - - public SelectableAdapter() { - selectedItems = new SparseBooleanArray(); - } - - /** - * Indicates if the item at position position is selected - * - * @param position Position of the item to check - * @return true if the item is selected, false otherwise - */ - public boolean isSelected(int position) { - return getSelectedItems().contains(position); - } - - /** - * Toggle the selection status of the item at a given position - * - * @param position Position of the item to toggle the selection status for - */ - public void toggleSelection(int position) { - if (selectedItems.get(position, false)) { - selectedItems.delete(position); - } else { - selectedItems.put(position, true); - } - notifyItemChanged(position); - } - - /** - * Clear the selection status for all items - */ - public void clearSelection() { - List selection = getSelectedItems(); - selectedItems.clear(); - for (Integer i : selection) { - notifyItemChanged(i); - } - } - - /** - * Count the selected items - * - * @return Selected items count - */ - public int getSelectedItemCount() { - return selectedItems.size(); - } - - /** - * Indicates the list of selected items - * - * @return List of selected items ids - */ - public List getSelectedItems() { - List items = new ArrayList<>(selectedItems.size()); - for (int i = 0; i < selectedItems.size(); ++i) { - items.add(selectedItems.keyAt(i)); - } - return items; - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/core/SelectableAdapter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/core/SelectableAdapter.kt new file mode 100644 index 00000000000..976a0c4fa53 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/core/SelectableAdapter.kt @@ -0,0 +1,68 @@ +package com.mifos.mifosxdroid.core + +import android.util.SparseBooleanArray +import androidx.recyclerview.widget.RecyclerView + +abstract class SelectableAdapter : RecyclerView.Adapter() { + private val selectedItems: SparseBooleanArray = SparseBooleanArray() + + /** + * Indicates if the item at position position is selected + * + * @param position Position of the item to check + * @return true if the item is selected, false otherwise + */ + fun isSelected(position: Int): Boolean { + return getSelectedItems().contains(position) + } + + /** + * Toggle the selection status of the item at a given position + * + * @param position Position of the item to toggle the selection status for + */ + fun toggleSelection(position: Int) { + if (selectedItems[position, false]) { + selectedItems.delete(position) + } else { + selectedItems.put(position, true) + } + notifyItemChanged(position) + } + + /** + * Clear the selection status for all items + */ + fun clearSelection() { + val selection = getSelectedItems() + selectedItems.clear() + for (i in selection) { + notifyItemChanged(i) + } + } + + /** + * Count the selected items + * + * @return Selected items count + */ + val selectedItemCount: Int + get() = selectedItems.size() + + /** + * Indicates the list of selected items + * + * @return List of selected items ids + */ + fun getSelectedItems(): List { + val items: MutableList = ArrayList(selectedItems.size()) + for (i in 0 until selectedItems.size()) { + items.add(selectedItems.keyAt(i)) + } + return items + } + + companion object { + private val LOG_TAG = SelectableAdapter::class.java.simpleName + } +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/identifierdialog/ClientIdentifierCreationListener.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/identifierdialog/ClientIdentifierCreationListener.java deleted file mode 100644 index 0668dfa53c0..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/identifierdialog/ClientIdentifierCreationListener.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.mifos.mifosxdroid.dialogfragments.identifierdialog; - -import com.mifos.objects.noncore.Identifier; - -/** - * Created by Tarun on 07-08-17. - */ - -public interface ClientIdentifierCreationListener { - - void onClientIdentifierCreationSuccess(Identifier identifier); - - void onClientIdentifierCreationFailure(String errorMessage); -} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/identifierdialog/ClientIdentifierCreationListener.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/identifierdialog/ClientIdentifierCreationListener.kt new file mode 100644 index 00000000000..ccb572e4044 --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/identifierdialog/ClientIdentifierCreationListener.kt @@ -0,0 +1,12 @@ +package com.mifos.mifosxdroid.dialogfragments.identifierdialog + +import com.mifos.objects.noncore.Identifier + +/** + * Created by Tarun on 07-08-17. + */ +interface ClientIdentifierCreationListener { + fun onClientIdentifierCreationSuccess(identifier: Identifier) + + fun onClientIdentifierCreationFailure(errorMessage: String) +} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/identifierdialog/IdentifierDialogFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/identifierdialog/IdentifierDialogFragment.kt index f6451d5c895..21dc4a1a9ae 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/identifierdialog/IdentifierDialogFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/identifierdialog/IdentifierDialogFragment.kt @@ -36,9 +36,9 @@ class IdentifierDialogFragment : ProgressableDialogFragment(), IdentifierDialogM private var clientIdentifierCreationListener: ClientIdentifierCreationListener? = null private var clientId = 0 private var identifierTemplate: IdentifierTemplate? = null - private var identifierDocumentTypeId : Int? = 0 + private var identifierDocumentTypeId: Int? = 0 private var status: String? = null - private var identifier: Identifier? = null + private lateinit var identifier: Identifier private var documentTypeHashMap: HashMap? = null private val mListIdentifierType: MutableList = ArrayList() private var mIdentifierTypeAdapter: ArrayAdapter? = null @@ -106,9 +106,9 @@ class IdentifierDialogFragment : ProgressableDialogFragment(), IdentifierDialogM // Add the values in the identifier. It'll be sent to the calling Fragment // if the request is successful. identifier = Identifier() - identifier!!.description = binding.etDescription.text.toString() - identifier!!.documentKey = binding.etUniqueId.text.toString() - identifier!!.documentType = documentTypeHashMap + identifier.description = binding.etDescription.text.toString() + identifier.documentKey = binding.etUniqueId.text.toString() + identifier.documentType = documentTypeHashMap ?.get(binding.spIdentifierType.selectedItem.toString()) mIdentifierDialogPresenter.createClientIdentifier(clientId, identifierPayload) } @@ -139,8 +139,8 @@ class IdentifierDialogFragment : ProgressableDialogFragment(), IdentifierDialogM activity, R.string.identifier_created_successfully, Toast.LENGTH_SHORT ).show() - identifier!!.clientId = identifierCreationResponse.clientId - identifier!!.id = identifierCreationResponse.resourceId + identifier.clientId = identifierCreationResponse.clientId + identifier.id = identifierCreationResponse.resourceId if (clientIdentifierCreationListener != null) { clientIdentifierCreationListener!!.onClientIdentifierCreationSuccess(identifier) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListFragment.kt index f9eaa1c5698..463cb9d28b3 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListFragment.kt @@ -322,7 +322,7 @@ class CenterListFragment : MifosBaseFragment(), CenterListMvpView, OnRefreshList return when (item.itemId) { R.id.action_sync -> { selectedCenters?.clear() - for (position in centersListAdapter.selectedItems) { + for (position in centersListAdapter.getSelectedItems()) { val center = centers?.get(position) if (center != null) { selectedCenters?.add(center) diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListFragment.kt index d82d64a4e4b..fdbaa0d1fb4 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListFragment.kt @@ -344,7 +344,7 @@ class ClientListFragment : MifosBaseFragment(), ClientListMvpView, OnRefreshList return when (item.itemId) { R.id.action_sync -> { selectedClients?.clear() - for (position in mClientNameListAdapter.selectedItems) { + for (position in mClientNameListAdapter.getSelectedItems()) { selectedClients?.let { list -> clientList?.get(position)?.let { client -> list.add(client) diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListFragment.kt index 6de0f972b6c..d1851d931cb 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListFragment.kt @@ -329,7 +329,7 @@ class GroupsListFragment : MifosBaseFragment(), GroupsListMvpView, OnRefreshList return when (item.itemId) { R.id.action_sync -> { selectedGroups?.clear() - for (position in mGroupListAdapter.selectedItems) { + for (position in mGroupListAdapter.getSelectedItems()) { selectedGroups?.add(mGroupList?.get(position) ?: continue) } val syncGroupsDialogFragment = diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/runreports/reportcategory/ReportCategoryMvpView.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/runreports/reportcategory/ReportCategoryMvpView.java deleted file mode 100644 index b148d8a6019..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/runreports/reportcategory/ReportCategoryMvpView.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.mifos.mifosxdroid.online.runreports.reportcategory; - -import com.mifos.mifosxdroid.base.MvpView; -import com.mifos.objects.runreports.client.ClientReportTypeItem; - -import java.util.List; - -/** - * Created by Tarun on 03-08-17. - */ - -public interface ReportCategoryMvpView extends MvpView { - - void showError(String error); - - void showReportCategories(List reportTypes); -} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/runreports/reportcategory/ReportCategoryMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/runreports/reportcategory/ReportCategoryMvpView.kt new file mode 100644 index 00000000000..dc0298ccf1e --- /dev/null +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/runreports/reportcategory/ReportCategoryMvpView.kt @@ -0,0 +1,13 @@ +package com.mifos.mifosxdroid.online.runreports.reportcategory + +import com.mifos.mifosxdroid.base.MvpView +import com.mifos.objects.runreports.client.ClientReportTypeItem + +/** + * Created by Tarun on 03-08-17. + */ +interface ReportCategoryMvpView : MvpView { + fun showError(error: String) + + fun showReportCategories(reportTypes: List) +} \ No newline at end of file