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 */
16package com.android.settings.wifi;
17
18import static android.support.test.espresso.Espresso.onView;
19import static android.support.test.espresso.action.ViewActions.click;
20import static android.support.test.espresso.assertion.ViewAssertions.matches;
21import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
22import static android.support.test.espresso.matcher.ViewMatchers.withText;
23
24import android.content.Context;
25import android.content.Intent;
26import android.support.test.InstrumentationRegistry;
27import android.support.test.rule.ActivityTestRule;
28import android.support.test.runner.AndroidJUnit4;
29
30import com.android.settings.Settings;
31
32import org.junit.Before;
33import org.junit.Rule;
34import org.junit.Test;
35import org.junit.runner.RunWith;
36
37
38@RunWith(AndroidJUnit4.class)
39public class SavedNetworkSettingsTest {
40
41    // Keys used to lookup resources by name (see the resourceId helper method).
42    private static final String STRING = "string";
43    private static final String WIFI_ADD_NETWORK = "wifi_add_network";
44    private static final String WIFI_NETWORK_LABEL = "wifi_ssid";
45
46    private Context mContext;
47
48    @Rule
49    public ActivityTestRule<Settings.SavedAccessPointsSettingsActivity> mActivityRule =
50            new ActivityTestRule<>(Settings.SavedAccessPointsSettingsActivity.class, true);
51
52    private int resourceId(String type, String name) {
53        return mContext.getResources().getIdentifier(name, type, mContext.getPackageName());
54    }
55
56    @Before
57    public void setUp() {
58        mContext = InstrumentationRegistry.getTargetContext();
59    }
60
61    private void launchSavedNetworksSettings() {
62        Intent intent = new Intent()
63                .setClassName(mContext.getPackageName(),
64                        Settings.SavedAccessPointsSettingsActivity.class.getName())
65                .setPackage(mContext.getPackageName());
66        mActivityRule.launchActivity(intent);
67    }
68
69    @Test
70    public void launchSavedNetworkSettings_shouldHaveAddNetworkField() {
71        launchSavedNetworksSettings();
72        onView(withText(resourceId(STRING, WIFI_ADD_NETWORK))).check(matches(isDisplayed()))
73                .perform(click());
74        onView(withText(resourceId(STRING, WIFI_NETWORK_LABEL))).check(matches(isDisplayed()));
75    }
76}
77