@@ -223,11 +223,11 @@ class FetchedResultsDataProviderTests: XCTestCase {
223223
224224 dataProvider = try ! FetchedResultsDataProvider ( fetchedResultsController: fetchedResultsController, dataProviderDidUpdate: { _ in } )
225225 dataProvider. whenDataProviderChanged = { updates in
226- if updates! . isEmpty {
226+ guard let updates = updates , !updates . isEmpty else {
227227 return
228228 }
229-
230- for update in updates! {
229+
230+ for update in updates {
231231 switch update {
232232 case . update( let indexPath, _) :
233233 updateIndexPath = indexPath
@@ -251,22 +251,57 @@ class FetchedResultsDataProviderTests: XCTestCase {
251251 XCTAssertEqual ( moveIndexPaths, [ oldIndexPath, newIndexPath] )
252252 }
253253
254+ func testProcessUpdatesOrderForMoveChange( ) {
255+ var updatesNumber = 0
256+ var isFirstMoveCall = false
257+ var isSecondUpdateCall = false
258+
259+ dataProvider = try ! FetchedResultsDataProvider ( fetchedResultsController: fetchedResultsController, dataProviderDidUpdate: { _ in } )
260+ dataProvider. whenDataProviderChanged = { updates in
261+ guard let updates = updates, !updates. isEmpty else {
262+ return
263+ }
264+
265+ updatesNumber += 1
266+
267+ if case . move( _, _) = updates. first! {
268+ isFirstMoveCall = true
269+ }
270+
271+ if case . update( _, _) = updates. first! {
272+ if isFirstMoveCall {
273+ isSecondUpdateCall = true
274+ }
275+ }
276+
277+ }
278+
279+ let oldIndexPath = IndexPath ( row: 0 , section: 0 )
280+ let newIndexPath = IndexPath ( row: 1 , section: 0 )
281+ dataProvider. controller ( fetchedResultsController as! NSFetchedResultsController < NSFetchRequestResult > ,
282+ didChange: 1 , at: oldIndexPath, for: . move, newIndexPath: newIndexPath)
283+
284+ //When
285+ dataProvider. controllerDidChangeContent ( fetchedResultsController as! NSFetchedResultsController < NSFetchRequestResult > )
286+
287+ //Then
288+ XCTAssertEqual ( updatesNumber, 2 )
289+ XCTAssert ( isFirstMoveCall)
290+ XCTAssert ( isSecondUpdateCall)
291+ }
292+
254293 func testProcessUpdatesForUpdateChange( ) {
255294 //Given
256295 var updateIndexPath = IndexPath ( )
257296
258297 dataProvider = try ! FetchedResultsDataProvider ( fetchedResultsController: fetchedResultsController, dataProviderDidUpdate: { _ in } )
259298 dataProvider. whenDataProviderChanged = { updates in
260- if updates! . isEmpty {
299+ guard let updates = updates , !updates . isEmpty else {
261300 return
262301 }
263-
264- for update in updates! {
265- switch update {
266- case . update( let indexPath, _) :
267- updateIndexPath = indexPath
268- default : break
269- }
302+
303+ if case . update( let indexPath, _) = updates. first! {
304+ updateIndexPath = indexPath
270305 }
271306 }
272307
0 commit comments