forked from getodk/collect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added StorageMigrationCompletedBannerTest
- Loading branch information
1 parent
a5c897d
commit 12853f6
Showing
4 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...androidTest/java/org/odk/collect/android/storage/StorageMigrationCompletedBannerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.odk.collect.android.storage; | ||
|
||
import androidx.test.rule.ActivityTestRule; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.odk.collect.android.activities.MainMenuActivity; | ||
import org.odk.collect.android.support.StorageMigrationCompletedRule; | ||
import org.odk.collect.android.support.pages.MainMenuPage; | ||
|
||
public class StorageMigrationCompletedBannerTest { | ||
|
||
@Rule | ||
public ActivityTestRule<MainMenuActivity> main = new ActivityTestRule<>(MainMenuActivity.class); | ||
|
||
@Rule | ||
public StorageMigrationCompletedRule storageMigrationCompletedRule = new StorageMigrationCompletedRule(); | ||
|
||
@Test | ||
public void when_storageMigrationCompleted_should_bannerBeVisibleAndPersistScreenRotation() { | ||
new MainMenuPage(main) | ||
.assertStorageMigrationCompletedBannerIsDisplayed() | ||
.rotateToLandscape(new MainMenuPage(main)) | ||
.assertStorageMigrationCompletedBannerIsDisplayed() | ||
.rotateToPortrait(new MainMenuPage(main)) | ||
.assertStorageMigrationCompletedBannerIsDisplayed() | ||
.clickDismissButton() | ||
.assertStorageMigrationCompletedBannerIsNotDisplayed() | ||
.rotateToLandscape(new MainMenuPage(main)) | ||
.assertStorageMigrationCompletedBannerIsNotDisplayed() | ||
.rotateToPortrait(new MainMenuPage(main)) | ||
.assertStorageMigrationCompletedBannerIsNotDisplayed(); | ||
} | ||
|
||
@Test | ||
public void when_storageMigrationCompleted_should_bannerBeVisibleAndDismissForEverIfAUserClicksDismissButton() { | ||
new MainMenuPage(main) | ||
.assertStorageMigrationCompletedBannerIsDisplayed() | ||
.clickDismissButton() | ||
.assertStorageMigrationCompletedBannerIsNotDisplayed() | ||
.rotateToLandscape(new MainMenuPage(main)) | ||
.assertStorageMigrationCompletedBannerIsNotDisplayed() | ||
.rotateToPortrait(new MainMenuPage(main)) | ||
.assertStorageMigrationCompletedBannerIsNotDisplayed() | ||
.reopenApp() | ||
.assertStorageMigrationCompletedBannerIsNotDisplayed(); | ||
} | ||
|
||
@Test | ||
public void when_storageMigrationCompleted_should_bannerBeVisibleAndDismissAfterReopeningApp() { | ||
new MainMenuPage(main) | ||
.assertStorageMigrationCompletedBannerIsDisplayed() | ||
.reopenApp() | ||
.assertStorageMigrationCompletedBannerIsNotDisplayed(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...p/src/androidTest/java/org/odk/collect/android/support/StorageMigrationCompletedRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.odk.collect.android.support; | ||
|
||
import org.junit.rules.TestRule; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
import org.odk.collect.android.storage.StorageStateProvider; | ||
import org.odk.collect.android.storage.migration.StorageMigrationRepository; | ||
import org.odk.collect.android.storage.migration.StorageMigrationResult; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import dagger.Provides; | ||
|
||
import static org.odk.collect.android.support.CollectHelpers.overrideAppDependencyModule; | ||
|
||
public class StorageMigrationCompletedRule implements TestRule { | ||
|
||
@Override | ||
public Statement apply(Statement base, Description description) { | ||
return new StorageMigrationCompletedStatement(base); | ||
} | ||
|
||
private class StorageMigrationCompletedStatement extends Statement { | ||
|
||
private final Statement base; | ||
|
||
StorageMigrationCompletedStatement(Statement base) { | ||
this.base = base; | ||
} | ||
|
||
@Override | ||
public void evaluate() throws Throwable { | ||
overrideAppDependencyModule(new AppDependencyModule()); | ||
new StorageStateProvider().enableUsingScopedStorage(); | ||
base.evaluate(); | ||
} | ||
} | ||
|
||
private static class AppDependencyModule extends org.odk.collect.android.injection.config.AppDependencyModule { | ||
|
||
@Provides | ||
@Singleton | ||
public StorageMigrationRepository providesStorageMigrationRepository() { | ||
StorageMigrationRepository storageMigrationRepository = new StorageMigrationRepository(); | ||
storageMigrationRepository.setResult(StorageMigrationResult.SUCCESS); | ||
return storageMigrationRepository; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters