generated from StanfordBDHG/SwiftPackageTemplate
-
-
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.
- Loading branch information
1 parent
e23dc48
commit 135d7dd
Showing
8 changed files
with
157 additions
and
40 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
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
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 |
---|---|---|
|
@@ -59,6 +59,9 @@ | |
} | ||
} | ||
} | ||
}, | ||
"Operation State: %@" : { | ||
|
||
}, | ||
"Reset" : { | ||
|
||
|
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
76 changes: 76 additions & 0 deletions
76
Tests/UITests/TestApp/ViewsTests/ViewStateMapperView.swift
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,76 @@ | ||
// | ||
// This source file is part of the Stanford Spezi open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2022 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import SpeziViews | ||
import SwiftUI | ||
|
||
|
||
struct ViewStateMapperTestView: View { | ||
enum OperationStateTest: OperationState { | ||
case ready | ||
case someOperationStep | ||
case error(LocalizedError) | ||
|
||
|
||
var representation: ViewState { | ||
switch self { | ||
case .ready: | ||
.idle | ||
case .someOperationStep: | ||
.processing | ||
case .error(let localizedError): | ||
.error(localizedError) | ||
} | ||
} | ||
} | ||
|
||
struct TestError: LocalizedError { | ||
var errorDescription: String? | ||
var failureReason: String? | ||
var helpAnchor: String? | ||
var recoverySuggestion: String? | ||
} | ||
|
||
var testError = TestError( | ||
errorDescription: nil, | ||
failureReason: "Failure Reason", | ||
helpAnchor: "Help Anchor", | ||
recoverySuggestion: "Recovery Suggestion" | ||
) | ||
|
||
@State var operationState: OperationStateTest = .ready | ||
@State var viewState: ViewState = .idle | ||
|
||
|
||
var body: some View { | ||
VStack { | ||
Text("View State: \(String(describing: viewState))") | ||
.padding(.bottom, 12) | ||
|
||
Text("Operation State: \(String(describing: operationState))") | ||
.accessibilityIdentifier("operationState") | ||
} | ||
.task { | ||
operationState = .someOperationStep | ||
try? await Task.sleep(for: .seconds(10)) | ||
operationState = .error( | ||
AnyLocalizedError( | ||
error: testError, | ||
defaultErrorDescription: "Error Description" | ||
) | ||
) | ||
} | ||
.map(state: operationState, to: $viewState) | ||
.viewStateAlert(state: $viewState) | ||
} | ||
} | ||
|
||
|
||
#Preview { | ||
ViewStateMapperTestView() | ||
} |
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