• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 android.healthconnect.cts.ui
17 
18 import android.health.connect.TimeInstantRangeFilter
19 import android.health.connect.datatypes.BasalMetabolicRateRecord
20 import android.health.connect.datatypes.HeartRateRecord
21 import android.health.connect.datatypes.StepsRecord
22 import android.healthconnect.cts.TestUtils.verifyDeleteRecords
23 import android.healthconnect.cts.lib.ActivityLauncher.launchMainActivity
24 import android.healthconnect.cts.lib.TestUtils.insertRecordAs
25 import android.healthconnect.cts.lib.UiTestUtils.clickOnText
26 import android.healthconnect.cts.lib.UiTestUtils.waitDisplayed
27 import androidx.test.uiautomator.By
28 import com.android.cts.install.lib.TestApp
29 import java.time.Instant
30 import org.junit.AfterClass
31 import org.junit.BeforeClass
32 import org.junit.Test
33 
34 /** CTS test for HealthConnect Home screen. */
35 class HomeFragmentTest : HealthConnectBaseTest() {
36 
37     companion object {
38 
39         private const val TAG = "HomeFragmentTest"
40 
41         private const val VERSION_CODE: Long = 1
42 
43         private val APP_A_WITH_READ_WRITE_PERMS: TestApp =
44             TestApp(
45                 "TestAppA",
46                 "android.healthconnect.cts.testapp.readWritePerms.A",
47                 VERSION_CODE,
48                 false,
49                 "CtsHealthConnectTestAppA.apk")
50 
51         @JvmStatic
52         @BeforeClass
setupnull53         fun setup() {
54             insertRecordAs(APP_A_WITH_READ_WRITE_PERMS)
55         }
56 
57         @JvmStatic
58         @AfterClass
teardownnull59         fun teardown() {
60             verifyDeleteRecords(
61                 StepsRecord::class.java,
62                 TimeInstantRangeFilter.Builder()
63                     .setStartTime(Instant.EPOCH)
64                     .setEndTime(Instant.now())
65                     .build())
66             verifyDeleteRecords(
67                 HeartRateRecord::class.java,
68                 TimeInstantRangeFilter.Builder()
69                     .setStartTime(Instant.EPOCH)
70                     .setEndTime(Instant.now())
71                     .build())
72             verifyDeleteRecords(
73                 BasalMetabolicRateRecord::class.java,
74                 TimeInstantRangeFilter.Builder()
75                     .setStartTime(Instant.EPOCH)
76                     .setEndTime(Instant.now())
77                     .build())
78         }
79     }
80 
81     @Test
homeFragment_openAppPermissionsnull82     fun homeFragment_openAppPermissions() {
83         context.launchMainActivity {
84             clickOnText("App permissions")
85 
86             waitDisplayed(By.text("Allowed access"))
87             // TODO(b/265789268): Fix flaky "DNot allowed access" not found.
88             // waitDisplayed(By.text("Not allowed access"))
89         }
90     }
91 
92     @Test
homeFragment_openDataManagementnull93     fun homeFragment_openDataManagement() {
94         context.launchMainActivity {
95             clickOnText("Data and access")
96 
97             waitDisplayed(By.text("Browse data"))
98             waitDisplayed(By.text("Manage data"))
99             waitDisplayed(By.text("Auto-delete"))
100 
101             waitDisplayed(By.text("Delete all data"))
102         }
103     }
104 
105     @Test
homeFragment_recentAccessShownOnHomeScreennull106     fun homeFragment_recentAccessShownOnHomeScreen() {
107         context.launchMainActivity {
108             waitDisplayed(By.textContains("CtsHealthConnectTest"))
109             waitDisplayed(By.text("See all recent access"))
110         }
111     }
112 
113     @Test
homeFragment_navigateToRecentAccessnull114     fun homeFragment_navigateToRecentAccess() {
115         context.launchMainActivity {
116             clickOnText("See all recent access")
117 
118             waitDisplayed(By.text("Today"))
119             waitDisplayed(By.textContains("CtsHealthConnectTest"))
120         }
121     }
122 }
123