Files
iOS/Tests/App/WebView/WebViewExternalBusMessageTests.swift
Bruno Pantaleão Gonçalves 1f24517b54 Support opening iOS Assist settings from frontend (#4410)
<!-- Thank you for submitting a Pull Request and helping to improve Home
Assistant. Please complete the following sections to help the processing
and review of your changes. Please do not delete anything from this
template. -->

## Summary
<!-- Provide a brief summary of the changes you have made and most
importantly what they aim to achieve -->

## Screenshots
<!-- If this is a user-facing change not in the frontend, please include
screenshots in light and dark mode. -->

## Link to pull request in Documentation repository
<!-- Pull requests that add, change or remove functionality must have a
corresponding pull request in the Companion App Documentation repository
(https://github.com/home-assistant/companion.home-assistant). Please add
the number of this pull request after the "#" -->
Documentation: home-assistant/companion.home-assistant#

## Any other notes
<!-- If there is any other information of note, like if this Pull
Request is part of a bigger change, please include it here. -->

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-03-24 13:11:55 +01:00

85 lines
4.2 KiB
Swift

@testable import HomeAssistant
import XCTest
final class WebViewExternalBusMessageTests: XCTestCase {
func testExternalBusMessageKeys() {
XCTAssertEqual(WebViewExternalBusMessage.configGet.rawValue, "config/get")
XCTAssertEqual(WebViewExternalBusMessage.configScreenShow.rawValue, "config_screen/show")
XCTAssertEqual(WebViewExternalBusMessage.haptic.rawValue, "haptic")
XCTAssertEqual(WebViewExternalBusMessage.connectionStatus.rawValue, "connection-status")
XCTAssertEqual(WebViewExternalBusMessage.tagRead.rawValue, "tag/read")
XCTAssertEqual(WebViewExternalBusMessage.tagWrite.rawValue, "tag/write")
XCTAssertEqual(WebViewExternalBusMessage.themeUpdate.rawValue, "theme-update")
XCTAssertEqual(WebViewExternalBusMessage.matterCommission.rawValue, "matter/commission")
XCTAssertEqual(WebViewExternalBusMessage.threadImportCredentials.rawValue, "thread/import_credentials")
XCTAssertEqual(WebViewExternalBusMessage.barCodeScanner.rawValue, "bar_code/scan")
XCTAssertEqual(WebViewExternalBusMessage.barCodeScannerClose.rawValue, "bar_code/close")
XCTAssertEqual(WebViewExternalBusMessage.barCodeScannerNotify.rawValue, "bar_code/notify")
XCTAssertEqual(
WebViewExternalBusMessage.threadStoreCredentialInAppleKeychain.rawValue,
"thread/store_in_platform_keychain"
)
XCTAssertEqual(
WebViewExternalBusMessage.assistShow.rawValue,
"assist/show"
)
XCTAssertEqual(
WebViewExternalBusMessage.assistSettings.rawValue,
"assist/settings"
)
XCTAssertEqual(WebViewExternalBusMessage.scanForImprov.rawValue, "improv/scan")
XCTAssertEqual(WebViewExternalBusMessage.improvConfigureDevice.rawValue, "improv/configure_device")
XCTAssertEqual(WebViewExternalBusMessage.focusElement.rawValue, "focus_element")
XCTAssertEqual(WebViewExternalBusMessage.toastShow.rawValue, "toast/show")
XCTAssertEqual(WebViewExternalBusMessage.toastHide.rawValue, "toast/hide")
XCTAssertEqual(WebViewExternalBusMessage.entityAddToGetActions.rawValue, "entity/add_to/get_actions")
XCTAssertEqual(WebViewExternalBusMessage.entityAddTo.rawValue, "entity/add_to")
XCTAssertEqual(WebViewExternalBusMessage.cameraPlayerShow.rawValue, "camera/show")
XCTAssertEqual(WebViewExternalBusMessage.allCases.count, 23)
}
func testExternalBusOutgoingMessageKeys() {
XCTAssertEqual(WebViewExternalBusOutgoingMessage.showSidebar.rawValue, "sidebar/show")
XCTAssertEqual(WebViewExternalBusOutgoingMessage.showAutomationEditor.rawValue, "automation/editor/show")
XCTAssertEqual(WebViewExternalBusOutgoingMessage.barCodeScanResult.rawValue, "bar_code/scan_result")
XCTAssertEqual(WebViewExternalBusOutgoingMessage.barCodeScanAborted.rawValue, "bar_code/aborted")
XCTAssertEqual(WebViewExternalBusOutgoingMessage.improvDiscoveredDevice.rawValue, "improv/discovered_device")
XCTAssertEqual(
WebViewExternalBusOutgoingMessage.improvDiscoveredDeviceSetupDone.rawValue,
"improv/device_setup_done"
)
XCTAssertEqual(
WebViewExternalBusOutgoingMessage.navigate.rawValue,
"navigate"
)
XCTAssertEqual(WebViewExternalBusOutgoingMessage.allCases.count, 7)
}
@MainActor func testConfigResultIncludesAllExpectedKeys() {
let result = WebViewExternalBusMessage.configResult
// Expected keys currently defined in WebViewExternalBusMessage.configResult
let expectedKeys: Set<String> = [
"hasSettingsScreen",
"canWriteTag",
"canCommissionMatter",
"canImportThreadCredentials",
"hasBarCodeScanner",
"canTransferThreadCredentialsToKeychain",
"hasAssist",
"hasAssistSettings",
"hasCameraPlayer",
"canSetupImprov",
"downloadFileSupported",
"hasEntityAddTo",
"appVersion",
"toastComponentVersion",
]
let actualKeys = Set(result.keys)
XCTAssertTrue(expectedKeys.isSubset(of: actualKeys), "Missing keys: \(expectedKeys.subtracting(actualKeys))")
}
}