package com.uramonk.androidtemplateapp.viewmodel;

import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;

import com.robotium.solo.Solo;
import com.squareup.spoon.Spoon;
import com.uramonk.androidtemplateapp.R;
import com.uramonk.androidtemplateapp.view.MainActivity;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

/**
 * Created by uramonk on 2016/07/03.
 */
public class MainFragmentViewModelTest {
    private Solo solo;

    @Rule
    public ActivityTestRule<MainActivity> activityTestRule = new ActivityTestRule<>(MainActivity.class, true, true);

    @Before
    public void setUp() throws Exception {
        solo = new Solo(InstrumentationRegistry.getInstrumentation(), activityTestRule.getActivity());
        solo.waitForActivity(MainActivity.class);
        solo.waitForFragmentById(R.id.container);
    }

    @Test
    public void changeTextStringWhenClickButton() {
        Spoon.screenshot(activityTestRule.getActivity(), "start_1");
        if(solo.searchButton("OK", true)) {
            solo.clickOnButton("OK");
        }

        Assert.assertTrue("wrong text 1", solo.searchText(""));
        Spoon.screenshot(activityTestRule.getActivity(), "start_2");

        solo.clickOnView(solo.getCurrentActivity().findViewById(R.id.main_fragment_button));
        Assert.assertTrue("wrong text 2", solo.searchText("Button Clicked!"));
        Spoon.screenshot(activityTestRule.getActivity(), "button_clicked_1");

        solo.clickOnView(solo.getCurrentActivity().findViewById(R.id.main_fragment_button));
        Assert.assertTrue("wrong text 3", solo.searchText(""));
        Spoon.screenshot(activityTestRule.getActivity(), "button_clicked_2");
    }
}
@@ -97,16 +97,294 @@
 gistry;%0A
+import android.support.test.espresso.Espresso;%0Aimport android.support.test.espresso.ViewAssertion;%0Aimport android.support.test.espresso.action.ViewActions;%0Aimport android.support.test.espresso.assertion.ViewAssertions;%0Aimport android.support.test.espresso.matcher.ViewMatchers;%0A
 import a
@@ -1183,16 +1183,45 @@
 ainer);%0A
+        solo.unlockScreen();%0A
     %7D%0A%0A 
@@ -1360,16 +1360,17 @@
       if
+ 
 (solo.se
@@ -1456,52 +1456,138 @@
     
-Assert.assertTrue(%22wrong text 1%22, solo.searc
+Espresso.onView(ViewMatchers.withId((R.id.main_fragment_textview)))%0A                .check(ViewAssertions.matches(ViewMatchers.wit
 hTex
@@ -1584,32 +1584,33 @@
 rs.withText(%22%22))
+)
 ;%0A        Spoon.
@@ -1677,64 +1677,164 @@
     
-solo.clickOnView(solo.getCurrentActivity().findViewBy
+Espresso.onView(ViewMatchers.withId(R.id.main_fragment_button))%0A                .perform(ViewActions.click());%0A        Espresso.onView(ViewMatchers.with
 Id(
+(
 R.id
@@ -1852,70 +1852,82 @@
 ent_
-button));%0A        Assert.assertTrue(%22wrong text 2%22, solo.searc
+textview)))%0A                .check(ViewAssertions.matches(ViewMatchers.wit
 hTex
@@ -1947,16 +1947,17 @@
 cked!%22))
+)
 ;%0A      
@@ -2041,64 +2041,164 @@
     
-solo.clickOnView(solo.getCurrentActivity().findViewBy
+Espresso.onView(ViewMatchers.withId(R.id.main_fragment_button))%0A                .perform(ViewActions.click());%0A        Espresso.onView(ViewMatchers.with
 Id(
+(
 R.id
@@ -2216,70 +2216,82 @@
 ent_
-button));%0A        Assert.assertTrue(%22wrong text 3%22, solo.searc
+textview)))%0A                .check(ViewAssertions.matches(ViewMatchers.wit
 hTex
@@ -2296,16 +2296,17 @@
 ext(%22%22))
+)
 ;%0A      

Fix MainFragmentViewModel test using Espresso