• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 
17 package com.android.settings.network.apn
18 
19 import android.content.Context
20 import android.net.Uri
21 import androidx.compose.runtime.mutableStateOf
22 import androidx.compose.ui.test.assertIsDisplayed
23 import androidx.compose.ui.test.hasScrollAction
24 import androidx.compose.ui.test.hasText
25 import androidx.compose.ui.test.junit4.createComposeRule
26 import androidx.compose.ui.test.onNodeWithText
27 import androidx.compose.ui.test.performScrollToNode
28 import androidx.test.core.app.ApplicationProvider
29 import androidx.test.ext.junit.runners.AndroidJUnit4
30 import com.android.settings.R
31 import com.google.common.truth.Truth.assertThat
32 import org.junit.Rule
33 import org.junit.Test
34 import org.junit.runner.RunWith
35 import org.mockito.kotlin.mock
36 
37 @RunWith(AndroidJUnit4::class)
38 class ApnEditPageProviderTest {
39     @get:Rule val composeTestRule = createComposeRule()
40 
41     private val context: Context = ApplicationProvider.getApplicationContext()
42     private val apnName = "apn_name"
43     private val proxy = "proxy"
44     private val port = "port"
45     private val apnType = context.resources.getString(R.string.apn_type)
46     private val apnRoaming = "IPv4"
47     private val apnProtocolOptions =
48         context.resources.getStringArray(R.array.apn_protocol_entries).toList()
49     private val passwordTitle = context.resources.getString(R.string.apn_password)
50     private val apnInit =
51         ApnData(
52             name = apnName,
53             proxy = proxy,
54             port = port,
55             apnType = apnType,
56             apnRoaming = apnProtocolOptions.indexOf(apnRoaming),
57         )
58     private val apnData = mutableStateOf(apnInit)
<lambda>null59     private val uri = mock<Uri> {}
60 
61     @Test
apnEditPageProvider_namenull62     fun apnEditPageProvider_name() {
63         assertThat(ApnEditPageProvider.name).isEqualTo("ApnEdit")
64     }
65 
66     @Test
title_displayednull67     fun title_displayed() {
68         composeTestRule.setContent { ApnPage(apnInit, apnData, uri) }
69 
70         composeTestRule.onNodeWithText(context.getString(R.string.apn_edit)).assertIsDisplayed()
71     }
72 
73     @Test
name_displayednull74     fun name_displayed() {
75         composeTestRule.setContent { ApnPage(apnInit, apnData, uri) }
76 
77         composeTestRule.onNodeWithText(apnName, true).assertIsDisplayed()
78     }
79 
80     @Test
proxy_displayednull81     fun proxy_displayed() {
82         composeTestRule.setContent { ApnPage(apnInit, apnData, uri) }
83 
84         composeTestRule.onNode(hasScrollAction()).performScrollToNode(hasText(proxy, true))
85         composeTestRule.onNodeWithText(proxy, true).assertIsDisplayed()
86     }
87 
88     @Test
port_displayednull89     fun port_displayed() {
90         composeTestRule.setContent { ApnPage(apnInit, apnData, uri) }
91 
92         composeTestRule.onNode(hasScrollAction()).performScrollToNode(hasText(port, true))
93         composeTestRule.onNodeWithText(port, true).assertIsDisplayed()
94     }
95 
96     @Test
apnType_displayednull97     fun apnType_displayed() {
98         composeTestRule.setContent { ApnPage(apnInit, apnData, uri) }
99 
100         composeTestRule.onNode(hasScrollAction()).performScrollToNode(hasText(apnType, true))
101         composeTestRule.onNodeWithText(apnType, true).assertIsDisplayed()
102     }
103 
104     @Test
apnRoaming_displayednull105     fun apnRoaming_displayed() {
106         composeTestRule.setContent { ApnPage(apnInit, apnData, uri) }
107 
108         composeTestRule.onNode(hasScrollAction()).performScrollToNode(hasText(apnRoaming, true))
109         composeTestRule.onNodeWithText(apnRoaming, true).assertIsDisplayed()
110     }
111 
112     @Test
password_displayednull113     fun password_displayed() {
114         composeTestRule.setContent { ApnPage(apnInit, apnData, uri) }
115 
116         composeTestRule.onNode(hasScrollAction()).performScrollToNode(hasText(passwordTitle, true))
117         composeTestRule.onNodeWithText(passwordTitle, true).assertIsDisplayed()
118     }
119 }
120