|  | @@ -1,124 +0,0 @@
 | 
	
		
			
			| 1 |  | -package com.reactnativenavigation.playground;
 | 
	
		
			
			| 2 |  | -
 | 
	
		
			
			| 3 |  | -import android.annotation.TargetApi;
 | 
	
		
			
			| 4 |  | -import android.provider.Settings;
 | 
	
		
			
			| 5 |  | -import android.support.test.espresso.Espresso;
 | 
	
		
			
			| 6 |  | -import android.support.test.filters.SdkSuppress;
 | 
	
		
			
			| 7 |  | -import android.support.test.rule.ActivityTestRule;
 | 
	
		
			
			| 8 |  | -import android.support.test.runner.AndroidJUnit4;
 | 
	
		
			
			| 9 |  | -import android.support.test.uiautomator.UiDevice;
 | 
	
		
			
			| 10 |  | -import android.support.test.uiautomator.UiSelector;
 | 
	
		
			
			| 11 |  | -
 | 
	
		
			
			| 12 |  | -import com.reactnativenavigation.views.NavigationSplashView;
 | 
	
		
			
			| 13 |  | -
 | 
	
		
			
			| 14 |  | -import org.junit.After;
 | 
	
		
			
			| 15 |  | -import org.junit.Before;
 | 
	
		
			
			| 16 |  | -import org.junit.FixMethodOrder;
 | 
	
		
			
			| 17 |  | -import org.junit.Rule;
 | 
	
		
			
			| 18 |  | -import org.junit.Test;
 | 
	
		
			
			| 19 |  | -import org.junit.runner.RunWith;
 | 
	
		
			
			| 20 |  | -import org.junit.runners.MethodSorters;
 | 
	
		
			
			| 21 |  | -
 | 
	
		
			
			| 22 |  | -import static android.support.test.InstrumentationRegistry.getInstrumentation;
 | 
	
		
			
			| 23 |  | -import static android.support.test.espresso.Espresso.onView;
 | 
	
		
			
			| 24 |  | -import static android.support.test.espresso.assertion.ViewAssertions.matches;
 | 
	
		
			
			| 25 |  | -import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
 | 
	
		
			
			| 26 |  | -import static android.support.test.espresso.matcher.ViewMatchers.withText;
 | 
	
		
			
			| 27 |  | -import static org.assertj.core.api.Java6Assertions.assertThat;
 | 
	
		
			
			| 28 |  | -
 | 
	
		
			
			| 29 |  | -@RunWith(AndroidJUnit4.class)
 | 
	
		
			
			| 30 |  | -@FixMethodOrder(value = MethodSorters.NAME_ASCENDING)
 | 
	
		
			
			| 31 |  | -@SdkSuppress(minSdkVersion = 23)
 | 
	
		
			
			| 32 |  | -@TargetApi(23)
 | 
	
		
			
			| 33 |  | -public class ApplicationLifecycleTest {
 | 
	
		
			
			| 34 |  | -
 | 
	
		
			
			| 35 |  | -    private ReactIdlingResource reactIdlingResource = new ReactIdlingResource();
 | 
	
		
			
			| 36 |  | -
 | 
	
		
			
			| 37 |  | -    @Rule
 | 
	
		
			
			| 38 |  | -    public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class, false, false);
 | 
	
		
			
			| 39 |  | -
 | 
	
		
			
			| 40 |  | -    @Before
 | 
	
		
			
			| 41 |  | -    public void beforeEach() throws Exception {
 | 
	
		
			
			| 42 |  | -        uiDevice().wakeUp();
 | 
	
		
			
			| 43 |  | -        reactIdlingResource.start();
 | 
	
		
			
			| 44 |  | -        Espresso.registerIdlingResources(reactIdlingResource);
 | 
	
		
			
			| 45 |  | -    }
 | 
	
		
			
			| 46 |  | -
 | 
	
		
			
			| 47 |  | -    @After
 | 
	
		
			
			| 48 |  | -    public void afterEach() {
 | 
	
		
			
			| 49 |  | -        reactIdlingResource.stop();
 | 
	
		
			
			| 50 |  | -        Espresso.unregisterIdlingResources(reactIdlingResource);
 | 
	
		
			
			| 51 |  | -        uiDevice().waitForIdle();
 | 
	
		
			
			| 52 |  | -    }
 | 
	
		
			
			| 53 |  | -
 | 
	
		
			
			| 54 |  | -    @Test
 | 
	
		
			
			| 55 |  | -    public void _1_showSplash_AcceptsOverlayPermissions_ShowsWelcomeScreen() throws Exception {
 | 
	
		
			
			| 56 |  | -        rule.launchActivity(null);
 | 
	
		
			
			| 57 |  | -        assertThat(rule.getActivity().getContentView()).isNotNull().isInstanceOf(NavigationSplashView.class);
 | 
	
		
			
			| 58 |  | -        acceptOverlayPermissionIfNeeded();
 | 
	
		
			
			| 59 |  | -        assertMainShown();
 | 
	
		
			
			| 60 |  | -    }
 | 
	
		
			
			| 61 |  | -
 | 
	
		
			
			| 62 |  | -    @Test
 | 
	
		
			
			| 63 |  | -    public void _2_relaunchFromBackground() throws Exception {
 | 
	
		
			
			| 64 |  | -        rule.launchActivity(null);
 | 
	
		
			
			| 65 |  | -        acceptOverlayPermissionIfNeeded();
 | 
	
		
			
			| 66 |  | -        assertMainShown();
 | 
	
		
			
			| 67 |  | -
 | 
	
		
			
			| 68 |  | -        uiDevice().pressHome();
 | 
	
		
			
			| 69 |  | -        uiDevice().pressRecentApps();
 | 
	
		
			
			| 70 |  | -        uiDevice().findObject(new UiSelector().text("Playground")).click();
 | 
	
		
			
			| 71 |  | -        uiDevice().waitForIdle();
 | 
	
		
			
			| 72 |  | -
 | 
	
		
			
			| 73 |  | -        assertMainShown();
 | 
	
		
			
			| 74 |  | -    }
 | 
	
		
			
			| 75 |  | -
 | 
	
		
			
			| 76 |  | -    @Test
 | 
	
		
			
			| 77 |  | -    public void _3_relaunchAfterClose() throws Exception {
 | 
	
		
			
			| 78 |  | -        rule.launchActivity(null);
 | 
	
		
			
			| 79 |  | -        acceptOverlayPermissionIfNeeded();
 | 
	
		
			
			| 80 |  | -        assertMainShown();
 | 
	
		
			
			| 81 |  | -
 | 
	
		
			
			| 82 |  | -        uiDevice().pressBack();
 | 
	
		
			
			| 83 |  | -        uiDevice().waitForIdle();
 | 
	
		
			
			| 84 |  | -
 | 
	
		
			
			| 85 |  | -        rule.launchActivity(null);
 | 
	
		
			
			| 86 |  | -        uiDevice().waitForIdle();
 | 
	
		
			
			| 87 |  | -
 | 
	
		
			
			| 88 |  | -        assertMainShown();
 | 
	
		
			
			| 89 |  | -    }
 | 
	
		
			
			| 90 |  | -
 | 
	
		
			
			| 91 |  | -    @Test
 | 
	
		
			
			| 92 |  | -    public void _4_deviceOrientationDoesNotDestroyActivity() throws Exception {
 | 
	
		
			
			| 93 |  | -        MainActivity mainActivity = rule.launchActivity(null);
 | 
	
		
			
			| 94 |  | -        acceptOverlayPermissionIfNeeded();
 | 
	
		
			
			| 95 |  | -        assertMainShown();
 | 
	
		
			
			| 96 |  | -
 | 
	
		
			
			| 97 |  | -        uiDevice().setOrientationRight();
 | 
	
		
			
			| 98 |  | -        uiDevice().waitForIdle();
 | 
	
		
			
			| 99 |  | -
 | 
	
		
			
			| 100 |  | -        Thread.sleep(5000);
 | 
	
		
			
			| 101 |  | -        assertMainShown();
 | 
	
		
			
			| 102 |  | -        assertThat(rule.getActivity()).isSameAs(mainActivity);
 | 
	
		
			
			| 103 |  | -    }
 | 
	
		
			
			| 104 |  | -
 | 
	
		
			
			| 105 |  | -    private void assertMainShown() {
 | 
	
		
			
			| 106 |  | -        onView(withText("React Native Navigation!")).check(matches(isDisplayed()));
 | 
	
		
			
			| 107 |  | -        uiDevice().waitForIdle();
 | 
	
		
			
			| 108 |  | -    }
 | 
	
		
			
			| 109 |  | -
 | 
	
		
			
			| 110 |  | -    private UiDevice uiDevice() {
 | 
	
		
			
			| 111 |  | -        return UiDevice.getInstance(getInstrumentation());
 | 
	
		
			
			| 112 |  | -    }
 | 
	
		
			
			| 113 |  | -
 | 
	
		
			
			| 114 |  | -    private void acceptOverlayPermissionIfNeeded() throws Exception {
 | 
	
		
			
			| 115 |  | -        if (Settings.canDrawOverlays(getInstrumentation().getContext())) {
 | 
	
		
			
			| 116 |  | -            return;
 | 
	
		
			
			| 117 |  | -        }
 | 
	
		
			
			| 118 |  | -        uiDevice().waitForIdle();
 | 
	
		
			
			| 119 |  | -        uiDevice().findObject(new UiSelector().text("Playground")).click();
 | 
	
		
			
			| 120 |  | -        uiDevice().findObject(new UiSelector().text("Permit drawing over other apps")).click();
 | 
	
		
			
			| 121 |  | -        uiDevice().pressBack();
 | 
	
		
			
			| 122 |  | -        uiDevice().pressBack();
 | 
	
		
			
			| 123 |  | -    }
 | 
	
		
			
			| 124 |  | -}
 |