Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Loop/Managers/Alerts/AlertManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public final class AlertManager {
let alertStore: AlertStore

private let bluetoothPoweredOffIdentifier = Alert.Identifier(managerIdentifier: managerIdentifier, alertIdentifier: "bluetoothPoweredOff")
static let bluetoothPoweredOffAlertDelay = TimeInterval(minutes: 10)

var analyticsServicesManager: AnalyticsServicesManager

Expand Down Expand Up @@ -177,8 +178,8 @@ public final class AlertManager {
await issueAlert(Alert(identifier: bluetoothPoweredOffIdentifier,
foregroundContent: fgcontent,
backgroundContent: bgcontent,
trigger: .immediate,
interruptionLevel: .critical))
trigger: .delayed(interval: Self.bluetoothPoweredOffAlertDelay),
interruptionLevel: .timeSensitive))
}
}

Expand Down
18 changes: 18 additions & 0 deletions LoopTests/Managers/Alerts/AlertManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,24 @@ class AlertManagerTests: XCTestCase {
XCTAssertEqual(request.content.sound, .defaultCriticalSound(withAudioVolume: 0))
}
}

func testBluetoothPoweredOffIssuesDelayedTimeSensitiveAlert() async {
mockModalScheduler.alertScheduledExpectation = expectation(description: "alert scheduled")
alertManager.bluetoothDidUpdateState(.poweredOff)
await fulfillment(of: [mockModalScheduler.alertScheduledExpectation!], timeout: 1)

let alert = mockModalScheduler.scheduledAlert
XCTAssertEqual(alert?.identifier.alertIdentifier, "bluetoothPoweredOff")
XCTAssertEqual(alert?.trigger, .delayed(interval: AlertManager.bluetoothPoweredOffAlertDelay))
XCTAssertEqual(alert?.interruptionLevel, .timeSensitive)
}

func testBluetoothPoweredOnRetractsAlert() async {
mockModalScheduler.alertUnscheduledExpectation = expectation(description: "alert unscheduled")
alertManager.bluetoothDidUpdateState(.poweredOn)
await fulfillment(of: [mockModalScheduler.alertUnscheduledExpectation!], timeout: 1)
XCTAssertEqual(mockModalScheduler.unscheduledAlertIdentifier?.alertIdentifier, "bluetoothPoweredOff")
}
}

extension Swift.Result {
Expand Down