2727import android .util .Log ;
2828import android .view .View ;
2929import android .widget .EditText ;
30+
3031import com .robotium .solo .Solo ;
32+
3133import org .gnucash .android .R ;
3234import org .gnucash .android .db .AccountsDbAdapter ;
3335import org .gnucash .android .db .DatabaseHelper ;
3739import org .gnucash .android .model .Money ;
3840import org .gnucash .android .model .Split ;
3941import org .gnucash .android .model .Transaction ;
40- import org .gnucash .android .test .util .ActionBarUtils ;
4142import org .gnucash .android .ui .account .AccountsActivity ;
4243import org .gnucash .android .ui .account .AccountsListFragment ;
4344
@@ -64,10 +65,7 @@ public AccountsActivityTest() {
6465
6566 protected void setUp () throws Exception {
6667 Context context = getInstrumentation ().getTargetContext ();
67- Editor editor = PreferenceManager .getDefaultSharedPreferences (context ).edit ();
68- editor .putBoolean (context .getString (R .string .key_first_run ), false );
69- editor .putInt (AccountsActivity .LAST_OPEN_TAB_INDEX , AccountsActivity .INDEX_TOP_LEVEL_ACCOUNTS_FRAGMENT );
70- editor .commit ();
68+ preventFirstRunDialogs (context );
7169
7270 mDbHelper = new DatabaseHelper (context );
7371 try {
@@ -86,32 +84,40 @@ protected void setUp() throws Exception {
8684 account .setUID (DUMMY_ACCOUNT_UID );
8785 account .setCurrency (Currency .getInstance (DUMMY_ACCOUNT_CURRENCY_CODE ));
8886 mAccountsDbAdapter .addAccount (account );
89-
90- //the What's new dialog is usually displayed on first run
91- String dismissDialog = getActivity ().getString (R .string .label_dismiss );
92- if (mSolo .waitForText (dismissDialog ,1 ,1000 )){
93- mSolo .clickOnText (dismissDialog );
94- }
9587 }
9688
97- /*
98- public void testDisplayAccountsList(){
99- final int NUMBER_OF_ACCOUNTS = 15;
100- for (int i = 0; i < NUMBER_OF_ACCOUNTS; i++) {
101- Account account = new Account("Acct " + i);
102- mAccountsDbAdapter.addAccount(account);
103- }
89+ public static void preventFirstRunDialogs (Context context ) {
90+ Editor editor = PreferenceManager .getDefaultSharedPreferences (context ).edit ();
10491
105- //there should exist a listview of accounts
106- refreshAccountsList();
107- mSolo.waitForText("Acct");
108- mSolo.scrollToBottom();
92+ //do not show first run dialog
93+ editor .putBoolean (context .getString (R .string .key_first_run ), false );
94+ editor .putInt (AccountsActivity .LAST_OPEN_TAB_INDEX , AccountsActivity .INDEX_TOP_LEVEL_ACCOUNTS_FRAGMENT );
10995
110- ListView accountsListView = (ListView) mSolo.getView(android.R.id.list);
111- assertNotNull(accountsListView);
112- assertEquals(NUMBER_OF_ACCOUNTS + 1, accountsListView.getCount());
113- }
114- */
96+ //do not show "What's new" dialog
97+ String minorVersion = context .getString (R .string .app_minor_version );
98+ int currentMinor = Integer .parseInt (minorVersion );
99+ editor .putInt (context .getString (R .string .key_previous_minor_version ), currentMinor );
100+ editor .commit ();
101+ }
102+
103+ /*
104+ public void testDisplayAccountsList(){
105+ final int NUMBER_OF_ACCOUNTS = 15;
106+ for (int i = 0; i < NUMBER_OF_ACCOUNTS; i++) {
107+ Account account = new Account("Acct " + i);
108+ mAccountsDbAdapter.addAccount(account);
109+ }
110+
111+ //there should exist a listview of accounts
112+ refreshAccountsList();
113+ mSolo.waitForText("Acct");
114+ mSolo.scrollToBottom();
115+
116+ ListView accountsListView = (ListView) mSolo.getView(android.R.id.list);
117+ assertNotNull(accountsListView);
118+ assertEquals(NUMBER_OF_ACCOUNTS + 1, accountsListView.getCount());
119+ }
120+ */
115121 public void testSearchAccounts (){
116122 String SEARCH_ACCOUNT_NAME = "Search Account" ;
117123
@@ -122,15 +128,17 @@ public void testSearchAccounts(){
122128 refreshAccountsList ();
123129
124130 //enter search query
125- ActionBarUtils .clickSherlockActionBarItem (mSolo , R .id .menu_search );
126- mSolo .sleep (200 );
131+ // ActionBarUtils.clickSherlockActionBarItem(mSolo, R.id.menu_search);
132+ mSolo .clickOnActionBarItem (R .id .menu_search );
133+ mSolo .sleep (2000 );
127134 mSolo .enterText (0 , "Se" );
128-
135+ mSolo . sleep ( 3000 );
129136 boolean accountFound = mSolo .waitForText (SEARCH_ACCOUNT_NAME , 1 , 2000 );
130137 assertTrue (accountFound );
131138
132139 mSolo .clearEditText (0 );
133140
141+ mSolo .sleep (2000 );
134142 //the child account should be hidden again
135143 accountFound = mSolo .waitForText (SEARCH_ACCOUNT_NAME , 1 , 2000 );
136144 assertFalse (accountFound );
@@ -174,13 +182,14 @@ public void testChangeParentAccount(){
174182 mSolo .waitForText (accountName );
175183
176184 mSolo .clickLongOnText (accountName );
177- mSolo .clickOnView (getActivity (). findViewById (R .id .context_menu_edit_accounts ));
185+ mSolo .clickOnView (mSolo . getView (R .id .context_menu_edit_accounts ));
178186 mSolo .waitForView (EditText .class );
179187
180188 mSolo .clickOnCheckBox (1 );
181189 mSolo .pressSpinnerItem (2 , 0 );
182190
183- mSolo .clickOnView (getActivity ().findViewById (R .id .menu_save ));
191+ // mSolo.clickOnView(mSolo.getView(R.id.menu_save));
192+ mSolo .clickOnActionBarItem (R .id .menu_save );
184193
185194 mSolo .waitForText (getActivity ().getString (R .string .title_accounts ));
186195 Account editedAccount = mAccountsDbAdapter .getAccount (accountUID );
@@ -192,6 +201,7 @@ public void testChangeParentAccount(){
192201
193202 public void testEditAccount (){
194203 refreshAccountsList ();
204+ mSolo .sleep (2000 );
195205 mSolo .waitForText (DUMMY_ACCOUNT_NAME );
196206
197207 String editedAccountName = "Edited Account" ;
@@ -207,7 +217,7 @@ public void testEditAccount(){
207217
208218 clickSherlockActionBarItem (R .id .menu_save );
209219
210- mSolo .waitForDialogToClose (2000 );
220+ mSolo .waitForDialogToClose ();
211221 mSolo .waitForText ("Accounts" );
212222
213223 List <Account > accounts = mAccountsDbAdapter .getAllAccounts ();
@@ -216,7 +226,8 @@ public void testEditAccount(){
216226 assertEquals ("Edited Account" , latest .getName ());
217227 assertEquals (DUMMY_ACCOUNT_CURRENCY_CODE , latest .getCurrency ().getCurrencyCode ());
218228 }
219-
229+
230+ //TODO: Add test for moving content of accounts before deleting it
220231 public void testDeleteAccount (){
221232 final String accountNameToDelete = "TO BE DELETED" ;
222233 final String accountUidToDelete = "to-be-deleted" ;
@@ -238,9 +249,11 @@ public void testDeleteAccount(){
238249
239250 clickSherlockActionBarItem (R .id .context_menu_delete );
240251
252+ mSolo .waitForDialogToOpen ();
253+ mSolo .clickOnRadioButton (0 );
241254 mSolo .clickOnView (mSolo .getView (R .id .btn_save ));
242255
243- mSolo .waitForDialogToClose (1000 );
256+ mSolo .waitForDialogToClose ();
244257 mSolo .waitForText ("Accounts" );
245258
246259 Exception expectedException = null ;
@@ -285,7 +298,8 @@ public void testIntentAccountCreation(){
285298
286299 protected void tearDown () throws Exception {
287300 mSolo .finishOpenedActivities ();
288- mSolo .sleep (1000 );
301+ mSolo .waitForEmptyActivityStack (20000 );
302+ mSolo .sleep (5000 );
289303 mAccountsDbAdapter .deleteAllRecords ();
290304
291305 super .tearDown ();
0 commit comments