Skip to content

Commit 3b839aa

Browse files
committed
Add exact countdown color boundary tests
1 parent a270916 commit 3b839aa

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

MeetingBar/UI/StatusBar/StatusBarItemController.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,13 +540,12 @@ func shortenTitle(title: String?, offset: Int) -> String {
540540
return eventTitle
541541
}
542542

543-
func countdownColor(for event: MBEvent) -> NSColor {
544-
let now = Date()
543+
func countdownColor(for event: MBEvent, now: Date = Date()) -> NSColor {
545544
let timeRemaining: TimeInterval
546545
if event.startDate <= now, event.endDate > now {
547-
timeRemaining = event.endDate.timeIntervalSinceNow
546+
timeRemaining = event.endDate.timeIntervalSince(now)
548547
} else {
549-
timeRemaining = event.startDate.timeIntervalSinceNow
548+
timeRemaining = event.startDate.timeIntervalSince(now)
550549
}
551550

552551
if timeRemaining >= 15 * 60 {

MeetingBarTests/StatusBarItem/MenuBuilderTests.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,28 @@ final class MenuBuilderEventItemTests: BaseTestCase {
257257
@MainActor
258258
final class CountdownColorTests: BaseTestCase {
259259

260+
func test_countdownColorIsGreenWhenEventStartsExactlyFifteenMinutesFromNow() {
261+
let now = Date()
262+
let event = makeFakeEvent(
263+
id: "GREEN_BOUNDARY",
264+
start: now.addingTimeInterval(15 * 60),
265+
end: now.addingTimeInterval(45 * 60)
266+
)
267+
268+
XCTAssertEqual(countdownColor(for: event, now: now), .systemGreen)
269+
}
270+
271+
func test_countdownColorIsYellowWhenEventStartsExactlyFiveMinutesFromNow() {
272+
let now = Date()
273+
let event = makeFakeEvent(
274+
id: "YELLOW_BOUNDARY",
275+
start: now.addingTimeInterval(5 * 60),
276+
end: now.addingTimeInterval(35 * 60)
277+
)
278+
279+
XCTAssertEqual(countdownColor(for: event, now: now), .systemYellow)
280+
}
281+
260282
func test_countdownColorIsGreenWhenEventStartsAtLeastFifteenMinutesFromNow() {
261283
let event = makeFakeEvent(
262284
id: "GREEN",

0 commit comments

Comments
 (0)