diff --git a/Tests/GravatarUITests/AvatarPickerProfileViewTests.swift b/Tests/GravatarUITests/AvatarPickerProfileViewTests.swift new file mode 100644 index 00000000..433dfafc --- /dev/null +++ b/Tests/GravatarUITests/AvatarPickerProfileViewTests.swift @@ -0,0 +1,37 @@ +@testable import GravatarUI +import SnapshotTesting +import SwiftUI +import XCTest + +final class AvatarPickerProfileViewTests: XCTestCase { + override func invokeTest() { + withSnapshotTesting(record: .failed) { + super.invokeTest() + } + } + + @MainActor + func testAvatarPickerProfileView() throws { + let testView = AvatarPickerProfileView( + avatarURL: .constant(nil), + model: .constant( + .init( + displayName: "Shelly Kimbrough", + location: "San Antonio, TX", + profileURL: URL(string: "https://gravatar.com") + ) + ), + isLoading: .constant(false) + ) + // put a border around so the bounds can be visible in the snapshots. + .markBounds() + + assertSnapshots( + of: testView, + as: [ + .testStrategy(userInterfaceStyle: .light), + .testStrategy(userInterfaceStyle: .dark), + ] + ) + } +} diff --git a/Tests/GravatarUITests/Snapshotting+Additions.swift b/Tests/GravatarUITests/Snapshotting+Additions.swift new file mode 100644 index 00000000..fc33d2b1 --- /dev/null +++ b/Tests/GravatarUITests/Snapshotting+Additions.swift @@ -0,0 +1,18 @@ +import SnapshotTesting +import SwiftUI +import XCTest + +extension Snapshotting where Value: SwiftUI.View, Format == UIImage { + static func testStrategy(userInterfaceStyle: UIUserInterfaceStyle = .light) -> Self { + let deviceConfig: ViewImageConfig = .iPhone13 + let traits = UITraitCollection(traitsFrom: [ + UITraitCollection(displayScale: deviceConfig.traits.displayScale), + UITraitCollection(userInterfaceStyle: userInterfaceStyle), + ]) + + return .image( + layout: .device(config: deviceConfig), + traits: traits + ) + } +} diff --git a/Tests/GravatarUITests/View+TestAdditions.swift b/Tests/GravatarUITests/View+TestAdditions.swift new file mode 100644 index 00000000..0a7528b0 --- /dev/null +++ b/Tests/GravatarUITests/View+TestAdditions.swift @@ -0,0 +1,13 @@ +import SwiftUI + +extension View { + func markBounds() -> some View { + self + .padding(1) // to prevent borders from intersecting with content + .clipShape(RoundedRectangle(cornerSize: .zero)) + .overlay( + RoundedRectangle(cornerSize: .zero) + .stroke(.red, lineWidth: 1) + ) + } +} diff --git a/Tests/GravatarUITests/__Snapshots__/AvatarPickerProfileViewTests/testAvatarPickerProfileView.1.png b/Tests/GravatarUITests/__Snapshots__/AvatarPickerProfileViewTests/testAvatarPickerProfileView.1.png new file mode 100644 index 00000000..c203cf1e Binary files /dev/null and b/Tests/GravatarUITests/__Snapshots__/AvatarPickerProfileViewTests/testAvatarPickerProfileView.1.png differ diff --git a/Tests/GravatarUITests/__Snapshots__/AvatarPickerProfileViewTests/testAvatarPickerProfileView.2.png b/Tests/GravatarUITests/__Snapshots__/AvatarPickerProfileViewTests/testAvatarPickerProfileView.2.png new file mode 100644 index 00000000..81e889ac Binary files /dev/null and b/Tests/GravatarUITests/__Snapshots__/AvatarPickerProfileViewTests/testAvatarPickerProfileView.2.png differ