1 /*
2  * Copyright (C) 2020 Google Inc.
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 
17 package com.android.car.carlauncher;
18 
19 import static androidx.test.espresso.Espresso.onView;
20 import static androidx.test.espresso.assertion.ViewAssertions.matches;
21 import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
22 import static androidx.test.espresso.matcher.ViewMatchers.withId;
23 
24 import android.testing.TestableContext;
25 
26 import androidx.lifecycle.Lifecycle;
27 import androidx.test.InstrumentationRegistry;
28 import androidx.test.core.app.ActivityScenario;
29 import androidx.test.ext.junit.runners.AndroidJUnit4;
30 import androidx.test.filters.SmallTest;
31 
32 import org.junit.After;
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 
37 @RunWith(AndroidJUnit4.class)
38 @SmallTest
39 public class CarLauncherTest {
40 
41     @Rule
42     public TestableContext mContext = new TestableContext(InstrumentationRegistry.getContext());
43     private ActivityScenario<CarLauncher> mActivityScenario;
44 
45     @After
tearDown()46     public void tearDown() {
47         if (mActivityScenario != null) {
48             mActivityScenario.close();
49         }
50     }
51 
52     @Test
onResume_mapsCard_isVisible()53     public void onResume_mapsCard_isVisible() {
54         mActivityScenario = ActivityScenario.launch(CarLauncher.class);
55         mActivityScenario.moveToState(Lifecycle.State.RESUMED);
56 
57         onView(withId(R.id.maps_card)).check(matches(isDisplayed()));
58     }
59 
60     @Test
onResume_assistiveCard_isVisible()61     public void onResume_assistiveCard_isVisible() {
62         mActivityScenario = ActivityScenario.launch(CarLauncher.class);
63         mActivityScenario.moveToState(Lifecycle.State.RESUMED);
64 
65         onView(withId(R.id.top_card)).check(matches(isDisplayed()));
66     }
67 
68     @Test
onResume_audioCard_isVisible()69     public void onResume_audioCard_isVisible() {
70         mActivityScenario = ActivityScenario.launch(CarLauncher.class);
71         mActivityScenario.moveToState(Lifecycle.State.RESUMED);
72 
73         onView(withId(R.id.bottom_card)).check(matches(isDisplayed()));
74     }
75 }
76