Skip to content

Commit bd1bb53

Browse files
committed
Add AnimationTestView
1 parent 34b59dd commit bd1bb53

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

Example/OpenSwiftUIUITests/Graphic/Color/ColorUITests.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ struct ColorUITests {
6060

6161
@Test
6262
func colorAnimation() {
63-
struct ContentView: View {
63+
struct ContentView: AnimationTestView {
64+
nonisolated static var model: AnimationTestModel {
65+
AnimationTestModel(duration: 1, count: 10)
66+
}
67+
6468
@State private var showRed = false
6569
var body: some View {
6670
VStack {
@@ -73,10 +77,9 @@ struct ColorUITests {
7377
}
7478
}
7579
}
76-
let model = AnimationTestModel(duration: 1, count: 10)
7780
openSwiftUIAssertAnimationSnapshot(
78-
of: ContentView(),
79-
model: model,
81+
of: ContentView()
82+
// precision: 0.8 // TODO: Maybe related with issue #340
8083
)
8184
}
8285
}

Example/OpenSwiftUIUITests/UITests/AnimationDebugController.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ struct AnimationTestModel: Hashable {
2020
}
2121
}
2222

23+
protocol AnimationTestView: View {
24+
static var model: AnimationTestModel { get }
25+
}
26+
2327
final class AnimationDebugController<V>: UIHostingController<V> where V: View {
2428
init(_ view: V) {
2529
super.init(rootView: view)

Example/OpenSwiftUIUITests/UITests/SnapshotTesting+Testing.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ private func openSwiftUIAssertSnapshot<Value, Format>(
158158

159159
// MARK: - Animation
160160

161-
func openSwiftUIAssertAnimationSnapshot<V: View>(
161+
func openSwiftUIAssertAnimationSnapshot<V: AnimationTestView>(
162162
of value: @autoclosure () -> V,
163-
model: AnimationTestModel,
163+
precision: Float = 1,
164164
perceptualPrecision: Float = 1,
165165
size: CGSize = defaultSize,
166166
record recording: Bool? = shouldRecord,
@@ -174,11 +174,12 @@ func openSwiftUIAssertAnimationSnapshot<V: View>(
174174
let vc = AnimationDebugController(value())
175175
// Flush the neccessary onAppear etc. stuff
176176
vc.advance(interval: .zero)
177+
let model = V.model
177178
model.intervals.enumerated().forEach { (index, interval) in
178179
vc.advance(interval: interval)
179180
openSwiftUIAssertSnapshot(
180181
of: vc,
181-
as: .image(perceptualPrecision: perceptualPrecision, size: size),
182+
as: .image(precision: precision, perceptualPrecision: perceptualPrecision, size: size),
182183
named: "\(index + 1)_\(model.intervals.count).\(Int(size.width))x\(Int(size.height))",
183184
record: recording,
184185
timeout: timeout,

0 commit comments

Comments
 (0)