Home | History | Annotate | Download | only in preferences
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.emergency.preferences;
     17 
     18 import static android.support.test.espresso.Espresso.onView;
     19 import static android.support.test.espresso.action.ViewActions.click;
     20 import static android.support.test.espresso.assertion.ViewAssertions.matches;
     21 import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
     22 import static android.support.test.espresso.matcher.ViewMatchers.withText;
     23 import static com.google.common.truth.Truth.assertThat;
     24 import static org.hamcrest.Matchers.allOf;
     25 import static org.hamcrest.Matchers.any;
     26 import static org.hamcrest.Matchers.not;
     27 
     28 import android.app.Instrumentation;
     29 import android.content.Context;
     30 import android.content.Intent;
     31 import android.os.Looper;
     32 import android.support.test.InstrumentationRegistry;
     33 import android.support.test.runner.AndroidJUnit4;
     34 import android.view.View;
     35 
     36 import com.android.emergency.PreferenceKeys;
     37 import com.android.emergency.R;
     38 import com.android.emergency.edit.EditMedicalInfoActivity;
     39 import com.android.emergency.edit.EditMedicalInfoFragment;
     40 
     41 import org.hamcrest.Matcher;
     42 import org.junit.Before;
     43 import org.junit.BeforeClass;
     44 import org.junit.Test;
     45 import org.junit.runner.RunWith;
     46 
     47 /** Unit tests for {@link NameAutoCompletePreference}. */
     48 @RunWith(AndroidJUnit4.class)
     49 public final class NameAutoCompletePreferenceTest {
     50     private NameAutoCompletePreference mNameAutoCompletePreference;
     51 
     52     @BeforeClass
     53     public static void oneTimeSetup() {
     54         if (Looper.myLooper() == null) {
     55             Looper.prepare();
     56         }
     57     }
     58 
     59     @Before
     60     public void setUp() {
     61         Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
     62 
     63         final Intent editActivityIntent = new Intent(
     64                 instrumentation.getTargetContext(), EditMedicalInfoActivity.class);
     65         EditMedicalInfoActivity activity =
     66                 (EditMedicalInfoActivity) instrumentation.startActivitySync(editActivityIntent);
     67         EditMedicalInfoFragment fragment = activity.getFragment();
     68 
     69         mNameAutoCompletePreference =
     70                 (NameAutoCompletePreference) fragment.findPreference(PreferenceKeys.KEY_NAME);
     71     }
     72 
     73     @Test
     74     public void testDialogShow() {
     75         onView(withText(R.string.name)).perform(click());
     76 
     77         onView(withText(android.R.string.ok))
     78                 .check(matches(isDisplayed()));
     79         onView(withText(android.R.string.cancel))
     80                 .check(matches(isDisplayed()));
     81     }
     82 }
     83