diff --git a/Example/GradientLoadingBar.xcodeproj/project.pbxproj b/Example/GradientLoadingBar.xcodeproj/project.pbxproj index 58ff340..d585593 100644 --- a/Example/GradientLoadingBar.xcodeproj/project.pbxproj +++ b/Example/GradientLoadingBar.xcodeproj/project.pbxproj @@ -28,6 +28,9 @@ 97B6F5FE2143F31F008CFEA5 /* UIColor+CustomColors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97B6F5FA2143F31F008CFEA5 /* UIColor+CustomColors.swift */; }; 97B6F5FF2143F31F008CFEA5 /* BlueFilledButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97B6F5FC2143F31F008CFEA5 /* BlueFilledButton.swift */; }; 97B6F6002143F31F008CFEA5 /* BlueBorderedButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97B6F5FD2143F31F008CFEA5 /* BlueBorderedButton.swift */; }; + DC190F622496A25A0069E2B0 /* NotchGradientLoadingBarControllerTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC190F602496A24F0069E2B0 /* NotchGradientLoadingBarControllerTestCase.swift */; }; + DCE3AB13249761B300889FFA /* Snapshotting+WindowedImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCE3AB11249761AB00889FFA /* Snapshotting+WindowedImage.swift */; }; + DCE3AB16249764BB00889FFA /* GradientLoadingBarControllerTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCE3AB14249764A000889FFA /* GradientLoadingBarControllerTestCase.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -81,6 +84,10 @@ A98CA9F1B0C1BD6864C14E01 /* Pods-GradientLoadingBar_SnapshotTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GradientLoadingBar_SnapshotTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-GradientLoadingBar_SnapshotTests/Pods-GradientLoadingBar_SnapshotTests.release.xcconfig"; sourceTree = ""; }; ABA9B1EF5F3928BA6E31D3EA /* Pods_GradientLoadingBar_SnapshotTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_GradientLoadingBar_SnapshotTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; C06CA4DFA1DCB931095ABD3D /* GradientLoadingBar.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = GradientLoadingBar.podspec; path = ../GradientLoadingBar.podspec; sourceTree = ""; }; + DC190F602496A24F0069E2B0 /* NotchGradientLoadingBarControllerTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotchGradientLoadingBarControllerTestCase.swift; sourceTree = ""; }; + DCE3AB11249761AB00889FFA /* Snapshotting+WindowedImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Snapshotting+WindowedImage.swift"; sourceTree = ""; }; + DCE3AB14249764A000889FFA /* GradientLoadingBarControllerTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradientLoadingBarControllerTestCase.swift; sourceTree = ""; }; + DCE3AB172497670400889FFA /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; E7B292793F03D669ACAA92D2 /* Pods-GradientLoadingBar_SnapshotTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GradientLoadingBar_SnapshotTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-GradientLoadingBar_SnapshotTests/Pods-GradientLoadingBar_SnapshotTests.debug.xcconfig"; sourceTree = ""; }; F76834BE9E43CA11377EC030 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; FECB95A4857728345199461F /* Pods-GradientLoadingBar_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GradientLoadingBar_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-GradientLoadingBar_Tests/Pods-GradientLoadingBar_Tests.debug.xcconfig"; sourceTree = ""; }; @@ -196,9 +203,11 @@ 649A163A23770B4400404F3C /* SnapshotTests */ = { isa = PBXGroup; children = ( - 649A163B23770B4400404F3C /* DefaultColorSnapshotTestCase.swift */, - 649A164323770E9300404F3C /* CustomColorSnapshotTestCase.swift */, + DCE3AB102497619600889FFA /* _Helper */, + DC190F5E2496A2290069E2B0 /* GradientActivityIndicatorView */, + DC190F5F2496A2380069E2B0 /* GradientLoadingBarController */, 649A163D23770B4400404F3C /* Info.plist */, + DCE3AB172497670400889FFA /* README.md */, ); path = SnapshotTests; sourceTree = ""; @@ -261,6 +270,32 @@ name = Frameworks; sourceTree = ""; }; + DC190F5E2496A2290069E2B0 /* GradientActivityIndicatorView */ = { + isa = PBXGroup; + children = ( + 649A163B23770B4400404F3C /* DefaultColorSnapshotTestCase.swift */, + 649A164323770E9300404F3C /* CustomColorSnapshotTestCase.swift */, + ); + path = GradientActivityIndicatorView; + sourceTree = ""; + }; + DC190F5F2496A2380069E2B0 /* GradientLoadingBarController */ = { + isa = PBXGroup; + children = ( + DCE3AB14249764A000889FFA /* GradientLoadingBarControllerTestCase.swift */, + DC190F602496A24F0069E2B0 /* NotchGradientLoadingBarControllerTestCase.swift */, + ); + path = GradientLoadingBarController; + sourceTree = ""; + }; + DCE3AB102497619600889FFA /* _Helper */ = { + isa = PBXGroup; + children = ( + DCE3AB11249761AB00889FFA /* Snapshotting+WindowedImage.swift */, + ); + path = _Helper; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -586,6 +621,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + DCE3AB13249761B300889FFA /* Snapshotting+WindowedImage.swift in Sources */, + DC190F622496A25A0069E2B0 /* NotchGradientLoadingBarControllerTestCase.swift in Sources */, + DCE3AB16249764BB00889FFA /* GradientLoadingBarControllerTestCase.swift in Sources */, 649A164423770E9300404F3C /* CustomColorSnapshotTestCase.swift in Sources */, 649A163C23770B4400404F3C /* DefaultColorSnapshotTestCase.swift in Sources */, ); diff --git a/Example/SnapshotTests/CustomColorSnapshotTestCase.swift b/Example/SnapshotTests/GradientActivityIndicatorView/CustomColorSnapshotTestCase.swift similarity index 100% rename from Example/SnapshotTests/CustomColorSnapshotTestCase.swift rename to Example/SnapshotTests/GradientActivityIndicatorView/CustomColorSnapshotTestCase.swift diff --git a/Example/SnapshotTests/DefaultColorSnapshotTestCase.swift b/Example/SnapshotTests/GradientActivityIndicatorView/DefaultColorSnapshotTestCase.swift similarity index 100% rename from Example/SnapshotTests/DefaultColorSnapshotTestCase.swift rename to Example/SnapshotTests/GradientActivityIndicatorView/DefaultColorSnapshotTestCase.swift diff --git a/Example/SnapshotTests/__Snapshots__/CustomColorSnapshotTestCase/testGradientProgressIndicatorViewShouldContainCorrectColorsInitially.1.png b/Example/SnapshotTests/GradientActivityIndicatorView/__Snapshots__/CustomColorSnapshotTestCase/testGradientProgressIndicatorViewShouldContainCorrectColorsInitially.1.png similarity index 100% rename from Example/SnapshotTests/__Snapshots__/CustomColorSnapshotTestCase/testGradientProgressIndicatorViewShouldContainCorrectColorsInitially.1.png rename to Example/SnapshotTests/GradientActivityIndicatorView/__Snapshots__/CustomColorSnapshotTestCase/testGradientProgressIndicatorViewShouldContainCorrectColorsInitially.1.png diff --git a/Example/SnapshotTests/__Snapshots__/DefaultColorSnapshotTestCase/testGradientProgressIndicatorViewShouldContainCorrectColorsInitially.1.png b/Example/SnapshotTests/GradientActivityIndicatorView/__Snapshots__/DefaultColorSnapshotTestCase/testGradientProgressIndicatorViewShouldContainCorrectColorsInitially.1.png similarity index 100% rename from Example/SnapshotTests/__Snapshots__/DefaultColorSnapshotTestCase/testGradientProgressIndicatorViewShouldContainCorrectColorsInitially.1.png rename to Example/SnapshotTests/GradientActivityIndicatorView/__Snapshots__/DefaultColorSnapshotTestCase/testGradientProgressIndicatorViewShouldContainCorrectColorsInitially.1.png diff --git a/Example/SnapshotTests/GradientLoadingBarController/GradientLoadingBarControllerTestCase.swift b/Example/SnapshotTests/GradientLoadingBarController/GradientLoadingBarControllerTestCase.swift new file mode 100644 index 0000000..a16cbe4 --- /dev/null +++ b/Example/SnapshotTests/GradientLoadingBarController/GradientLoadingBarControllerTestCase.swift @@ -0,0 +1,49 @@ +// +// GradientLoadingBarControllerTestCase.swift +// GradientLoadingBar_SnapshotTests +// +// Created by Felix Mau on 06/14/20. +// Copyright © 2020 CocoaPods. All rights reserved. +// + +import XCTest +import SnapshotTesting + +@testable import GradientLoadingBar + +class GradientLoadingBarControllerTestCase: XCTestCase { + // MARK: - Private properties + + private var gradientLoadingBarController: GradientLoadingBarController! + + // MARK: - Public methods + + override func setUpWithError() throws { + try super.setUpWithError() + + gradientLoadingBarController = GradientLoadingBarController() + gradientLoadingBarController.fadeIn(duration: 0) + } + + override func tearDownWithError() throws { + gradientLoadingBarController = nil + + try super.tearDownWithError() + } + + // MARK: - Tests + + func testGradientLoadingBarController() { + // Given + let rootViewController = UIViewController() + + let expectation = self.expectation(description: "Waiting for view to appear.") + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + expectation.fulfill() + } + + // Then + wait(for: [expectation], timeout: 1) + assertSnapshot(matching: rootViewController, as: .windowedImage) + } +} diff --git a/Example/SnapshotTests/GradientLoadingBarController/NotchGradientLoadingBarControllerTestCase.swift b/Example/SnapshotTests/GradientLoadingBarController/NotchGradientLoadingBarControllerTestCase.swift new file mode 100644 index 0000000..c21db3b --- /dev/null +++ b/Example/SnapshotTests/GradientLoadingBarController/NotchGradientLoadingBarControllerTestCase.swift @@ -0,0 +1,51 @@ +// +// NotchGradientLoadingBarControllerTestCase.swift +// GradientLoadingBar_SnapshotTests +// +// Created by Felix Mau on 06/14/20. +// Copyright © 2020 CocoaPods. All rights reserved. +// + +import XCTest +import SnapshotTesting + +@testable import GradientLoadingBar + +class NotchGradientLoadingBarControllerTestCase: XCTestCase { + // swiftlint:disable:previous type_name + + // MARK: - Private properties + + private var notchGradientLoadingBarController: NotchGradientLoadingBarController! + + // MARK: - Public methods + + override func setUpWithError() throws { + try super.setUpWithError() + + notchGradientLoadingBarController = NotchGradientLoadingBarController() + notchGradientLoadingBarController.fadeIn(duration: 0) + } + + override func tearDownWithError() throws { + notchGradientLoadingBarController = nil + + try super.tearDownWithError() + } + + // MARK: - Tests + + func testNotchGradientLoadingBarController() { + // Given + let rootViewController = UIViewController() + + let expectation = self.expectation(description: "Waiting for view to appear.") + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + expectation.fulfill() + } + + // Then + wait(for: [expectation], timeout: 1) + assertSnapshot(matching: rootViewController, as: .windowedImage) + } +} diff --git a/Example/SnapshotTests/GradientLoadingBarController/__Snapshots__/GradientLoadingBarControllerTestCase/testGradientLoadingBarController.1.png b/Example/SnapshotTests/GradientLoadingBarController/__Snapshots__/GradientLoadingBarControllerTestCase/testGradientLoadingBarController.1.png new file mode 100644 index 0000000..e3a7194 Binary files /dev/null and b/Example/SnapshotTests/GradientLoadingBarController/__Snapshots__/GradientLoadingBarControllerTestCase/testGradientLoadingBarController.1.png differ diff --git a/Example/SnapshotTests/GradientLoadingBarController/__Snapshots__/NotchGradientLoadingBarControllerTestCase/testNotchGradientLoadingBarController.1.png b/Example/SnapshotTests/GradientLoadingBarController/__Snapshots__/NotchGradientLoadingBarControllerTestCase/testNotchGradientLoadingBarController.1.png new file mode 100644 index 0000000..91f7d8b Binary files /dev/null and b/Example/SnapshotTests/GradientLoadingBarController/__Snapshots__/NotchGradientLoadingBarControllerTestCase/testNotchGradientLoadingBarController.1.png differ diff --git a/Example/SnapshotTests/README.md b/Example/SnapshotTests/README.md new file mode 100644 index 0000000..e5ab619 --- /dev/null +++ b/Example/SnapshotTests/README.md @@ -0,0 +1,4 @@ +# Snapshot-Tests + +## Device +Run test-cases with the `iPhone X` using `iOS 13.5`. diff --git a/Example/SnapshotTests/_Helper/Snapshotting+WindowedImage.swift b/Example/SnapshotTests/_Helper/Snapshotting+WindowedImage.swift new file mode 100644 index 0000000..ce9530d --- /dev/null +++ b/Example/SnapshotTests/_Helper/Snapshotting+WindowedImage.swift @@ -0,0 +1,44 @@ +// +// Snapshotting+WindowedImage.swift +// GradientLoadingBar_SnapshotTests +// +// Created by Felix Mau on 06/14/20. +// Copyright © 2020 CocoaPods. All rights reserved. +// + +import SnapshotTesting + +// MARK: - Config + +private enum Config { + /// Allow for a 1% pixel difference. + static let precision: Float = 0.99 +} + +// MARK: - Public properties + +extension Snapshotting where Value: UIViewController, Format == UIImage { + /// Based on: + /// and + static var windowedImage: Snapshotting { + Snapshotting.image(precision: Config.precision).asyncPullback { viewController in + Async { callback in + UIView.setAnimationsEnabled(false) + + guard let keyWindow = UIApplication.shared.windows.first(where: { $0.isKeyWindow }) else { + fatalError("⚠️ – Failed to get key window from application!") + } + keyWindow.rootViewController = viewController + + DispatchQueue.main.async { + let image = UIGraphicsImageRenderer(bounds: keyWindow.bounds).image { _ in + keyWindow.drawHierarchy(in: keyWindow.bounds, afterScreenUpdates: true) + } + callback(image) + + UIView.setAnimationsEnabled(true) + } + } + } + } +} diff --git a/GradientLoadingBar/Classes/GradientLoadingBarController.swift b/GradientLoadingBar/Classes/GradientLoadingBarController.swift index f535983..1f2398e 100644 --- a/GradientLoadingBar/Classes/GradientLoadingBarController.swift +++ b/GradientLoadingBar/Classes/GradientLoadingBarController.swift @@ -80,6 +80,10 @@ open class GradientLoadingBarController { bindViewModelToView() } + deinit { + gradientActivityIndicatorView.removeFromSuperview() + } + // MARK: - Public methods /// Apply layout constraints for gradient loading view.