Update Preview tests for Xcode 16.

This commit is contained in:
Doug 2024-09-18 17:18:18 +01:00 committed by Doug
parent 3514eba4a5
commit d41dd47b51
1179 changed files with 1455 additions and 1457 deletions

View File

@ -5,6 +5,7 @@
// Please see LICENSE in the repository root for full details.
//
import Compound
import SwiftUI
struct AvatarHeaderView<Footer: View>: View {
@ -193,7 +194,7 @@ struct AvatarHeaderView_Previews: PreviewProvider, TestablePreview {
mediaProvider: MockMediaProvider()) {
HStack(spacing: 32) {
ShareLink(item: "test") {
Image(systemName: "square.and.arrow.up")
CompoundIcon(\.shareIos)
}
.buttonStyle(FormActionButtonStyle(title: "Test"))
}
@ -207,7 +208,7 @@ struct AvatarHeaderView_Previews: PreviewProvider, TestablePreview {
mediaProvider: MockMediaProvider()) {
HStack(spacing: 32) {
ShareLink(item: "test") {
Image(systemName: "square.and.arrow.up")
CompoundIcon(\.shareIos)
}
.buttonStyle(FormActionButtonStyle(title: "Test"))
}

View File

@ -29,7 +29,7 @@ struct MatrixUserShareLink<Label: View>: View {
struct MatrixUserPermalink_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
MatrixUserShareLink(userID: "@someone:somewhere.org") {
Label("Share", systemImage: "square.and.arrow.up")
Label("Share", icon: \.shareIos)
}
}
}

View File

@ -5,7 +5,7 @@
// Please see LICENSE in the repository root for full details.
//
import Foundation
import Compound
import SwiftUI
struct FileRoomTimelineView: View {
@ -13,15 +13,15 @@ struct FileRoomTimelineView: View {
var body: some View {
TimelineStyler(timelineItem: timelineItem) {
Label(title: { Text(timelineItem.body) },
icon: { Image(systemName: "doc.text.fill")
.foregroundColor(.compound.iconPrimary)
})
.labelStyle(RoomTimelineViewLabelStyle())
.font(.compound.bodyLG)
.padding(.vertical, 12)
.padding(.horizontal, 6)
.accessibilityLabel(L10n.commonFile)
Label { Text(timelineItem.body) } icon: {
CompoundIcon(\.document)
.foregroundColor(.compound.iconPrimary)
}
.labelStyle(RoomTimelineViewLabelStyle())
.font(.compound.bodyLG)
.padding(.vertical, 8)
.padding(.horizontal, 6)
.accessibilityLabel(L10n.commonFile)
}
}
}

View File

@ -18,8 +18,8 @@ import AccessibilitySnapshot
class PreviewTests: XCTestCase {
private let deviceConfig: ViewImageConfig = .iPhoneX
private var simulatorDevice: String? = "iPhone14,6" // iPhone SE 3rd Generation
private var requiredOSVersion = (major: 17, minor: 5)
private let snapshotDevices = ["iPhone 15", "iPad"]
private var requiredOSVersion = (major: 18, minor: 0)
private let snapshotDevices = ["iPhone 16", "iPad"]
override func setUp() {
super.setUp()
@ -28,17 +28,27 @@ class PreviewTests: XCTestCase {
UIView.setAnimationsEnabled(false)
}
func assertSnapshots(matching preview: _Preview, testName: String = #function) {
guard !snapshotDevices.isEmpty else {
if let failure = assertSnapshots(matching: AnyView(preview.content),
name: preview.displayName,
isScreen: preview.layout == .device,
device: preview.device?.snapshotDevice() ?? deviceConfig,
testName: testName) {
XCTFail(failure)
/// Check environments to avoid problems with snapshots on different devices or OS.
private func checkEnvironments() {
if let simulatorDevice {
let deviceModel = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"]
guard deviceModel?.contains(simulatorDevice) ?? false else {
fatalError("\(deviceModel ?? "Unknown") is the wrong one. Switch to using \(simulatorDevice) for these tests.")
}
return
}
let osVersion = ProcessInfo().operatingSystemVersion
guard osVersion.majorVersion == requiredOSVersion.major, osVersion.minorVersion == requiredOSVersion.minor else {
fatalError("Switch to iOS \(requiredOSVersion) for these tests.")
}
guard !snapshotDevices.isEmpty else {
fatalError("Specify at least one snapshot device to test on.")
}
}
// MARK: - Snapshots
func assertSnapshots(matching preview: _Preview, testName: String = #function) {
for deviceName in snapshotDevices {
guard var device = PreviewDevice(rawValue: deviceName).snapshotDevice() else {
fatalError("Unknown device name: \(deviceName)")
@ -92,14 +102,16 @@ class PreviewTests: XCTestCase {
.fixedSize(horizontal: false, vertical: true)
)
let failure = verifySnapshot(of: matchingView,
as: .prefireImage(precision: { precision },
perceptualPrecision: { perceptualPrecision },
duration: { delay },
layout: isScreen ? .device(config: device) : .sizeThatFits,
traits: traits),
named: name,
testName: testName)
let failure = withSnapshotTesting(record: .missing) {
verifySnapshot(of: matchingView,
as: .prefireImage(precision: { precision },
perceptualPrecision: { perceptualPrecision },
duration: { delay },
layout: isScreen ? .device(config: device) : .sizeThatFits,
traits: traits),
named: name,
testName: testName)
}
#if canImport(AccessibilitySnapshot)
let vc = UIHostingController(rootView: matchingView)
@ -111,21 +123,6 @@ class PreviewTests: XCTestCase {
#endif
return failure
}
/// Check environments to avoid problems with snapshots on different devices or OS.
private func checkEnvironments() {
if let simulatorDevice {
let deviceModel = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"]
guard deviceModel?.contains(simulatorDevice) ?? false else {
fatalError("\(deviceModel ?? "Unknown") is the wrong one. Switch to using \(simulatorDevice) for these tests.")
}
}
let osVersion = ProcessInfo().operatingSystemVersion
guard osVersion.majorVersion == requiredOSVersion.major, osVersion.minorVersion == requiredOSVersion.minor else {
fatalError("Switch to iOS \(requiredOSVersion) for these tests.")
}
}
}
// MARK: - SnapshotTesting + Extensions
@ -133,7 +130,7 @@ class PreviewTests: XCTestCase {
private extension PreviewDevice {
func snapshotDevice() -> ViewImageConfig? {
switch rawValue {
case "iPhone 15", "iPhone 14", "iPhone 13", "iPhone 12", "iPhone 11", "iPhone 10":
case "iPhone 16", "iPhone 15", "iPhone 14", "iPhone 13", "iPhone 12", "iPhone 11", "iPhone 10":
return .iPhoneX
case "iPhone 6", "iPhone 6s", "iPhone 7", "iPhone 8":
return .iPhone8

Some files were not shown because too many files have changed in this diff Show More