mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-03-28 20:31:39 -04:00
Fix unit tests
This commit is contained in:
@@ -75,6 +75,7 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
|
||||
|
||||
boolean hasChanged = false;
|
||||
boolean initDone = false;
|
||||
AlertDialog confirmExitDialog = null;
|
||||
|
||||
private void extractIntentFields(Intent intent)
|
||||
{
|
||||
@@ -397,28 +398,26 @@ public class LoyaltyCardEditActivity extends AppCompatActivity
|
||||
return;
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.leaveWithoutSaveTitle);
|
||||
builder.setMessage(R.string.leaveWithoutSaveConfirmation);
|
||||
builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
finish();
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
if (confirmExitDialog == null) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.leaveWithoutSaveTitle);
|
||||
builder.setMessage(R.string.leaveWithoutSaveConfirmation);
|
||||
builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
finish();
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
confirmExitDialog = builder.create();
|
||||
}
|
||||
confirmExitDialog.show();
|
||||
}
|
||||
|
||||
class EditCardIdAndBarcode implements View.OnClickListener
|
||||
|
||||
@@ -352,7 +352,7 @@ public class LoyaltyCardViewActivityTest
|
||||
activityController.visible();
|
||||
activityController.resume();
|
||||
|
||||
Activity activity = (Activity)activityController.get();
|
||||
LoyaltyCardEditActivity activity = (LoyaltyCardEditActivity) activityController.get();
|
||||
|
||||
checkAllFields(activity, ViewMode.ADD_CARD, "", "", "", "");
|
||||
|
||||
@@ -363,7 +363,17 @@ public class LoyaltyCardViewActivityTest
|
||||
|
||||
// Cancel the loyalty card creation
|
||||
assertEquals(false, activity.isFinishing());
|
||||
|
||||
// A change was made
|
||||
shadowOf(activity).clickMenuItem(android.R.id.home);
|
||||
assertEquals(true, activity.confirmExitDialog.isShowing());
|
||||
assertEquals(true, activity.hasChanged);
|
||||
assertEquals(false, activity.isFinishing());
|
||||
|
||||
// Exit after setting hasChanged to false
|
||||
activity.hasChanged = false;
|
||||
shadowOf(activity).clickMenuItem(android.R.id.home);
|
||||
assertEquals(false, activity.hasChanged);
|
||||
assertEquals(true, activity.isFinishing());
|
||||
}
|
||||
|
||||
@@ -448,7 +458,7 @@ public class LoyaltyCardViewActivityTest
|
||||
public void startWithLoyaltyCardWithReceiptUpdateReceiptCancel() throws IOException
|
||||
{
|
||||
ActivityController activityController = createActivityWithLoyaltyCard(true);
|
||||
Activity activity = (Activity)activityController.get();
|
||||
LoyaltyCardEditActivity activity = (LoyaltyCardEditActivity) activityController.get();
|
||||
DBHelper db = new DBHelper(activity);
|
||||
|
||||
db.insertLoyaltyCard("store", "note", EAN_BARCODE_DATA, EAN_BARCODE_TYPE, Color.BLACK, 0);
|
||||
@@ -466,7 +476,16 @@ public class LoyaltyCardViewActivityTest
|
||||
|
||||
// Cancel the loyalty card creation
|
||||
assertEquals(false, activity.isFinishing());
|
||||
// A change was made
|
||||
shadowOf(activity).clickMenuItem(android.R.id.home);
|
||||
assertEquals(true, activity.confirmExitDialog.isShowing());
|
||||
assertEquals(true, activity.hasChanged);
|
||||
assertEquals(false, activity.isFinishing());
|
||||
|
||||
// Exit after setting hasChanged to false
|
||||
activity.hasChanged = false;
|
||||
shadowOf(activity).clickMenuItem(android.R.id.home);
|
||||
assertEquals(false, activity.hasChanged);
|
||||
assertEquals(true, activity.isFinishing());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user