diff --git a/.travis.yml b/.travis.yml index beb47cd1..2cb55bc0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,4 +26,5 @@ android: - extra-google-m2repository - extra-android-m2repository -script: "./gradlew build --stacktrace" \ No newline at end of file +script: "./gradlew build --stacktrace" + "./gradlew build connectedAndroidTest --stacktrace" diff --git a/app/src/androidTest/java/org/apache/fineract/ui/online/products/CreateEditProductAndroidTest.kt b/app/src/androidTest/java/org/apache/fineract/ui/online/products/CreateEditProductAndroidTest.kt new file mode 100644 index 00000000..2a17e84e --- /dev/null +++ b/app/src/androidTest/java/org/apache/fineract/ui/online/products/CreateEditProductAndroidTest.kt @@ -0,0 +1,167 @@ +package org.apache.fineract.ui.online.products + +import android.content.Intent +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions.* +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.contrib.RecyclerViewActions +import androidx.test.espresso.matcher.RootMatchers.isDialog +import androidx.test.espresso.matcher.ViewMatchers.* +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.rule.ActivityTestRule +import org.apache.fineract.R +import org.apache.fineract.couchbase.SynchronizationManager +import org.apache.fineract.data.models.product.InterestBasis +import org.apache.fineract.data.models.product.Product +import org.apache.fineract.ui.adapters.ProductAccountAssignmentsAdapter +import org.apache.fineract.ui.product.ProductAction +import org.apache.fineract.ui.product.createproduct.CreateProductActivity +import org.apache.fineract.utils.Constants +import org.apache.fineract.utils.toDataClass +import org.junit.* +import org.junit.runner.RunWith + +/** + * Created by Varun Jain on 21/8/2021. + */ + +@RunWith(AndroidJUnit4::class) +class CreateEditProductAndroidTest { + + @get:Rule + var activityTestRule = + ActivityTestRule(CreateProductActivity::class.java, false, false) + + lateinit var synchronizationManager: SynchronizationManager + + @Before + fun before() { + + val intent = Intent().apply { + putExtra(Constants.PRODUCT_ACTION, ProductAction.CREATE) + } + + activityTestRule.launchActivity(intent) + + synchronizationManager = + SynchronizationManager(InstrumentationRegistry.getInstrumentation().context) + } + + @Test + fun createTeller() { + + // Filling all the details in Product Details Step fragment + onView(withId(R.id.etIdentifier)) + .perform(typeText("test identifier")) + onView(withId(R.id.etName)) + .perform(typeText("test Name")) + onView(withId(R.id.etPatternPackage)) + .perform(typeText("pattern package")) + onView(withId(R.id.etDescription)) + .perform(typeText("product description")) + onView(withId(R.id.etCurrencyCode)) + .perform(typeText("Currency code")) + onView(withId(R.id.scrollViewProductDetailsStep)) + .perform(swipeUp()) + onView(withId(R.id.etParameters)) + .perform(typeText("Parameters")) + onView(withId(R.id.etMinorCurrencyUnitDigits)) + .perform(typeText("1000")) + onView(withId(R.id.etTemporalUnit)) + .perform(typeText("Temporal unit")) + onView(withId(R.id.scrollViewProductDetailsStep)) + .perform(swipeUp()) + onView(withId(R.id.etTermRangeMax)) + .perform(typeText("1000")) + onView(withId(R.id.etBalanceRangeMinimum)) + .perform(typeText("10")) + onView(withId(R.id.etMaximumBalanceRange)) + .perform(typeText("1000")) + onView(withId(R.id.scrollViewProductDetailsStep)) + .perform(swipeUp()) + onView(withId(R.id.etMinInterestRange)) + .perform(typeText("10")) + onView(withId(R.id.etMaximumInterestRange)) + .perform(typeText("1000")) + .perform(closeSoftKeyboard()) + + // Navigate to the next step + onView(withText("NEXT")).perform(click()) + + // Create, editing and deleting the Account Assignments + onView(withId(R.id.ibAddAccountAssignment)) + .perform(click()) + onView(withId(R.id.etDesignator)) + .perform(typeText("Desig")) + onView(withId(R.id.etAccountIdentifier)) + .perform(typeText("Account Identifier")) + onView(withId(R.id.scrollViewAddAccountAssignmentsStep)) + .perform(swipeUp()) + onView(withId(R.id.etLedgerIdentifier)) + .perform(typeText("Ledger Identifier")) + onView(withId(R.id.btnAddProductAccountAssignment)) + .perform(click()) + + // Edit an Account assignment + onView(withId(R.id.ivEditProductAccountAss)) + .perform(click()) + onView(withId(R.id.etDesignator)) + .perform(typeText("nator")) + onView(withId(R.id.scrollViewAddAccountAssignmentsStep)) + .perform(swipeUp()) + onView(withId(R.id.btnAddProductAccountAssignment)) + .perform(click()) + + // Delete a Account assignment + onView(withId(R.id.ivDeleteProductAccountAss)) + .perform(click()) + + // Dismiss the Delete dialog + onView(withText("DELETE")).inRoot(isDialog()).check(matches(isDisplayed())).perform(pressBack()); + + // Navigate to the next step + onView(withText("NEXT")).perform(click()) + + // Test if the Product Review Step is populated with the correct values + onView(withId(R.id.tvProductIdentifier)).check(matches(withText("test identifier"))) + onView(withId(R.id.tvProductName)).check(matches(withText("test Name"))) + onView(withId(R.id.tvPatternPackageProduct)).check(matches(withText("pattern package"))) + onView(withId(R.id.tvProductDescription)).check(matches(withText("product description"))) + onView(withId(R.id.tvProductCurrencyCode)).check(matches(withText("Currency code"))) + onView(withId(R.id.tvProductMinorCurrencyUnit)).check(matches(withText("1000"))) + onView(withId(R.id.tvParameters)).check(matches(withText("Parameters"))) + onView(withId(R.id.tvInterestBasis)).check(matches(withText(InterestBasis.BEGINNING_BALANCE.toString()))) + onView(withId(R.id.scrollViewProductReviewStep)) + .perform(swipeUp()) + onView(withId(R.id.rvProductAccountAssignmentsStepReview)) + .perform( + RecyclerViewActions.actionOnItem( + hasDescendant(withText("Designator")), click() + ) + ) + onView(withId(R.id.tvProductTemporalUnit)).check(matches(withText("Temporal unit"))) + + // Complete defining the Product + onView(withText("COMPLETE")).perform(click()) + + // assert if the product has been created successfully + val mapItem = synchronizationManager.getDocumentForTest( + "test identifier", + InstrumentationRegistry.getInstrumentation().context + ) + + val product = mapItem.toDataClass() + + Assert.assertEquals(product.name, "test Name") + Assert.assertEquals(product.patternPackage, "pattern package") + } + + @After + fun after() { + //delete the created document during the test + synchronizationManager.deleteDocument( + "test identifier" + ) + } +} \ No newline at end of file diff --git a/app/src/androidTest/java/org/apache/fineract/ui/online/products/ProductListFragmentAndroidTest.kt b/app/src/androidTest/java/org/apache/fineract/ui/online/products/ProductListFragmentAndroidTest.kt new file mode 100644 index 00000000..1a0c91f3 --- /dev/null +++ b/app/src/androidTest/java/org/apache/fineract/ui/online/products/ProductListFragmentAndroidTest.kt @@ -0,0 +1,53 @@ +package org.apache.fineract.ui.online.products + +import androidx.test.espresso.Espresso +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.assertion.ViewAssertions +import androidx.test.espresso.contrib.DrawerActions +import androidx.test.espresso.contrib.NavigationViewActions +import androidx.test.espresso.contrib.RecyclerViewActions +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.rule.ActivityTestRule +import org.apache.fineract.R +import org.apache.fineract.ui.adapters.GroupsAdapter +import org.apache.fineract.ui.online.DashboardActivity +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Created by Varun Jain on 21/8/2021. + */ + +@RunWith(AndroidJUnit4::class) +class ProductListFragmentAndroidTest { + + @get:Rule + val activityRule = + ActivityTestRule(DashboardActivity::class.java) + + @Test + fun openDrawer_OpenGroupList_ClickOnRecyclerViewItem() { + + //Open drawer + Espresso.onView(ViewMatchers.withId(R.id.drawer_layout)) + .perform(DrawerActions.open()) + + //From NavigationView navigate to Products list screen + Espresso.onView(ViewMatchers.withId(R.id.nav_view)) + .perform(NavigationViewActions.navigateTo(R.id.item_product)) + + //Click on a recycler View item + Espresso.onView(ViewMatchers.withId(R.id.rvProduct)).perform( + RecyclerViewActions.actionOnItem( + ViewMatchers.hasDescendant(ViewMatchers.withText("product identifier")), + ViewActions.click() + ) + ) + + //Assert if the item has been displayed correctly + Espresso.onView(ViewMatchers.withId(R.id.tvIdentifierProduct)) + .check(ViewAssertions.matches(ViewMatchers.withText("product identifier"))) + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_step_add_account_assignments.xml b/app/src/main/res/layout/fragment_step_add_account_assignments.xml index 74514f8b..12333913 100644 --- a/app/src/main/res/layout/fragment_step_add_account_assignments.xml +++ b/app/src/main/res/layout/fragment_step_add_account_assignments.xml @@ -7,6 +7,7 @@ android:layout_margin="@dimen/default_margin"> @@ -18,6 +19,7 @@ android:layout_marginBottom="@dimen/default_margin"> diff --git a/app/src/main/res/layout/fragment_step_product_review.xml b/app/src/main/res/layout/fragment_step_product_review.xml index a7a9cd43..e95b78f1 100644 --- a/app/src/main/res/layout/fragment_step_product_review.xml +++ b/app/src/main/res/layout/fragment_step_product_review.xml @@ -7,6 +7,7 @@ android:layout_margin="@dimen/default_margin">