Skip to content

Commit f7d7834

Browse files
committed
fix: 위젯 설정 변경 시 동기화 트리거 추가
1 parent 1e119d2 commit f7d7834

3 files changed

Lines changed: 118 additions & 2 deletions

File tree

Application/DevLogData/Sources/DataAssembler.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ public final class DataAssembler: Assembler {
110110
UserPreferencesRepositoryImpl(
111111
store: container.resolve(UserDefaultsStore.self),
112112
themeStore: container.resolve(ThemeStore.self),
113-
widgetSnapshotPreferenceStore: container.resolve(WidgetSnapshotPreferenceStore.self)
113+
widgetSnapshotPreferenceStore: container.resolve(WidgetSnapshotPreferenceStore.self),
114+
widgetSyncEventBus: container.resolve(WidgetSyncEventBus.self)
114115
)
115116
}
116117
}

Application/DevLogData/Sources/Repository/UserPreferencesRepositoryImpl.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@ final class UserPreferencesRepositoryImpl: UserPreferencesRepository {
2222
private let store: UserDefaultsStore
2323
private let themeStore: ThemeStore
2424
private let widgetSnapshotPreferenceStore: WidgetSnapshotPreferenceStore
25+
private let widgetSyncEventBus: WidgetSyncEventBus
2526

2627
init(
2728
store: UserDefaultsStore,
2829
themeStore: ThemeStore,
29-
widgetSnapshotPreferenceStore: WidgetSnapshotPreferenceStore
30+
widgetSnapshotPreferenceStore: WidgetSnapshotPreferenceStore,
31+
widgetSyncEventBus: WidgetSyncEventBus
3032
) {
3133
self.store = store
3234
self.themeStore = themeStore
3335
self.widgetSnapshotPreferenceStore = widgetSnapshotPreferenceStore
36+
self.widgetSyncEventBus = widgetSyncEventBus
3437
themeStore.send(systemTheme())
3538
}
3639

@@ -92,6 +95,7 @@ final class UserPreferencesRepositoryImpl: UserPreferencesRepository {
9295

9396
func setHeatmapActivityTypes(_ activityTypes: [String]) {
9497
widgetSnapshotPreferenceStore.setHeatmapActivityTypes(activityTypes)
98+
widgetSyncEventBus.publish(.syncRequested)
9599
}
96100

97101
func todayDisplayOptions() -> TodayDisplayOptions {
@@ -100,5 +104,6 @@ final class UserPreferencesRepositoryImpl: UserPreferencesRepository {
100104

101105
func setTodayDisplayOptions(_ options: TodayDisplayOptions) {
102106
widgetSnapshotPreferenceStore.setTodayDisplayOptions(options)
107+
widgetSyncEventBus.publish(.syncRequested)
103108
}
104109
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
//
2+
// UserPreferencesRepositoryImplTests.swift
3+
// DevLogDataTests
4+
//
5+
// Created by opfic on 6/1/26.
6+
//
7+
8+
import Combine
9+
import Foundation
10+
import Testing
11+
import DevLogCore
12+
@testable import DevLogData
13+
14+
struct UserPreferencesRepositoryImplTests {
15+
@Test("위젯 설정 변경 시 위젯 동기화 이벤트를 발행한다")
16+
func 위젯_설정_변경_시_위젯_동기화_이벤트를_발행한다() {
17+
let widgetSnapshotPreferenceStore = WidgetSnapshotPreferenceStoreSpy()
18+
let widgetSyncEventBus = WidgetSyncEventBusSpy()
19+
let repository = UserPreferencesRepositoryImpl(
20+
store: UserDefaultsStoreSpy(),
21+
themeStore: ThemeStoreSpy(),
22+
widgetSnapshotPreferenceStore: widgetSnapshotPreferenceStore,
23+
widgetSyncEventBus: widgetSyncEventBus
24+
)
25+
26+
repository.setHeatmapActivityTypes(["created", "deleted"])
27+
repository.setTodayDisplayOptions(
28+
TodayDisplayOptions(
29+
dueDateVisibility: .withDueDateOnly,
30+
focusVisibility: .focusedOnly
31+
)
32+
)
33+
34+
#expect(widgetSnapshotPreferenceStore.heatmapActivityTypesValue == ["created", "deleted"])
35+
#expect(
36+
widgetSnapshotPreferenceStore.todayDisplayOptionsValue == TodayDisplayOptions(
37+
dueDateVisibility: .withDueDateOnly,
38+
focusVisibility: .focusedOnly
39+
)
40+
)
41+
#expect(widgetSyncEventBus.events == [.syncRequested, .syncRequested])
42+
}
43+
}
44+
45+
private final class UserDefaultsStoreSpy: UserDefaultsStore {
46+
func string(forKey key: String) -> String? {
47+
nil
48+
}
49+
50+
func setString(_ value: String?, forKey key: String) { }
51+
52+
func stringArray(forKey key: String) -> [String] {
53+
[]
54+
}
55+
56+
func setStringArray(_ value: [String], forKey key: String) { }
57+
58+
func bool(forKey key: String) -> Bool {
59+
false
60+
}
61+
62+
func setBool(_ value: Bool, forKey key: String) { }
63+
}
64+
65+
private final class ThemeStoreSpy: ThemeStore {
66+
func observeTheme() -> AnyPublisher<SystemTheme, Never> {
67+
Empty().eraseToAnyPublisher()
68+
}
69+
70+
func send(_ theme: SystemTheme) { }
71+
}
72+
73+
private final class WidgetSnapshotPreferenceStoreSpy: WidgetSnapshotPreferenceStore {
74+
private(set) var heatmapActivityTypesValue = [String]()
75+
private(set) var todayDisplayOptionsValue = TodayDisplayOptions.default
76+
77+
func heatmapActivityTypes() -> [String] {
78+
heatmapActivityTypesValue
79+
}
80+
81+
func setHeatmapActivityTypes(_ activityTypes: [String]) {
82+
heatmapActivityTypesValue = activityTypes
83+
}
84+
85+
func selectedActivityKinds() -> Set<ActivityKind> {
86+
[]
87+
}
88+
89+
func todayDisplayOptions() -> TodayDisplayOptions {
90+
todayDisplayOptionsValue
91+
}
92+
93+
func setTodayDisplayOptions(_ options: TodayDisplayOptions) {
94+
todayDisplayOptionsValue = options
95+
}
96+
97+
func clear() { }
98+
}
99+
100+
private final class WidgetSyncEventBusSpy: WidgetSyncEventBus {
101+
private(set) var events = [WidgetSyncEvent]()
102+
103+
func publish(_ event: WidgetSyncEvent) {
104+
events.append(event)
105+
}
106+
107+
func observe() -> AnyPublisher<WidgetSyncEvent, Never> {
108+
Empty().eraseToAnyPublisher()
109+
}
110+
}

0 commit comments

Comments
 (0)