-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTests.swift
73 lines (56 loc) · 2.82 KB
/
Tests.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
import XCTest
import SnapshotTesting
import SDWebImageMockPlugin
@testable import SDWebImageMockPlugin_Example
// swiftlint:disable implicitly_unwrapped_optional
class Tests: XCTestCase {
var imageMocker: ImageCacheMocker!
override func setUp() {
super.setUp()
imageMocker = ImageCacheMocker()
imageMocker.registerProvider(.bundleImageProvider(
bundlesWithIdentifiers: ["testBundle": Bundle(for: Tests.self)])
)
imageMocker.setupSDWebImageMocking()
}
func testViewController() throws {
let viewController = SDWebImageMockPlugin_Example.ViewController()
viewController.configure(with: URL(string: "http://127.0.0.1"))
assertSnapshot(matching: viewController, as: .image(on: .iPhoneX))
}
func testMultipleImagesViewController() throws {
let viewController = SDWebImageMockPlugin_Example.MultipleImagesViewController()
assertSnapshot(matching: viewController, as: .image(on: .iPhoneX))
}
func testConfiguredMultipleImagesViewController() throws {
let viewController = SDWebImageMockPlugin_Example.MultipleImagesViewController()
viewController.loadViewIfNeeded()
viewController.configure(with: [
(.imageMock(forWidth: 500, height: 100), .scaleAspectFit),
(.imageMock(forWidth: 50, height: 500), .scaleAspectFill),
(.imageMock(withRatio: Double(16) / Double(9)), .scaleAspectFit),
(.imageMock(withRatio: Double(3) / Double(2)), .scaleAspectFit),
(.imageMock(named: "sampleImage1", inBundleID: "testBundle"), .scaleAspectFit),
(.imageMock(named: "sampleImage2", inBundleID: "testBundle"), .scaleAspectFit),
(URL(string: "http://127.0.0.1"), .scaleToFill)
])
assertSnapshot(matching: viewController, as: .image(on: .iPhoneX))
}
func testMultipleSwiftUIImagesViewController() throws {
let viewController = SDWebImageMockPlugin_Example.SwiftUIHostingViewController()
assertSnapshot(matching: viewController, as: .image(on: .iPhoneX))
}
func testConfiguredMultipleSwiftUIImagesViewController() throws {
let viewController = SDWebImageMockPlugin_Example.SwiftUIHostingViewController()
viewController.viewModel.configure(with: [
(.imageMock(forWidth: 500, height: 100), .fit),
(.imageMock(forWidth: 50, height: 200), .fill),
(.imageMock(withRatio: Double(16) / Double(9)), .fit),
(.imageMock(withRatio: Double(3) / Double(2)), .fit),
(.imageMock(named: "sampleImage1", inBundleID: "testBundle"), .fit),
(.imageMock(named: "sampleImage2", inBundleID: "testBundle"), .fit),
(URL(string: "http://127.0.0.1"), nil)
])
assertSnapshot(matching: viewController, as: .image(on: .iPhoneX))
}
}