Prefire compatibility with Xcode 15 (#1773)

* xcode ready solution

* now the previews won't fail but get generated

* delay in some screens that require a waiting state (the bloom does not work in previews)

* better code

* longer delay

removed and redone lfs

readded as lfs
This commit is contained in:
Mauro 2023-09-21 09:50:34 +02:00 committed by Mauro Romito
parent 7048a0e4ad
commit 8b69308e05
195 changed files with 39 additions and 848 deletions

2
.gitattributes vendored
View File

@ -1,3 +1,3 @@
UITests/Sources/__Snapshots__/** filter=lfs diff=lfs merge=lfs -text
UnitTests/Resources/** filter=lfs diff=lfs merge=lfs -text
UnitTests/Sources/__Snapshots__/** filter=lfs diff=lfs merge=lfs -text
UnitTests/__Snapshots__/** filter=lfs diff=lfs merge=lfs -text

View File

@ -1,5 +1,4 @@
test_configuration:
- test_file_path: UnitTests/Sources/PreviewTests.swift
- template_file_path: Tools/Prefire/PreviewTests.stencil
- simulator_device: "iPhone14"
- required_os: 16

View File

@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 54;
objectVersion = 56;
objects = {
/* Begin PBXBuildFile section */
@ -493,7 +493,6 @@
9BEA56957B3AF954E7321658 /* ComposerToolbarViewModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = E44928D844E16EE48A311FCA /* ComposerToolbarViewModelProtocol.swift */; };
9C45CE85325CD591DADBC4CA /* ElementXTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBFEAC3AC691CBB84983E275 /* ElementXTests.swift */; };
9C5A07E7C33F3F40287D7861 /* SettingsScreenUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8EC57A32ABC80D774CC663DB /* SettingsScreenUITests.swift */; };
9C7895941669EA7976A18D88 /* PreviewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A01505B6371171413C3C4BD /* PreviewTests.swift */; };
9CCC77C31CB399661A034739 /* UserProperties+Element.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A6C4BE591FE5C38CE9C7EF3 /* UserProperties+Element.swift */; };
9D2E03DB175A6AB14589076D /* Algorithms in Frameworks */ = {isa = PBXBuildFile; productRef = 290FDEDA4D764B9F7EBE55A9 /* Algorithms */; };
9D79B94493FB32249F7E472F /* PlaceholderAvatarImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C705E605EF57C19DBE86FFA1 /* PlaceholderAvatarImage.swift */; };
@ -937,7 +936,7 @@
127C8472672A5BA09EF1ACF8 /* CurrentValuePublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentValuePublisher.swift; sourceTree = "<group>"; };
12EDAFB64FA5F6812D54F39A /* MigrationScreenViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MigrationScreenViewModel.swift; sourceTree = "<group>"; };
12F1E7F9C2BE8BB751037826 /* WaitlistScreenCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WaitlistScreenCoordinator.swift; sourceTree = "<group>"; };
1304D9191300873EADA52D6E /* IntegrationTests.xctestplan */ = {isa = PBXFileReference; path = IntegrationTests.xctestplan; sourceTree = "<group>"; };
1304D9191300873EADA52D6E /* IntegrationTests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = IntegrationTests.xctestplan; sourceTree = "<group>"; };
130ED565A078F7E0B59D9D25 /* UNTextInputNotificationResponse+Creator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UNTextInputNotificationResponse+Creator.swift"; sourceTree = "<group>"; };
13802897C7AFA360EA74C0B0 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = en; path = en.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
1423AB065857FA546444DB15 /* NotificationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationManager.swift; sourceTree = "<group>"; };
@ -1089,7 +1088,7 @@
47111410B6E659A697D472B5 /* RoomProxyProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomProxyProtocol.swift; sourceTree = "<group>"; };
471EB7D96AFEA8D787659686 /* EmoteRoomTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmoteRoomTimelineView.swift; sourceTree = "<group>"; };
47873756E45B46683D97DC32 /* LegalInformationScreenModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegalInformationScreenModels.swift; sourceTree = "<group>"; };
478BE8591BD13E908EF70C0C /* DesignKit */ = {isa = PBXFileReference; lastKnownFileType = folder; name = DesignKit; path = DesignKit; sourceTree = SOURCE_ROOT; };
478BE8591BD13E908EF70C0C /* DesignKit */ = {isa = PBXFileReference; lastKnownFileType = folder; path = DesignKit; sourceTree = SOURCE_ROOT; };
4798B3B7A1E8AE3901CEE8C6 /* FramePreferenceKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FramePreferenceKey.swift; sourceTree = "<group>"; };
47EBB5D698CE9A25BB553A2D /* Strings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Strings.swift; sourceTree = "<group>"; };
47F29139BC2A804CE5E0757E /* MediaUploadPreviewScreenViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaUploadPreviewScreenViewModel.swift; sourceTree = "<group>"; };
@ -1099,7 +1098,6 @@
49E45C3DC740D3AB9A47FD32 /* SwipeToReplyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwipeToReplyView.swift; sourceTree = "<group>"; };
49E6066092ED45E36BB306F7 /* zh-Hant-TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "zh-Hant-TW"; path = "zh-Hant-TW.lproj/Localizable.stringsdict"; sourceTree = "<group>"; };
49E751D7EDB6043238111D90 /* UNNotificationRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UNNotificationRequest.swift; sourceTree = "<group>"; };
4A01505B6371171413C3C4BD /* PreviewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewTests.swift; sourceTree = "<group>"; };
4A4AD793D50748F8997E5B15 /* TimelineItemMacContextMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineItemMacContextMenu.swift; sourceTree = "<group>"; };
4AB7D7DAAAF662DED9D02379 /* MockMediaLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockMediaLoader.swift; sourceTree = "<group>"; };
4ADC55DFF46083BC957E0019 /* CreatePollScreenModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePollScreenModels.swift; sourceTree = "<group>"; };
@ -1287,7 +1285,7 @@
8D55702474F279D910D2D162 /* RoomStateEventStringBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomStateEventStringBuilder.swift; sourceTree = "<group>"; };
8D8169443E5AC5FF71BFB3DB /* cs */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = cs; path = cs.lproj/Localizable.strings; sourceTree = "<group>"; };
8DC2C9E0E15C79BBDA80F0A2 /* TimelineStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineStyle.swift; sourceTree = "<group>"; };
8E088F2A1B9EC529D3221931 /* UITests.xctestplan */ = {isa = PBXFileReference; path = UITests.xctestplan; sourceTree = "<group>"; };
8E088F2A1B9EC529D3221931 /* UITests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = UITests.xctestplan; sourceTree = "<group>"; };
8E1BBA73B611EDEEA6E20E05 /* InvitesScreenModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InvitesScreenModels.swift; sourceTree = "<group>"; };
8EC57A32ABC80D774CC663DB /* SettingsScreenUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsScreenUITests.swift; sourceTree = "<group>"; };
8F21ED7205048668BEB44A38 /* AppActivityView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppActivityView.swift; sourceTree = "<group>"; };
@ -1401,7 +1399,7 @@
B4CFE236419E830E8946639C /* Analytics+SwiftUI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Analytics+SwiftUI.swift"; sourceTree = "<group>"; };
B590BD4507D4F0A377FDE01A /* LoadableAvatarImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadableAvatarImage.swift; sourceTree = "<group>"; };
B5B243E7818E5E9F6A4EDC7A /* NoticeRoomTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoticeRoomTimelineView.swift; sourceTree = "<group>"; };
B61C339A2FDDBD067FF6635C /* ConfettiScene.scn */ = {isa = PBXFileReference; path = ConfettiScene.scn; sourceTree = "<group>"; };
B61C339A2FDDBD067FF6635C /* ConfettiScene.scn */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; path = ConfettiScene.scn; sourceTree = "<group>"; };
B6311F21F911E23BE4DF51B4 /* ReadMarkerRoomTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReadMarkerRoomTimelineView.swift; sourceTree = "<group>"; };
B63B69F9A2BC74DD40DC75C8 /* AdvancedSettingsScreenViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdvancedSettingsScreenViewModel.swift; sourceTree = "<group>"; };
B697816AF93DA06EC58C5D70 /* WaitlistScreenViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WaitlistScreenViewModelProtocol.swift; sourceTree = "<group>"; };
@ -1492,7 +1490,7 @@
CD95B3714F806AC9CF9A557B /* ComposerToolbarViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposerToolbarViewModel.swift; sourceTree = "<group>"; };
CDB3227C7A74B734924942E9 /* RoomSummaryProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomSummaryProvider.swift; sourceTree = "<group>"; };
CEE0E6043EFCF6FD2A341861 /* TimelineReplyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineReplyView.swift; sourceTree = "<group>"; };
CEE41494C837AA403A06A5D9 /* UnitTests.xctestplan */ = {isa = PBXFileReference; path = UnitTests.xctestplan; sourceTree = "<group>"; };
CEE41494C837AA403A06A5D9 /* UnitTests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = UnitTests.xctestplan; sourceTree = "<group>"; };
CF48AF076424DBC1615C74AD /* AuthenticationServiceProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationServiceProxy.swift; sourceTree = "<group>"; };
D0140615D2232612C813FD6C /* EncryptedHistoryRoomTimelineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncryptedHistoryRoomTimelineItem.swift; sourceTree = "<group>"; };
D071F86CD47582B9196C9D16 /* UserDiscoverySection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDiscoverySection.swift; sourceTree = "<group>"; };
@ -1578,7 +1576,7 @@
ECF79FB25E2D4BD6F50CE7C9 /* RoomMembersListScreenViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomMembersListScreenViewModel.swift; sourceTree = "<group>"; };
ED044D00F2176681CC02CD54 /* HomeScreenRoomCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeScreenRoomCell.swift; sourceTree = "<group>"; };
ED1D792EB82506A19A72C8DE /* RoomTimelineItemProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomTimelineItemProtocol.swift; sourceTree = "<group>"; };
ED482057AE39D5C6D9C5F3D8 /* message.caf */ = {isa = PBXFileReference; path = message.caf; sourceTree = "<group>"; };
ED482057AE39D5C6D9C5F3D8 /* message.caf */ = {isa = PBXFileReference; lastKnownFileType = file; path = message.caf; sourceTree = "<group>"; };
ED983D4DCA5AFA6E1ED96099 /* StateRoomTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StateRoomTimelineView.swift; sourceTree = "<group>"; };
EDAA4472821985BF868CC21C /* ServerSelectionViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerSelectionViewModelTests.swift; sourceTree = "<group>"; };
EE378083653EF0C9B5E9D580 /* EmoteRoomTimelineItemContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmoteRoomTimelineItemContent.swift; sourceTree = "<group>"; };
@ -1592,7 +1590,7 @@
F174A5627CDB3CAF280D1880 /* EmojiPickerScreenModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiPickerScreenModels.swift; sourceTree = "<group>"; };
F17EFA1D3D09FC2F9C5E1CB2 /* MediaProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaProvider.swift; sourceTree = "<group>"; };
F1B8500C152BC59445647DA8 /* UnsupportedRoomTimelineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnsupportedRoomTimelineItem.swift; sourceTree = "<group>"; };
F2D513D2477B57F90E98EEC0 /* portrait_test_video.mp4 */ = {isa = PBXFileReference; path = portrait_test_video.mp4; sourceTree = "<group>"; };
F2D513D2477B57F90E98EEC0 /* portrait_test_video.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = portrait_test_video.mp4; sourceTree = "<group>"; };
F31F59030205A6F65B057E1A /* MatrixEntityRegexTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatrixEntityRegexTests.swift; sourceTree = "<group>"; };
F348B5F2C12F9D4F4B4D3884 /* VideoRoomTimelineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoRoomTimelineItem.swift; sourceTree = "<group>"; };
F36C0A6D59717193F49EA986 /* UserSessionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSessionTests.swift; sourceTree = "<group>"; };
@ -2693,7 +2691,6 @@
514363244AE7D68080D44C6F /* NotificationSettingsScreenViewModelTests.swift */,
D53D6BB7E8E5EC031281872C /* OnboardingScreenViewModelTests.swift */,
6FB31A32C93D94930B253FBF /* PermalinkBuilderTests.swift */,
4A01505B6371171413C3C4BD /* PreviewTests.swift */,
086C19086DD16E9B38E25954 /* ReportContentViewModelTests.swift */,
00E5B2CBEF8F96424F095508 /* RoomDetailsEditScreenViewModelTests.swift */,
2EFE1922F39398ABFB36DF3F /* RoomDetailsViewModelTests.swift */,
@ -4469,7 +4466,6 @@
E3AC72E3E58F364EF15C1CC7 /* NotificationSettingsScreenViewModelTests.swift in Sources */,
0C26A1588B17DCDE5F490FE3 /* OnboardingScreenViewModelTests.swift in Sources */,
27E9263DA75E266690A37EB1 /* PermalinkBuilderTests.swift in Sources */,
9C7895941669EA7976A18D88 /* PreviewTests.swift in Sources */,
D415764645491F10344FC6AC /* Publisher.swift in Sources */,
D53B80EF02C1062E68659EDD /* ReportContentViewModelTests.swift in Sources */,
9DD84E014ADFB2DD813022D5 /* RoomDetailsEditScreenViewModelTests.swift in Sources */,
@ -5698,7 +5694,7 @@
repositoryURL = "https://github.com/BarredEwe/Prefire";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 1.4.1;
minimumVersion = 1.5.0;
};
};
395DE6AE429B7ACC7C7FE31D /* XCRemoteSwiftPackageReference "KZFileWatchers" */ = {

View File

@ -156,8 +156,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/BarredEwe/Prefire",
"state" : {
"revision" : "abb8dfa44391b4f47edb4937a4ba124e76270a87",
"version" : "1.4.1"
"revision" : "898a4a9f5d5eb0a0b07adb1a7c89daf0f068b129",
"version" : "1.5.0"
}
},
{

View File

@ -324,11 +324,13 @@ struct HomeScreen_Previews: PreviewProvider, TestablePreview {
HomeScreen(context: loadedViewModel.context)
}
.previewDisplayName("Loaded")
.snapshot(delay: 2.0)
NavigationStack {
HomeScreen(context: emptyViewModel.context)
}
.previewDisplayName("Empty")
.snapshot(delay: 2.0)
}
static func viewModel(_ state: MockRoomSummaryProviderState) -> HomeScreenViewModel {

View File

@ -42,8 +42,8 @@ class PreviewTests: XCTestCase {
private func assertSnapshots(matching preview: _Preview, testName: String = #function) {
let isScreen = preview.layout == .device
let device = preview.device?.snapshotDevice() ?? deviceConfig
var delay: TimeInterval = 1.0
var precision: Float = 0.99
var delay: TimeInterval = 0
var precision: Float = 1
let view = preview.content
.onPreferenceChange(DelayPreferenceKey.self) { delay = $0 }
@ -54,13 +54,17 @@ class PreviewTests: XCTestCase {
.fixedSize(horizontal: false, vertical: true)
)
assertSnapshot(
matching: matchingView,
as: .prefireImage(precision: { precision }, duration: { delay }, layout: isScreen ? .device(config: device) : .sizeThatFits),
named: preview.displayName{% if argument.file %},
file: file{% endif %},
testName: testName
)
let failure = verifySnapshot(of: matchingView,
as: .prefireImage(precision: { precision }, duration: { delay }, layout: isScreen ? .device(config: device) : .sizeThatFits),
named: preview.displayName{% if argument.file %},
file: file{% endif %},
testName: testName)
if let failure,
!failure.contains("No reference was found on disk."),
!failure.contains("to test against the newly-recorded snapshot") {
XCTFail(failure)
}
#if canImport(AccessibilitySnapshot)
let vc = UIHostingController(rootView: matchingView)
@ -83,9 +87,13 @@ class PreviewTests: XCTestCase {
fatalError("Switch to using \(simulatorDevice) for these tests.")
}
guard osVersion.majorVersion == requiredOSVersion else {
guard osVersion.majorVersion == requiredOSVersion else {
fatalError("Switch to iOS \(requiredOSVersion) for these tests.")
}
guard UITraitCollection.current.userInterfaceStyle == .light else {
fatalError("Switch to light mode for these tests.")
}
}
}

View File

@ -1,812 +0,0 @@
// Generated using Sourcery 2.0.1 https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
// swiftlint:disable all
// swiftformat:disable all
import XCTest
import SwiftUI
import Prefire
@testable import SnapshotTesting
#if canImport(AccessibilitySnapshot)
import AccessibilitySnapshot
#endif
@testable import ElementX
class PreviewTests: XCTestCase {
private let deviceConfig: ViewImageConfig = .iPhoneX
private let simulatorDevice = "iPhone14"
private let requiredOSVersion = 16
override func setUp() {
super.setUp()
checkEnvironments()
UIView.setAnimationsEnabled(false)
}
func test_advancedSettingsScreen() {
for preview in AdvancedSettingsScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_analyticsPromptScreenCheckmarkItem() {
for preview in AnalyticsPromptScreenCheckmarkItem_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_analyticsPromptScreen() {
for preview in AnalyticsPromptScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_analyticsSettingsScreen() {
for preview in AnalyticsSettingsScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_audioRoomTimelineView() {
for preview in AudioRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_authenticationIconImage() {
for preview in AuthenticationIconImage_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_bugReport() {
for preview in BugReport_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_collapsibleRoomTimelineView() {
for preview in CollapsibleRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_composerToolbar() {
for preview in ComposerToolbar_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_createPollScreen() {
for preview in CreatePollScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_createRoom() {
for preview in CreateRoom_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_emojiPickerScreenHeaderView() {
for preview in EmojiPickerScreenHeaderView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_emojiPickerScreen() {
for preview in EmojiPickerScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_emoteRoomTimelineView() {
for preview in EmoteRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_encryptedHistoryRoomTimelineView() {
for preview in EncryptedHistoryRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_encryptedRoomTimelineView() {
for preview in EncryptedRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_fileRoomTimelineView() {
for preview in FileRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_formButtonStyles() {
for preview in FormButtonStyles_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_formRowLabelStyle() {
for preview in FormRowLabelStyle_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_formattedBodyText() {
for preview in FormattedBodyText_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_fullscreenDialog() {
for preview in FullscreenDialog_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_headerView() {
for preview in HeaderView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_homeScreenEmptyStateView() {
for preview in HomeScreenEmptyStateView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_homeScreenInvitesButton() {
for preview in HomeScreenInvitesButton_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_homeScreenRoomCell() {
for preview in HomeScreenRoomCell_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_homeScreen() {
for preview in HomeScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_imageRoomTimelineView() {
for preview in ImageRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_inviteUsersScreenSelectedItem() {
for preview in InviteUsersScreenSelectedItem_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_inviteUsersScreen() {
for preview in InviteUsersScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_invitesScreenCell() {
for preview in InvitesScreenCell_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_invitesScreen() {
for preview in InvitesScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_legalInformationScreen() {
for preview in LegalInformationScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_locationMarkerView() {
for preview in LocationMarkerView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_locationRoomTimelineView() {
for preview in LocationRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_loginScreen() {
for preview in LoginScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_longPressWithFeedback() {
for preview in LongPressWithFeedback_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_mapLibreStaticMapView() {
for preview in MapLibreStaticMapView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_matrixUserPermalink() {
for preview in MatrixUserPermalink_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_mediaUploadPreviewScreen() {
for preview in MediaUploadPreviewScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_messageComposer() {
for preview in MessageComposer_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_messageForwardingScreen() {
for preview in MessageForwardingScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_messageText() {
for preview in MessageText_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_migrationScreen() {
for preview in MigrationScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_noticeRoomTimelineView() {
for preview in NoticeRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_notificationSettingsEditScreenRoomCell() {
for preview in NotificationSettingsEditScreenRoomCell_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_notificationSettingsEditScreen() {
for preview in NotificationSettingsEditScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_notificationSettingsScreen() {
for preview in NotificationSettingsScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_onboardingScreen() {
for preview in OnboardingScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_paginationIndicatorRoomTimelineView() {
for preview in PaginationIndicatorRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_pillView() {
for preview in PillView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_placeholderAvatarImage() {
for preview in PlaceholderAvatarImage_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_placeholderScreen() {
for preview in PlaceholderScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_pollOptionView() {
for preview in PollOptionView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_pollRoomTimelineView() {
for preview in PollRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_reactionsSummaryView() {
for preview in ReactionsSummaryView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_readMarkerRoomTimelineView() {
for preview in ReadMarkerRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_redactedRoomTimelineView() {
for preview in RedactedRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_reportContentScreen() {
for preview in ReportContentScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_roomAttachmentPicker() {
for preview in RoomAttachmentPicker_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_roomDetailsEditScreen() {
for preview in RoomDetailsEditScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_roomDetailsScreen() {
for preview in RoomDetailsScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_roomHeaderView() {
for preview in RoomHeaderView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_roomMemberDetailsScreen() {
for preview in RoomMemberDetailsScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_roomMembersListMemberCell() {
for preview in RoomMembersListMemberCell_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_roomMembersListScreen() {
for preview in RoomMembersListScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_roomNotificationSettingsCustomSectionView() {
for preview in RoomNotificationSettingsCustomSectionView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_roomNotificationSettingsScreen() {
for preview in RoomNotificationSettingsScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_roomNotificationSettingsUserDefinedScreen() {
for preview in RoomNotificationSettingsUserDefinedScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_roomScreen() {
for preview in RoomScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_separatorRoomTimelineView() {
for preview in SeparatorRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_serverConfirmationScreen() {
for preview in ServerConfirmationScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_serverSelection() {
for preview in ServerSelection_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_sessionVerification() {
for preview in SessionVerification_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_settingsScreen() {
for preview in SettingsScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_shimmerOverlay() {
for preview in ShimmerOverlay_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_softLogoutScreen() {
for preview in SoftLogoutScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_splashScreen() {
for preview in SplashScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_startChatScreen() {
for preview in StartChatScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_stateRoomTimelineView() {
for preview in StateRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_staticLocationScreenViewer() {
for preview in StaticLocationScreenViewer_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_stickerRoomTimelineView() {
for preview in StickerRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_swipeRightAction() {
for preview in SwipeRightAction_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_swipeToReplyView() {
for preview in SwipeToReplyView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_templateScreen() {
for preview in TemplateScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_textRoomTimelineView() {
for preview in TextRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_threadDecorator() {
for preview in ThreadDecorator_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_timelineDeliveryStatusView() {
for preview in TimelineDeliveryStatusView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_timelineItemBubbledStylerView() {
for preview in TimelineItemBubbledStylerView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_timelineItemDebugView() {
for preview in TimelineItemDebugView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_timelineItemMenu() {
for preview in TimelineItemMenu_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_timelineItemPlainStylerView() {
for preview in TimelineItemPlainStylerView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_timelineItemStyler() {
for preview in TimelineItemStyler_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_timelineReactionView() {
for preview in TimelineReactionView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_timelineReadReceiptsView() {
for preview in TimelineReadReceiptsView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_timelineReplyView() {
for preview in TimelineReplyView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_timelineStartRoomTimelineView() {
for preview in TimelineStartRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_timelineView() {
for preview in TimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_uITimelineView() {
for preview in UITimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_unsupportedRoomTimelineView() {
for preview in UnsupportedRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_userDetailsEditScreen() {
for preview in UserDetailsEditScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_userIndicatorModalView() {
for preview in UserIndicatorModalView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_userIndicatorToastView() {
for preview in UserIndicatorToastView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_userProfileCell() {
for preview in UserProfileCell_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_videoRoomTimelineView() {
for preview in VideoRoomTimelineView_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_waitingDialog() {
for preview in WaitingDialog_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_waitlistScreen() {
for preview in WaitlistScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
func test_welcomeScreen() {
for preview in WelcomeScreen_Previews._allPreviews {
assertSnapshots(matching: preview)
}
}
// MARK: Private
private func assertSnapshots(matching preview: _Preview, testName: String = #function) {
let isScreen = preview.layout == .device
let device = preview.device?.snapshotDevice() ?? deviceConfig
var delay: TimeInterval = 1.0
var precision: Float = 0.99
let view = preview.content
.onPreferenceChange(DelayPreferenceKey.self) { delay = $0 }
.onPreferenceChange(PrecisionPreferenceKey.self) { precision = $0 }
let matchingView = isScreen ? AnyView(view) : AnyView(view
.frame(width: device.size?.width)
.fixedSize(horizontal: false, vertical: true)
)
assertSnapshot(
matching: matchingView,
as: .prefireImage(precision: { precision }, duration: { delay }, layout: isScreen ? .device(config: device) : .sizeThatFits),
named: preview.displayName,
testName: testName
)
#if canImport(AccessibilitySnapshot)
let vc = UIHostingController(rootView: matchingView)
vc.view.frame = UIScreen.main.bounds
assertSnapshot(
matching: vc,
as: .wait(for: delay, on: .accessibilityImage(showActivationPoints: .always)),
named: preview.displayName.map { $0 + ".accessibility" },
testName: testName
)
#endif
}
/// Check environments to avoid problems with snapshots on different devices or OS.
private func checkEnvironments() {
let deviceModel = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"]
let osVersion = ProcessInfo().operatingSystemVersion
guard deviceModel?.contains(simulatorDevice) ?? false else {
fatalError("Switch to using \(simulatorDevice) for these tests.")
}
guard osVersion.majorVersion == requiredOSVersion else {
fatalError("Switch to iOS \(requiredOSVersion) for these tests.")
}
}
}
// MARK: - SnapshotTesting + Extensions
private extension PreviewDevice {
func snapshotDevice() -> ViewImageConfig? {
switch rawValue {
case "iPhone 14", "iPhone 13", "iPhone 12", "iPhone 11", "iPhone 10":
return .iPhoneX
case "iPhone 6", "iPhone 6s", "iPhone 7", "iPhone 8":
return .iPhone8
case "iPhone 6 Plus", "iPhone 6s Plus", "iPhone 8 Plus":
return .iPhone8Plus
case "iPhone SE (1st generation)", "iPhone SE (2nd generation)":
return .iPhoneSe
default: return nil
}
}
}
private extension Snapshotting where Value: SwiftUI.View, Format == UIImage {
static func prefireImage(
drawHierarchyInKeyWindow: Bool = false,
precision: @escaping () -> Float,
duration: @escaping () -> TimeInterval,
layout: SwiftUISnapshotLayout = .sizeThatFits,
traits: UITraitCollection = .init()
) -> Snapshotting {
let config: ViewImageConfig
switch layout {
#if os(iOS) || os(tvOS)
case let .device(config: deviceConfig):
config = deviceConfig
#endif
case .sizeThatFits:
config = .init(safeArea: .zero, size: nil, traits: traits)
case let .fixed(width: width, height: height):
let size = CGSize(width: width, height: height)
config = .init(safeArea: .zero, size: size, traits: traits)
}
return SimplySnapshotting<UIImage>(pathExtension: "png", diffing: .prefireImage(precision: precision, scale: traits.displayScale))
.asyncPullback { view in
var config = config
let controller: UIViewController
if config.size != nil {
controller = UIHostingController(rootView: view)
} else {
let hostingController = UIHostingController(rootView: view)
let maxSize = CGSize.zero
config.size = hostingController.sizeThatFits(in: maxSize)
controller = hostingController
}
return Async<UIImage> { callback in
let strategy = snapshotView(
config: config,
drawHierarchyInKeyWindow: drawHierarchyInKeyWindow,
traits: traits,
view: controller.view,
viewController: controller
)
let duration = duration()
if duration != .zero {
let expectation = XCTestExpectation(description: "Wait")
DispatchQueue.main.asyncAfter(deadline: .now() + duration) {
expectation.fulfill()
}
_ = XCTWaiter.wait(for: [expectation], timeout: duration + 1)
}
strategy.run(callback)
}
}
}
}
private extension Diffing where Value == UIImage {
static func prefireImage(precision: @escaping () -> Float, scale: CGFloat?) -> Diffing {
lazy var originalDiffing = Diffing.image(precision: precision(), perceptualPrecision: 0.98, scale: scale)
return Diffing(
toData: { originalDiffing.toData($0) },
fromData: { originalDiffing.fromData($0) },
diff: { originalDiffing.diff($0, $1) }
)
}
}
// swiftlint:enable all
// swiftformat:enable all

View File

@ -49,8 +49,6 @@ targets:
sources:
- path: ../Sources
excludes:
- "**/__Snapshots__/**"
- path: ../SupportingFiles
- path: ../../ElementX/Sources/Other/InfoPlistReader.swift
- path: ../../Tools/Scripts/Templates/SimpleScreenExample/Tests/Unit

Binary file not shown.

Binary file not shown.

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