-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UN trace tool compose test framework and cursory test case. (#561)
* UN trace tool compose test framework and cursory test case. * change name of test to be more descriptive. remove unnecessary annotation. * use TraceState in tests, not anonymous object * remove unnecessary function --------- Co-authored-by: Soren Roth <sor10874@esri.com>
- Loading branch information
1 parent
ab9e034
commit cb82461
Showing
7 changed files
with
168 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
...ks/src/androidTest/java/com/arcgismaps/toolkit/utilitynetworks/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
...tworks/src/androidTest/java/com/arcgismaps/toolkit/utilitynetworks/TraceToolTestRunner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright 2024 Esri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.arcgismaps.toolkit.utilitynetworks | ||
|
||
import com.arcgismaps.ArcGISEnvironment | ||
import com.arcgismaps.httpcore.authentication.TokenCredential | ||
import com.arcgismaps.mapping.ArcGISMap | ||
import com.arcgismaps.mapping.PortalItem | ||
import com.arcgismaps.portal.Portal | ||
import kotlinx.coroutines.test.TestScope | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Before | ||
|
||
/** | ||
* A test runner for utility network tests. This class is responsible for loading the map with the | ||
* given [url] and the first UtilityNetwork | ||
* If the map fails to load or the UtilityNetwork is not found, the test will fail. | ||
* | ||
* @property url The URL of the web map. | ||
* @property itemId the item id on agol to load as a webmap | ||
* @since 200.6.0 | ||
*/ | ||
open class TraceToolTestRunner( | ||
private val url: String, | ||
private val itemId: String | ||
) { | ||
/** | ||
* The trace tool TraceState object | ||
*/ | ||
private var _traceState: TraceState? = null | ||
internal val traceState: TraceState | ||
get() = _traceState ?: throw IllegalStateException("trace state is not initialized") | ||
|
||
@Before | ||
fun setup(): Unit = runTest { | ||
// If the utility network is already initialized, return | ||
if (_traceState != null) return@runTest | ||
// Set the authentication challenge handler | ||
val tokenCred = | ||
TokenCredential.create( | ||
url, | ||
username = BuildConfig.traceToolUser, | ||
password = BuildConfig.traceToolPassword | ||
).getOrThrow() | ||
|
||
ArcGISEnvironment.authenticationManager.arcGISCredentialStore.add(tokenCred) | ||
|
||
val map = ArcGISMap( | ||
PortalItem( | ||
Portal.arcGISOnline(connection = Portal.Connection.Anonymous), | ||
itemId | ||
) | ||
) | ||
_traceState = TraceState(map, coroutineScope = TestScope()) | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...itynetworks/src/androidTest/java/com/arcgismaps/toolkit/utilitynetworks/TraceToolTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* | ||
* Copyright 2024 Esri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.arcgismaps.toolkit.utilitynetworks | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithContentDescription | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class TraceToolTests : TraceToolTestRunner( | ||
url = "https://sampleserver7.arcgisonline.com/portal/sharing/rest", | ||
itemId = "471eb0bf37074b1fbb972b1da70fb310" | ||
) { | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Before | ||
fun setContent() = runTest { | ||
composeTestRule.setContent { | ||
Trace( | ||
traceState = traceState | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Given a Trace composable | ||
* When it is rendered | ||
* Then the top level Surface exists | ||
* | ||
* @since 200.6.0 | ||
*/ | ||
@Test | ||
fun testTraceToolSurface() { | ||
val surface = composeTestRule.onNodeWithContentDescription(traceSurfaceContentDescription) | ||
surface.assertExists("the base surface of the Trace tool composable does not exist") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
...t/utilitynetworks/src/test/java/com/arcgismaps/toolkit/utilitynetworks/ExampleUnitTest.kt
This file was deleted.
Oops, something went wrong.