mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-05-18 21:58:52 -04:00
Fix unit tests
This commit is contained in:
@@ -16,17 +16,21 @@ public class ImportURIHelper {
|
||||
private final Context context;
|
||||
private final String host;
|
||||
private final String path;
|
||||
private final String oldHost;
|
||||
private final String oldPath;
|
||||
private final String shareText;
|
||||
|
||||
public ImportURIHelper(Context context) {
|
||||
this.context = context;
|
||||
host = context.getResources().getString(R.string.intent_import_card_from_url_host);
|
||||
path = context.getResources().getString(R.string.intent_import_card_from_url_path_prefix);
|
||||
oldHost = "brarcher.github.io";
|
||||
oldPath = "/loyalty-card-locker/share";
|
||||
shareText = context.getResources().getString(R.string.intent_import_card_from_url_share_text);
|
||||
}
|
||||
|
||||
private boolean isImportUri(Uri uri) {
|
||||
return uri.getHost().equals(host) && uri.getPath().equals(path);
|
||||
return (uri.getHost().equals(host) && uri.getPath().equals(path)) || (uri.getHost().equals(oldHost) && uri.getPath().equals(oldPath));
|
||||
}
|
||||
|
||||
public LoyaltyCard parse(Uri uri) throws InvalidObjectException {
|
||||
|
||||
@@ -119,7 +119,7 @@ public class LoyaltyCardViewActivityTest
|
||||
barcodeTypeField.setText(barcodeType);
|
||||
|
||||
assertEquals(false, activity.isFinishing());
|
||||
shadowOf(activity).clickMenuItem(R.id.action_save);
|
||||
activity.findViewById(R.id.fabSave).performClick();
|
||||
assertEquals(true, activity.isFinishing());
|
||||
|
||||
assertEquals(1, db.getLoyaltyCardCount());
|
||||
@@ -278,15 +278,15 @@ public class LoyaltyCardViewActivityTest
|
||||
final EditText noteField = activity.findViewById(R.id.noteEdit);
|
||||
final TextView cardIdField = activity.findViewById(R.id.cardIdView);
|
||||
|
||||
shadowOf(activity).clickMenuItem(R.id.action_save);
|
||||
activity.findViewById(R.id.fabSave).performClick();
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
|
||||
storeField.setText("store");
|
||||
shadowOf(activity).clickMenuItem(R.id.action_save);
|
||||
activity.findViewById(R.id.fabSave).performClick();
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
|
||||
noteField.setText("note");
|
||||
shadowOf(activity).clickMenuItem(R.id.action_save);
|
||||
activity.findViewById(R.id.fabSave).performClick();
|
||||
assertEquals(0, db.getLoyaltyCardCount());
|
||||
}
|
||||
|
||||
@@ -488,12 +488,11 @@ public class LoyaltyCardViewActivityTest
|
||||
final Menu menu = shadowOf(activity).getOptionsMenu();
|
||||
assertTrue(menu != null);
|
||||
|
||||
// The share, settings and add button should be present
|
||||
assertEquals(menu.size(), 3);
|
||||
// The share and settings button should be present
|
||||
assertEquals(menu.size(), 2);
|
||||
|
||||
assertEquals("Block Rotation", menu.findItem(R.id.action_lock_unlock).getTitle().toString());
|
||||
assertEquals("Share", menu.findItem(R.id.action_share).getTitle().toString());
|
||||
assertEquals("Edit", menu.findItem(R.id.action_edit).getTitle().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -755,6 +754,27 @@ public class LoyaltyCardViewActivityTest
|
||||
|
||||
@Test
|
||||
public void importCard()
|
||||
{
|
||||
Uri importUri = Uri.parse("https://thelastproject.github.io/Catima/share?store=Example%20Store¬e=&cardid=123456&barcodetype=AZTEC&headercolor=-416706&headertextcolor=-1");
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.setData(importUri);
|
||||
|
||||
ActivityController activityController = Robolectric.buildActivity(LoyaltyCardEditActivity.class, intent).create();
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
activityController.resume();
|
||||
|
||||
Activity activity = (Activity)activityController.get();
|
||||
|
||||
checkAllFields(activity, ViewMode.ADD_CARD, "Example Store", "", "123456", "AZTEC");
|
||||
assertEquals(-416706, ((ColorDrawable) activity.findViewById(R.id.headingColorSample).getBackground()).getColor());
|
||||
assertEquals(-1, ((ColorDrawable) activity.findViewById(R.id.headingStoreTextColorSample).getBackground()).getColor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void importCardOldURL()
|
||||
{
|
||||
Uri importUri = Uri.parse("https://brarcher.github.io/loyalty-card-locker/share?store=Example%20Store¬e=&cardid=123456&barcodetype=AZTEC&headercolor=-416706&headertextcolor=-1");
|
||||
|
||||
|
||||
@@ -37,14 +37,6 @@ public class MainActivityTest
|
||||
{
|
||||
private SharedPreferences prefs;
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
{
|
||||
// Assume that this is not the first launch
|
||||
prefs = RuntimeEnvironment.application.getSharedPreferences("protect.card_locker", Context.MODE_PRIVATE);
|
||||
prefs.edit().putBoolean("firstrun", false).commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initiallyNoLoyaltyCards() throws Exception
|
||||
{
|
||||
@@ -70,12 +62,9 @@ public class MainActivityTest
|
||||
assertTrue(menu != null);
|
||||
|
||||
// The settings, search and add button should be present
|
||||
assertEquals(menu.size(), 6);
|
||||
|
||||
assertEquals(menu.size(), 4);
|
||||
assertEquals("Search", menu.findItem(R.id.action_search).getTitle().toString());
|
||||
assertEquals("Add", menu.findItem(R.id.action_add).getTitle().toString());
|
||||
assertEquals("Import/Export", menu.findItem(R.id.action_import_export).getTitle().toString());
|
||||
assertEquals("Start Intro", menu.findItem(R.id.action_intro).getTitle().toString());
|
||||
assertEquals("About", menu.findItem(R.id.action_about).getTitle().toString());
|
||||
assertEquals("Settings", menu.findItem(R.id.action_settings).getTitle().toString());
|
||||
}
|
||||
@@ -85,7 +74,7 @@ public class MainActivityTest
|
||||
{
|
||||
final MainActivity activity = Robolectric.setupActivity(MainActivity.class);
|
||||
|
||||
shadowOf(activity).clickMenuItem(R.id.action_add);
|
||||
activity.findViewById(R.id.fabAdd).performClick();
|
||||
|
||||
Intent intent = shadowOf(activity).peekNextStartedActivityForResult().intent;
|
||||
|
||||
@@ -219,26 +208,4 @@ public class MainActivityTest
|
||||
|
||||
assertEquals(2, list.getCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFirstRunStartsIntro()
|
||||
{
|
||||
prefs.edit().remove("firstrun").commit();
|
||||
|
||||
ActivityController controller = Robolectric.buildActivity(MainActivity.class).create();
|
||||
Activity activity = (Activity)controller.get();
|
||||
|
||||
assertTrue(activity.isFinishing() == false);
|
||||
|
||||
Intent next = shadowOf(activity).getNextStartedActivity();
|
||||
|
||||
ComponentName componentName = next.getComponent();
|
||||
String name = componentName.flattenToShortString();
|
||||
assertEquals("protect.card_locker/.intro.IntroActivity", name);
|
||||
|
||||
Bundle extras = next.getExtras();
|
||||
assertNull(extras);
|
||||
|
||||
assertEquals(false, prefs.getBoolean("firstrun", true));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user