|
| 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