|
35 | 35 | import org.gnucash.android.db.SplitsDbAdapter; |
36 | 36 | import org.gnucash.android.db.TransactionsDbAdapter; |
37 | 37 | import org.gnucash.android.model.Account; |
| 38 | +import org.gnucash.android.model.AccountType; |
38 | 39 | import org.gnucash.android.model.Money; |
39 | 40 | import org.gnucash.android.receivers.AccountCreator; |
40 | 41 | import org.gnucash.android.ui.account.AccountsActivity; |
|
47 | 48 | import java.util.Currency; |
48 | 49 | import java.util.List; |
49 | 50 |
|
| 51 | +import static android.support.test.espresso.Espresso.onData; |
50 | 52 | import static android.support.test.espresso.Espresso.onView; |
51 | 53 | import static android.support.test.espresso.action.ViewActions.clearText; |
52 | 54 | import static android.support.test.espresso.action.ViewActions.click; |
53 | 55 | import static android.support.test.espresso.action.ViewActions.longClick; |
54 | 56 | import static android.support.test.espresso.action.ViewActions.scrollTo; |
| 57 | +import static android.support.test.espresso.action.ViewActions.swipeRight; |
55 | 58 | import static android.support.test.espresso.action.ViewActions.typeText; |
56 | 59 | import static android.support.test.espresso.assertion.ViewAssertions.matches; |
| 60 | +import static android.support.test.espresso.matcher.ViewMatchers.isChecked; |
57 | 61 | import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; |
58 | 62 | import static android.support.test.espresso.matcher.ViewMatchers.isNotChecked; |
59 | 63 | import static android.support.test.espresso.matcher.ViewMatchers.withId; |
60 | 64 | import static android.support.test.espresso.matcher.ViewMatchers.withText; |
61 | 65 | import static org.assertj.core.api.Assertions.assertThat; |
62 | 66 | import static org.hamcrest.Matchers.allOf; |
| 67 | +import static org.hamcrest.Matchers.instanceOf; |
| 68 | +import static org.hamcrest.Matchers.is; |
63 | 69 | import static org.hamcrest.Matchers.not; |
64 | 70 |
|
65 | 71 | @RunWith(AndroidJUnit4.class) |
@@ -213,6 +219,31 @@ public void testChangeParentAccount() { |
213 | 219 | assertThat(DUMMY_ACCOUNT_UID).isEqualTo(parentUID); |
214 | 220 | } |
215 | 221 |
|
| 222 | + /** |
| 223 | + * When creating a sub-account (starting from within another account), if we change the account |
| 224 | + * type to another type with no accounts of that type, then the parent account list should be hidden. |
| 225 | + * The account which is then created is not a sub-account, but rather a top-level account |
| 226 | + */ |
| 227 | + @Test |
| 228 | + public void shouldHideParentAccountViewWhenNoParentsExist(){ |
| 229 | + onView(withText(DUMMY_ACCOUNT_NAME)).perform(click()); |
| 230 | + onView(withId(R.id.fragment_transaction_list)).perform(swipeRight()); |
| 231 | + onView(withText(R.string.label_create_account)).check(matches(isDisplayed())).perform(click()); |
| 232 | + sleep(1000); |
| 233 | + onView(withId(R.id.checkbox_parent_account)).check(matches(allOf(isChecked()))); |
| 234 | + onView(withId(R.id.input_account_name)).perform(typeText("Trading account")); |
| 235 | + onView(withId(R.id.input_account_type_spinner)).perform(click()); |
| 236 | + onData(allOf(is(instanceOf(String.class)), is(AccountType.TRADING.name()))).perform(click()); |
| 237 | + |
| 238 | + onView(withId(R.id.layout_parent_account)).check(matches(not(isDisplayed()))); |
| 239 | + onView(withId(R.id.menu_save)).perform(click()); |
| 240 | + |
| 241 | + //no sub-accounts |
| 242 | + assertThat(mAccountsDbAdapter.getSubAccountCount(DUMMY_ACCOUNT_UID)).isEqualTo(0); |
| 243 | + assertThat(mAccountsDbAdapter.getSubAccountCount(mAccountsDbAdapter.getOrCreateGnuCashRootAccountUID())).isEqualTo(2); |
| 244 | + assertThat(mAccountsDbAdapter.getSimpleAccountList()).extracting("mAccountType").contains(AccountType.TRADING); |
| 245 | + } |
| 246 | + |
216 | 247 | @Test |
217 | 248 | public void testEditAccount(){ |
218 | 249 | String editedAccountName = "Edited Account"; |
|
0 commit comments