diff --git a/Example/ExampleSnapshotTests/GradientLoadingBarController/GradientLoadingBarControllerTestCase.swift b/Example/ExampleSnapshotTests/GradientLoadingBarController/GradientLoadingBarControllerTestCase.swift index 0798134..fb7dfdf 100644 --- a/Example/ExampleSnapshotTests/GradientLoadingBarController/GradientLoadingBarControllerTestCase.swift +++ b/Example/ExampleSnapshotTests/GradientLoadingBarController/GradientLoadingBarControllerTestCase.swift @@ -13,25 +13,42 @@ import XCTest final class GradientLoadingBarControllerTestCase: XCTestCase { - // MARK: - Config + // MARK: - Private properties - private enum Config { - /// The percentage of pixels that must match. - static let precision: Float = 0.99 + private var window: UIWindow! + + // MARK: - Public methods + + override func setUp() { + super.setUp() + + window = UIApplication.shared.keyWindowInConnectedScenes + } + + override func tearDown() { + window = nil + + super.tearDown() } // MARK: - Test cases func test_gradientLoadingBarController() { // Given + // Show an empty view controller behind loading bar in our test. let rootViewController = UIViewController() - let gradientLoadingBarController = GradientLoadingBarController() + window.rootViewController = rootViewController + + let expectation = expectation(description: "Expect view to be completely fade in.") // When - gradientLoadingBarController.fadeIn(duration: 0) + let gradientLoadingBarController = GradientLoadingBarController() + gradientLoadingBarController.fadeIn(duration: 0) { _ in + expectation.fulfill() + } // Then - assertSnapshot(matching: rootViewController, - as: .image(drawHierarchyInKeyWindow: true, precision: Config.precision)) + wait(for: [expectation], timeout: 0.1) + assertSnapshot(matching: window, as: .image) } } diff --git a/Example/ExampleSnapshotTests/GradientLoadingBarController/NotchGradientLoadingBarControllerTestCase.swift b/Example/ExampleSnapshotTests/GradientLoadingBarController/NotchGradientLoadingBarControllerTestCase.swift index 815fc1f..e1c51f8 100644 --- a/Example/ExampleSnapshotTests/GradientLoadingBarController/NotchGradientLoadingBarControllerTestCase.swift +++ b/Example/ExampleSnapshotTests/GradientLoadingBarController/NotchGradientLoadingBarControllerTestCase.swift @@ -14,25 +14,42 @@ import XCTest final class NotchGradientLoadingBarControllerTestCase: XCTestCase { // swiftlint:disable:previous type_name - // MARK: - Config + // MARK: - Private properties - private enum Config { - /// The percentage of pixels that must match. - static let precision: Float = 0.99 + private var window: UIWindow! + + // MARK: - Public methods + + override func setUp() { + super.setUp() + + window = UIApplication.shared.keyWindowInConnectedScenes + } + + override func tearDown() { + window = nil + + super.tearDown() } // MARK: - Test cases func test_notchGradientLoadingBarController() { // Given + // Show an empty view controller behind loading bar in our test. let rootViewController = UIViewController() - let notchGradientLoadingBarController = NotchGradientLoadingBarController() + window.rootViewController = rootViewController + + let expectation = expectation(description: "Expect view to be completely fade in.") // When - notchGradientLoadingBarController.fadeIn(duration: 0) + let gradientLoadingBarController = NotchGradientLoadingBarController() + gradientLoadingBarController.fadeIn(duration: 0) { _ in + expectation.fulfill() + } // Then - assertSnapshot(matching: rootViewController, - as: .image(drawHierarchyInKeyWindow: true, precision: Config.precision)) + wait(for: [expectation], timeout: 0.1) + assertSnapshot(matching: window, as: .image) } } diff --git a/Example/ExampleSnapshotTests/GradientLoadingBarController/__Snapshots__/GradientLoadingBarControllerTestCase/test_gradientLoadingBarController.1.png b/Example/ExampleSnapshotTests/GradientLoadingBarController/__Snapshots__/GradientLoadingBarControllerTestCase/test_gradientLoadingBarController.1.png index d83e2c9..671fe28 100644 Binary files a/Example/ExampleSnapshotTests/GradientLoadingBarController/__Snapshots__/GradientLoadingBarControllerTestCase/test_gradientLoadingBarController.1.png and b/Example/ExampleSnapshotTests/GradientLoadingBarController/__Snapshots__/GradientLoadingBarControllerTestCase/test_gradientLoadingBarController.1.png differ diff --git a/Example/ExampleSnapshotTests/GradientLoadingBarController/__Snapshots__/NotchGradientLoadingBarControllerTestCase/test_notchGradientLoadingBarController.1.png b/Example/ExampleSnapshotTests/GradientLoadingBarController/__Snapshots__/NotchGradientLoadingBarControllerTestCase/test_notchGradientLoadingBarController.1.png index d83e2c9..28f144c 100644 Binary files a/Example/ExampleSnapshotTests/GradientLoadingBarController/__Snapshots__/NotchGradientLoadingBarControllerTestCase/test_notchGradientLoadingBarController.1.png and b/Example/ExampleSnapshotTests/GradientLoadingBarController/__Snapshots__/NotchGradientLoadingBarControllerTestCase/test_notchGradientLoadingBarController.1.png differ