Skip to content

Commit

Permalink
Added StorageMigrationBannerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed Feb 26, 2020
1 parent d932897 commit c45f65a
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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.StorageMigrationNotPerformedRule;
import org.odk.collect.android.support.pages.MainMenuPage;

public class StorageMigrationBannerTest {

@Rule
public ActivityTestRule<MainMenuActivity> main = new ActivityTestRule<>(MainMenuActivity.class);

@Rule
public StorageMigrationNotPerformedRule storageMigrationNotPerformedRule = new StorageMigrationNotPerformedRule();

@Test
public void when_storageMigrationNotPerformed_should_bannerBeVisible() {
new MainMenuPage(main)
.assertStorageMigrationBannerIsDisplayed()
.rotateToLandscape(new MainMenuPage(main))
.assertStorageMigrationBannerIsDisplayed()
.rotateToPortrait(new MainMenuPage(main))
.assertStorageMigrationBannerIsDisplayed()
.reopenApp()
.assertStorageMigrationBannerIsDisplayed();
}

@Test
public void when_learMoreButtonClicked_should_storageMigrationDialogAppear() {
new MainMenuPage(main)
.clickLearnMoreButton();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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;

public class StorageMigrationNotPerformedRule implements TestRule {

@Override
public Statement apply(Statement base, Description description) {
return new StorageMigrationNotPerformedRuleStatement(base);
}

private class StorageMigrationNotPerformedRuleStatement extends Statement {

private final Statement base;

StorageMigrationNotPerformedRuleStatement(Statement base) {
this.base = base;
}

@Override
public void evaluate() throws Throwable {
new StorageStateProvider().disableUsingScopedStorage();
base.evaluate();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ public MainMenuPage assertNumberOfFinalizedForms(int number) {
return this;
}

public MainMenuPage assertStorageMigrationBannerIsDisplayed() {
onView(withText(R.string.scoped_storage_banner_text)).check(matches(isDisplayed()));
onView(withText(R.string.scoped_storage_learn_more)).check(matches(isDisplayed()));
return this;
}

public MainMenuPage assertStorageMigrationCompletedBannerIsDisplayed() {
onView(withText(R.string.storage_migration_completed)).check(matches(isDisplayed()));
onView(withText(R.string.scoped_storage_dismiss)).check(matches(isDisplayed()));
Expand All @@ -102,6 +108,11 @@ public MainMenuPage assertStorageMigrationCompletedBannerIsNotDisplayed() {
return this;
}

public StorageMigrationDialogPage clickLearnMoreButton() {
onView(withId(R.id.storageMigrationBannerLearnMoreButton)).perform(click());
return new StorageMigrationDialogPage<>(rule);
}

public MainMenuPage clickDismissButton() {
onView(withId(R.id.storageMigrationBannerDismissButton)).perform(click());
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.odk.collect.android.support.pages;

import androidx.test.rule.ActivityTestRule;

import org.odk.collect.android.R;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.matcher.ViewMatchers.withId;

public class StorageMigrationDialogPage<D extends Page<D>> extends Page<StorageMigrationDialogPage<D>> {

public StorageMigrationDialogPage(ActivityTestRule rule) {
super(rule);
}

@Override
public StorageMigrationDialogPage<D> assertOnPage() {
checkIsStringDisplayed(R.string.storage_migration_dialog_title);
return this;
}

public MainMenuPage clickMigrate() {
onView(withId(R.id.migrateButton)).perform(click());
return new MainMenuPage(rule).assertOnPage();
}
}

0 comments on commit c45f65a

Please sign in to comment.