Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#I Improve snapshot test #783

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 40 additions & 24 deletions GliaWidgets.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

49 changes: 8 additions & 41 deletions SnapshotTests/AlertViewControllerDynamicTypeFontTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,8 @@ final class AlertViewControllerDynamicTypeFontTests: SnapshotTestCase {
accepted: {},
declined: {}
))
assertSnapshot(
matching: alert,
as: .extra3LargeFontStrategy,
named: nameForDevice()
)
assertSnapshot(
matching: alert,
as: .extra3LargeFontStrategyLandscape,
named: nameForDevice(.landscape)
)
alert.assertSnapshot(as: .extra3LargeFont, in: .portrait)
alert.assertSnapshot(as: .extra3LargeFont, in: .landscape)
}

func test_mediaUpgradeOffer_extra3Large() {
Expand All @@ -28,16 +20,8 @@ final class AlertViewControllerDynamicTypeFontTests: SnapshotTestCase {
accepted: {},
declined: {}
))
assertSnapshot(
matching: alert,
as: .extra3LargeFontStrategy,
named: nameForDevice()
)
assertSnapshot(
matching: alert,
as: .extra3LargeFontStrategyLandscape,
named: nameForDevice(.landscape)
)
alert.assertSnapshot(as: .extra3LargeFont, in: .portrait)
alert.assertSnapshot(as: .extra3LargeFont, in: .landscape)
}

func test_messageAlert_extra3Large() {
Expand All @@ -46,16 +30,8 @@ final class AlertViewControllerDynamicTypeFontTests: SnapshotTestCase {
accessibilityIdentifier: nil,
dismissed: {}
))
assertSnapshot(
matching: alert,
as: .extra3LargeFontStrategy,
named: nameForDevice()
)
assertSnapshot(
matching: alert,
as: .extra3LargeFontStrategyLandscape,
named: nameForDevice(.landscape)
)
alert.assertSnapshot(as: .extra3LargeFont, in: .portrait)
alert.assertSnapshot(as: .extra3LargeFont, in: .landscape)
}

func test_singleAction_extra3Large() {
Expand All @@ -64,24 +40,15 @@ final class AlertViewControllerDynamicTypeFontTests: SnapshotTestCase {
accessibilityIdentifier: "mocked-accessibility-identifier",
actionTapped: {}
))
assertSnapshot(
matching: alert,
as: .extra3LargeFontStrategy,
named: nameForDevice()
)
assertSnapshot(
matching: alert,
as: .extra3LargeFontStrategyLandscape,
named: nameForDevice(.landscape)
)
alert.assertSnapshot(as: .extra3LargeFont, in: .portrait)
alert.assertSnapshot(as: .extra3LargeFont, in: .landscape)
}

private func alert(ofKind kind: AlertViewController.Kind) -> AlertViewController {
let viewController = AlertViewController(
kind: kind,
viewFactory: .mock()
)
viewController.view.frame = UIScreen.main.bounds
return viewController
}
}
49 changes: 8 additions & 41 deletions SnapshotTests/AlertViewControllerLayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,8 @@ final class AlertViewControllerLayoutTests: SnapshotTestCase {
accepted: {},
declined: {}
))
assertSnapshot(
matching: alert,
as: .image,
named: nameForDevice()
)
assertSnapshot(
matching: alert,
as: .imageLandscape,
named: nameForDevice(.landscape)
)
alert.assertSnapshot(as: .image, in: .portrait)
alert.assertSnapshot(as: .image, in: .landscape)
}

func test_mediaUpgradeOffer() {
Expand All @@ -27,16 +19,8 @@ final class AlertViewControllerLayoutTests: SnapshotTestCase {
accepted: {},
declined: {}
))
assertSnapshot(
matching: alert,
as: .image,
named: nameForDevice()
)
assertSnapshot(
matching: alert,
as: .imageLandscape,
named: nameForDevice(.landscape)
)
alert.assertSnapshot(as: .image, in: .portrait)
alert.assertSnapshot(as: .image, in: .landscape)
}

func test_messageAlert() {
Expand All @@ -45,16 +29,8 @@ final class AlertViewControllerLayoutTests: SnapshotTestCase {
accessibilityIdentifier: nil,
dismissed: {}
))
assertSnapshot(
matching: alert,
as: .image,
named: nameForDevice()
)
assertSnapshot(
matching: alert,
as: .imageLandscape,
named: nameForDevice(.landscape)
)
alert.assertSnapshot(as: .image, in: .portrait)
alert.assertSnapshot(as: .image, in: .landscape)
}

func test_singleAction() {
Expand All @@ -63,24 +39,15 @@ final class AlertViewControllerLayoutTests: SnapshotTestCase {
accessibilityIdentifier: "mocked-accessibility-identifier",
actionTapped: {}
))
assertSnapshot(
matching: alert,
as: .image,
named: nameForDevice()
)
assertSnapshot(
matching: alert,
as: .imageLandscape,
named: nameForDevice(.landscape)
)
alert.assertSnapshot(as: .image, in: .portrait)
alert.assertSnapshot(as: .image, in: .landscape)
}

private func alert(ofKind kind: AlertViewController.Kind) -> AlertViewController {
let viewController = AlertViewController(
kind: kind,
viewFactory: .mock()
)
viewController.view.frame = UIScreen.main.bounds
return viewController
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ import AccessibilitySnapshot
import SnapshotTesting
import XCTest

final class AlertViewControllerTests: SnapshotTestCase {
final class AlertViewControllerVoiceOverTests: SnapshotTestCase {
func test_screenSharingOffer() {
let alert = alert(ofKind: .screenShareOffer(
.mock(),
accepted: {},
declined: {}
))
assertSnapshot(
matching: alert,
as: .accessibilityImage(precision: Self.possiblePrecision),
named: nameForDevice()
)
alert.assertSnapshot(as: .accessibilityImage)
}

func test_mediaUpgradeOffer() {
Expand All @@ -23,11 +19,7 @@ final class AlertViewControllerTests: SnapshotTestCase {
accepted: {},
declined: {}
))
assertSnapshot(
matching: alert,
as: .accessibilityImage(precision: Self.possiblePrecision),
named: nameForDevice()
)
alert.assertSnapshot(as: .accessibilityImage)
}

func test_messageAlert() {
Expand All @@ -36,11 +28,7 @@ final class AlertViewControllerTests: SnapshotTestCase {
accessibilityIdentifier: nil,
dismissed: {}
))
assertSnapshot(
matching: alert,
as: .accessibilityImage(precision: Self.possiblePrecision),
named: nameForDevice()
)
alert.assertSnapshot(as: .accessibilityImage)
}

func test_singleAction() {
Expand All @@ -49,19 +37,14 @@ final class AlertViewControllerTests: SnapshotTestCase {
accessibilityIdentifier: "mocked-accessibility-identifier",
actionTapped: {}
))
assertSnapshot(
matching: alert,
as: .accessibilityImage(precision: Self.possiblePrecision),
named: nameForDevice()
)
alert.assertSnapshot(as: .accessibilityImage)
}

private func alert(ofKind kind: AlertViewController.Kind) -> AlertViewController {
let viewController = AlertViewController(
kind: kind,
viewFactory: .mock()
)
viewController.view.frame = UIScreen.main.bounds
return viewController
}
}
11 changes: 2 additions & 9 deletions SnapshotTests/BubbleViewDynamicTypeFontTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@ final class BubbleViewDynamicTypeFontTests: SnapshotTestCase {
func test_bubble_extra3Large() {
let bubble = ViewFactory.mock().makeBubbleView()
bubble.frame = .init(origin: .zero, size: .init(width: 50, height: 50))
assertSnapshot(
matching: bubble,
as: .extra3LargeFontStrategy
)
assertSnapshot(
matching: bubble,
as: .extra3LargeFontStrategyLandscape,
named: nameForDevice(.landscape)
)
bubble.assertSnapshot(as: .extra3LargeFont, in: .portrait)
bubble.assertSnapshot(as: .extra3LargeFont, in: .landscape)
}
}
11 changes: 2 additions & 9 deletions SnapshotTests/BubbleViewLayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@ final class BubbleViewLayoutTests: SnapshotTestCase {
func test_bubble() {
let bubble = ViewFactory.mock().makeBubbleView()
bubble.frame = .init(origin: .zero, size: .init(width: 50, height: 50))
assertSnapshot(
matching: bubble,
as: .image
)
assertSnapshot(
matching: bubble,
as: .imageLandscape,
named: nameForDevice(.landscape)
)
bubble.assertSnapshot(as: .image, in: .portrait)
bubble.assertSnapshot(as: .image, in: .landscape)
}
}
2 changes: 1 addition & 1 deletion SnapshotTests/BubbleViewVoiceOverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ final class BubbleViewVoiceOverTests: SnapshotTestCase {
func test_bubble() {
let bubble = ViewFactory.mock().makeBubbleView()
bubble.frame = .init(origin: .zero, size: .init(width: 50, height: 50))
assertSnapshot(matching: bubble, as: .accessibilityImage(precision: SnapshotTestCase.possiblePrecision))
bubble.assertSnapshot(as: .accessibilityImage)
}
}
3 changes: 2 additions & 1 deletion SnapshotTests/BubbleWindowLayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ final class BubbleWindowLayoutTests: XCTestCase {
)
)
bubbleWindow.makeKeyAndVisible()
assertSnapshot(matching: bubbleWindow, as: .image)
bubbleWindow.assertSnapshot(as: .image, in: .portrait)
bubbleWindow.assertSnapshot(as: .image, in: .landscape)
}
}
78 changes: 12 additions & 66 deletions SnapshotTests/CallViewControllerDynamicTypeFontTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,91 +5,37 @@ import XCTest
final class CallViewControllerDynamicTypeFontTests: SnapshotTestCase {
func test_audioCallQueueState_extra3Large() throws {
let viewController = try CallViewController.mockAudioCallQueueState()
viewController.view.frame = UIScreen.main.bounds
assertSnapshot(
matching: viewController,
as: .extra3LargeFontStrategy,
named: nameForDevice()
)
assertSnapshot(
matching: viewController,
as: .extra3LargeFontStrategyLandscape,
named: nameForDevice(.landscape)
)
viewController.assertSnapshot(as: .extra3LargeFont, in: .portrait)
viewController.assertSnapshot(as: .extra3LargeFont, in: .landscape)
}

func test_audioCallConnectingState_extra3Large() throws {
let viewController = try CallViewController.mockAudioCallConnectingState()
viewController.view.frame = UIScreen.main.bounds
assertSnapshot(
matching: viewController,
as: .extra3LargeFontStrategy,
named: nameForDevice()
)
assertSnapshot(
matching: viewController,
as: .extra3LargeFontStrategyLandscape,
named: nameForDevice(.landscape)
)
viewController.assertSnapshot(as: .extra3LargeFont, in: .portrait)
viewController.assertSnapshot(as: .extra3LargeFont, in: .landscape)
}

func test_audioCallConnectedState_extra3Large() throws {
let viewController = try CallViewController.mockAudioCallConnectedState()
viewController.view.frame = UIScreen.main.bounds
assertSnapshot(
matching: viewController,
as: .extra3LargeFontStrategy,
named: nameForDevice()
)
assertSnapshot(
matching: viewController,
as: .extra3LargeFontStrategyLandscape,
named: nameForDevice(.landscape)
)
viewController.assertSnapshot(as: .extra3LargeFont, in: .portrait)
viewController.assertSnapshot(as: .extra3LargeFont, in: .landscape)
}

func test_mockVideoCallConnectingState_extra3Large() throws {
let viewController = try CallViewController.mockVideoCallConnectingState()
viewController.view.frame = UIScreen.main.bounds
assertSnapshot(
matching: viewController,
as: .extra3LargeFontStrategy,
named: nameForDevice()
)
assertSnapshot(
matching: viewController,
as: .extra3LargeFontStrategyLandscape,
named: nameForDevice(.landscape)
)
viewController.assertSnapshot(as: .extra3LargeFont, in: .portrait)
viewController.assertSnapshot(as: .extra3LargeFont, in: .landscape)
}

func test_mockVideoCallQueueState_extra3Large() throws {
let viewController = try CallViewController.mockVideoCallQueueState()
viewController.view.frame = UIScreen.main.bounds
assertSnapshot(
matching: viewController,
as: .extra3LargeFontStrategy,
named: nameForDevice()
)
assertSnapshot(
matching: viewController,
as: .extra3LargeFontStrategyLandscape,
named: nameForDevice(.landscape)
)
viewController.assertSnapshot(as: .extra3LargeFont, in: .portrait)
viewController.assertSnapshot(as: .extra3LargeFont, in: .landscape)
}

func test_mockVideoCallConnectedState_extra3Large() throws {
let viewController = try CallViewController.mockVideoCallConnectedState()
viewController.view.frame = UIScreen.main.bounds
assertSnapshot(
matching: viewController,
as: .extra3LargeFontStrategy,
named: nameForDevice()
)
assertSnapshot(
matching: viewController,
as: .extra3LargeFontStrategyLandscape,
named: nameForDevice(.landscape)
)
viewController.assertSnapshot(as: .extra3LargeFont, in: .portrait)
viewController.assertSnapshot(as: .extra3LargeFont, in: .landscape)
}
}
Loading