package nz.org.winters.android.nzmobileaccountwidget.tests.setup; // NOTE THIS IS INCOMPLETE, ONLY AND EXAMPLE import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Color; import android.preference.Preference; import android.preference.PreferenceManager; import android.support.test.InstrumentationRegistry; import android.support.test.espresso.DataInteraction; import android.support.test.espresso.action.ViewActions; import android.support.test.espresso.matcher.BoundedMatcher; import android.support.test.espresso.matcher.ViewMatchers; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; import android.util.Log; import android.widget.CheckedTextView; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import java.text.MessageFormat; import static android.support.test.espresso.Espresso.onData; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.Espresso.pressBack; import static android.support.test.espresso.action.ViewActions.clearText; import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.action.ViewActions.typeText; import static android.support.test.espresso.assertion.ViewAssertions.matches; import static android.support.test.espresso.matcher.PreferenceMatchers.withKey; import static android.support.test.espresso.matcher.PreferenceMatchers.withSummary; import static android.support.test.espresso.matcher.PreferenceMatchers.withSummaryText; import static android.support.test.espresso.matcher.ViewMatchers.assertThat; import static android.support.test.espresso.matcher.ViewMatchers.hasSibling; import static android.support.test.espresso.matcher.ViewMatchers.isChecked; import static android.support.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.isEnabled; import static android.support.test.espresso.matcher.ViewMatchers.withChild; import static android.support.test.espresso.matcher.ViewMatchers.withClassName; import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription; import static android.support.test.espresso.matcher.ViewMatchers.withId; import static android.support.test.espresso.matcher.ViewMatchers.withParent; import static android.support.test.espresso.matcher.ViewMatchers.withText; import static com.google.android.apps.common.testing.deps.guava.base.Preconditions.checkNotNull; import static nz.org.winters.android.widgetscommon.tests.CustomMatchers.onSettingRow; import static nz.org.winters.android.widgetscommon.tests.CustomMatchers.withSettingItemContent; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; /** * Created by mathew on 5/05/15. */ @SuppressWarnings({"unchecked", "FieldCanBeLocal"}) @RunWith(AndroidJUnit4.class) public class AccountSettingsTest { private static final String TITLE_ACCOUNTS = "Accounts"; private static final String ACCOUNT_1_NAME = "Bob Smith"; private static final String ACCOUNT_1_USERNAME = "BOBSUSERNAME"; private static final String ACCOUNT_1_PASSWORD = "would you like to know"; private static final String COLOUR_ORANGE_CONTENT_DESCRIPTION = "Colour 7"; private static final int COLOUR_ORANGE = 0xffff8800; private static final String COLOUR_CONTENT_DESCRIPTION = "Colour "; //SettingGroupListActivity_.intent(this).accountId(mAccountId).appWidgetId(mAppWidgetId).startForResult(REQUEST_CODE_SETTINGS_FINISHED); @SuppressWarnings("unchecked") @Before public void onBefore(){ assertThat(InstrumentationRegistry.getContext(), is(notNullValue())); assertThat(InstrumentationRegistry.getTargetContext(), is(notNullValue())); Intent intent = new Intent(); intent.putExtra(SettingGroupListActivity_.ACCOUNT_ID_EXTRA, accountId1); testCase.launchActivity(intent); context = testCase.getActivity(); preferences = PreferenceManager.getDefaultSharedPreferences(context); } @Rule public ActivityTestRule testCase = new ActivityTestRule<>(SettingGroupListActivity_.class, false, false); private Context context; SharedPreferences preferences; @SuppressWarnings("unchecked") @Test() public void testAccountSettings() { onView(allOf(withParent(withId(R.id.toolbar)), withText(R.string.settings))).check(matches(isDisplayed())); onSettingRow(SettingsConstants.PREF_GENERAL).check(matches(isCompletelyDisplayed())); onSettingRow(SettingsConstants.PREF_ACCOUNTS).check(matches(isCompletelyDisplayed())); onSettingRow(SettingsConstants.PREF_LICENSE).check(matches(isCompletelyDisplayed())); onPreferenceRow(SettingsConstants.PREF_USE_WIFI_ONLY).check(matches(isDisplayed())); onPreferenceRow(SettingsConstants.PREF_USE_WIFI_ONLY).onChildView(withClassName(is(Switch.class.getName()))).check(matches(not(isChecked()))); onPreferenceRow(SettingsConstants.PREF_NUMBERFORMATLOCALE).check(matches(isDisplayed())); onPreferenceRow(SettingsConstants.PREF_UPDATE_WHEN).check(matches(isDisplayed())); onPreferenceRow(SettingsConstants.PREF_QUIET_TIME).check(matches(isDisplayed())); onPreferenceRow(SettingsConstants.PREF_ERROR_REPORTING).check(matches(isDisplayed())); } }