@@ -70,45 +70,44 @@ final class RiveControllerTests: XCTestCase {
7070 }
7171
7272 @MainActor
73- func test_advance_whenSettledAndFirstDraw_returnsConfiguration_andDoesNotAdvance ( ) async throws {
73+ func test_advance_whenSettledAndFirstDraw_returnsConfiguration_andAdvances ( ) async throws {
7474 let fixture = try await makeController ( dataBind: . none)
7575 await expectSettled ( within: fixture)
7676
7777 let configuration = fixture. controller. advance (
7878 now: 10 ,
79- isPaused: false ,
8079 isOnscreen: true ,
8180 drawableSize: CGSize ( width: 100 , height: 200 ) ,
8281 scaleProvider: MockScaleProvider ( )
8382 )
8483
8584 XCTAssertNotNil ( configuration)
86- XCTAssertTrue ( fixture. commandQueue. advanceStateMachineCalls. isEmpty)
85+ XCTAssertEqual ( fixture. commandQueue. advanceStateMachineCalls. count, 1 )
86+ XCTAssertEqual ( fixture. commandQueue. advanceStateMachineCalls [ 0 ] . time, 0 )
8787 }
8888
8989 @MainActor
90- func test_advance_whenSettledAfterFirstDraw_returnsNil_andDoesNotAdvance ( ) async throws {
90+ func test_advance_whenSettledAfterFirstDraw_skipsSecondFrame_andOnlyFirstFrameAdvances ( ) async throws {
9191 let fixture = try await makeController ( dataBind: . none)
9292 await expectSettled ( within: fixture)
9393
9494 let firstConfiguration = fixture. controller. advance (
9595 now: 10 ,
96- isPaused: false ,
9796 isOnscreen: true ,
9897 drawableSize: CGSize ( width: 100 , height: 200 ) ,
9998 scaleProvider: MockScaleProvider ( )
10099 )
101100 let secondConfiguration = fixture. controller. advance (
102101 now: 10.5 ,
103- isPaused: false ,
104102 isOnscreen: true ,
105103 drawableSize: CGSize ( width: 100 , height: 200 ) ,
106104 scaleProvider: MockScaleProvider ( )
107105 )
108106
109107 XCTAssertNotNil ( firstConfiguration)
110108 XCTAssertNil ( secondConfiguration)
111- XCTAssertTrue ( fixture. commandQueue. advanceStateMachineCalls. isEmpty)
109+ XCTAssertEqual ( fixture. commandQueue. advanceStateMachineCalls. count, 1 )
110+ XCTAssertEqual ( fixture. commandQueue. advanceStateMachineCalls [ 0 ] . time, 0 )
112111 }
113112
114113 @MainActor
@@ -117,7 +116,6 @@ final class RiveControllerTests: XCTestCase {
117116
118117 _ = fixture. controller. advance (
119118 now: 10 ,
120- isPaused: false ,
121119 isOnscreen: false ,
122120 drawableSize: CGSize ( width: 100 , height: 200 ) ,
123121 scaleProvider: MockScaleProvider ( )
@@ -126,7 +124,6 @@ final class RiveControllerTests: XCTestCase {
126124
127125 let configuration = fixture. controller. advance (
128126 now: 10.5 ,
129- isPaused: false ,
130127 isOnscreen: true ,
131128 drawableSize: CGSize ( width: 100 , height: 200 ) ,
132129 scaleProvider: MockScaleProvider ( )
@@ -143,7 +140,6 @@ final class RiveControllerTests: XCTestCase {
143140
144141 let configuration = fixture. controller. advance (
145142 now: 10 ,
146- isPaused: false ,
147143 isOnscreen: false ,
148144 drawableSize: CGSize ( width: 100 , height: 200 ) ,
149145 scaleProvider: MockScaleProvider ( )
@@ -160,14 +156,12 @@ final class RiveControllerTests: XCTestCase {
160156
161157 let firstConfiguration = fixture. controller. advance (
162158 now: 10 ,
163- isPaused: false ,
164159 isOnscreen: false ,
165160 drawableSize: CGSize ( width: 100 , height: 200 ) ,
166161 scaleProvider: MockScaleProvider ( )
167162 )
168163 let secondConfiguration = fixture. controller. advance (
169164 now: 10.5 ,
170- isPaused: false ,
171165 isOnscreen: false ,
172166 drawableSize: CGSize ( width: 100 , height: 200 ) ,
173167 scaleProvider: MockScaleProvider ( )
@@ -186,14 +180,12 @@ final class RiveControllerTests: XCTestCase {
186180
187181 let firstConfiguration = fixture. controller. advance (
188182 now: 10 ,
189- isPaused: false ,
190183 isOnscreen: true ,
191184 drawableSize: CGSize ( width: 100 , height: 200 ) ,
192185 scaleProvider: MockScaleProvider ( )
193186 )
194187 let secondConfiguration = fixture. controller. advance (
195188 now: 10.5 ,
196- isPaused: false ,
197189 isOnscreen: false ,
198190 drawableSize: CGSize ( width: 100 , height: 200 ) ,
199191 scaleProvider: MockScaleProvider ( )
@@ -212,7 +204,6 @@ final class RiveControllerTests: XCTestCase {
212204
213205 let configuration = fixture. controller. advance (
214206 now: 10 ,
215- isPaused: false ,
216207 isOnscreen: true ,
217208 drawableSize: CGSize ( width: 640 , height: 480 ) ,
218209 scaleProvider: MockScaleProvider ( )
@@ -229,14 +220,12 @@ final class RiveControllerTests: XCTestCase {
229220
230221 _ = fixture. controller. advance (
231222 now: 10 ,
232- isPaused: false ,
233223 isOnscreen: false ,
234224 drawableSize: CGSize ( width: 100 , height: 200 ) ,
235225 scaleProvider: MockScaleProvider ( )
236226 )
237227 _ = fixture. controller. advance (
238228 now: 10.5 ,
239- isPaused: false ,
240229 isOnscreen: false ,
241230 drawableSize: CGSize ( width: 100 , height: 200 ) ,
242231 scaleProvider: MockScaleProvider ( )
@@ -250,17 +239,16 @@ final class RiveControllerTests: XCTestCase {
250239 @MainActor
251240 func test_advance_whenPaused_allowsFirstDraw_thenBlocksSubsequentDraws( ) async throws {
252241 let fixture = try await makeController ( dataBind: . none)
242+ fixture. controller. isPaused = true
253243
254244 let firstConfiguration = fixture. controller. advance (
255245 now: 10 ,
256- isPaused: true ,
257246 isOnscreen: true ,
258247 drawableSize: CGSize ( width: 100 , height: 200 ) ,
259248 scaleProvider: MockScaleProvider ( )
260249 )
261250 let secondConfiguration = fixture. controller. advance (
262251 now: 10.5 ,
263- isPaused: true ,
264252 isOnscreen: true ,
265253 drawableSize: CGSize ( width: 100 , height: 200 ) ,
266254 scaleProvider: MockScaleProvider ( )
@@ -275,25 +263,24 @@ final class RiveControllerTests: XCTestCase {
275263 @MainActor
276264 func test_advance_whenResumedAfterPausedBlock_usesZeroDeltaFirstFrame_withoutResetTiming( ) async throws {
277265 let fixture = try await makeController ( dataBind: . none)
266+ fixture. controller. isPaused = true
278267
279268 _ = fixture. controller. advance (
280269 now: 10 ,
281- isPaused: true ,
282270 isOnscreen: true ,
283271 drawableSize: CGSize ( width: 100 , height: 200 ) ,
284272 scaleProvider: MockScaleProvider ( )
285273 )
286274 _ = fixture. controller. advance (
287275 now: 10.5 ,
288- isPaused: true ,
289276 isOnscreen: true ,
290277 drawableSize: CGSize ( width: 100 , height: 200 ) ,
291278 scaleProvider: MockScaleProvider ( )
292279 )
293280
281+ fixture. controller. isPaused = false
294282 _ = fixture. controller. advance (
295283 now: 11 ,
296- isPaused: false ,
297284 isOnscreen: false ,
298285 drawableSize: CGSize ( width: 100 , height: 200 ) ,
299286 scaleProvider: MockScaleProvider ( )
@@ -304,6 +291,62 @@ final class RiveControllerTests: XCTestCase {
304291 XCTAssertEqual ( fixture. commandQueue. advanceStateMachineCalls [ 1 ] . time, 0 )
305292 }
306293
294+ @MainActor
295+ func test_advance_whenResumedAfterPauseTransition_usesZeroDeltaEvenIfTimestampWasSet( ) async throws {
296+ let fixture = try await makeController ( dataBind: . none)
297+
298+ _ = fixture. controller. advance (
299+ now: 10 ,
300+ isOnscreen: true ,
301+ drawableSize: CGSize ( width: 100 , height: 200 ) ,
302+ scaleProvider: MockScaleProvider ( )
303+ )
304+ fixture. controller. isPaused = true
305+ _ = fixture. controller. advance (
306+ now: 20 ,
307+ isOnscreen: true ,
308+ drawableSize: CGSize ( width: 100 , height: 200 ) ,
309+ scaleProvider: MockScaleProvider ( )
310+ )
311+ fixture. controller. isPaused = false
312+ _ = fixture. controller. advance (
313+ now: 30 ,
314+ isOnscreen: true ,
315+ drawableSize: CGSize ( width: 100 , height: 200 ) ,
316+ scaleProvider: MockScaleProvider ( )
317+ )
318+
319+ XCTAssertEqual ( fixture. commandQueue. advanceStateMachineCalls. count, 2 )
320+ XCTAssertEqual ( fixture. commandQueue. advanceStateMachineCalls [ 0 ] . time, 0 )
321+ XCTAssertEqual ( fixture. commandQueue. advanceStateMachineCalls [ 1 ] . time, 0 )
322+ }
323+
324+ @MainActor
325+ func test_settingIsPausedTrue_resetsTimingForNextUnpausedAdvance( ) async throws {
326+ let fixture = try await makeController ( dataBind: . none)
327+
328+ _ = fixture. controller. advance (
329+ now: 10 ,
330+ isOnscreen: true ,
331+ drawableSize: CGSize ( width: 100 , height: 200 ) ,
332+ scaleProvider: MockScaleProvider ( )
333+ )
334+
335+ fixture. controller. isPaused = true
336+ fixture. controller. isPaused = false
337+
338+ _ = fixture. controller. advance (
339+ now: 30 ,
340+ isOnscreen: true ,
341+ drawableSize: CGSize ( width: 100 , height: 200 ) ,
342+ scaleProvider: MockScaleProvider ( )
343+ )
344+
345+ XCTAssertEqual ( fixture. commandQueue. advanceStateMachineCalls. count, 2 )
346+ XCTAssertEqual ( fixture. commandQueue. advanceStateMachineCalls [ 0 ] . time, 0 )
347+ XCTAssertEqual ( fixture. commandQueue. advanceStateMachineCalls [ 1 ] . time, 0 )
348+ }
349+
307350 // MARK: - Helpers
308351
309352 @MainActor
0 commit comments