Skip to content

Commit

Permalink
Include future transactions when computing account balance in account…
Browse files Browse the repository at this point in the history
… list - fixes #465

  - This would make it consistent with GnuCash desktop accounts display
  • Loading branch information
codinguser committed Mar 2, 2018
1 parent 261a109 commit bec24f6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
package org.gnucash.android.test.ui;

import android.Manifest;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences.Editor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.test.espresso.Espresso;
import android.support.test.espresso.matcher.ViewMatchers;
Expand All @@ -32,6 +30,7 @@
import android.support.test.runner.AndroidJUnit4;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.View;

import com.kobakei.ratethisapp.RateThisApp;

Expand All @@ -54,6 +53,9 @@
import org.gnucash.android.test.ui.util.DisableAnimationsRule;
import org.gnucash.android.ui.account.AccountsActivity;
import org.gnucash.android.ui.account.AccountsListFragment;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -87,6 +89,7 @@
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
Expand Down Expand Up @@ -236,6 +239,21 @@ public void testCreateAccount(){
assertThat(newestAccount.isPlaceholderAccount()).isTrue();
}

@Test
public void should_IncludeFutureTransactionsInAccountBalance(){
Transaction transaction = new Transaction("Future transaction");
Split split1 = new Split(new Money("4.15", ACCOUNTS_CURRENCY_CODE), SIMPLE_ACCOUNT_UID);
transaction.addSplit(split1);
transaction.setTime(System.currentTimeMillis() + 4815162342L);
mTransactionsDbAdapter.addRecord(transaction);

refreshAccountsList();

List<Transaction> trxns = mTransactionsDbAdapter.getAllTransactions();

onView(first(withText(containsString("4.15")))).check(matches(isDisplayed()));
}

@Test
public void testChangeParentAccount() {
final String accountName = "Euro Account";
Expand Down Expand Up @@ -511,4 +529,31 @@ public void run() {
System.err.println("Failed to refresh fragment");
}
}

/**
* Matcher to select the first of multiple views which are matched in the UI
* @param expected Matcher which fits multiple views
* @return Single match
*/
public static Matcher<View> first(final Matcher<View> expected){

return new TypeSafeMatcher<View>() {
private boolean first = false;

@Override
protected boolean matchesSafely(View item) {

if( expected.matches(item) && !first ){
return first = true;
}

return false;
}

@Override
public void describeTo(Description description) {
description.appendText("Matcher.first( " + expected.toString() + " )" );
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected Money doInBackground(String... params) {

Money balance = Money.getZeroInstance();
try {
balance = accountsDbAdapter.getAccountBalance(params[0], -1, System.currentTimeMillis());
balance = accountsDbAdapter.getAccountBalance(params[0], -1, -1);
} catch (Exception ex) {
Log.e(LOG_TAG, "Error computing account balance ", ex);
Crashlytics.logException(ex);
Expand Down

0 comments on commit bec24f6

Please sign in to comment.