Skip to content

Commit 59eac24

Browse files
authored
Merge pull request #86 from ArcGIS/sor10874/remove-creds-from-test
remove creds from test
2 parents 7813e30 + 86098e4 commit 59eac24

File tree

2 files changed

+311
-45
lines changed

2 files changed

+311
-45
lines changed

toolkit/featureforms/src/androidTest/java/com/arcgismaps/toolkit/featureforms/FormTextFieldTests.kt

+1-45
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,9 @@ import androidx.compose.ui.test.performImeAction
3737
import androidx.compose.ui.test.performTextInput
3838
import androidx.compose.ui.text.AnnotatedString
3939
import androidx.compose.ui.text.TextLayoutResult
40-
import com.arcgismaps.ArcGISEnvironment
41-
import com.arcgismaps.httpcore.authentication.ArcGISAuthenticationChallenge
42-
import com.arcgismaps.httpcore.authentication.ArcGISAuthenticationChallengeHandler
43-
import com.arcgismaps.httpcore.authentication.ArcGISAuthenticationChallengeResponse
44-
import com.arcgismaps.httpcore.authentication.TokenCredential
45-
import com.arcgismaps.mapping.ArcGISMap
46-
import com.arcgismaps.mapping.layers.FeatureLayer
4740
import com.arcgismaps.toolkit.featureforms.api.FeatureFormDefinition
4841
import com.arcgismaps.toolkit.featureforms.api.FieldFeatureFormElement
4942
import com.arcgismaps.toolkit.featureforms.api.TextBoxFeatureFormInput
50-
import com.arcgismaps.toolkit.featureforms.api.formInfoJson
5143
import com.arcgismaps.toolkit.featureforms.components.text.FormTextField
5244
import com.arcgismaps.toolkit.featureforms.components.text.FormTextFieldState
5345
import junit.framework.TestCase.assertEquals
@@ -57,31 +49,6 @@ import org.junit.Before
5749
import org.junit.Rule
5850
import org.junit.Test
5951

60-
61-
class FormsArcGISAuthenticationChallengeHandler(
62-
private val username: String,
63-
private val password: String
64-
) : ArcGISAuthenticationChallengeHandler {
65-
override suspend fun handleArcGISAuthenticationChallenge(
66-
challenge: ArcGISAuthenticationChallenge
67-
): ArcGISAuthenticationChallengeResponse {
68-
val result: Result<TokenCredential> =
69-
TokenCredential.create(
70-
challenge.requestUrl,
71-
username,
72-
password,
73-
tokenExpirationInterval = 0
74-
)
75-
return result.let {
76-
if (it.isSuccess) {
77-
ArcGISAuthenticationChallengeResponse.ContinueWithCredential(it.getOrThrow())
78-
} else {
79-
ArcGISAuthenticationChallengeResponse.ContinueAndFailWithError(it.exceptionOrNull()!!)
80-
}
81-
}
82-
}
83-
}
84-
8552
@OptIn(ExperimentalCoroutinesApi::class)
8653
class FormTextFieldTests {
8754
lateinit var featureFormDefinition: FeatureFormDefinition
@@ -93,17 +60,7 @@ class FormTextFieldTests {
9360

9461
@Before
9562
fun setUp() = runTest {
96-
ArcGISEnvironment.authenticationManager.arcGISAuthenticationChallengeHandler =
97-
FormsArcGISAuthenticationChallengeHandler(
98-
//TODO: run these tests from json in a file.
99-
"c_api_publisher",
100-
"c_api_pub1"
101-
)
102-
val map =
103-
ArcGISMap("https://runtimecoretest.maps.arcgis.com/home/item.html?id=5d69e2301ad14ec8a73b568dfc29450a")
104-
map.load()
105-
val layer = map.operationalLayers.first() as FeatureLayer
106-
featureFormDefinition = FeatureFormDefinition.fromJsonOrNull(layer.formInfoJson!!)!!
63+
featureFormDefinition = FeatureFormDefinition.fromJsonOrNull(TestData.inputValidationFeatureFormJson)!!
10764
}
10865

10966
@get:Rule
@@ -117,7 +74,6 @@ class FormTextFieldTests {
11774
*/
11875
@Test
11976
fun testNoValueUnfocusedState() = runTest {
120-
12177
val fieldFeatureFormElement = featureFormDefinition.formElements
12278
.filterIsInstance<FieldFeatureFormElement>()
12379
.first {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
/*
2+
*
3+
* Copyright 2023 Esri
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package com.arcgismaps.toolkit.featureforms
20+
21+
object TestData {
22+
val inputValidationFeatureFormJson: String = """
23+
{
24+
"expressionInfos": [
25+
{
26+
"expression": "false",
27+
"name": "expr/system/false",
28+
"returnType": "boolean",
29+
"title": "False"
30+
},
31+
{
32+
"expression": "true",
33+
"name": "expr/system/true",
34+
"returnType": "boolean",
35+
"title": "True"
36+
}
37+
],
38+
"formElements": [
39+
{
40+
"type": "field",
41+
"label": "No_Value Multiline",
42+
"editableExpression": "expr/system/true",
43+
"fieldName": "No_Value",
44+
"inputType": {
45+
"type": "text-area",
46+
"maxLength": 255.0
47+
}
48+
},
49+
{
50+
"type": "field",
51+
"label": "Populated Short String",
52+
"editableExpression": "expr/system/true",
53+
"fieldName": "Populated",
54+
"inputType": {
55+
"type": "text-area",
56+
"maxLength": 255.0
57+
}
58+
},
59+
{
60+
"type": "field",
61+
"label": "Populated Long String",
62+
"editableExpression": "expr/system/true",
63+
"fieldName": "Populated_Multiline",
64+
"inputType": {
65+
"type": "text-area",
66+
"maxLength": 255.0
67+
}
68+
},
69+
{
70+
"type": "field",
71+
"label": "Populated_Max_Error (100)",
72+
"editableExpression": "expr/system/true",
73+
"fieldName": "Populated_Max_Error",
74+
"inputType": {
75+
"type": "text-area",
76+
"maxLength": 100.0
77+
}
78+
},
79+
{
80+
"type": "field",
81+
"label": "Populated_Constrained 10 to 90",
82+
"editableExpression": "expr/system/true",
83+
"fieldName": "Populated_Constrained",
84+
"inputType": {
85+
"type": "text-area",
86+
"maxLength": 90.0,
87+
"minLength": 10.0
88+
}
89+
},
90+
{
91+
"type": "field",
92+
"label": "No_Value_Placeholder",
93+
"editableExpression": "expr/system/true",
94+
"fieldName": "No_Value_Placeholder",
95+
"inputType": {
96+
"type": "text-area",
97+
"maxLength": 255.0
98+
},
99+
"hint": "Hello this is a Placeholder !!!"
100+
},
101+
{
102+
"type": "field",
103+
"description": "This is a Description",
104+
"label": "No_Value_Description",
105+
"editableExpression": "expr/system/true",
106+
"fieldName": "No_Value_Description",
107+
"inputType": {
108+
"type": "text-area",
109+
"maxLength": 255.0
110+
}
111+
},
112+
{
113+
"type": "field",
114+
"label": "Read_Only",
115+
"fieldName": "Read_Only",
116+
"inputType": {
117+
"type": "text-box",
118+
"maxLength": 255.0
119+
}
120+
},
121+
{
122+
"type": "field",
123+
"label": "Single Line No Value, Placeholder or Description",
124+
"editableExpression": "expr/system/true",
125+
"fieldName": "Single_Line_No_Value_Placeholder_or_Description",
126+
"inputType": {
127+
"type": "text-box",
128+
"maxLength": 256.0
129+
}
130+
},
131+
{
132+
"type": "field",
133+
"label": "Populated Single Line",
134+
"editableExpression": "expr/system/true",
135+
"fieldName": "Populated_Single_Line",
136+
"inputType": {
137+
"type": "text-box",
138+
"maxLength": 256.0
139+
}
140+
},
141+
{
142+
"type": "field",
143+
"label": "Populated Max Error ",
144+
"editableExpression": "expr/system/true",
145+
"fieldName": "Populated_Max_Error_SingleLine",
146+
"inputType": {
147+
"type": "text-box",
148+
"maxLength": 10.0
149+
}
150+
},
151+
{
152+
"type": "field",
153+
"label": "NoPlaceholderordescription_required",
154+
"editableExpression": "expr/system/true",
155+
"fieldName": "NoPlaceholderordescription_required",
156+
"inputType": {
157+
"type": "text-box",
158+
"maxLength": 256.0
159+
},
160+
"requiredExpression": "expr/system/true"
161+
},
162+
{
163+
"type": "field",
164+
"label": "NoPlaceholderDescription_CharConstrained",
165+
"editableExpression": "expr/system/true",
166+
"fieldName": "NoPlaceholderDescription_CharConstrained",
167+
"inputType": {
168+
"type": "text-box",
169+
"maxLength": 25.0,
170+
"minLength": 10.0
171+
}
172+
},
173+
{
174+
"type": "field",
175+
"label": "noPlaceholderDescription_CharCons_required",
176+
"editableExpression": "expr/system/true",
177+
"fieldName": "noPlaceholderDescription_CharCons_required",
178+
"inputType": {
179+
"type": "text-box",
180+
"maxLength": 25.0,
181+
"minLength": 10.0
182+
},
183+
"requiredExpression": "expr/system/true"
184+
},
185+
{
186+
"type": "field",
187+
"label": "NoPlaceholderDescription_CharConstrainedError",
188+
"editableExpression": "expr/system/true",
189+
"fieldName": "NoPlaceholderDescription_CharConstrainedError",
190+
"inputType": {
191+
"type": "text-box",
192+
"maxLength": 25.0,
193+
"minLength": 10.0
194+
}
195+
},
196+
{
197+
"type": "field",
198+
"description": "This is a description that is very long the maximume lenght in fact just typing until I can type no more and on and on , will this thing every stop letting me type, I think it will just keep on typing typein more and more until it stops and it ends in Z",
199+
"label": "No Value with Long Placeholder and Description",
200+
"editableExpression": "expr/system/true",
201+
"fieldName": "NoValueWithLongPlaceholderandDescription",
202+
"inputType": {
203+
"type": "text-box",
204+
"maxLength": 256.0
205+
},
206+
"hint": "This is a placeholder that is the longest placeholder that it can be, I don;t know how long it can be, but it seem that it can be very long as I am typing this out it does not seem to be stopping the amount that I can type, very odd that field maps designers would llet a string get so long they are notorious for not letting user have long strings in stuff that they create, very strange indeed. that input form is not stopping oh I give up!"
207+
},
208+
{
209+
"type": "field",
210+
"description": "In error because value is less than 10 and long description mmm",
211+
"label": "Placeholder and Description Min Lengh Error",
212+
"editableExpression": "expr/system/true",
213+
"fieldName": "Placeholder_and_Description_Min_Lengh_Error",
214+
"inputType": {
215+
"type": "text-box",
216+
"maxLength": 256.0,
217+
"minLength": 10.0
218+
},
219+
"hint": "Placeholder for min length error"
220+
},
221+
{
222+
"type": "field",
223+
"description": "THis is in error because the length is more than 25",
224+
"label": "Placeholder and Description Max Length Error",
225+
"editableExpression": "expr/system/true",
226+
"fieldName": "Placeholder_and_Description_Max_Length_Error",
227+
"inputType": {
228+
"type": "text-box",
229+
"maxLength": 25.0
230+
},
231+
"hint": "A placeholder for max length error"
232+
},
233+
{
234+
"type": "field",
235+
"description": "This is a really long description xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxZ",
236+
"label": "Placholder and Descripton Required",
237+
"editableExpression": "expr/system/true",
238+
"fieldName": "Placholder_and_Descripton_Required",
239+
"inputType": {
240+
"type": "text-box",
241+
"maxLength": 256.0
242+
},
243+
"requiredExpression": "expr/system/true",
244+
"hint": "This is a placeholder"
245+
},
246+
{
247+
"type": "field",
248+
"label": "Read Only No Value",
249+
"fieldName": "ReadONlyNoValue",
250+
"inputType": {
251+
"type": "text-box",
252+
"maxLength": 256.0
253+
}
254+
},
255+
{
256+
"type": "field",
257+
"label": "Read Only Populated",
258+
"fieldName": "Read_Only_Populated",
259+
"inputType": {
260+
"type": "text-box",
261+
"maxLength": 256.0
262+
}
263+
},
264+
{
265+
"type": "field",
266+
"description": "Description for ready only single line with no value",
267+
"label": "Read Only No Value Description",
268+
"fieldName": "Read_Only_No_Value_Description",
269+
"inputType": {
270+
"type": "text-box",
271+
"maxLength": 256.0
272+
}
273+
},
274+
{
275+
"type": "field",
276+
"description": "Not sure this one makes sense,",
277+
"label": "Read Only No Value and Required",
278+
"fieldName": "Read_Only_No_Value_and_Required",
279+
"inputType": {
280+
"type": "text-box",
281+
"maxLength": 256.0
282+
},
283+
"requiredExpression": "expr/system/true"
284+
},
285+
{
286+
"type": "field",
287+
"description": "This is a description for a Read Only Populated form",
288+
"label": "Read Only Populated with Description",
289+
"fieldName": "Read_Only_Populated_with_Description",
290+
"inputType": {
291+
"type": "text-box",
292+
"maxLength": 256.0
293+
}
294+
},
295+
{
296+
"type": "field",
297+
"description": "More that 10 char in length",
298+
"label": "Read Only Form with Max Length Error",
299+
"fieldName": "Read_Only_Form_with_Max_Length_Error",
300+
"inputType": {
301+
"type": "text-box",
302+
"maxLength": 10.0
303+
}
304+
}
305+
],
306+
"title": "InputValidation"
307+
}
308+
309+
""".trimIndent()
310+
}

0 commit comments

Comments
 (0)