75 lines
2.3 KiB
Swift
75 lines
2.3 KiB
Swift
//
|
|
// TheNoiseClockTests.swift
|
|
// TheNoiseClockTests
|
|
//
|
|
// Created by Matt Bruce on 9/7/25.
|
|
//
|
|
|
|
import Testing
|
|
@testable import The_Noise_Clock
|
|
import Foundation
|
|
|
|
@MainActor
|
|
struct TheNoiseClockTests {
|
|
|
|
@Test
|
|
func defaultAlarmSoundIsMP3() {
|
|
#expect(AppConstants.SystemSounds.defaultSound.hasSuffix(".mp3"))
|
|
}
|
|
|
|
@Test
|
|
func nextOccurrenceIsInFuture() {
|
|
let oneMinuteAgo = Calendar.current.date(byAdding: .minute, value: -1, to: Date()) ?? Date()
|
|
let next = oneMinuteAgo.nextOccurrence()
|
|
|
|
#expect(next > Date())
|
|
#expect(next.timeIntervalSinceNow < 26 * 60 * 60)
|
|
}
|
|
|
|
@Test
|
|
func clockStyleCodableRoundTripPreservesSettings() throws {
|
|
let style = ClockStyle()
|
|
style.showSeconds = true
|
|
style.showDate = false
|
|
style.keepAwake = true
|
|
style.fontFamily = .avenir
|
|
style.digitAnimationStyle = .glitch
|
|
|
|
let data = try JSONEncoder().encode(style)
|
|
let decoded = try JSONDecoder().decode(ClockStyle.self, from: data)
|
|
|
|
#expect(decoded.showSeconds)
|
|
#expect(decoded.showDate == false)
|
|
#expect(decoded.keepAwake)
|
|
#expect(decoded.fontFamily == .avenir)
|
|
#expect(decoded.digitAnimationStyle == .glitch)
|
|
}
|
|
|
|
@Test
|
|
func repeatingAlarmComputesNextMatchingWeekday() {
|
|
let calendar = Calendar.current
|
|
let now = Date()
|
|
let targetDate = calendar.date(byAdding: .day, value: 2, to: now) ?? now
|
|
let targetWeekday = calendar.component(.weekday, from: targetDate)
|
|
|
|
let templateTime = calendar.date(bySettingHour: 9, minute: 30, second: 0, of: now) ?? now
|
|
let alarm = Alarm(time: templateTime, repeatWeekdays: [targetWeekday])
|
|
let next = alarm.nextTriggerTime()
|
|
|
|
let components = calendar.dateComponents([.hour, .minute, .weekday], from: next)
|
|
#expect(next > now)
|
|
#expect(components.weekday == targetWeekday)
|
|
#expect(components.hour == 9)
|
|
#expect(components.minute == 30)
|
|
}
|
|
|
|
@Test
|
|
func repeatSummaryRecognizesCommonPatterns() {
|
|
#expect(Alarm.repeatSummary(for: []) == "Once")
|
|
#expect(Alarm.repeatSummary(for: [1, 2, 3, 4, 5, 6, 7]) == "Every day")
|
|
#expect(Alarm.repeatSummary(for: [2, 3, 4, 5, 6]) == "Weekdays")
|
|
#expect(Alarm.repeatSummary(for: [1, 7]) == "Weekends")
|
|
}
|
|
|
|
}
|