Skip to content

Commit 306f032

Browse files
authored
Merge pull request #1309 from Esri/df/apollo/1427
`FeatureFormView` - UI tests for adding UNA associations, warning resolutions, logging improvements, small bug fix
2 parents eb75d4c + 7a85bf1 commit 306f032

File tree

5 files changed

+545
-7
lines changed

5 files changed

+545
-7
lines changed

Sources/ArcGISToolkit/Components/FeatureFormView/EmbeddedFeatureFormViewModel.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import ArcGIS
1616
import Observation
1717

18+
private import os
19+
1820
@MainActor @Observable
1921
class EmbeddedFeatureFormViewModel {
2022
/// The current focused element, if one exists.
@@ -88,7 +90,13 @@ class EmbeddedFeatureFormViewModel {
8890
func evaluateExpressions() {
8991
evaluateTask?.cancel()
9092
evaluateTask = Task {
91-
_ = try? await featureForm.evaluateExpressions()
93+
if let errors = try? await featureForm.evaluateExpressions(), !errors.isEmpty {
94+
for evaluationError in errors {
95+
Logger.featureFormView.error(
96+
"Error evaluating expression: \(evaluationError.error.localizedDescription)"
97+
)
98+
}
99+
}
92100
}
93101
}
94102

Sources/ArcGISToolkit/Components/FeatureFormView/Subviews/FormElements/UtilityAssociationsFormElement/UtilityAssociationAssetTypesView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ extension FeatureFormView {
6363
embeddedFeatureFormViewModel, element, filter, source, assetType
6464
)
6565
)
66+
.accessibilityIdentifier("Asset Type \(assetType.name) \(assetType.code)")
6667
}
6768
} header: {
6869
HStack {

Sources/ArcGISToolkit/Components/FeatureFormView/Subviews/FormElements/UtilityAssociationsFormElement/UtilityAssociationCreationView.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import ArcGIS
1616
import SwiftUI
1717

18+
private import os
19+
1820
extension FeatureFormView {
1921
/// A view to configure and add a utility network association.
2022
struct UtilityAssociationCreationView: View {
@@ -30,7 +32,7 @@ extension FeatureFormView {
3032
/// See also: `includeContentVisibility`.
3133
@State private var contentIsVisible: Bool = false
3234
/// How far along an edge the association is located.
33-
@State private var fractionAlongEdge: Double = 0.5
35+
@State private var fractionAlongEdge: Double = 0
3436
/// The options for a utility network feature when creating an association.
3537
@State private var options: UtilityAssociationFeatureOptions? = nil
3638
/// A Boolean value which indicates when the configured association is being added.
@@ -82,17 +84,18 @@ extension FeatureFormView {
8284
func addAssociation() async {
8385
guard let options else { return }
8486
do {
87+
let result: UtilityAssociationResult
8588
if includeContentVisibility {
86-
try await element.addAssociation(feature: candidate.feature, filter: filter, isContainmentVisible: contentIsVisible)
89+
result = try await element.addAssociation(feature: candidate.feature, filter: filter, isContainmentVisible: contentIsVisible)
8790
} else {
88-
switch (options.isFractionAlongEdgeValid, terminalForFromSide, terminalForToSide) {
91+
result = switch (options.isFractionAlongEdgeValid, terminalForFromSide, terminalForToSide) {
8992
case let (true, .some(terminal), .none):
9093
try await element.addAssociation(feature: candidate.feature, filter: filter, fractionAlongEdge: fractionAlongEdge, terminal: terminal)
9194
case let (true, .none, .some(terminal)):
9295
try await element.addAssociation(feature: candidate.feature, filter: filter, fractionAlongEdge: fractionAlongEdge, terminal: terminal)
9396
case (true, .none, .none):
9497
try await element.addAssociation(feature: candidate.feature, filter: filter, fractionAlongEdge: fractionAlongEdge)
95-
case (false, .some, .some):
98+
case (false, _, _):
9699
try await element.addAssociation(
97100
feature: candidate.feature,
98101
featureTerminal: candidateIsToElement
@@ -107,6 +110,7 @@ extension FeatureFormView {
107110
try await element.addAssociation(feature: candidate.feature, filter: filter)
108111
}
109112
}
113+
Logger.featureFormView.info("Association added to \(result.title)")
110114
// After the association is created, remove the creation
111115
// workflow views from the navigation path. This includes:
112116
// 1. UtilityAssociationCreationView
@@ -120,6 +124,9 @@ extension FeatureFormView {
120124
// views to avoid errors here. (FB20395585)
121125
// https://developer.apple.com/forums/thread/802221#802221021
122126
navigationPath?.wrappedValue.removeLast(4)
127+
} catch let error as ArcGIS.InvalidArgumentError {
128+
addAssociationError = .other(error.details)
129+
alertIsPresented = true
123130
} catch {
124131
addAssociationError = .anyError(error)
125132
alertIsPresented = true
@@ -243,8 +250,8 @@ extension FeatureFormView {
243250
} label: {
244251
Text(LocalizedStringResource.fractionAlongEdge)
245252
}
246-
Slider(value: $fractionAlongEdge, in: 0...1) { _ in
247-
LocalizedStringResource.fractionAlongEdge
253+
Slider(value: $fractionAlongEdge, in: 0...1) {
254+
Text(LocalizedStringResource.fractionAlongEdge)
248255
}
249256
}
250257
}

Test Runner/Test Runner/TestViews/FeatureFormTestView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ private extension FeatureFormTestView {
230230
.init("testCase_12_4", objectID: 2584, layerName: "Electric Distribution Device", portalID: .napervilleElectricUtilityNetwork, credentialInfo: .sampleServer7Viewer01),
231231
.init("testCase_12_5", objectID: 3321, layerName: "Electric Distribution Device", portalID: .napervilleElectricUtilityNetwork, credentialInfo: .sampleServer7Viewer01),
232232
.init("testCase_12_6", objectID: 3321, layerName: "Electric Distribution Device", portalID: .napervilleElectricUtilityNetwork, credentialInfo: .sampleServer7Viewer01),
233+
.init("testCase_13_1", objectID: 3321, layerName: "Electric Distribution Device", portalID: .napervilleElectricUtilityNetwork, credentialInfo: .sampleServer7Viewer01),
234+
.init("testCase_13_2", objectID: 5050, layerName: "Electric Distribution Device", portalID: .napervilleElectricUtilityNetwork, credentialInfo: .sampleServer7Viewer01),
235+
.init("testCase_13_3", objectID: 311, layerName: "Electric Distribution Junction", portalID: .napervilleElectricUtilityNetwork, credentialInfo: .sampleServer7Viewer01),
233236
]}
234237
}
235238

0 commit comments

Comments
 (0)