mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-05-18 13:49:15 -04:00
Merge branch 'master' of ssh://github.com/brarcher/loyalty-card-locker into feature/pkpass
This commit is contained in:
@@ -63,6 +63,8 @@ public class BarcodeSelectorActivityTest {
|
||||
// Clicking button should create "empty" barcode
|
||||
activity.findViewById(R.id.noBarcode).performClick();
|
||||
Intent resultIntent = shadowOf(activity).getResultIntent();
|
||||
|
||||
// The BarcodeSelectorActivity should return an empty string
|
||||
assertEquals("", resultIntent.getStringExtra(BarcodeSelectorActivity.BARCODE_FORMAT));
|
||||
assertEquals("abcdefg", resultIntent.getStringExtra(BarcodeSelectorActivity.BARCODE_CONTENTS));
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.robolectric.annotation.Config;
|
||||
import java.io.InvalidObjectException;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static protect.card_locker.DBHelper.LoyaltyCardDbIds;
|
||||
|
||||
@@ -76,6 +77,30 @@ public class ImportURITest {
|
||||
assertEquals(card.extras.toJSON().toString(), parsedCard.extras.toJSON().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ensureNoCrashOnMissingHeaderFields() throws InvalidObjectException, JSONException
|
||||
{
|
||||
// Generate card
|
||||
db.insertLoyaltyCard("store", "note", BarcodeFormat.UPC_A.toString(), LoyaltyCardDbIds.BARCODE_TYPE, null, null, null, new ExtrasHelper());
|
||||
|
||||
// Get card
|
||||
LoyaltyCard card = db.getLoyaltyCard(1);
|
||||
|
||||
// Card to URI
|
||||
Uri cardUri = importURIHelper.toUri(card);
|
||||
|
||||
// Parse URI
|
||||
LoyaltyCard parsedCard = importURIHelper.parse(cardUri);
|
||||
|
||||
// Compare everything
|
||||
assertEquals(card.barcodeType, parsedCard.barcodeType);
|
||||
assertEquals(card.cardId, parsedCard.cardId);
|
||||
assertEquals(card.note, parsedCard.note);
|
||||
assertEquals(card.store, parsedCard.store);
|
||||
assertNull(parsedCard.headerColor);
|
||||
assertNull(parsedCard.headerTextColor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failToParseInvalidUri()
|
||||
{
|
||||
|
||||
@@ -126,7 +126,16 @@ public class LoyaltyCardViewActivityTest
|
||||
assertEquals(store, card.store);
|
||||
assertEquals(note, card.note);
|
||||
assertEquals(cardId, card.cardId);
|
||||
assertEquals(barcodeType, card.barcodeType);
|
||||
|
||||
// The special "No barcode" string shouldn't actually be written to the loyalty card
|
||||
if(barcodeType.equals(LoyaltyCardEditActivity.NO_BARCODE))
|
||||
{
|
||||
assertEquals("", card.barcodeType);
|
||||
}
|
||||
else
|
||||
{
|
||||
assertEquals(barcodeType, card.barcodeType);
|
||||
}
|
||||
assertNotNull(card.headerColor);
|
||||
assertNotNull(card.headerTextColor);
|
||||
}
|
||||
@@ -155,10 +164,10 @@ public class LoyaltyCardViewActivityTest
|
||||
assertNotNull(bundle);
|
||||
|
||||
Intent resultIntent = new Intent(intent);
|
||||
Bundle resultBuddle = new Bundle();
|
||||
resultBuddle.putString(Intents.Scan.RESULT, BARCODE_DATA);
|
||||
resultBuddle.putString(Intents.Scan.RESULT_FORMAT, BARCODE_TYPE);
|
||||
resultIntent.putExtras(resultBuddle);
|
||||
Bundle resultBundle = new Bundle();
|
||||
resultBundle.putString(Intents.Scan.RESULT, BARCODE_DATA);
|
||||
resultBundle.putString(Intents.Scan.RESULT_FORMAT, BARCODE_TYPE);
|
||||
resultIntent.putExtras(resultBundle);
|
||||
|
||||
// Respond to image capture, success
|
||||
shadowOf(activity).receiveResult(
|
||||
@@ -167,6 +176,38 @@ public class LoyaltyCardViewActivityTest
|
||||
resultIntent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate and complete a barcode selection, either in success
|
||||
* or in failure
|
||||
*/
|
||||
private void selectBarcodeWithResult(final Activity activity, final int buttonId, final String barcodeData, final String barcodeType, final boolean success) throws IOException
|
||||
{
|
||||
// Start image capture
|
||||
final Button captureButton = activity.findViewById(buttonId);
|
||||
captureButton.performClick();
|
||||
|
||||
ShadowActivity.IntentForResult intentForResult = shadowOf(activity).peekNextStartedActivityForResult();
|
||||
assertNotNull(intentForResult);
|
||||
|
||||
Intent intent = intentForResult.intent;
|
||||
assertNotNull(intent);
|
||||
|
||||
Bundle bundle = intent.getExtras();
|
||||
assertNotNull(bundle);
|
||||
|
||||
Intent resultIntent = new Intent(intent);
|
||||
Bundle resultBundle = new Bundle();
|
||||
resultBundle.putString(BarcodeSelectorActivity.BARCODE_FORMAT, barcodeType);
|
||||
resultBundle.putString(BarcodeSelectorActivity.BARCODE_CONTENTS, barcodeData);
|
||||
resultIntent.putExtras(resultBundle);
|
||||
|
||||
// Respond to barcode selection, success
|
||||
shadowOf(activity).receiveResult(
|
||||
intent,
|
||||
success ? Activity.RESULT_OK : Activity.RESULT_CANCELED,
|
||||
resultIntent);
|
||||
}
|
||||
|
||||
private void checkFieldProperties(final Activity activity, final int id, final int visibility,
|
||||
final String contents)
|
||||
{
|
||||
@@ -540,7 +581,33 @@ public class LoyaltyCardViewActivityTest
|
||||
activityController.resume();
|
||||
|
||||
// Save and check the loyalty card
|
||||
saveLoyaltyCardWithArguments(activity, "store", "note", BARCODE_DATA, "", false);
|
||||
saveLoyaltyCardWithArguments(activity, "store", "note", BARCODE_DATA, LoyaltyCardEditActivity.NO_BARCODE, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeBarcodeFromLoyaltyCard() throws IOException, JSONException
|
||||
{
|
||||
ActivityController activityController = createActivityWithLoyaltyCard(true);
|
||||
Activity activity = (Activity)activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
|
||||
db.insertLoyaltyCard("store", "note", BARCODE_DATA, BARCODE_TYPE, Color.BLACK, Color.WHITE, null, new ExtrasHelper());
|
||||
|
||||
activityController.start();
|
||||
activityController.visible();
|
||||
activityController.resume();
|
||||
|
||||
// First check if the card is as expected
|
||||
checkAllFields(activity, ViewMode.UPDATE_CARD, "store", "note", BARCODE_DATA, BARCODE_TYPE);
|
||||
|
||||
// Complete empty barcode selection successfully
|
||||
selectBarcodeWithResult(activity, R.id.enterButton, BARCODE_DATA, "", true);
|
||||
|
||||
// Check if the barcode type is NO_BARCODE as expected
|
||||
checkAllFields(activity, ViewMode.UPDATE_CARD, "store", "note", BARCODE_DATA, LoyaltyCardEditActivity.NO_BARCODE);
|
||||
|
||||
// Check if the special NO_BARCODE string doesn't get saved
|
||||
saveLoyaltyCardWithArguments(activity, "store", "note", BARCODE_DATA, LoyaltyCardEditActivity.NO_BARCODE, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user