Skip to content

Commit da27b31

Browse files
committed
UI test optimizations
Tests currently pass on actual devices but some fail on emulators
1 parent 1ea9d7b commit da27b31

4 files changed

Lines changed: 14 additions & 18 deletions

File tree

app/src/androidTest/java/org/gnucash/android/test/ui/AccountsActivityTest.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.database.sqlite.SQLiteDatabase;
2424
import android.preference.PreferenceManager;
2525
import android.support.test.InstrumentationRegistry;
26+
import android.support.test.espresso.Espresso;
2627
import android.support.test.runner.AndroidJUnit4;
2728
import android.support.v4.app.Fragment;
2829
import android.test.ActivityInstrumentationTestCase2;
@@ -52,6 +53,7 @@
5253
import static android.support.test.espresso.action.ViewActions.clearText;
5354
import static android.support.test.espresso.action.ViewActions.click;
5455
import static android.support.test.espresso.action.ViewActions.longClick;
56+
import static android.support.test.espresso.action.ViewActions.scrollTo;
5557
import static android.support.test.espresso.action.ViewActions.typeText;
5658
import static android.support.test.espresso.assertion.ViewAssertions.matches;
5759
import 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
}

app/src/androidTest/java/org/gnucash/android/test/ui/TransactionsActivityTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ private void clickOnView(int viewId){
540540
@After
541541
public void tearDown() throws Exception {
542542
mTransactionsActivity.finish();
543-
Thread.sleep(2000);
543+
Thread.sleep(1000);
544544
mAccountsDbAdapter.deleteAllRecords();
545545
super.tearDown();
546546
}

app/src/main/java/org/gnucash/android/ui/account/AccountFormFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public void onNothingSelected(AdapterView<?> adapterView) {
264264
mParentAccountSpinner = (Spinner) view.findViewById(R.id.input_parent_account);
265265
mParentAccountSpinner.setEnabled(false);
266266

267-
mParentCheckBox = (CheckBox) view.findViewById(R.id.checkbox_transaction);
267+
mParentCheckBox = (CheckBox) view.findViewById(R.id.checkbox_parent_account);
268268
mParentCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
269269

270270
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
android:layout_marginBottom="@dimen/form_row_bottom_margin"
9898
android:orientation="horizontal" >
9999

100-
<CheckBox android:id="@+id/checkbox_transaction"
100+
<CheckBox android:id="@+id/checkbox_parent_account"
101101
android:layout_width="wrap_content"
102102
android:layout_height="wrap_content"
103103
android:focusable="false" />

0 commit comments

Comments
 (0)