iOS/Sources/SharedTesting/SnapshotTestingHelper.swift
Bruno Pantaleão Gonçalves 7a0e42adc0
Update main window tint (#3572)
<!-- 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. -->
2025-04-28 16:03:40 +02:00

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
)
}
}