Skip to content

Commit

Permalink
Correction in code - refactoring of tests - correction in setQuery in…
Browse files Browse the repository at this point in the history
…stead of mFilter
  • Loading branch information
vp193dt committed Oct 30, 2024
1 parent 9097119 commit 51340ee
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions app/src/test/java/protect/card_locker/MainActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -713,24 +713,26 @@ public void testSearchQueryRestorationAfterNavigatingBack() {
activityController.start();
activityController.resume();

final Menu menu = shadowOf(Robolectric.setupActivity(MainActivity.class)).getOptionsMenu();
MenuItem searchMenuItem = menu.findItem(R.id.action_search);
SearchView mSearchView = (SearchView) searchMenuItem.getActionView();


SQLiteDatabase database = TestHelpers.getEmptyDb(mainActivity).getWritableDatabase();
DBHelper.insertLoyaltyCard(database, "The First Store", "Initial note", null, null, new BigDecimal("0"), null, "cardId", null, CatimaBarcode.fromBarcode(BarcodeFormat.UPC_A), Color.BLACK, 0, null,0);
DBHelper.insertLoyaltyCard(database, "The Second Store", "Secondary note", null, null, new BigDecimal("0"), null, "cardId", null, CatimaBarcode.fromBarcode(BarcodeFormat.UPC_A), Color.BLACK, 0, null,0);

mainActivity.mFilter = "store";
String finalQuery = "store";
assert mSearchView != null;
mSearchView.setQuery(finalQuery, false);

activityController.pause();
activityController.resume();

// Simulation of what happens when users comes back after picking up card
final Menu menu = shadowOf(Robolectric.setupActivity(MainActivity.class)).getOptionsMenu();
MenuItem searchMenuItem = menu.findItem(R.id.action_search);
SearchView mSearchView = (SearchView) searchMenuItem.getActionView();

// We simulate expanding and setting the Query that we want to restore (in code it is from finalQuery String)
searchMenuItem.expandActionView();
String finalQuery = "store";
assert mSearchView != null;

mSearchView.setQuery(finalQuery, false);

activityController.pause();
Expand Down

0 comments on commit 51340ee

Please sign in to comment.