@@ -21,7 +21,7 @@ class WebImageTests: XCTestCase {
2121 let expectation = self . expectation ( description: " WebImage static url initializer " )
2222 let imageUrl = URL ( string: " https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png " )
2323 let imageView = WebImage ( url: imageUrl)
24- let introspectView = imageView. onSuccess { image, cacheType in
24+ let introspectView = imageView. onSuccess { image, data , cacheType in
2525 #if os(iOS) || os(tvOS)
2626 let displayImage = try ? imageView. inspect ( ) . group ( ) . image ( 0 ) . uiImage ( )
2727 #else
@@ -43,7 +43,7 @@ class WebImageTests: XCTestCase {
4343 let imageUrl = URL ( string: " https://apng.onevcat.com/assets/elephant.png " )
4444 let binding = Binding < Bool > ( wrappedValue: true )
4545 let imageView = WebImage ( url: imageUrl, isAnimating: binding)
46- let introspectView = imageView. onSuccess { image, cacheType in
46+ let introspectView = imageView. onSuccess { image, data , cacheType in
4747 if let animatedImage = image as? SDAnimatedImage {
4848 XCTAssertTrue ( imageView. isAnimating)
4949 #if os(iOS) || os(tvOS)
@@ -73,7 +73,7 @@ class WebImageTests: XCTestCase {
7373 let imageUrl = URL ( string: " https://raw.githubusercontent.com/ibireme/YYImage/master/Demo/YYImageDemo/mew_baseline.jpg " )
7474 let imageView = WebImage ( url: imageUrl, options: [ . progressiveLoad] , context: [ . imageScaleFactor: 1 ] )
7575 let introspectView = imageView
76- . onSuccess { _, _ in
76+ . onSuccess { _, _, _ in
7777 expectation. fulfill ( )
7878 }
7979 . onFailure { _ in
@@ -111,7 +111,7 @@ class WebImageTests: XCTestCase {
111111 }
112112
113113 func testWebImageOnSuccessWhenMemoryCacheHit( ) throws {
114- let expectation = self . expectation ( description: " WebImage onSuccess when memory hit " )
114+ let expectation = self . expectation ( description: " WebImage onSuccess when memory cache hit " )
115115 let imageUrl = URL ( string: " https://foo.bar/buzz.png " )
116116 let cacheKey = SDWebImageManager . shared. cacheKey ( for: imageUrl)
117117 #if os(macOS)
@@ -121,7 +121,7 @@ class WebImageTests: XCTestCase {
121121 #endif
122122 SDImageCache . shared. storeImage ( toMemory: testImage, forKey: cacheKey)
123123 let imageView = WebImage ( url: imageUrl)
124- let introspectView = imageView. onSuccess { image, cacheType in
124+ let introspectView = imageView. onSuccess { image, data , cacheType in
125125 XCTAssert ( cacheType == . memory)
126126 XCTAssertNotNil ( image)
127127 XCTAssertEqual ( image, testImage)
@@ -133,12 +133,31 @@ class WebImageTests: XCTestCase {
133133 ViewHosting . expel ( )
134134 }
135135
136+ func testWebImageOnSuccessWhenCacheMiss( ) throws {
137+ let expectation = self . expectation ( description: " WebImage onSuccess when cache miss " )
138+ let imageUrl = URL ( string: " http://via.placeholder.com/100x100.png " )
139+ let cacheKey = SDWebImageManager . shared. cacheKey ( for: imageUrl)
140+ SDImageCache . shared. removeImageFromMemory ( forKey: cacheKey)
141+ SDImageCache . shared. removeImageFromDisk ( forKey: cacheKey)
142+ let imageView = WebImage ( url: imageUrl)
143+ let introspectView = imageView. onSuccess { image, data, cacheType in
144+ XCTAssert ( cacheType == . none)
145+ XCTAssertNotNil ( image)
146+ XCTAssertNotNil ( data)
147+ expectation. fulfill ( )
148+ }
149+ _ = try introspectView. inspect ( )
150+ ViewHosting . host ( view: introspectView)
151+ self . waitForExpectations ( timeout: 5 , handler: nil )
152+ ViewHosting . expel ( )
153+ }
154+
136155 func testWebImageEXIFImage( ) throws {
137156 let expectation = self . expectation ( description: " WebImage EXIF image url " )
138157 // EXIF 5, Left Mirrored
139158 let imageUrl = URL ( string: " https://raw.githubusercontent.com/recurser/exif-orientation-examples/master/Landscape_5.jpg " )
140159 let imageView = WebImage ( url: imageUrl)
141- let introspectView = imageView. onSuccess { image, cacheType in
160+ let introspectView = imageView. onSuccess { image, data , cacheType in
142161 let displayImage = try ? imageView. inspect ( ) . group ( ) . image ( 0 ) . cgImage ( )
143162 let orientation = try ! imageView. inspect ( ) . group ( ) . image ( 0 ) . orientation ( )
144163 XCTAssertNotNil ( displayImage)
0 commit comments