package ca.six.todo.addedittask;

import android.support.test.espresso.matcher.ViewMatchers;
import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import ca.six.todo.R;

import static android.support.test.espresso.Espresso.onView;
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.ViewMatchers.withEffectiveVisibility;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.junit.Assert.*;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class AddEditTaskFragmentTest {

    @Rule
    public ActivityTestRule<AddEditTaskActivity> actvRule = new ActivityTestRule<>(AddEditTaskActivity. class);

    @Test
    public void createTask_emptyView(){
        onView(withId(R.id.add_task_title))
                .check(matches(withText("")));

        onView(withId(R.id.fab_edit_task_done))
                .perform(click());

        String message = "TO DOs cannot be empty";
        onView(withText(message))
                .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));

    }

//    @Test
//    public void createTask_inputAndSaveTask(){
//        // screen is empty at first
//        onView(withId(R.id.add_task_title))
//                .check(matches(withText("")));
//
//        // type text and save
//        onView(withId(R.id.add_task_title))
//                .perform(typeText("grocery"));
//        onView(withId(R.id.add_task_description))
//                .perform(typeText("tomato, onion, garlic, eggplant"));
//        onView(withId(R.id.fab_edit_task_done))
//                .perform(click());
//
//        // check the result
//
//
//    }

}
@@ -620,16 +620,94 @@
 atches;%0A
+import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;%0A
 import s
@@ -1397,24 +1397,80 @@
 (click());%0A%0A
+        /*%0A        // SnackBar is not testable for now.%0A
         Stri
@@ -1546,36 +1546,32 @@
 e))%0A            
-    
 .check(matches(w
@@ -1624,24 +1624,216 @@
 .VISIBLE)));
+%0A        */%0A%0A        // Verify that the activity is still displayed (a correct task would close it).%0A        onView(withId(R.id.add_task_title))%0A                .check(matches(isDisplayed()));
 %0A%0A    %7D%0A%0A// 

write unit test code