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

Commit cd67684

Browse files
committed
Added UI/Integration tests for all the product features
1 parent 1bf474a commit cd67684

File tree

6 files changed

+226
-1
lines changed

6 files changed

+226
-1
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ android:
2626
- extra-google-m2repository
2727
- extra-android-m2repository
2828

29-
script: "./gradlew build --stacktrace"
29+
script: "./gradlew build --stacktrace"
30+
"./gradlew build connectedAndroidTest --stacktrace"
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
package org.apache.fineract.ui.online.products
2+
3+
import android.content.Intent
4+
import androidx.test.espresso.Espresso.onView
5+
import androidx.test.espresso.action.ViewActions.*
6+
import androidx.test.espresso.assertion.ViewAssertions.matches
7+
import androidx.test.espresso.contrib.RecyclerViewActions
8+
import androidx.test.espresso.matcher.RootMatchers.isDialog
9+
import androidx.test.espresso.matcher.ViewMatchers.*
10+
import androidx.test.ext.junit.runners.AndroidJUnit4
11+
import androidx.test.platform.app.InstrumentationRegistry
12+
import androidx.test.rule.ActivityTestRule
13+
import org.apache.fineract.R
14+
import org.apache.fineract.couchbase.SynchronizationManager
15+
import org.apache.fineract.data.models.product.InterestBasis
16+
import org.apache.fineract.data.models.product.Product
17+
import org.apache.fineract.ui.adapters.ProductAccountAssignmentsAdapter
18+
import org.apache.fineract.ui.product.ProductAction
19+
import org.apache.fineract.ui.product.createproduct.CreateProductActivity
20+
import org.apache.fineract.utils.Constants
21+
import org.apache.fineract.utils.toDataClass
22+
import org.junit.*
23+
import org.junit.runner.RunWith
24+
25+
/**
26+
* Created by Varun Jain on 21/8/2021.
27+
*/
28+
29+
@RunWith(AndroidJUnit4::class)
30+
class CreateEditProductAndroidTest {
31+
32+
@get:Rule
33+
var activityTestRule =
34+
ActivityTestRule<CreateProductActivity>(CreateProductActivity::class.java, false, false)
35+
36+
lateinit var synchronizationManager: SynchronizationManager
37+
38+
@Before
39+
fun before() {
40+
41+
val intent = Intent().apply {
42+
putExtra(Constants.PRODUCT_ACTION, ProductAction.CREATE)
43+
}
44+
45+
activityTestRule.launchActivity(intent)
46+
47+
synchronizationManager =
48+
SynchronizationManager(InstrumentationRegistry.getInstrumentation().context)
49+
}
50+
51+
@Test
52+
fun checkIfProductCreatedSuccessfully() {
53+
54+
// Filling all the details in Product Details Step fragment
55+
onView(withId(R.id.etIdentifier))
56+
.perform(typeText("test identifier"))
57+
onView(withId(R.id.etName))
58+
.perform(typeText("test Name"))
59+
onView(withId(R.id.etPatternPackage))
60+
.perform(typeText("pattern package"))
61+
onView(withId(R.id.etDescription))
62+
.perform(typeText("product description"))
63+
onView(withId(R.id.etCurrencyCode))
64+
.perform(typeText("Currency code"))
65+
onView(withId(R.id.scrollViewProductDetailsStep))
66+
.perform(swipeUp())
67+
onView(withId(R.id.etParameters))
68+
.perform(typeText("Parameters"))
69+
onView(withId(R.id.etMinorCurrencyUnitDigits))
70+
.perform(typeText("1000"))
71+
onView(withId(R.id.etTemporalUnit))
72+
.perform(typeText("Temporal unit"))
73+
onView(withId(R.id.scrollViewProductDetailsStep))
74+
.perform(swipeUp())
75+
onView(withId(R.id.etTermRangeMax))
76+
.perform(typeText("1000"))
77+
onView(withId(R.id.etBalanceRangeMinimum))
78+
.perform(typeText("10"))
79+
onView(withId(R.id.etMaximumBalanceRange))
80+
.perform(typeText("1000"))
81+
onView(withId(R.id.scrollViewProductDetailsStep))
82+
.perform(swipeUp())
83+
onView(withId(R.id.etMinInterestRange))
84+
.perform(typeText("10"))
85+
onView(withId(R.id.etMaximumInterestRange))
86+
.perform(typeText("1000"))
87+
.perform(closeSoftKeyboard())
88+
89+
// Navigate to the next step
90+
onView(withText("NEXT")).perform(click())
91+
92+
// Create, editing and deleting the Account Assignments
93+
onView(withId(R.id.ibAddAccountAssignment))
94+
.perform(click())
95+
onView(withId(R.id.etDesignator))
96+
.perform(typeText("Desig"))
97+
onView(withId(R.id.etAccountIdentifier))
98+
.perform(typeText("Account Identifier"))
99+
onView(withId(R.id.scrollViewAddAccountAssignmentsStep))
100+
.perform(swipeUp())
101+
onView(withId(R.id.etLedgerIdentifier))
102+
.perform(typeText("Ledger Identifier"))
103+
onView(withId(R.id.btnAddProductAccountAssignment))
104+
.perform(click())
105+
106+
// Edit an Account assignment
107+
onView(withId(R.id.ivEditProductAccountAss))
108+
.perform(click())
109+
onView(withId(R.id.etDesignator))
110+
.perform(typeText("nator"))
111+
onView(withId(R.id.scrollViewAddAccountAssignmentsStep))
112+
.perform(swipeUp())
113+
onView(withId(R.id.btnAddProductAccountAssignment))
114+
.perform(click())
115+
116+
// Delete a Account assignment
117+
onView(withId(R.id.ivDeleteProductAccountAss))
118+
.perform(click())
119+
120+
// Dismiss the Delete dialog
121+
onView(withText("DELETE")).inRoot(isDialog()).check(matches(isDisplayed())).perform(pressBack());
122+
123+
// Navigate to the next step
124+
onView(withText("NEXT")).perform(click())
125+
126+
// Test if the Product Review Step is populated with the correct values
127+
onView(withId(R.id.tvProductIdentifier)).check(matches(withText("test identifier")))
128+
onView(withId(R.id.tvProductName)).check(matches(withText("test Name")))
129+
onView(withId(R.id.tvPatternPackageProduct)).check(matches(withText("pattern package")))
130+
onView(withId(R.id.tvProductDescription)).check(matches(withText("product description")))
131+
onView(withId(R.id.tvProductCurrencyCode)).check(matches(withText("Currency code")))
132+
onView(withId(R.id.tvProductMinorCurrencyUnit)).check(matches(withText("1000")))
133+
onView(withId(R.id.tvParameters)).check(matches(withText("Parameters")))
134+
onView(withId(R.id.tvInterestBasis)).check(matches(withText(InterestBasis.BEGINNING_BALANCE.toString())))
135+
onView(withId(R.id.scrollViewProductReviewStep))
136+
.perform(swipeUp())
137+
onView(withId(R.id.rvProductAccountAssignmentsStepReview))
138+
.perform(
139+
RecyclerViewActions.actionOnItem<ProductAccountAssignmentsAdapter.ViewHolder>(
140+
hasDescendant(withText("Designator")), click()
141+
)
142+
)
143+
onView(withId(R.id.tvProductTemporalUnit)).check(matches(withText("Temporal unit")))
144+
145+
// Complete defining the Product
146+
onView(withText("COMPLETE")).perform(click())
147+
148+
// assert if the product has been created successfully
149+
val mapItem = synchronizationManager.getDocumentForTest(
150+
"test identifier",
151+
InstrumentationRegistry.getInstrumentation().context
152+
)
153+
154+
val product = mapItem.toDataClass<Product>()
155+
156+
Assert.assertEquals(product.name, "test Name")
157+
Assert.assertEquals(product.patternPackage, "pattern package")
158+
}
159+
160+
@After
161+
fun after() {
162+
//delete the created document during the test
163+
synchronizationManager.deleteDocument(
164+
"test identifier"
165+
)
166+
}
167+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.apache.fineract.ui.online.products
2+
3+
import androidx.test.espresso.Espresso
4+
import androidx.test.espresso.action.ViewActions
5+
import androidx.test.espresso.assertion.ViewAssertions
6+
import androidx.test.espresso.contrib.DrawerActions
7+
import androidx.test.espresso.contrib.NavigationViewActions
8+
import androidx.test.espresso.contrib.RecyclerViewActions
9+
import androidx.test.espresso.matcher.ViewMatchers
10+
import androidx.test.ext.junit.runners.AndroidJUnit4
11+
import androidx.test.rule.ActivityTestRule
12+
import org.apache.fineract.R
13+
import org.apache.fineract.ui.adapters.GroupsAdapter
14+
import org.apache.fineract.ui.online.DashboardActivity
15+
import org.junit.Rule
16+
import org.junit.Test
17+
import org.junit.runner.RunWith
18+
19+
/**
20+
* Created by Varun Jain on 21/8/2021.
21+
*/
22+
23+
@RunWith(AndroidJUnit4::class)
24+
class ProductListFragmentAndroidTest {
25+
26+
@get:Rule
27+
val activityRule =
28+
ActivityTestRule<DashboardActivity>(DashboardActivity::class.java)
29+
30+
@Test
31+
fun openDrawerOpenProductListClickOnRecyclerViewItem() {
32+
33+
//Open drawer
34+
Espresso.onView(ViewMatchers.withId(R.id.drawer_layout))
35+
.perform(DrawerActions.open())
36+
37+
//From NavigationView navigate to Products list screen
38+
Espresso.onView(ViewMatchers.withId(R.id.nav_view))
39+
.perform(NavigationViewActions.navigateTo(R.id.item_product))
40+
41+
//Click on a recycler View item
42+
Espresso.onView(ViewMatchers.withId(R.id.rvProduct)).perform(
43+
RecyclerViewActions.actionOnItem<GroupsAdapter.ViewHolder>(
44+
ViewMatchers.hasDescendant(ViewMatchers.withText("product identifier")),
45+
ViewActions.click()
46+
)
47+
)
48+
49+
//Assert if the item has been displayed correctly
50+
Espresso.onView(ViewMatchers.withId(R.id.tvIdentifierProduct))
51+
.check(ViewAssertions.matches(ViewMatchers.withText("product identifier")))
52+
}
53+
}

app/src/main/res/layout/fragment_step_add_account_assignments.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
android:layout_margin="@dimen/default_margin">
88

99
<androidx.core.widget.NestedScrollView
10+
android:id="@+id/scrollViewAddAccountAssignmentsStep"
1011
android:layout_width="match_parent"
1112
android:layout_height="match_parent"
1213
app:layout_behavior="@string/appbar_scrolling_view_behavior">
@@ -18,6 +19,7 @@
1819
android:layout_marginBottom="@dimen/default_margin">
1920

2021
<LinearLayout
22+
android:id="@+id/llAddProductAccountAssignmentsStep"
2123
android:layout_width="match_parent"
2224
android:layout_height="wrap_content"
2325
android:orientation="vertical"

app/src/main/res/layout/fragment_step_product_details.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
android:layout_margin="@dimen/default_margin">
99

1010
<androidx.core.widget.NestedScrollView
11+
android:id="@+id/scrollViewProductDetailsStep"
1112
android:layout_width="match_parent"
1213
android:layout_height="match_parent"
1314
app:layout_behavior="@string/appbar_scrolling_view_behavior">

app/src/main/res/layout/fragment_step_product_review.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
android:layout_margin="@dimen/default_margin">
88

99
<androidx.core.widget.NestedScrollView
10+
android:id="@+id/scrollViewProductReviewStep"
1011
android:layout_width="match_parent"
1112
android:layout_height="match_parent"
1213
app:layout_behavior="@string/appbar_scrolling_view_behavior">

0 commit comments

Comments
 (0)