Retrofit deferFulfillment onto snapshot tests. (#3641)

* Retrofit `deferFulfillment` onto snapshot tests.

* Convert a bunch of preview tests to the new fulfillment publisher

* Convert more tests

* Remove unneeded delays from the remaining tests

* Remove snapshotting delay option.
This commit is contained in:
Stefan Ceriu
2024-12-20 15:30:59 +02:00
committed by GitHub
parent 365797c8b7
commit 536f01abbd
49 changed files with 606 additions and 532 deletions
@@ -36,3 +36,17 @@ extension Publisher where Output == String, Failure == Never {
}
}
}
extension Published.Publisher {
/// Returns the next output from the publisher skipping the current value stored into it (which is readable from the @Published property itself).
/// - Returns: the next output from the publisher
var nextValue: Output? {
get async {
var iterator = values.makeAsyncIterator()
// skips the publisher's current value
_ = await iterator.next()
return await iterator.next()
}
}
}
@@ -14,33 +14,43 @@
// limitations under the License.
//
import Combine
import SwiftUI
public struct SnapshotDelayPreferenceKey: PreferenceKey {
public static var defaultValue: TimeInterval = 0.0
struct SnapshotPrecisionPreferenceKey: PreferenceKey {
static var defaultValue: Float = 1.0
public static func reduce(value: inout TimeInterval, nextValue: () -> TimeInterval) {
static func reduce(value: inout Float, nextValue: () -> Float) {
value = nextValue()
}
}
public struct SnapshotPrecisionPreferenceKey: PreferenceKey {
public static var defaultValue: Float = 1.0
struct SnapshotPerceptualPrecisionPreferenceKey: PreferenceKey {
static var defaultValue: Float = 0.98
public static func reduce(value: inout Float, nextValue: () -> Float) {
static func reduce(value: inout Float, nextValue: () -> Float) {
value = nextValue()
}
}
public struct SnapshotPerceptualPrecisionPreferenceKey: PreferenceKey {
public static var defaultValue: Float = 0.98
struct FulfillmentPublisherEquatableWrapper: Equatable {
let publisher: AnyPublisher<Bool, Never>?
// Publisher equatability complicates things but, luckily, we're only interesting in them changing from nil
static func == (lhs: FulfillmentPublisherEquatableWrapper, rhs: FulfillmentPublisherEquatableWrapper) -> Bool {
lhs.publisher != nil && rhs.publisher != nil
}
}
public static func reduce(value: inout Float, nextValue: () -> Float) {
struct SnapshotFulfillmentPublisherPreferenceKey: PreferenceKey {
static var defaultValue: FulfillmentPublisherEquatableWrapper?
static func reduce(value: inout FulfillmentPublisherEquatableWrapper?, nextValue: () -> FulfillmentPublisherEquatableWrapper?) {
value = nextValue()
}
}
public extension SwiftUI.View {
extension SwiftUI.View {
/// Use this modifier when you want to apply snapshot-specific preferences,
/// like delay and precision, to the view.
/// These preferences can then be retrieved and used elsewhere in your view hierarchy.
@@ -49,10 +59,11 @@ public extension SwiftUI.View {
/// - delay: The delay time in seconds that you want to set as a preference to the View.
/// - precision: The percentage of pixels that must match.
/// - perceptualPrecision: The percentage a pixel must match the source pixel to be considered a match. 98-99% mimics the precision of the human eye.
@inlinable
func snapshotPreferences(delay: TimeInterval = .zero, precision: Float = 1.0, perceptualPrecision: Float = 0.98) -> some SwiftUI.View {
preference(key: SnapshotDelayPreferenceKey.self, value: delay)
.preference(key: SnapshotPrecisionPreferenceKey.self, value: precision)
func snapshotPreferences(expect fulfillmentPublisher: (any Publisher<Bool, Never>)? = nil,
precision: Float = 1.0,
perceptualPrecision: Float = 0.98) -> some SwiftUI.View {
preference(key: SnapshotPrecisionPreferenceKey.self, value: precision)
.preference(key: SnapshotPerceptualPrecisionPreferenceKey.self, value: perceptualPrecision)
.preference(key: SnapshotFulfillmentPublisherPreferenceKey.self, value: FulfillmentPublisherEquatableWrapper(publisher: fulfillmentPublisher?.eraseToAnyPublisher()))
}
}
@@ -0,0 +1,111 @@
//
// Copyright 2023, 2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only
// Please see LICENSE in the repository root for full details.
//
import Combine
import XCTest
extension XCTestCase {
/// XCTest utility that assists in subscribing to a publisher and deferring the fulfilment and results until some other actions have been performed.
/// - Parameters:
/// - publisher: The publisher to wait on.
/// - timeout: A timeout after which we give up.
/// - message: An optional custom expectation message
/// - until: callback that evaluates outputs until some condition is reached
/// - Returns: The deferred fulfilment to be executed after some actions and that returns the result of the publisher.
func deferFulfillment<P: Publisher>(_ publisher: P,
timeout: TimeInterval = 10,
message: String? = nil,
until condition: @escaping (P.Output) -> Bool) -> DeferredFulfillment<P.Output> {
var result: Result<P.Output, Error>?
let expectation = expectation(description: message ?? "Awaiting publisher")
var hasFullfilled = false
let cancellable = publisher
.sink { completion in
switch completion {
case .failure(let error):
result = .failure(error)
expectation.fulfill()
case .finished:
break
}
} receiveValue: { value in
if condition(value), !hasFullfilled {
result = .success(value)
expectation.fulfill()
hasFullfilled = true
}
}
return DeferredFulfillment<P.Output> {
await self.fulfillment(of: [expectation], timeout: timeout)
cancellable.cancel()
let unwrappedResult = try XCTUnwrap(result, "Awaited publisher did not produce any output")
return try unwrappedResult.get()
}
}
/// XCTest utility that assists in subscribing to a publisher and deferring the fulfilment and results until some other actions have been performed.
/// - Parameters:
/// - publisher: The publisher to wait on.
/// - keyPath: the key path for the expected values
/// - transitionValues: the values through which the keypath needs to transition through
/// - timeout: A timeout after which we give up.
/// - message: An optional custom expectation message
/// - Returns: The deferred fulfilment to be executed after some actions and that returns the result of the publisher.
func deferFulfillment<P: Publisher, K: KeyPath<P.Output, V>, V: Equatable>(_ publisher: P,
keyPath: K,
transitionValues: [V],
timeout: TimeInterval = 10,
message: String? = nil) -> DeferredFulfillment<P.Output> {
var expectedOrder = transitionValues
let deferred = deferFulfillment<P>(publisher, timeout: timeout, message: message) { value in
let receivedValue = value[keyPath: keyPath]
if let index = expectedOrder.firstIndex(where: { $0 == receivedValue }), index == 0 {
expectedOrder.remove(at: index)
}
return expectedOrder.isEmpty
}
return deferred
}
/// XCTest utility that assists in subscribing to a publisher and deferring the failure for a particular value until some other actions have been performed.
/// - Parameters:
/// - publisher: The publisher to wait on.
/// - timeout: A timeout after which we give up.
/// - message: An optional custom expectation message
/// - until: callback that evaluates outputs until some condition is reached
/// - Returns: The deferred fulfilment to be executed after some actions. The publisher's result is not returned from this fulfilment.
func deferFailure<P: Publisher>(_ publisher: P,
timeout: TimeInterval,
message: String? = nil,
until condition: @escaping (P.Output) -> Bool) -> DeferredFulfillment<Void> where P.Failure == Never {
let expectation = expectation(description: message ?? "Awaiting publisher")
expectation.isInverted = true
var hasFulfilled = false
let cancellable = publisher
.sink { value in
if condition(value), !hasFulfilled {
expectation.fulfill()
hasFulfilled = true
}
}
return DeferredFulfillment<Void> {
await self.fulfillment(of: [expectation], timeout: timeout)
cancellable.cancel()
}
}
struct DeferredFulfillment<T> {
let closure: () async throws -> T
@discardableResult func fulfill() async throws -> T {
try await closure()
}
}
}
@@ -136,20 +136,23 @@ struct LoginScreen_Previews: PreviewProvider, TestablePreview {
NavigationStack {
LoginScreen(context: viewModel.context)
}
.snapshotPreferences(expect: viewModel.context.$viewState.map { state in
state.homeserver.loginMode == .password
})
.previewDisplayName("matrix.org")
.snapshotPreferences(delay: 1)
NavigationStack {
LoginScreen(context: credentialsViewModel.context)
}
.snapshotPreferences(expect: credentialsViewModel.context.$viewState.map { state in
state.homeserver.loginMode == .password
})
.previewDisplayName("Credentials Entered")
.snapshotPreferences(delay: 1)
NavigationStack {
LoginScreen(context: unconfiguredViewModel.context)
}
.previewDisplayName("Unsupported")
.snapshotPreferences(delay: 1)
}
static func makeViewModel(homeserverAddress: String = "matrix.org", withCredentials: Bool = false) -> LoginScreenViewModel {
@@ -107,7 +107,9 @@ struct ServerSelection_Previews: PreviewProvider, TestablePreview {
NavigationStack {
ServerSelectionScreen(context: invalidViewModel.context)
}
.snapshotPreferences(delay: 1)
.snapshotPreferences(expect: invalidViewModel.context.$viewState.map { state in
state.hasValidationError == true
})
}
static func makeViewModel(for homeserverAddress: String) -> ServerSelectionScreenViewModel {
@@ -332,12 +332,16 @@ struct CreateRoom_Previews: PreviewProvider, TestablePreview {
NavigationStack {
CreateRoomScreen(context: publicRoomInvalidAliasViewModel.context)
}
.snapshotPreferences(delay: 1.5)
.snapshotPreferences(expect: publicRoomExistingAliasViewModel.context.$viewState.map { state in
!state.aliasErrors.isEmpty
})
.previewDisplayName("Create Public Room, invalid alias")
NavigationStack {
CreateRoomScreen(context: publicRoomExistingAliasViewModel.context)
}
.snapshotPreferences(delay: 1.5)
.snapshotPreferences(expect: publicRoomExistingAliasViewModel.context.$viewState.map { state in
!state.aliasErrors.isEmpty
})
.previewDisplayName("Create Public Room, existing alias")
}
}
@@ -97,7 +97,9 @@ struct EmojiPickerScreen_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
EmojiPickerScreen(context: viewModel.context, selectedEmojis: ["😀", "😄"])
.previewDisplayName("Screen")
.snapshotPreferences(delay: 0.5)
.snapshotPreferences(expect: viewModel.context.$viewState.map { state in
!state.categories.isEmpty
})
}
}
@@ -152,16 +152,17 @@ struct TimelineMediaPreviewDetailsView_Previews: PreviewProvider, TestablePrevie
TimelineMediaPreviewDetailsView(item: viewModel.state.currentItem,
context: viewModel.context)
.previewDisplayName("Image")
.snapshotPreferences(delay: 0.1)
.snapshotPreferences(expect: viewModel.context.$viewState.map { state in
state.currentItemActions?.secondaryActions.contains(.redact) ?? false
})
TimelineMediaPreviewDetailsView(item: unknownTypeViewModel.state.currentItem,
context: unknownTypeViewModel.context)
.previewDisplayName("Unknown type")
.snapshotPreferences(delay: 0.1)
TimelineMediaPreviewDetailsView(item: presentedOnRoomViewModel.state.currentItem,
context: presentedOnRoomViewModel.context)
.previewDisplayName("Incoming on Room")
.snapshotPreferences(delay: 0.1)
}
static func makeViewModel(contentType: UTType? = nil, isOutgoing: Bool = false, isPresentedOnRoomScreen: Bool = false) -> TimelineMediaPreviewViewModel {
@@ -196,19 +196,26 @@ struct HomeScreen_Previews: PreviewProvider, TestablePreview {
NavigationStack {
HomeScreen(context: loadingViewModel.context)
}
.snapshotPreferences(expect: loadedViewModel.context.$viewState.map { state in
state.roomListMode == .skeletons
})
.previewDisplayName("Loading")
NavigationStack {
HomeScreen(context: emptyViewModel.context)
}
.snapshotPreferences(expect: emptyViewModel.context.$viewState.map { state in
state.roomListMode == .empty
})
.previewDisplayName("Empty")
.snapshotPreferences(delay: 4.0)
NavigationStack {
HomeScreen(context: loadedViewModel.context)
}
.snapshotPreferences(expect: loadedViewModel.context.$viewState.map { state in
state.roomListMode == .rooms
})
.previewDisplayName("Loaded")
.snapshotPreferences(delay: 4.0)
}
static func viewModel(_ mode: HomeScreenRoomListMode) -> HomeScreenViewModel {
@@ -202,32 +202,42 @@ struct JoinRoomScreen_Previews: PreviewProvider, TestablePreview {
NavigationStack {
JoinRoomScreen(context: unknownViewModel.context)
}
.snapshotPreferences(expect: unknownViewModel.context.$viewState.map { state in
state.roomDetails != nil
})
.previewDisplayName("Unknown")
.snapshotPreferences(delay: 0.25)
NavigationStack {
JoinRoomScreen(context: knockViewModel.context)
}
.snapshotPreferences(expect: knockViewModel.context.$viewState.map { state in
state.roomDetails != nil
})
.previewDisplayName("Knock")
.snapshotPreferences(delay: 0.25)
NavigationStack {
JoinRoomScreen(context: joinViewModel.context)
}
.snapshotPreferences(expect: joinViewModel.context.$viewState.map { state in
state.roomDetails != nil
})
.previewDisplayName("Join")
.snapshotPreferences(delay: 0.25)
NavigationStack {
JoinRoomScreen(context: inviteViewModel.context)
}
.snapshotPreferences(expect: inviteViewModel.context.$viewState.map { state in
state.roomDetails != nil
})
.previewDisplayName("Invite")
.snapshotPreferences(delay: 0.25)
NavigationStack {
JoinRoomScreen(context: knockedViewModel.context)
}
.snapshotPreferences(expect: knockedViewModel.context.$viewState.map { state in
state.roomDetails != nil
})
.previewDisplayName("Knocked")
.snapshotPreferences(delay: 0.25)
}
static func makeViewModel(mode: JoinRoomScreenInteractionMode) -> JoinRoomScreenViewModel {
@@ -127,23 +127,32 @@ struct KnockRequestsListScreen_Previews: PreviewProvider, TestablePreview {
NavigationStack {
KnockRequestsListScreen(context: viewModel.context)
}
.snapshotPreferences(delay: 0.2)
.snapshotPreferences(expect: viewModel.context.$viewState.map { state in
state.shouldDisplayRequests == true
})
NavigationStack {
KnockRequestsListScreen(context: singleRequestViewModel.context)
}
.snapshotPreferences(expect: singleRequestViewModel.context.$viewState.map { state in
state.shouldDisplayRequests == true
})
.previewDisplayName("Single Request")
.snapshotPreferences(delay: 0.2)
NavigationStack {
KnockRequestsListScreen(context: emptyViewModel.context)
}
.snapshotPreferences(expect: emptyViewModel.context.$viewState.map { state in
state.shouldDisplayEmptyView == true
})
.previewDisplayName("Empty state")
.snapshotPreferences(delay: 0.2)
NavigationStack {
KnockRequestsListScreen(context: loadingViewModel.context)
}
.snapshotPreferences(expect: loadingViewModel.context.$viewState.map { state in
state.isLoading == true
})
.previewDisplayName("Loading state")
}
}
@@ -108,7 +108,9 @@ struct IdentityConfirmationScreen_Previews: PreviewProvider, TestablePreview {
NavigationStack {
IdentityConfirmationScreen(context: viewModel.context)
}
.snapshotPreferences(delay: 1)
.snapshotPreferences(expect: viewModel.context.$viewState.map { state in
state.availableActions.contains([.interactiveVerification, .recovery])
})
}
private static var viewModel: IdentityConfirmationScreenViewModel {
@@ -174,12 +174,13 @@ struct RoomDetailsEditScreen_Previews: PreviewProvider, TestablePreview {
RoomDetailsEditScreen(context: readOnlyViewModel.context)
}
.previewDisplayName("Read only")
.snapshotPreferences(delay: 0.25)
NavigationStack {
RoomDetailsEditScreen(context: editableViewModel.context)
}
.snapshotPreferences(expect: editableViewModel.context.$viewState.map { state in
state.canEditTopic == true
})
.previewDisplayName("Editable")
.snapshotPreferences(delay: 0.25)
}
}
@@ -419,13 +419,21 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
RoomDetailsScreen(context: simpleRoomViewModel.context)
.snapshotPreferences(expect: simpleRoomViewModel.context.$viewState.map { state in
state.shortcuts.contains(.invite)
})
.previewDisplayName("Simple Room")
.snapshotPreferences(delay: 2)
RoomDetailsScreen(context: dmRoomViewModel.context)
.snapshotPreferences(expect: dmRoomViewModel.context.$viewState.map { state in
state.accountOwner != nil
})
.previewDisplayName("DM Room")
.snapshotPreferences(delay: 0.25)
RoomDetailsScreen(context: genericRoomViewModel.context)
.snapshotPreferences(expect: genericRoomViewModel.context.$viewState.map { state in
state.shortcuts.contains(.invite)
})
.previewDisplayName("Generic Room")
.snapshotPreferences(delay: 0.25)
}
}
@@ -98,6 +98,5 @@ struct RoomDirectorySearchScreen_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
RoomDirectorySearchScreen(context: viewModel.context)
.snapshotPreferences(delay: 1.0)
}
}
@@ -139,17 +139,28 @@ struct RoomMemberDetailsScreen_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
RoomMemberDetailsScreen(context: verifiedUserViewModel.context)
.snapshotPreferences(expect: verifiedUserViewModel.context.$viewState.map { state in
state.isVerified == true
})
.previewDisplayName("Verified User")
.snapshotPreferences(delay: 0.25)
RoomMemberDetailsScreen(context: otherUserViewModel.context)
.snapshotPreferences(expect: otherUserViewModel.context.$viewState.map { state in
state.memberDetails?.role == .user
})
.previewDisplayName("Other User")
.snapshotPreferences(delay: 0.25)
RoomMemberDetailsScreen(context: accountOwnerViewModel.context)
.snapshotPreferences(expect: accountOwnerViewModel.context.$viewState.map { state in
state.isOwnMemberDetails == true
})
.previewDisplayName("Account Owner")
.snapshotPreferences(delay: 0.25)
RoomMemberDetailsScreen(context: ignoredUserViewModel.context)
.snapshotPreferences(expect: ignoredUserViewModel.context.$viewState.map { state in
state.memberDetails?.isIgnored ?? false
})
.previewDisplayName("Ignored User")
.snapshotPreferences(delay: 0.25)
}
static func makeViewModel(member: RoomMemberProxyMock) -> RoomMemberDetailsScreenViewModel {
@@ -72,13 +72,11 @@ struct RoomMembersListManageMemberSheet_Previews: PreviewProvider, TestablePrevi
actions: [.kick, .ban],
context: viewModel.context)
.previewDisplayName("Joined")
.snapshotPreferences(delay: 0.2)
RoomMembersListManageMemberSheet(member: .init(withProxy: RoomMemberProxyMock.mockBanned[3]),
actions: [],
context: viewModel.context)
.previewDisplayName("Banned")
.snapshotPreferences(delay: 0.2)
}
}
@@ -117,31 +117,41 @@ struct RoomMembersListScreen_Previews: PreviewProvider, TestablePreview {
NavigationStack {
RoomMembersListScreen(context: viewModel.context)
}
.snapshotPreferences(delay: 1.0)
.snapshotPreferences(expect: viewModel.context.$viewState.map { state in
!state.visibleJoinedMembers.isEmpty
})
.previewDisplayName("Member")
NavigationStack {
RoomMembersListScreen(context: invitesViewModel.context)
}
.snapshotPreferences(delay: 1.0)
.snapshotPreferences(expect: invitesViewModel.context.$viewState.map { state in
!state.visibleJoinedMembers.isEmpty
})
.previewDisplayName("Invites")
NavigationStack {
RoomMembersListScreen(context: adminViewModel.context)
}
.snapshotPreferences(delay: 1.0)
.snapshotPreferences(expect: adminViewModel.context.$viewState.map { state in
state.canBanUsers == true
})
.previewDisplayName("Admin: Members")
NavigationStack {
RoomMembersListScreen(context: bannedViewModel.context)
}
.snapshotPreferences(delay: 1.0)
.snapshotPreferences(expect: bannedViewModel.context.$viewState.map { state in
state.canBanUsers == true
})
.previewDisplayName("Admin: Banned")
NavigationStack {
RoomMembersListScreen(context: emptyBannedViewModel.context)
}
.snapshotPreferences(delay: 1.0)
.snapshotPreferences(expect: emptyBannedViewModel.context.$viewState.map { state in
state.canBanUsers == true
})
.previewDisplayName("Admin: Empty Banned")
}
@@ -151,12 +151,10 @@ struct RoomPollsHistoryScreen_Previews: PreviewProvider, TestablePreview {
RoomPollsHistoryScreen(context: viewModelEmpty.context)
}
.previewDisplayName("No polls")
.snapshotPreferences(delay: 1.0)
NavigationStack {
RoomPollsHistoryScreen(context: viewModel.context)
}
.previewDisplayName("polls")
.snapshotPreferences(delay: 1.0)
}
}
@@ -224,7 +224,7 @@ struct SecureBackupRecoveryKeyScreen: View {
struct SecureBackupRecoveryKeyScreen_Previews: PreviewProvider, TestablePreview {
static let key = "EsTM njec uHYA yHmh dQdW Nj4o bNRU 9jMN XGMc KUNM UFr5 R8GY"
static let notSetUpViewModel = viewModel(recoveryState: .disabled)
static let generatingViewModel = viewModel(recoveryState: .disabled, generateKey: true)
static let generatingViewModel = viewModel(recoveryState: .disabled, generateKey: true, key: key)
static let setupViewModel = viewModel(recoveryState: .enabled, generateKey: true, key: key)
static let incompleteViewModel = viewModel(recoveryState: .incomplete)
static let unknownViewModel = viewModel(recoveryState: .unknown)
@@ -239,14 +239,15 @@ struct SecureBackupRecoveryKeyScreen_Previews: PreviewProvider, TestablePreview
SecureBackupRecoveryKeyScreen(context: generatingViewModel.context)
}
.previewDisplayName("Generating")
.snapshotPreferences(delay: 0.25)
NavigationStack {
SecureBackupRecoveryKeyScreen(context: setupViewModel.context)
}
.snapshotPreferences(expect: setupViewModel.context.$viewState.map { state in
state.recoveryKey != nil
})
.previewDisplayName("Set up")
.snapshotPreferences(delay: 0.25)
NavigationStack {
SecureBackupRecoveryKeyScreen(context: incompleteViewModel.context)
}
@@ -125,28 +125,37 @@ struct SecureBackupScreen_Previews: PreviewProvider, TestablePreview {
static let recoveryIncompleteViewModel = viewModel(keyBackupState: .enabled, recoveryState: .incomplete)
static var previews: some View {
Group {
NavigationStack {
SecureBackupScreen(context: bothSetupViewModel.context)
}
.previewDisplayName("Both setup")
NavigationStack {
SecureBackupScreen(context: onlyKeyBackupSetUpViewModel.context)
}
.previewDisplayName("Only key backup setup")
NavigationStack {
SecureBackupScreen(context: keyBackupDisabledViewModel.context)
}
.previewDisplayName("Key backup disabled")
NavigationStack {
SecureBackupScreen(context: recoveryIncompleteViewModel.context)
}
.previewDisplayName("Recovery incomplete")
NavigationStack {
SecureBackupScreen(context: bothSetupViewModel.context)
}
.snapshotPreferences(delay: 1.0)
.snapshotPreferences(expect: bothSetupViewModel.context.$viewState.map { state in
state.keyBackupState == .enabled
})
.previewDisplayName("Both setup")
NavigationStack {
SecureBackupScreen(context: onlyKeyBackupSetUpViewModel.context)
}
.snapshotPreferences(expect: onlyKeyBackupSetUpViewModel.context.$viewState.map { state in
state.keyBackupState == .enabled
})
.previewDisplayName("Only key backup setup")
NavigationStack {
SecureBackupScreen(context: keyBackupDisabledViewModel.context)
}
.snapshotPreferences(expect: keyBackupDisabledViewModel.context.$viewState.map { state in
state.keyBackupState == .unknown
})
.previewDisplayName("Key backup disabled")
NavigationStack {
SecureBackupScreen(context: recoveryIncompleteViewModel.context)
}
.snapshotPreferences(expect: recoveryIncompleteViewModel.context.$viewState.map { state in
state.recoveryState == .incomplete
})
.previewDisplayName("Recovery incomplete")
}
static func viewModel(keyBackupState: SecureBackupKeyBackupState,
@@ -253,9 +253,14 @@ struct NotificationSettingsScreen_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
NotificationSettingsScreen(context: viewModel.context)
.snapshotPreferences(delay: 2.0)
.snapshotPreferences(expect: viewModel.context.$viewState.map { state in
state.settings != nil
})
NotificationSettingsScreen(context: viewModelConfigurationMismatch.context)
.snapshotPreferences(delay: 2.0)
.snapshotPreferences(expect: viewModelConfigurationMismatch.context.$viewState.map { state in
state.settings != nil
})
.previewDisplayName("Configuration mismatch")
}
}
@@ -239,7 +239,9 @@ struct SettingsScreen_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
NavigationStack {
SettingsScreen(context: viewModel.context)
.snapshotPreferences(delay: 1.0)
.snapshotPreferences(expect: viewModel.context.$viewState.map { state in
state.accountSessionsListURL != nil
})
}
}
}
@@ -321,8 +321,6 @@ struct TimelineReplyView_Previews: PreviewProvider, TestablePreview {
}
.padding()
.environmentObject(viewModel.context)
// Allow member names to load. Reduce precission as the `mockThumbnail` randomly renders slightly differently
.snapshotPreferences(delay: 0.2, precision: 0.98)
.previewLayout(.sizeThatFits)
}
}
@@ -355,14 +355,12 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
.previewDisplayName("Replies")
threads
.previewDisplayName("Thread decorator")
.snapshotPreferences(delay: 1)
.previewLayout(.fixed(width: 390, height: 1700))
.padding(.bottom, 20)
encryptionAuthenticity
.previewDisplayName("Encryption Indicators")
pinned
.previewDisplayName("Pinned messages")
.snapshotPreferences(delay: 1)
.previewLayout(.fixed(width: 390, height: 1150))
.padding(.bottom, 20)
}
@@ -205,6 +205,5 @@ struct FormattedBodyText_Previews: PreviewProvider, TestablePreview {
.padding()
}
.previewLayout(.sizeThatFits)
.snapshotPreferences(delay: 0.25)
}
}
@@ -112,14 +112,22 @@ struct UserProfileScreen_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
UserProfileScreen(context: verifiedUserViewModel.context)
.snapshotPreferences(expect: verifiedUserViewModel.context.$viewState.map { state in
state.isVerified != nil
})
.previewDisplayName("Verified User")
.snapshotPreferences(delay: 0.25)
UserProfileScreen(context: otherUserViewModel.context)
.snapshotPreferences(expect: otherUserViewModel.context.$viewState.map { state in
state.isVerified != nil
})
.previewDisplayName("Other User")
.snapshotPreferences(delay: 0.25)
UserProfileScreen(context: accountOwnerViewModel.context)
.snapshotPreferences(expect: accountOwnerViewModel.context.$viewState.map { state in
state.isVerified != nil
})
.previewDisplayName("Account Owner")
.snapshotPreferences(delay: 0.25)
}
static func makeViewModel(userID: String) -> UserProfileScreenViewModel {