-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
222 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
Snap/Core/Application/Expectation/SnapshotLayerExpectation.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import UIKit | ||
import XCTest | ||
|
||
// MARK: - XCTestCase + CALayer Expectation | ||
|
||
extension XCTestCase { | ||
public func expect(_ layer: CALayer, function: String = #function, file: String = #file ) -> Matcher { | ||
let testTarget = TestTarget( | ||
function: function, | ||
file: file | ||
) | ||
return resolver.makeMatcher( | ||
with: layer, | ||
isRecording: isRecording, | ||
tesTarget: testTarget | ||
) | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
.../Expectation/SnapshotViewExpecation.swift → ...Expectation/SnapshotViewExpectation.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import UIKit | ||
|
||
protocol SnapshotLayerMatcherProvider { | ||
func makeMatcher(with layer: CALayer, isRecording: Bool, tesTarget: TestTarget) -> Matcher | ||
} | ||
|
||
struct SnapshotLayerMatcher: Matcher { | ||
|
||
private let layer: CALayer | ||
private let isRecording: Bool | ||
private let testTarget: TestTarget | ||
private let viewMatcherProvider: SnapshotViewMatcherProvider | ||
|
||
init(layer: CALayer, | ||
isRecording: Bool, | ||
testTarget: TestTarget, | ||
viewMatcherProvider: SnapshotViewMatcherProvider) | ||
{ | ||
self.layer = layer | ||
self.isRecording = isRecording | ||
self.testTarget = testTarget | ||
self.viewMatcherProvider = viewMatcherProvider | ||
} | ||
|
||
func toMatchSnapshot() { | ||
let view = UIView(frame: layer.frame) | ||
view.layer.insertSublayer(layer, at: 0) | ||
|
||
viewMatcherProvider.makeMatcher( | ||
with: view, | ||
isRecording: isRecording, | ||
tesTarget: testTarget | ||
).toMatchSnapshot() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Snap/Core/Infrastructure/Extension/CALayer/CALayer+Image.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import UIKit | ||
|
||
extension CALayer { | ||
/// Extract image from CALayer | ||
func image() -> UIImage? { | ||
defer { | ||
UIGraphicsEndImageContext() | ||
} | ||
UIGraphicsBeginImageContextWithOptions(bounds.size, isOpaque, contentsScale) | ||
guard let context = UIGraphicsGetCurrentContext() else { return nil } | ||
render(in: context) | ||
return UIGraphicsGetImageFromCurrentImageContext() | ||
} | ||
} |
Oops, something went wrong.