Skip to content
Snippets Groups Projects
Commit f08b09d7 authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Setup logging when app starts

parent 530c5485
No related branches found
No related tags found
2 merge requests!126Migrate example app to ComposableArchitecture's ReducerProtocol,!102Release 1.0.0
......@@ -7,14 +7,17 @@ import SwiftUI
struct App: SwiftUI.App {
init() {
LoggingSystem.bootstrap(PersistentLogHandler.init)
ViewStore(store.stateless).send(.setupLogging)
}
let store = Store(
initialState: AppComponent.State(),
reducer: AppComponent()
)
var body: some Scene {
WindowGroup {
AppView(store: Store(
initialState: AppComponent.State(),
reducer: AppComponent()
))
AppView(store: store)
}
}
}
......@@ -23,6 +23,7 @@ struct AppComponent: ReducerProtocol {
}
enum Action: Equatable, BindableAction {
case setupLogging
case start
case stop
case binding(BindingAction<State>)
......@@ -55,6 +56,11 @@ struct AppComponent: ReducerProtocol {
let log = self.log
switch action {
case .setupLogging:
_ = try! messenger.setLogLevel(.debug)
messenger.startLogging()
return .none
case .start, .welcome(.finished), .restore(.finished), .home(.deleteAccount(.success)):
state.screen = .loading
return Effect.run { subscriber in
......
......@@ -9,6 +9,29 @@ import XXClient
@testable import AppFeature
final class AppComponentTests: XCTestCase {
func testSetupLogging() {
var actions: [Action] = []
let store = TestStore(
initialState: AppComponent.State(),
reducer: AppComponent()
)
store.dependencies.app.messenger.setLogLevel.run = { level in
actions.append(.didSetLogLevel(level))
return true
}
store.dependencies.app.messenger.startLogging.run = {
actions.append(.didStartLogging)
}
store.send(.setupLogging)
XCTAssertNoDifference(actions, [
.didSetLogLevel(.debug),
.didStartLogging,
])
}
func testStartWithoutMessengerCreated() {
var actions: [Action]!
......@@ -514,4 +537,6 @@ private enum Action: Equatable {
case didCancelBackupCallback
case didLog(Logger.Message)
case didStoreBackup(Data)
case didSetLogLevel(LogLevel)
case didStartLogging
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment