macsync/@packages/iphoto/Tests/IPhotoSyncTests/SyncStatsTests.swift

46 lines
1.6 KiB
Swift

import Testing
@testable import IPhotoSync
import Foundation
@Suite("IPhotoSyncStats")
struct SyncStatsTests {
@Test("ETA returns nil when no upload is in progress")
func etaNilWhenIdle() {
let stats = IPhotoSyncStats()
#expect(stats.eta == nil)
}
@Test("ETA returns seconds string when remaining < 60")
func etaSeconds() {
var stats = IPhotoSyncStats()
stats.uploadStartTime = Date().addingTimeInterval(-10)
stats.currentSessionUploaded = 10 // 1/sec
stats.pendingUpload = 30
// rate 1.0/sec eta 30s
guard let eta = stats.eta else {
Issue.record("Expected non-nil ETA")
return
}
#expect(eta.hasSuffix("s"), "Expected seconds suffix, got '\(eta)'")
}
@Test("uploadRateString shows per-minute when rate < 1/sec")
func ratePerMinute() {
var stats = IPhotoSyncStats()
// 1 photo uploaded in 120s 0.5/sec < 1 per-minute format
stats.uploadStartTime = Date().addingTimeInterval(-120)
stats.currentSessionUploaded = 1
let s = stats.uploadRateString
#expect(s.hasSuffix("/min"), "Expected /min suffix, got '\(s)'")
}
@Test("uploadRateString shows per-second when rate >= 1/sec")
func ratePerSecond() {
var stats = IPhotoSyncStats()
stats.uploadStartTime = Date().addingTimeInterval(-10)
stats.currentSessionUploaded = 20 // 2/sec
let s = stats.uploadRateString
#expect(s.hasSuffix("/sec"), "Expected /sec suffix, got '\(s)'")
}
}