summaryrefslogtreecommitdiffstats
path: root/tests/unit/src/com/android/settings/notification/ZenModeSettingsIntegrationTest.java
blob: e7a057c358f327a86c94533c074f967516aa9126 (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
package com.android.settings;

import static android.support.test.espresso.Espresso.onView;
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.withText;

import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.LargeTest;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.UiDevice;

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

@RunWith(AndroidJUnit4.class)
@LargeTest
public class ZenModeSettingsIntegrationTest {
    private static final String WM_DISMISS_KEYGUARD_COMMAND = "wm dismiss-keyguard";

    private Context mContext;
    private UiDevice mUiDevice;

    @Before
    public void setUp() throws Exception {
        mContext = InstrumentationRegistry.getTargetContext();
        mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
        mUiDevice.wakeUp();
        mUiDevice.executeShellCommand(WM_DISMISS_KEYGUARD_COMMAND);
    }

    @Test
    public void testZenModeSettingsPreferences() {
        launchZenSettings();
        onView(withText("Behavior")).check(matches(isDisplayed()));
        onView(withText("Turn on automatically")).check(matches(isDisplayed()));
    }

    @Test
    public void testZenModeBehaviorPreferences() {
        launchZenBehaviorSettings();
        onView(withText("Alarms")).check(matches(isDisplayed()));
        onView(withText("Media and system feedback")).check(matches(isDisplayed()));
        onView(withText("Reminders")).check(matches(isDisplayed()));
        onView(withText("Events")).check(matches(isDisplayed()));
        onView(withText("Messages")).check(matches(isDisplayed()));
        onView(withText("Calls")).check(matches(isDisplayed()));
        onView(withText("Repeat callers")).check(matches(isDisplayed()));
    }

    @Test
    public void testZenModeAutomationPreferences() {
        launchZenAutomationSettings();
        onView(withText("Weekend")).check(matches(isDisplayed()));
        onView(withText("Add rule")).check(matches(isDisplayed()));
    }

    private void launchZenSettings() {
        Intent settingsIntent = new Intent(Settings.ACTION_ZEN_MODE_SETTINGS)
                .setPackage(mContext.getPackageName())
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(settingsIntent);
    }

    private void launchZenAutomationSettings() {
        Intent settingsIntent = new Intent(Settings.ACTION_ZEN_MODE_AUTOMATION_SETTINGS)
                .setPackage(mContext.getPackageName())
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(settingsIntent);
    }

    private void launchZenBehaviorSettings() {
        Intent settingsIntent = new Intent(Settings.ACTION_ZEN_MODE_PRIORITY_SETTINGS)
                .setPackage(mContext.getPackageName())
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(settingsIntent);
    }
}