CGMManagerAlertOwnershipTests.swift 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import CGMBLEKit
  2. import Foundation
  3. import G7SensorKit
  4. import LibreTransmitter
  5. import LoopKit
  6. import Testing
  7. @testable import Trio
  8. @Suite("Trio Alerts: CGMManagerAlertOwnership") struct CGMManagerAlertOwnershipTests {
  9. @Test("nil manager + .none source → no owner") func noneSourceNoManager() {
  10. #expect(CGMManagerAlertOwnership.owningApp(manager: nil, sourceType: .none) == nil)
  11. #expect(!CGMManagerAlertOwnership.providesOwnGlucoseAlerts(manager: nil, sourceType: .none))
  12. }
  13. /// Pins the xDrip4iOS case that was missed before: .xdrip runs through
  14. /// AppGroupSource without a CGMManager instance, so the ownership check
  15. /// must trigger off the source type alone.
  16. @Test(".xdrip source → xDrip4iOS owner + xdripswift:// deep link") func xdripSourceWinsWithNilManager() {
  17. let app = CGMManagerAlertOwnership.owningApp(manager: nil, sourceType: .xdrip)
  18. #expect(app?.name == "xDrip4iOS")
  19. #expect(app?.deepLink == URL(string: "xdripswift://"))
  20. #expect(CGMManagerAlertOwnership.providesOwnGlucoseAlerts(manager: nil, sourceType: .xdrip))
  21. }
  22. @Test("nightscout / simulator / enlite sources → no owner") func nonOwnerSources() {
  23. for source in [CGMType.nightscout, .simulator, .enlite] {
  24. #expect(CGMManagerAlertOwnership.owningApp(manager: nil, sourceType: source) == nil)
  25. }
  26. }
  27. /// Each known manager type maps to a fixed (name, deepLink) pair. Pinning
  28. /// the strings here means a rename in CGMManagerAlertOwnership.swift
  29. /// surfaces as a failing test rather than a silent UI copy change.
  30. @Test("G6CGMManager → Dexcom G6 / One + dexcomg6://") func g6Mapping() {
  31. let manager = G6CGMManager(state: TransmitterManagerState(transmitterID: "TEST6A"))
  32. let app = CGMManagerAlertOwnership.owningApp(manager: manager, sourceType: .plugin)
  33. #expect(app?.name == "Dexcom G6 / One")
  34. #expect(app?.deepLink == URL(string: "dexcomg6://"))
  35. }
  36. @Test("G7CGMManager → Dexcom G7 / One+ + dexcomg7://") func g7Mapping() {
  37. let app = CGMManagerAlertOwnership.owningApp(manager: G7CGMManager(), sourceType: .plugin)
  38. #expect(app?.name == "Dexcom G7 / One+")
  39. #expect(app?.deepLink == URL(string: "dexcomg7://"))
  40. }
  41. @Test("G5CGMManager → Dexcom G5, no known deep link") func g5Mapping() {
  42. let manager = G5CGMManager(state: TransmitterManagerState(transmitterID: "TEST5A"))
  43. let app = CGMManagerAlertOwnership.owningApp(manager: manager, sourceType: .plugin)
  44. #expect(app?.name == "Dexcom G5")
  45. #expect(app?.deepLink == nil)
  46. }
  47. }