2323import android .database .sqlite .SQLiteDatabase ;
2424import android .preference .PreferenceManager ;
2525import android .support .test .InstrumentationRegistry ;
26+ import android .support .test .espresso .Espresso ;
2627import android .support .test .runner .AndroidJUnit4 ;
2728import android .support .v4 .app .Fragment ;
2829import android .test .ActivityInstrumentationTestCase2 ;
5253import static android .support .test .espresso .action .ViewActions .clearText ;
5354import static android .support .test .espresso .action .ViewActions .click ;
5455import static android .support .test .espresso .action .ViewActions .longClick ;
56+ import static android .support .test .espresso .action .ViewActions .scrollTo ;
5557import static android .support .test .espresso .action .ViewActions .typeText ;
5658import static android .support .test .espresso .assertion .ViewAssertions .matches ;
5759import static android .support .test .espresso .matcher .ViewMatchers .isDisplayed ;
@@ -165,19 +167,18 @@ public void testSearchAccounts(){
165167 public void testCreateAccount (){
166168 onView (withId (R .id .menu_add_account )).check (matches (isDisplayed ())).perform (click ());
167169
168- onView (withId (R .id .checkbox_transaction ))
169- // .check(matches(allOf(isDisplayed(), isNotChecked())))
170- .perform (click ());
171-
172170 String NEW_ACCOUNT_NAME = "A New Account" ;
173171 onView (withId (R .id .input_account_name )).perform (typeText (NEW_ACCOUNT_NAME ));
172+ Espresso .closeSoftKeyboard ();
174173 onView (withId (R .id .checkbox_placeholder_account ))
175174 .check (matches (isNotChecked ()))
176175 .perform (click ());
177- onView (withId (R .id .menu_save )).perform (click ());
178176
179- //check displayed
180- // onView(withId(android.R.id.list)).check(matches(hasDescendant(withText(NEW_ACCOUNT_NAME))));
177+ onView (withId (R .id .checkbox_parent_account )).perform (scrollTo ())
178+ .check (matches (allOf (isDisplayed (), isNotChecked ())))
179+ .perform (click ());
180+
181+ onView (withId (R .id .menu_save )).perform (click ());
181182
182183 List <Account > accounts = mAccountsDbAdapter .getAllAccounts ();
183184 assertThat (accounts ).isNotNull ();
@@ -196,13 +197,12 @@ public void testChangeParentAccount() {
196197 mAccountsDbAdapter .addAccount (account );
197198
198199 refreshAccountsList ();
199- // onView(withId(android.R.id.list))
200- // .check(matches(allOf(isDisplayed(), hasDescendant(withText(accountName)))));
201200
202201 onView (withText (accountName )).perform (longClick ());
203202 onView (withId (R .id .context_menu_edit_accounts )).perform (click ());
204203 onView (withId (R .id .fragment_account_form )).check (matches (isDisplayed ()));
205- onView (withId (R .id .checkbox_transaction ))
204+ Espresso .closeSoftKeyboard ();
205+ onView (withId (R .id .checkbox_parent_account )).perform (scrollTo ())
206206 .check (matches (isNotChecked ()))
207207 .perform (click ());
208208
@@ -228,10 +228,6 @@ public void testEditAccount(){
228228
229229 onView (withId (R .id .menu_save )).perform (click ());
230230
231- //test refresh
232- // onView(withId(android.R.id.empty))
233- // .check(matches(not(isDisplayed())));
234-
235231 List <Account > accounts = mAccountsDbAdapter .getAllAccounts ();
236232 Account latest = accounts .get (0 ); //will be the first due to alphabetical sorting
237233
@@ -285,7 +281,7 @@ public void testIntentAccountCreation(){
285281 @ After
286282 public void tearDown () throws Exception {
287283 mAcccountsActivity .finish ();
288- Thread .sleep (2000 );
284+ Thread .sleep (1000 );
289285 mAccountsDbAdapter .deleteAllRecords (); //clear the data
290286 super .tearDown ();
291287 }
0 commit comments