mirror of
https://github.com/home-assistant/iOS.git
synced 2026-02-15 07:49:30 -06:00
## Summary Allows attachments to be loaded on-the-fly in the content extension if they are not present. ## Link to pull request in Documentation repository Documentation: home-assistant/companion.home-assistant#510 ## Any other notes - Adds `lazy` as an option to the `attachment` dictionary. When true, this prevents the attachment from being downloaded except when displayed in the content extension. This is similar, but not identical, to hide-thumbnail. Hiding the thumbnail still uses the internal storage of the notifications which are limited to e.g. 50mb. However, we'd still want to pre-load those attachments even if the thumbnail is hidden. - Retries non-lazy attachments which failed due to a network error when the content extension opens.
112 lines
3.6 KiB
Swift
112 lines
3.6 KiB
Swift
import CoreServices
|
|
import Foundation
|
|
import PromiseKit
|
|
@testable import Shared
|
|
import XCTest
|
|
|
|
class NotificationAttachmentParserCameraTests: XCTestCase {
|
|
private typealias CameraError = NotificationAttachmentParserCamera.CameraError
|
|
|
|
private var parser: NotificationAttachmentParserCamera!
|
|
|
|
override func setUp() {
|
|
super.setUp()
|
|
|
|
parser = NotificationAttachmentParserCamera()
|
|
}
|
|
|
|
func testMissingEntityID() {
|
|
let content = UNMutableNotificationContent()
|
|
let promise = parser.attachmentInfo(from: content)
|
|
XCTAssertEqual(promise.wait(), .missing)
|
|
}
|
|
|
|
func testInvalidEntityID() {
|
|
let content = UNMutableNotificationContent()
|
|
content.userInfo["entity_id"] = "\\"
|
|
let promise = parser.attachmentInfo(from: content)
|
|
XCTAssertEqual(promise.wait(), .missing)
|
|
}
|
|
|
|
func testNonCameraEntityID() {
|
|
let content = UNMutableNotificationContent()
|
|
content.userInfo["entity_id"] = "light.bedroom"
|
|
let promise = parser.attachmentInfo(from: content)
|
|
XCTAssertEqual(promise.wait(), .missing)
|
|
}
|
|
|
|
func testAttachmentHidden() {
|
|
let content = UNMutableNotificationContent()
|
|
content.userInfo["entity_id"] = "camera.any"
|
|
content.userInfo["attachment"] = [
|
|
"hide-thumbnail": true,
|
|
]
|
|
let promise = parser.attachmentInfo(from: content)
|
|
|
|
guard let result = promise.wait().attachmentInfo else {
|
|
XCTFail("not an attachment")
|
|
return
|
|
}
|
|
|
|
XCTAssertEqual(result.url, URL(string: "/api/camera_proxy/camera.any"))
|
|
XCTAssertEqual(result.needsAuth, true)
|
|
XCTAssertEqual(result.typeHint, kUTTypeJPEG)
|
|
XCTAssertEqual(result.hideThumbnail, true)
|
|
}
|
|
|
|
func testAttachmentLazy() {
|
|
let content = UNMutableNotificationContent()
|
|
content.userInfo["entity_id"] = "camera.any"
|
|
content.userInfo["attachment"] = [
|
|
"lazy": true,
|
|
]
|
|
let promise = parser.attachmentInfo(from: content)
|
|
|
|
guard let result = promise.wait().attachmentInfo else {
|
|
XCTFail("not an attachment")
|
|
return
|
|
}
|
|
|
|
XCTAssertEqual(result.url, URL(string: "/api/camera_proxy/camera.any"))
|
|
XCTAssertEqual(result.needsAuth, true)
|
|
XCTAssertEqual(result.typeHint, kUTTypeJPEG)
|
|
XCTAssertEqual(result.hideThumbnail, nil)
|
|
XCTAssertEqual(result.lazy, true)
|
|
}
|
|
|
|
func testAttachmentNotHidden() {
|
|
let content = UNMutableNotificationContent()
|
|
content.userInfo["entity_id"] = "camera.any"
|
|
content.userInfo["attachment"] = [
|
|
"hide-thumbnail": false,
|
|
]
|
|
let promise = parser.attachmentInfo(from: content)
|
|
|
|
guard let result = promise.wait().attachmentInfo else {
|
|
XCTFail("not an attachment")
|
|
return
|
|
}
|
|
|
|
XCTAssertEqual(result.url, URL(string: "/api/camera_proxy/camera.any"))
|
|
XCTAssertEqual(result.needsAuth, true)
|
|
XCTAssertEqual(result.typeHint, kUTTypeJPEG)
|
|
XCTAssertEqual(result.hideThumbnail, false)
|
|
}
|
|
|
|
func testAttachmentInfo() {
|
|
let content = UNMutableNotificationContent()
|
|
content.userInfo["entity_id"] = "camera.any"
|
|
let promise = parser.attachmentInfo(from: content)
|
|
|
|
guard let result = promise.wait().attachmentInfo else {
|
|
XCTFail("not an attachment")
|
|
return
|
|
}
|
|
|
|
XCTAssertEqual(result.url, URL(string: "/api/camera_proxy/camera.any"))
|
|
XCTAssertEqual(result.needsAuth, true)
|
|
XCTAssertEqual(result.typeHint, kUTTypeJPEG)
|
|
XCTAssertEqual(result.hideThumbnail, nil)
|
|
}
|
|
}
|