Skip to content

Commit

Permalink
Update snapshot tolerances
Browse files Browse the repository at this point in the history
  • Loading branch information
KatherineInCode committed Oct 16, 2024
1 parent edbe5f6 commit 2e3d142
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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)
}
}
22 changes: 19 additions & 3 deletions GlobalTestHelpers/Extensions/Snapshotting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
)
}
}

0 comments on commit 2e3d142

Please sign in to comment.