summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/MainActivityTest.java
blob: a5f3a2e791c361e34aeb42a3d233e5fd0bacfebb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
package com.mapbox.mapboxsdk.testapp;

import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;

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

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.doubleClick;
import static android.support.test.espresso.action.ViewActions.longClick;
import static android.support.test.espresso.action.ViewActions.swipeDown;
import static android.support.test.espresso.action.ViewActions.swipeLeft;
import static android.support.test.espresso.action.ViewActions.swipeRight;
import static android.support.test.espresso.action.ViewActions.swipeUp;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.not;

/**
 * Tests on MainActivity
 */
@RunWith(AndroidJUnit4.class)
@LargeTest
public class MainActivityTest extends BaseTest {

    @Rule
    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(
            MainActivity.class);

    private MainActivity mActivity = null;

    @Before
    public void setActivity() {
        mActivity = mActivityRule.getActivity();
    }

    /*
     * Note that we need to keep the `test` prefix if we want to be able to run these
     * tests on AWS Device Farm, annotations are not enough:
     * https://github.com/awslabs/aws-device-farm-sample-app-for-android/issues/5#issuecomment-138258444
     */

    @Test
    public void testSanity() {
        checkViewIsDisplayed(R.id.mainMapView);
    }

    /*
     * Check UI ids are visible
     */

    @Test
    public void testDrawerLayoutIsDisplayed() {
        onView(withId(R.id.drawer_layout))
                .check(matches(isDisplayed()));
    }

    @Test
    public void testToolbarIsDisplayed() {
        onView(withId(R.id.toolbar))
                .check(matches(isDisplayed()));
    }

    @Test
    public void testContentFrameIsDisplayed() {
        onView(withId(R.id.content_frame))
                .check(matches(isDisplayed()));
    }

    @Test
    public void testViewFpsIsDisplayed() {
        // By default, R.id.view_fps is not displayed
        onView(withId(R.id.view_fps))
                .check(matches(not(isDisplayed())));
    }

    @Test
    public void testLocationFABIsDisplayed() {
        onView(withId(R.id.locationFAB))
                .check(matches(isDisplayed()));
    }

    @Test
    public void testNavViewIsNotDisplayed() {
        // By default, nav_view not displayed
        onView(withId(R.id.nav_view))
                .check(matches(not(isDisplayed())));
    }

    @Test
    public void testNavViewIsDisplayed() {
        // However, it's displayed when we click the home icon
        onView(withContentDescription(HOME_BUTTON_STRING))
                .perform(click());
        onView(withId(R.id.nav_view))
                .check(matches(isDisplayed()));
    }

    /*
     * Some more tests on the map view (clicks, gestures)
     */

    @Test
    public void testClickMap() {
        onView(withId(R.id.mainMapView))
                .perform(click())
                .check(matches(isDisplayed()));
    }

    @Test
    public void testDoubleClickMap() {
        onView(withId(R.id.mainMapView))
                .perform(doubleClick())
                .check(matches(isDisplayed()));
    }

    @Test
    public void testLongClickMap() {
        onView(withId(R.id.mainMapView))
                .perform(longClick())
                .check(matches(isDisplayed()));
    }

    /*
     * Test the main drawer options
     */

    @Test
    public void testNavViewActionDebug() {
        onView(withContentDescription(HOME_BUTTON_STRING))
                .perform(click());
        onView(withText(R.string.action_debug))
                .perform(click());

        // Clicking the item closes the drawer
        onView(withId(R.id.nav_view))
                .check(matches(not(isDisplayed())));
    }

    @Test
    public void testNavViewActionPointAnnotations() {
        onView(withContentDescription(HOME_BUTTON_STRING))
                .perform(click());
        onView(withText(R.string.action_point_annotations))
                .perform(click());

        // Clicking the item closes the drawer
        onView(withId(R.id.nav_view))
                .check(matches(not(isDisplayed())));
    }

    @Test
    public void testNavViewActionCompass() {
        onView(withContentDescription(HOME_BUTTON_STRING))
                .perform(click());
        onView(withText(R.string.action_compass))
                .perform(click());

        // Clicking the item closes the drawer
        onView(withId(R.id.nav_view))
                .check(matches(not(isDisplayed())));
    }

    @Test
    public void testNavViewStyleMapboxStreets() {
        onView(withContentDescription(HOME_BUTTON_STRING))
                .perform(click());
        onView(withText(R.string.styleMapboxStreets))
                .perform(click());

        // Clicking the item closes the drawer
        onView(withId(R.id.nav_view))
                .check(matches(not(isDisplayed())));
    }

    @Test
    public void testNavViewStyleEmerald() {
        onView(withContentDescription(HOME_BUTTON_STRING))
                .perform(click());
        onView(withText(R.string.styleEmerald))
                .perform(click());

        // Clicking the item closes the drawer
        onView(withId(R.id.nav_view))
                .check(matches(not(isDisplayed())));
    }

    @Test
    public void testNavViewStyleLight() {
        onView(withContentDescription(HOME_BUTTON_STRING))
                .perform(click());
        onView(withText(R.string.styleLight))
                .perform(click());

        // Clicking the item closes the drawer
        onView(withId(R.id.nav_view))
                .check(matches(not(isDisplayed())));
    }

    @Test
    public void testNavViewStyleDark() {
        onView(withContentDescription(HOME_BUTTON_STRING))
                .perform(click());
        onView(withText(R.string.styleDark))
                .perform(click());

        // Clicking the item closes the drawer
        onView(withId(R.id.nav_view))
                .check(matches(not(isDisplayed())));
    }

    @Test
    public void testNavViewStyleSatellite() {
        onView(withContentDescription(HOME_BUTTON_STRING))
                .perform(click());
        onView(withText(R.string.styleSatellite))
                .perform(click());

        // Clicking the item closes the drawer
        onView(withId(R.id.nav_view))
                .check(matches(not(isDisplayed())));
    }

    /*
     * We can also check the map inner elements are visible
     */

    @Test
    public void testMapIconContentDescription() {
        // Mapbox logo
        onView(withContentDescription(mActivity.getResources()
                .getString(R.string.mapboxIconContentDescription)))
                .check(matches(isDisplayed()));
    }

//    @Test
//    public void testMapCompassContentDescription() {
//        //FIXME this is currently broken hence compass view is only being showed when rotating the map
//        // Map compass
////        onView(withContentDescription(mActivity.getResources()
////                .getString(R.string.compassContentDescription)))
////                .check(matches(isDisplayed()));
//    }

    @Test
    public void testMapAttributionsIconContentDescription() {
        // Attribution icon
        onView(withContentDescription(mActivity.getResources()
                .getString(R.string.attributionsIconContentDescription)))
                .check(matches(isDisplayed()));
    }

}