-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWidgetSnapshotUpdaterTests.swift
More file actions
171 lines (157 loc) · 5.97 KB
/
Copy pathWidgetSnapshotUpdaterTests.swift
File metadata and controls
171 lines (157 loc) · 5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//
// WidgetSnapshotUpdaterTests.swift
// DevLogPersistenceTests
//
// Created by opfic on 4/30/26.
//
import Foundation
import DevLogCore
import DevLogData
import Testing
@testable import DevLogPersistence
@testable import DevLogWidgetCore
struct WidgetSnapshotUpdaterTests {
@Test("Today 스냅샷 갱신은 Today 스냅샷을 저장한다")
func today_스냅샷_갱신은_Today_스냅샷을_저장한다() throws {
let fixture = makeFixture()
let now = try #require(Calendar.current.date(from: DateComponents(year: 2026, month: 4, day: 30)))
let todo = makeTodo(
id: "today",
createdAt: now,
dueDate: now
)
fixture.updater.updateTodaySnapshot(
todos: [todo],
displayOptions: .default,
now: now
)
let snapshot = try #require(try fixture.snapshotStore.loadTodaySnapshot())
#expect(snapshot.totalCount == 1)
#expect(snapshot.sections.first?.items.first?.id == todo.id)
}
@Test("Heatmap 스냅샷 갱신은 Heatmap 스냅샷을 저장한다")
func heatmap_스냅샷_갱신은_Heatmap_스냅샷을_저장한다() throws {
let calendar = Calendar(identifier: .gregorian)
let quarterStart = try #require(calendar.date(from: DateComponents(year: 2026, month: 4, day: 1)))
let now = try #require(calendar.date(from: DateComponents(year: 2026, month: 4, day: 30)))
let completedAt = try #require(calendar.date(from: DateComponents(year: 2026, month: 4, day: 3)))
let deletedAt = try #require(calendar.date(from: DateComponents(year: 2026, month: 4, day: 4)))
let fixture = makeFixture(calendar: calendar)
fixture.preferenceStore.setHeatmapActivityTypes(["created", "completed"])
fixture.updater.updateHeatmapSnapshot(
createdTodos: [
makeTodo(
id: "created",
createdAt: try #require(calendar.date(from: DateComponents(year: 2026, month: 4, day: 2)))
)
],
completedTodos: [
makeTodo(
id: "completed",
createdAt: quarterStart,
completedAt: completedAt
)
],
deletedTodos: [
makeTodo(
id: "deleted",
createdAt: quarterStart,
deletedAt: deletedAt
)
],
quarterStart: quarterStart,
now: now
)
let snapshot = try #require(try fixture.snapshotStore.loadHeatmapSnapshot())
#expect(snapshot.quarterStart == quarterStart)
#expect(snapshot.selectedActivityKindRawValues == ["created", "completed"])
#expect(snapshot.maxCount == 1)
}
@Test("WidgetSnapshotUpdaterImpl는 모든 위젯 스냅샷을 삭제한다")
func widgetSnapshotUpdater는_모든_위젯_스냅샷을_삭제한다() throws {
let calendar = Calendar(identifier: .gregorian)
let quarterStart = try #require(calendar.date(from: DateComponents(year: 2026, month: 4, day: 1)))
let now = try #require(calendar.date(from: DateComponents(year: 2026, month: 4, day: 30)))
let fixture = makeFixture(calendar: calendar)
let todo = makeTodo(
id: "today",
createdAt: now,
dueDate: now
)
fixture.preferenceStore.setHeatmapActivityTypes(["created"])
fixture.preferenceStore.setTodayDisplayOptions(
TodayDisplayOptions(
dueDateVisibility: .withDueDateOnly,
focusVisibility: .focusedOnly
)
)
fixture.updater.updateTodaySnapshot(
todos: [todo],
displayOptions: .default,
now: now
)
fixture.updater.updateHeatmapSnapshot(
createdTodos: [
makeTodo(
id: "created",
createdAt: now
)
],
completedTodos: [],
deletedTodos: [],
quarterStart: quarterStart,
now: now
)
fixture.updater.clear()
#expect(try fixture.snapshotStore.loadTodaySnapshot() == nil)
#expect(try fixture.snapshotStore.loadHeatmapSnapshot() == nil)
#expect(fixture.preferenceStore.heatmapActivityTypes().isEmpty)
#expect(fixture.preferenceStore.todayDisplayOptions() == .default)
}
private func makeFixture(
calendar: Calendar = .current
) -> Fixture {
let suiteName = "WidgetSnapshotUpdaterTests.\(UUID().uuidString)"
let userDefaults = UserDefaults(suiteName: suiteName) ?? .standard
userDefaults.removePersistentDomain(forName: suiteName)
let snapshotStore = WidgetSnapshotStore(
store: WidgetSharedDefaultsStore(userDefaults: userDefaults)
)
let preferenceStore = WidgetSnapshotPreferenceStoreImpl(
userDefaults: userDefaults
)
let updater = WidgetSnapshotUpdaterImpl(
snapshotStore: snapshotStore,
preferenceStore: preferenceStore,
heatmapFactory: HeatmapWidgetSnapshotFactory(calendar: calendar)
)
return Fixture(
updater: updater,
snapshotStore: snapshotStore,
preferenceStore: preferenceStore
)
}
private func makeTodo(
id: String,
createdAt: Date,
completedAt: Date? = nil,
deletedAt: Date? = nil,
dueDate: Date? = nil
) -> WidgetTodoSnapshot {
WidgetTodoSnapshot(
id: id,
number: 1,
title: id,
isPinned: false,
createdAt: createdAt,
completedAt: completedAt,
deletedAt: deletedAt,
dueDate: dueDate
)
}
}
private struct Fixture {
let updater: WidgetSnapshotUpdaterImpl
let snapshotStore: WidgetSnapshotStore
let preferenceStore: WidgetSnapshotPreferenceStoreImpl
}