Skip to content

Commit

Permalink
feat: More DemoApp tests and cases
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria committed Nov 29, 2024
1 parent 63d85b2 commit 780cff3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
41 changes: 33 additions & 8 deletions ConfidenceDemoApp/ConfidenceDemoApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ struct ContentView: View {
@AppStorage("loggedUser") private var loggedUser: String?

Check failure on line 7 in ConfidenceDemoApp/ConfidenceDemoApp/ContentView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Attributes Violation: Attributes with arguments or inside always_on_line_above must be on a new line instead of the same line (attributes)
@State var isLoggingOut: Bool = false
@State var loggedOut: Bool = false
@State var textColor: Color = .red

private let confidence: Confidence

Expand All @@ -19,21 +20,25 @@ struct ContentView: View {
if (status.state == .loading && !isLoggingOut) {

Check failure on line 20 in ConfidenceDemoApp/ConfidenceDemoApp/ContentView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Control Statement Violation: `if`, `for`, `guard`, `switch`, `while`, and `catch` statements shouldn't unnecessarily wrap their conditionals or arguments in parentheses (control_statement)
VStack {
Spacer()
Text("Welcome \(loggedUser ?? "?")")
Text("Login successful: \(loggedUser ?? "?")")
Text("We are preparing your experience...")
ProgressView()
Spacer()
}
} else {
VStack {
Text("Hello World!")
.font(.largeTitle)
.foregroundStyle(ContentView.getColor(color: confidence.getValue(key: "swift-demoapp.color", defaultValue: "Gray")))
if (status.state == .ready) {

Check failure on line 28 in ConfidenceDemoApp/ConfidenceDemoApp/ContentView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Control Statement Violation: `if`, `for`, `guard`, `switch`, `while`, and `catch` statements shouldn't unnecessarily wrap their conditionals or arguments in parentheses (control_statement)
VStack {
Spacer()
if (loggedUser != nil) {

Check failure on line 31 in ConfidenceDemoApp/ConfidenceDemoApp/ContentView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Control Statement Violation: `if`, `for`, `guard`, `switch`, `while`, and `catch` statements shouldn't unnecessarily wrap their conditionals or arguments in parentheses (control_statement)
Text("Hello World!")
.font(.largeTitle)
// This dynamically changes with the cache of flags, but it's wrapped into a conditional that makes sure flagStatus is "ready"
.foregroundStyle(ContentView.getColor(color: confidence.getValue(key: "swift-demoapp.color", defaultValue: "Gray")))
.padding()
}
}
}
.padding()
Button("Logout") {
isLoggingOut = true

loggedUser = nil
status.state = .loading
Task {
Expand All @@ -46,6 +51,26 @@ struct ContentView: View {
.navigationDestination(isPresented: $loggedOut) {
LoginView(confidence: confidence)
}
Spacer()
}
ZStack {
VStack {
Spacer()
Text("This text doesn't wait flags to be loaded")
.font(.caption)
.foregroundStyle(textColor)
Text("This text dynamically change on flag re-load")
.font(.caption)
.foregroundStyle(ContentView.getColor(color: confidence.getValue(key: "swift-demoapp.color", defaultValue: "Gray")))
}
}.onAppear {
let eval = confidence.getEvaluation(key: "swift-demoapp.color", defaultValue: "Gray")
/*
Due to syntetic delay, the new context hasn't entered the SDK yet se we are operating with

Check failure on line 69 in ConfidenceDemoApp/ConfidenceDemoApp/ContentView.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Indentation Width Violation: Code should be indented using one tab or 4 spaces (indentation_width)
the same empty context activated at logout, which leads to noSegmentMatch
*/
print(">> Evaluation reason: \(eval)")
textColor = ContentView.getColor(color: eval.value)
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions ConfidenceDemoApp/ConfidenceDemoApp/LoginView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,4 @@ struct LoginView: View {
}
}
}
private var combinedBinding: Binding<Bool> {
Binding(
get: { loginCompleted && flagsLoaded },
set: { _ in } // No-op; navigation state is derived from other properties
)
}
}
4 changes: 0 additions & 4 deletions Sources/Confidence/Confidence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ public class Confidence: ConfidenceEventSender {
}
let savedFlags = try storage.load(defaultValue: FlagResolution.EMPTY)
cache = savedFlags
debugLogger?.logMessage(
message: "[Activating stored cache]",
isWarning: false
)
}
}

Expand Down

0 comments on commit 780cff3

Please sign in to comment.