Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
Added UI/Integration tests for all the product features
Browse files Browse the repository at this point in the history
  • Loading branch information
varsvat committed Aug 21, 2021
1 parent 1bf474a commit d22e5dc
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ android:
- extra-google-m2repository
- extra-android-m2repository

script: "./gradlew build --stacktrace"
script: "./gradlew build --stacktrace"
"./gradlew build connectedAndroidTest --stacktrace"
Original file line number Diff line number Diff line change
@@ -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>(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<ProductAccountAssignmentsAdapter.ViewHolder>(
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<Product>()

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"
)
}
}
Original file line number Diff line number Diff line change
@@ -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>(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<GroupsAdapter.ViewHolder>(
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")))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
android:layout_margin="@dimen/default_margin">

<androidx.core.widget.NestedScrollView
android:id="@+id/scrollViewAddAccountAssignmentsStep"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
Expand All @@ -18,6 +19,7 @@
android:layout_marginBottom="@dimen/default_margin">

<LinearLayout
android:id="@+id/llAddProductAccountAssignmentsStep"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_step_product_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
android:layout_margin="@dimen/default_margin">

<androidx.core.widget.NestedScrollView
android:id="@+id/scrollViewProductDetailsStep"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_step_product_review.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
android:layout_margin="@dimen/default_margin">

<androidx.core.widget.NestedScrollView
android:id="@+id/scrollViewProductReviewStep"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
Expand Down

0 comments on commit d22e5dc

Please sign in to comment.