Skip to content

Instantly share code, notes, and snippets.

@riwnodennyk
Created December 4, 2015 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riwnodennyk/054c068c8de7ce32d4a7 to your computer and use it in GitHub Desktop.
Save riwnodennyk/054c068c8de7ce32d4a7 to your computer and use it in GitHub Desktop.
package com.netpulse.mobile.refer_friend;
import android.content.ComponentName;
import android.support.test.espresso.intent.rule.IntentsTestRule;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.netpulse.mobile.R;
import com.netpulse.mobile.core.api.MockReferralApi;
import com.netpulse.mobile.core.api.Referral;
import com.netpulse.mobile.dashboard.ui.DashboardActivity;
import com.netpulse.mobile.utils.AppStateUtils;
import com.netpulse.mobile.utils.rules.CleanAppData;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExternalResource;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.intent.Intents.intended;
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.core.IsEqual.equalTo;
@RunWith(AndroidJUnit4.class)
public class ReferFriendTest {
private final ActivityTestRule<DashboardActivity> activityTestRule = new IntentsTestRule<>(DashboardActivity.class, false, false);
@Rule
public TestRule chain = RuleChain.emptyRuleChain()
.around(new CleanAppData())
.around(new ExternalResource() {
@Override
protected void before() throws Throwable {
AppStateUtils.setAuthenticated();
}
})
.around(activityTestRule);
@Test
public void withNetpulse() {
MockReferralApi.myReferral = Referral.netpulse();
activityTestRule.launchActivity(null);
onView(withText(R.string.title_refer_friend)).perform(click());
intended(hasComponent(equalTo(new ComponentName(getTargetContext(), ReferFriendExtActivity.class))));
}
@Test
public void withExternalUrl() {
MockReferralApi.myReferral = Referral.external("https://www.genymotion.com/#!/");
activityTestRule.launchActivity(null);
onView(withText(R.string.title_refer_friend)).perform(click());
intended(hasComponent(equalTo(new ComponentName(getTargetContext(), WebViewActivity.class))));
}
@Test
public void withPerkVille() {
MockReferralApi.myReferral = Referral.perkVille();
activityTestRule.launchActivity(null);
onView(withText(R.string.title_refer_friend)).perform(click());
intended(hasComponent(equalTo(new ComponentName(getTargetContext(), ReferFriendActivity.class))));
}
@Test
public void withNull() {
MockReferralApi.myReferral = null;
activityTestRule.launchActivity(null);
onView(withText(R.string.title_refer_friend)).perform(click());
onView(withText(R.string.sorry_no_refer_friend_feature)).inRoot(new ToastMatcher()).perform(click());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment