Fix as reviewed and add test

This commit is contained in:
Sylvia van Os
2020-01-02 21:15:06 +01:00
parent cc99af13e4
commit ce81d3afd4
4 changed files with 69 additions and 11 deletions

View File

@@ -64,9 +64,8 @@ public class BarcodeSelectorActivityTest {
activity.findViewById(R.id.noBarcode).performClick();
Intent resultIntent = shadowOf(activity).getResultIntent();
// The BarcodeSelectorActivity should return the special NO_BARCODE string to differentiate
// from nothing being set yet
assertEquals(LoyaltyCardEditActivity.NO_BARCODE, resultIntent.getStringExtra(BarcodeSelectorActivity.BARCODE_FORMAT));
// The BarcodeSelectorActivity should return an empty string
assertEquals("", resultIntent.getStringExtra(BarcodeSelectorActivity.BARCODE_FORMAT));
assertEquals("abcdefg", resultIntent.getStringExtra(BarcodeSelectorActivity.BARCODE_CONTENTS));
}

View File

@@ -164,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(
@@ -176,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)
{
@@ -551,6 +583,32 @@ public class LoyaltyCardViewActivityTest
saveLoyaltyCardWithArguments(activity, "store", "note", BARCODE_DATA, LoyaltyCardEditActivity.NO_BARCODE, false);
}
@Test
public void removeBarcodeFromLoyaltyCard() throws IOException
{
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);
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
public void startCheckFontSizes()
{