@@ -498,6 +498,62 @@ class LoopDataManagerDosingTests: XCTestCase {
498498 XCTAssertEqual ( recommendedBolus!. amount, 1.52 , accuracy: 0.01 )
499499 }
500500
501+ func testIsClosedLoopAvoidsTriggeringTempBasalCancelOnCreation( ) {
502+ let settings = LoopSettings (
503+ dosingEnabled: false ,
504+ glucoseTargetRangeSchedule: glucoseTargetRangeSchedule,
505+ maximumBasalRatePerHour: maxBasalRate,
506+ maximumBolus: maxBolus,
507+ suspendThreshold: suspendThreshold
508+ )
509+
510+ let doseStore = MockDoseStore ( )
511+ let glucoseStore = MockGlucoseStore ( )
512+ let carbStore = MockCarbStore ( )
513+
514+ let currentDate = Date ( )
515+
516+ dosingDecisionStore = MockDosingDecisionStore ( )
517+ automaticDosingStatus = AutomaticDosingStatus ( isClosedLoop: false , isClosedLoopAllowed: true )
518+ let existingTempBasal = DoseEntry (
519+ type: . tempBasal,
520+ startDate: currentDate. addingTimeInterval ( - . minutes ( 2 ) ) ,
521+ endDate: currentDate. addingTimeInterval ( . minutes( 28 ) ) ,
522+ value: 1.0 ,
523+ unit: . unitsPerHour,
524+ deliveredUnits: nil ,
525+ description: " Mock Temp Basal " ,
526+ syncIdentifier: " asdf " ,
527+ scheduledBasalRate: nil ,
528+ insulinType: . novolog,
529+ automatic: true ,
530+ manuallyEntered: false ,
531+ isMutable: true )
532+ loopDataManager = LoopDataManager (
533+ lastLoopCompleted: currentDate. addingTimeInterval ( - . minutes ( 5 ) ) ,
534+ basalDeliveryState: . tempBasal( existingTempBasal) ,
535+ settings: settings,
536+ overrideHistory: TemporaryScheduleOverrideHistory ( ) ,
537+ lastPumpEventsReconciliation: nil , // this date is only used to init the doseStore if a DoseStoreProtocol isn't passed in, so this date can be nil
538+ analyticsServicesManager: AnalyticsServicesManager ( ) ,
539+ localCacheDuration: . days( 1 ) ,
540+ doseStore: doseStore,
541+ glucoseStore: glucoseStore,
542+ carbStore: carbStore,
543+ dosingDecisionStore: dosingDecisionStore,
544+ settingsStore: MockSettingsStore ( ) ,
545+ now: { currentDate } ,
546+ pumpInsulinType: . novolog,
547+ automaticDosingStatus: automaticDosingStatus
548+ )
549+ let mockDelegate = MockDelegate ( )
550+ loopDataManager. delegate = mockDelegate
551+
552+ // Dose enacting happens asynchronously, as does receiving isClosedLoop signals
553+ waitOnMain ( timeout: 5 )
554+ XCTAssertNil ( mockDelegate. recommendation)
555+ }
556+
501557}
502558
503559extension LoopDataManagerDosingTests {
0 commit comments