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