-
Notifications
You must be signed in to change notification settings - Fork 0
/
SnapshotTests.swift
86 lines (69 loc) · 2.65 KB
/
SnapshotTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import Foundation
import XCTest
import SnapshotTesting
import TestHelpers
import Combine
import UIKit
@testable import Networking
@testable import CV_UIKit
class SnapshotTests: XCTestCase {
override func setUp() async throws {
try await super.setUp()
UIFont.registerFonts()
mainScheduler = .immediate
// isRecording = true
}
func testLoadingViewController() {
let viewControllerFactory = UIViewControllerFactory(apiClient: .noop, imageProvider: .noop)
let sut = viewControllerFactory.loadingViewController()
assertSnapshots(matching: sut, as: .testStrategies())
}
func testErrorViewController() {
let viewControllerFactory = UIViewControllerFactory(apiClient: .noop, imageProvider: .noop)
let sut = viewControllerFactory.errorViewController(refreshAction: {})
assertSnapshots(matching: sut, as: .testStrategies(precision: 0.999))
}
func testCollectionViewController_imageLoading() {
testCollectionViewController()
}
func testCollectionViewController_imageLoadingFailed() {
var imageProvider = ImageProvider.noop
imageProvider.imagePathPublisher = stubReturn(with: .stubFailure(errorStub))
testCollectionViewController(precision: 0.999, imageProvider: imageProvider)
}
func testCollectionViewController_imageLoadingSucceeded() {
var imageProvider = ImageProvider.noop
imageProvider.imagePathPublisher = stubReturn(with: .stubOutput(Image.whitePixel.url.path))
testCollectionViewController(imageProvider: imageProvider)
}
// MARK: -
func testCollectionViewController(
precision: Float = 1,
imageProvider: ImageProvider = .noop,
file: StaticString = #file,
testName: String = #function,
line: UInt = #line
) {
let viewControllerFactory = UIViewControllerFactory(apiClient: .noop, imageProvider: imageProvider)
let sut = viewControllerFactory.collectionViewController(.mock)
assertSnapshots(
matching: sut,
as: .testStrategies(precision: precision),
file: file,
testName: testName,
line: line
)
}
}
private extension Dictionary where Key == String, Value == Snapshotting<UIViewController, UIImage> {
static func testStrategies(precision: Float = 1) -> Self {
[
"light": .image(
on: .iPhoneXsMax,
precision: precision,
traits: .init(userInterfaceStyle: .light)
),
"dark": .image(on: .iPhoneXsMax, precision: 0.99, traits: .init(userInterfaceStyle: .dark))
]
}
}