|
37 | 37 | import org.gnucash.android.model.Account; |
38 | 38 | import org.gnucash.android.model.AccountType; |
39 | 39 | import org.gnucash.android.model.Money; |
| 40 | +import org.gnucash.android.model.Split; |
| 41 | +import org.gnucash.android.model.Transaction; |
40 | 42 | import org.gnucash.android.receivers.AccountCreator; |
41 | 43 | import org.gnucash.android.ui.account.AccountsActivity; |
42 | 44 | import org.gnucash.android.ui.account.AccountsListFragment; |
|
45 | 47 | import org.junit.Test; |
46 | 48 | import org.junit.runner.RunWith; |
47 | 49 |
|
| 50 | +import java.math.BigDecimal; |
48 | 51 | import java.util.Currency; |
49 | 52 | import java.util.List; |
50 | 53 |
|
|
71 | 74 | @RunWith(AndroidJUnit4.class) |
72 | 75 | public class AccountsActivityTest extends ActivityInstrumentationTestCase2<AccountsActivity> { |
73 | 76 | private static final String DUMMY_ACCOUNT_CURRENCY_CODE = "USD"; |
| 77 | + private static final Currency DUMMY_ACCOUNT_CURRENCY = Currency.getInstance(DUMMY_ACCOUNT_CURRENCY_CODE); |
74 | 78 | private static final String DUMMY_ACCOUNT_NAME = "Dummy account"; |
75 | 79 | public static final String DUMMY_ACCOUNT_UID = "dummy-account"; |
76 | 80 | private DatabaseHelper mDbHelper; |
@@ -226,7 +230,7 @@ public void testChangeParentAccount() { |
226 | 230 | */ |
227 | 231 | @Test |
228 | 232 | public void shouldHideParentAccountViewWhenNoParentsExist(){ |
229 | | - onView(withText(DUMMY_ACCOUNT_NAME)).perform(click()); |
| 233 | + onView(allOf(withText(DUMMY_ACCOUNT_NAME), isDisplayed())).perform(click()); |
230 | 234 | onView(withId(R.id.fragment_transaction_list)).perform(swipeRight()); |
231 | 235 | onView(withText(R.string.label_create_account)).check(matches(isDisplayed())).perform(click()); |
232 | 236 | sleep(1000); |
@@ -264,6 +268,31 @@ public void testEditAccount(){ |
264 | 268 | assertThat(latest.getCurrency().getCurrencyCode()).isEqualTo(DUMMY_ACCOUNT_CURRENCY_CODE); |
265 | 269 | } |
266 | 270 |
|
| 271 | + @Test |
| 272 | + public void editingAccountShouldNotDeleteTransactions(){ |
| 273 | + onView(allOf(withText(DUMMY_ACCOUNT_NAME), isDisplayed())) |
| 274 | + .perform(longClick()); |
| 275 | + Account account = new Account("Transfer Account"); |
| 276 | + |
| 277 | + Transaction transaction = new Transaction("Simple trxn"); |
| 278 | + Split split = new Split(new Money(BigDecimal.TEN, DUMMY_ACCOUNT_CURRENCY), account.getUID()); |
| 279 | + transaction.addSplit(split); |
| 280 | + transaction.addSplit(split.createPair(DUMMY_ACCOUNT_UID)); |
| 281 | + account.addTransaction(transaction); |
| 282 | + mAccountsDbAdapter.addAccount(account); |
| 283 | + |
| 284 | + assertThat(mAccountsDbAdapter.getAccount(DUMMY_ACCOUNT_UID).getTransactionCount()).isEqualTo(1); |
| 285 | + assertThat(mSplitsDbAdapter.getSplitsForTransaction(transaction.getUID())).hasSize(2); |
| 286 | + |
| 287 | + onView(withId(R.id.context_menu_edit_accounts)).perform(click()); |
| 288 | + |
| 289 | + onView(withId(R.id.menu_save)).perform(click()); |
| 290 | + assertThat(mAccountsDbAdapter.getAccount(DUMMY_ACCOUNT_UID).getTransactionCount()).isEqualTo(1); |
| 291 | + assertThat(mSplitsDbAdapter.fetchSplitsForAccount(DUMMY_ACCOUNT_UID).getCount()).isEqualTo(1); |
| 292 | + assertThat(mSplitsDbAdapter.getSplitsForTransaction(transaction.getUID())).hasSize(2); |
| 293 | + |
| 294 | + } |
| 295 | + |
267 | 296 | /** |
268 | 297 | * Sleep the thread for a specified period |
269 | 298 | * @param millis Duration to sleep in milliseconds |
|
0 commit comments