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+ }
0 commit comments