MultiUsePanelStateTests.swift 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import Foundation
  2. import Testing
  3. @testable import Trio
  4. @Suite("Multi-Use Panel State Tests") struct MultiUsePanelStateTests {
  5. private let now = Date(timeIntervalSinceReferenceDate: 800_000_000)
  6. private var fresh: Date { now.addingTimeInterval(-5 * 60) }
  7. private var stale: Date { now.addingTimeInterval(-20 * 60) }
  8. private func resolve(
  9. notificationsDisabled: Bool = false,
  10. pumpTimeMismatch: Bool = false,
  11. lastGlucoseDate: Date?,
  12. maxIOB: Decimal = 10
  13. ) -> MultiUsePanelState {
  14. MultiUsePanelState.resolve(
  15. notificationsDisabled: notificationsDisabled,
  16. pumpTimeMismatch: pumpTimeMismatch,
  17. lastGlucoseDate: lastGlucoseDate,
  18. maxIOB: maxIOB,
  19. now: now
  20. )
  21. }
  22. @Test("All healthy shows stats") func testStatsDefault() {
  23. #expect(resolve(lastGlucoseDate: fresh) == .stats)
  24. }
  25. @Test("Missing notifications outranks everything") func testNotificationsTop() {
  26. #expect(resolve(
  27. notificationsDisabled: true,
  28. pumpTimeMismatch: true,
  29. lastGlucoseDate: nil,
  30. maxIOB: 0
  31. ) == .notificationsDisabled)
  32. }
  33. @Test("Pump time mismatch outranks CGM and MaxIOB") func testTimeMismatchSecond() {
  34. #expect(resolve(pumpTimeMismatch: true, lastGlucoseDate: nil, maxIOB: 0) == .pumpTimeMismatch)
  35. }
  36. @Test("Stale glucose outranks MaxIOB") func testCgmStaleThird() {
  37. #expect(resolve(lastGlucoseDate: stale, maxIOB: 0) == .cgmStale)
  38. }
  39. @Test("No glucose at all counts as stale") func testNoGlucoseIsStale() {
  40. #expect(resolve(lastGlucoseDate: nil) == .cgmStale)
  41. }
  42. @Test("Fresh glucose within threshold is not stale") func testFreshGlucose() {
  43. #expect(resolve(lastGlucoseDate: now.addingTimeInterval(-11 * 60)) == .stats)
  44. }
  45. @Test("MaxIOB zero shows its warning") func testMaxIOBZero() {
  46. #expect(resolve(lastGlucoseDate: fresh, maxIOB: 0) == .maxIOBZero)
  47. }
  48. }