From 2e3d142799ab7492c922f59c0cb35b575ea36eb4 Mon Sep 17 00:00:00 2001 From: Katherine Bertelsen Date: Wed, 16 Oct 2024 15:49:39 -0500 Subject: [PATCH] Update snapshot tolerances --- .../UITabBarControllerExtensionsTests.swift | 16 +++++++------- .../Extensions/Snapshotting.swift | 22 ++++++++++++++++--- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/BitwardenShared/UI/Platform/Application/Extensions/UITabBarControllerExtensionsTests.swift b/BitwardenShared/UI/Platform/Application/Extensions/UITabBarControllerExtensionsTests.swift index 15eb6f7a1..bd9c0dde4 100644 --- a/BitwardenShared/UI/Platform/Application/Extensions/UITabBarControllerExtensionsTests.swift +++ b/BitwardenShared/UI/Platform/Application/Extensions/UITabBarControllerExtensionsTests.swift @@ -57,41 +57,41 @@ class UITabBarControllerExtensionsTests: BitwardenTestCase { /// Tests that the tab bar items are laid out correctly with vault selected (default) in light mode. func test_snapshot_tabBarItems_vaultSelected_lightMode() { subject.overrideUserInterfaceStyle = .light - assertSnapshot(of: subject, as: .image) + assertSnapshot(of: subject, as: .standardImage) } /// Tests that the tab bar items are laid out correctly with vault selected (default) in dark mode. func test_snapshot_tabBarItems_vaultSelected_darkMode() { subject.overrideUserInterfaceStyle = .dark - assertSnapshot(of: subject, as: .image) + assertSnapshot(of: subject, as: .standardImage) } /// Tests that the tab bar items are laid out correctly with send selected in light mode. func test_snapshot_tabBarItems_sendSelected_lightMode() { subject.overrideUserInterfaceStyle = .light subject.selectedIndex = 1 - assertSnapshot(of: subject, as: .image) + assertSnapshot(of: subject, as: .standardImage) } /// Tests that the tab bar items are laid out correctly with send selected in dark mode. func test_snapshot_tabBarItems_sendSelected_darkMode() { subject.overrideUserInterfaceStyle = .dark subject.selectedIndex = 1 - assertSnapshot(of: subject, as: .image) + assertSnapshot(of: subject, as: .standardImage) } /// Tests that the tab bar items are laid out correctly with generator selected in light mode. func test_snapshot_tabBarItems_generatorSelected_lightMode() { subject.overrideUserInterfaceStyle = .light subject.selectedIndex = 2 - assertSnapshot(of: subject, as: .image) + assertSnapshot(of: subject, as: .standardImage) } /// Tests that the tab bar items are laid out correctly with generator selected in dark mode. func test_snapshot_tabBarItems_generatorSelected_darkMode() { subject.overrideUserInterfaceStyle = .dark subject.selectedIndex = 2 - assertSnapshot(of: subject, as: .image) + assertSnapshot(of: subject, as: .standardImage) } /// Tests that the tab bar items are laid out correctly with settings selected in light mode. @@ -100,7 +100,7 @@ class UITabBarControllerExtensionsTests: BitwardenTestCase { module.settingsNavigator?.rootViewController?.tabBarItem.badgeValue = "1" subject.overrideUserInterfaceStyle = .light subject.selectedIndex = 3 - assertSnapshot(of: subject, as: .image) + assertSnapshot(of: subject, as: .standardImage) } /// Tests that the tab bar items are laid out correctly with settings selected in dark mode. @@ -109,6 +109,6 @@ class UITabBarControllerExtensionsTests: BitwardenTestCase { module.settingsNavigator?.rootViewController?.tabBarItem.badgeValue = "1" subject.overrideUserInterfaceStyle = .dark subject.selectedIndex = 3 - assertSnapshot(of: subject, as: .image) + assertSnapshot(of: subject, as: .standardImage) } } diff --git a/GlobalTestHelpers/Extensions/Snapshotting.swift b/GlobalTestHelpers/Extensions/Snapshotting.swift index e4fabdf3b..c55b1de5a 100644 --- a/GlobalTestHelpers/Extensions/Snapshotting.swift +++ b/GlobalTestHelpers/Extensions/Snapshotting.swift @@ -2,10 +2,10 @@ import SnapshotTesting import SwiftUI extension Snapshotting where Value: SwiftUI.View, Format == UIImage { - /// The default precision for all snapshots in this project. Defaults to `1`. - private static var defaultPrecision: Float { 1 } + /// The default precision for all view snapshots in this project. Defaults to `1`. + private static var defaultPrecision: Float { 0.99 } - /// The default perceptual precision for all snapshots in this project. Defaults to `0.95`. + /// The default perceptual precision for all view snapshots in this project. Defaults to `0.95`. private static var defaultPerceptualPrecision: Float { 0.95 } /// A default snapshot in landscape on iPhone 13, with precision 1 and perceptual precision of 0.95. @@ -162,3 +162,19 @@ extension Snapshotting where Value: SwiftUI.View, Format == UIImage { ) } } + +extension Snapshotting where Value == UIViewController, Format == UIImage { + /// The default precision for all view controller snapshots in this project. Defaults to `1`. + private static var defaultPrecision: Float { 0.99 } + + /// The default perceptual precision for all view controller snapshots in this project. Defaults to `0.95`. + private static var defaultPerceptualPrecision: Float { 0.95 } + + /// A default snapshot in landscape on iPhone 13, with precision 1 and perceptual precision of 0.95. + static var standardImage: Snapshotting { + .image( + precision: defaultPrecision, + perceptualPrecision: defaultPerceptualPrecision + ) + } +}