-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTodayWidgetSnapshotFactoryTests.swift
More file actions
194 lines (180 loc) · 7.23 KB
/
Copy pathTodayWidgetSnapshotFactoryTests.swift
File metadata and controls
194 lines (180 loc) · 7.23 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//
// TodayWidgetSnapshotFactoryTests.swift
// DevLog_Unit
//
// Created by opfic on 4/17/26.
//
import Foundation
import Testing
@testable import DevLog
struct TodayWidgetSnapshotFactoryTests {
@Test("Today 위젯 스냅샷은 화면 규칙과 같은 순서로 섹션과 요약 수치를 만든다")
func today_위젯_스냅샷은_화면_규칙과_같은_순서로_섹션과_요약_수치를_만든다() throws {
let calendar = Calendar(identifier: .gregorian)
let now = try #require(calendar.date(from: DateComponents(year: 2026, month: 4, day: 17)))
let factory = TodayWidgetSnapshotFactory(calendar: calendar)
let snapshot = factory.makeSnapshot(
todos: try makeTodayTodos(now: now, calendar: calendar),
displayOptions: .default,
now: now
)
#expect(snapshot.totalCount == 5)
#expect(snapshot.focusedCount == 1)
#expect(snapshot.overdueCount == 1)
#expect(snapshot.dueSoonCount == 2)
#expect(snapshot.sections.map(\.category) == ["focused", "overdue", "dueSoon", "later", "unscheduled"])
#expect(snapshot.sections[0].items.map(\.title) == ["고정된 할 일"])
#expect(snapshot.sections[1].items.map(\.title) == ["지난 일정"])
#expect(snapshot.sections[2].items.map(\.title) == ["임박 일정"])
#expect(snapshot.sections[3].items.map(\.title) == ["나중 일정"])
#expect(snapshot.sections[4].items.map(\.title) == ["미정 일정"])
}
@Test("Today 위젯 스냅샷은 화면과 같은 display option 필터를 적용한다")
func today_위젯_스냅샷은_화면과_같은_display_option_필터를_적용한다() throws {
let calendar = Calendar(identifier: .gregorian)
let now = try #require(calendar.date(from: DateComponents(year: 2026, month: 4, day: 17)))
let factory = TodayWidgetSnapshotFactory(calendar: calendar)
let snapshot = factory.makeSnapshot(
todos: try makeTodayTodos(now: now, calendar: calendar),
displayOptions: TodayDisplayOptions(
dueDateVisibility: .withDueDateOnly,
focusVisibility: .focusedOnly
),
now: now
)
#expect(snapshot.totalCount == 1)
#expect(snapshot.focusedCount == 1)
#expect(snapshot.overdueCount == 0)
#expect(snapshot.dueSoonCount == 1)
#expect(snapshot.sections.map(\.category) == ["focused"])
#expect(snapshot.sections[0].items.map(\.title) == ["고정된 할 일"])
}
@Test("Today 위젯 스냅샷은 날짜 경계에 따라 일정 섹션을 구분한다")
func today_위젯_스냅샷은_날짜_경계에_따라_일정_섹션을_구분한다() throws {
let calendar = Calendar(identifier: .gregorian)
let now = try #require(calendar.date(from: DateComponents(year: 2026, month: 4, day: 17, hour: 12)))
let yesterday = try #require(calendar.date(byAdding: .day, value: -1, to: now))
let sevenDaysLater = try #require(calendar.date(byAdding: .day, value: 7, to: now))
let eightDaysLater = try #require(calendar.date(byAdding: .day, value: 8, to: now))
let factory = TodayWidgetSnapshotFactory(calendar: calendar)
let snapshot = factory.makeSnapshot(
todos: try [
makeTodayTodoItem(
id: "todo-overdue",
number: 1,
title: "지난 일정",
isPinned: false,
dueDate: yesterday
),
makeTodayTodoItem(
id: "todo-today",
number: 2,
title: "오늘 일정",
isPinned: false,
dueDate: now
),
makeTodayTodoItem(
id: "todo-seven-days-later",
number: 3,
title: "7일 뒤 일정",
isPinned: false,
dueDate: sevenDaysLater
),
makeTodayTodoItem(
id: "todo-eight-days-later",
number: 4,
title: "8일 뒤 일정",
isPinned: false,
dueDate: eightDaysLater
),
makeTodayTodoItem(
id: "todo-unscheduled",
number: 5,
title: "미정 일정",
isPinned: false,
dueDate: nil
)
],
displayOptions: .default,
now: now
)
#expect(snapshot.totalCount == 5)
#expect(snapshot.overdueCount == 1)
#expect(snapshot.dueSoonCount == 2)
#expect(snapshot.sections.map(\.category) == ["overdue", "dueSoon", "later", "unscheduled"])
#expect(snapshot.sections[0].items.map(\.title) == ["지난 일정"])
#expect(snapshot.sections[1].items.map(\.title) == ["오늘 일정", "7일 뒤 일정"])
#expect(snapshot.sections[2].items.map(\.title) == ["8일 뒤 일정"])
#expect(snapshot.sections[3].items.map(\.title) == ["미정 일정"])
}
private func makeTodayTodos(
now: Date,
calendar: Calendar
) throws -> [TodayTodoItem] {
let overdueDate = try #require(calendar.date(byAdding: .day, value: -1, to: now))
let dueSoonDate = try #require(calendar.date(byAdding: .day, value: 3, to: now))
let laterDate = try #require(calendar.date(byAdding: .day, value: 9, to: now))
return try [
makeTodayTodoItem(
id: "todo-1",
number: 1,
title: "고정된 할 일",
isPinned: true,
dueDate: dueSoonDate
),
makeTodayTodoItem(
id: "todo-2",
number: 2,
title: "지난 일정",
isPinned: false,
dueDate: overdueDate
),
makeTodayTodoItem(
id: "todo-3",
number: 3,
title: "임박 일정",
isPinned: false,
dueDate: dueSoonDate
),
makeTodayTodoItem(
id: "todo-4",
number: 4,
title: "나중 일정",
isPinned: false,
dueDate: laterDate
),
makeTodayTodoItem(
id: "todo-5",
number: 5,
title: "미정 일정",
isPinned: false,
dueDate: nil
)
]
}
private func makeTodayTodoItem(
id: String,
number: Int,
title: String,
isPinned: Bool,
dueDate: Date?
) throws -> TodayTodoItem {
let todo = Todo(
id: id,
isPinned: isPinned,
isCompleted: false,
isChecked: false,
number: number,
title: title,
content: "",
createdAt: .now,
updatedAt: .now,
completedAt: nil,
deletedAt: nil,
dueDate: dueDate,
tags: [],
category: .system(.feature)
)
return try #require(TodayTodoItem(from: todo))
}
}