mirror of
https://github.com/home-assistant/iOS.git
synced 2026-02-04 21:15:17 -06:00
<!-- 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. -->
75 lines
2.3 KiB
Swift
75 lines
2.3 KiB
Swift
import SwiftUI
|
|
|
|
import SnapshotTesting
|
|
|
|
public func assertSnapshot<Value>(
|
|
of value: @autoclosure () throws -> Value,
|
|
drawHierarchyInKeyWindow: Bool = false,
|
|
layout: SwiftUISnapshotLayout = SwiftUISnapshotLayout.device(config: .iPhone13(.portrait)),
|
|
traits: UITraitCollection = .init(),
|
|
named: String? = nil,
|
|
record recording: Bool? = nil,
|
|
timeout: TimeInterval = 5,
|
|
fileID: StaticString = #fileID,
|
|
file filePath: StaticString = #filePath,
|
|
testName: String = #function,
|
|
line: UInt = #line,
|
|
column: UInt = #column
|
|
) where Value: SwiftUI.View {
|
|
try assertSnapshot(
|
|
of: value(),
|
|
as: Snapshotting<Value, UIImage>.image(
|
|
drawHierarchyInKeyWindow: drawHierarchyInKeyWindow,
|
|
precision: 0.96,
|
|
perceptualPrecision: 0.96,
|
|
layout: layout,
|
|
traits: traits
|
|
),
|
|
named: named,
|
|
record: recording,
|
|
timeout: timeout,
|
|
fileID: fileID,
|
|
file: filePath,
|
|
testName: testName,
|
|
line: line,
|
|
column: column
|
|
)
|
|
}
|
|
|
|
public func assertLightDarkSnapshots(
|
|
of value: @autoclosure () throws -> some SwiftUI.View,
|
|
drawHierarchyInKeyWindow: Bool = false,
|
|
layout: SwiftUISnapshotLayout = SwiftUISnapshotLayout.device(config: .iPhone13(.portrait)),
|
|
named: String? = nil,
|
|
record recording: Bool? = nil,
|
|
timeout: TimeInterval = 5,
|
|
fileID: StaticString = #fileID,
|
|
file filePath: StaticString = #filePath,
|
|
testName: String = #function,
|
|
line: UInt = #line,
|
|
column: UInt = #column
|
|
) {
|
|
for style in [UIUserInterfaceStyle.light, UIUserInterfaceStyle.dark] {
|
|
let finalNamed: String
|
|
if let named {
|
|
finalNamed = "\(named)-\(style == .light ? "light" : "dark")"
|
|
} else {
|
|
finalNamed = style == .light ? "light" : "dark"
|
|
}
|
|
try assertSnapshot(
|
|
of: value(),
|
|
drawHierarchyInKeyWindow: drawHierarchyInKeyWindow,
|
|
layout: layout,
|
|
traits: .init(userInterfaceStyle: style),
|
|
named: finalNamed,
|
|
record: recording,
|
|
timeout: timeout,
|
|
fileID: fileID,
|
|
file: filePath,
|
|
testName: testName,
|
|
line: line,
|
|
column: column
|
|
)
|
|
}
|
|
}
|