-
Notifications
You must be signed in to change notification settings - Fork 102
/
DynamicTypeTests.swift
121 lines (95 loc) · 4.82 KB
/
DynamicTypeTests.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import Nimble
import Nimble_Snapshots
import Quick
import UIKit
@testable import Bootstrap
@MainActor
final class DynamicTypeTests: QuickSpec {
override func spec() {
describe("in some context") {
var view: UIView!
beforeEach {
setNimbleTolerance(0)
setNimbleTestFolder("tests")
view = DynamicTypeView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))
}
it("has a valid snapshot for all content size categories (iOS 10)") {
let version = ProcessInfo.processInfo.operatingSystemVersion
guard version.iOS10 else {
return
}
expect(view).to(haveValidDynamicTypeSnapshot())
let name = "something custom_\(version.majorVersion)_\(version.minorVersion)"
expect(view).to(haveValidDynamicTypeSnapshot(named: name))
}
it("has a valid snapshot for a single content size category (iOS 10)") {
let version = ProcessInfo.processInfo.operatingSystemVersion
guard version.iOS10 else {
return
}
expect(view).to(haveValidDynamicTypeSnapshot(sizes: [.extraLarge]))
let name = "something custom_\(version.majorVersion)_\(version.minorVersion)"
expect(view).to(haveValidDynamicTypeSnapshot(named: name, sizes: [.extraLarge]))
}
it("has a valid pretty-syntax snapshot (iOS 10)") {
let version = ProcessInfo.processInfo.operatingSystemVersion
guard version.iOS10 else {
return
}
expect(view) == dynamicTypeSnapshot()
}
it("has a valid pretty-syntax snapshot for only one size category (iOS 10)") {
let version = ProcessInfo.processInfo.operatingSystemVersion
guard version.iOS10 else {
return
}
expect(view) == dynamicTypeSnapshot(sizes: [.extraLarge])
}
it("has a valid snapshot with model and OS in name") {
// expect(view).to(recordDynamicTypeSnapshot(isDeviceAgnostic: true))
expect(view).to(haveValidDynamicTypeSnapshot(isDeviceAgnostic: true))
// expect(view).to(recordDynamicTypeSnapshot(named: "something custom with model and OS",
// isDeviceAgnostic: true))
expect(view).to(haveValidDynamicTypeSnapshot(named: "something custom with model and OS",
isDeviceAgnostic: true))
}
it("has a valid snapshot with identifier") {
// expect(view).to(recordDynamicTypeSnapshot(identifier: "bootstrap"))
expect(view).to(haveValidDynamicTypeSnapshot(identifier: "bootstrap"))
// expect(view).to(recordDynamicTypeSnapshot(named: "something custom with model and OS",
// identifier: "bootstrap"))
expect(view).to(haveValidDynamicTypeSnapshot(named: "something custom with model and OS",
identifier: "bootstrap"))
}
it("works with adjustsFontForContentSizeCategory") {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 100))
label.text = "Example"
label.adjustsFontForContentSizeCategory = true
label.font = .preferredFont(forTextStyle: .body)
expect(label) == dynamicTypeSnapshot()
}
it("works with adjustsFontForContentSizeCategory in a subview") {
let frame = CGRect(x: 0, y: 0, width: 300, height: 100)
let view = UIView(frame: frame)
let label = UILabel(frame: frame)
label.text = "Example"
label.adjustsFontForContentSizeCategory = true
label.font = .preferredFont(forTextStyle: .body)
view.addSubview(label)
expect(view) == dynamicTypeSnapshot()
}
it("works with traitCollectionDidChange in a view controller from a storyboard") {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateInitialViewController()
controller?.beginAppearanceTransition(true, animated: false)
controller?.endAppearanceTransition()
expect(controller).to(haveValidDynamicTypeSnapshot())
}
}
}
}
private extension OperatingSystemVersion {
var iOS10: Bool {
return majorVersion == 10 && minorVersion == 3
}
}