Преглед изворни кода

Add tests for `waitForCache`

Yigitcan Yurtsever пре 7 година
родитељ
комит
9bb8fb2006
1 измењених фајлова са 39 додато и 0 уклоњено
  1. 39 0
      Tests/KingfisherTests/KingfisherManagerTests.swift

+ 39 - 0
Tests/KingfisherTests/KingfisherManagerTests.swift

@@ -459,6 +459,45 @@ class KingfisherManagerTests: XCTestCase {
         
         waitForExpectations(timeout: 5, handler: nil)
     }
+    
+    func testWaitForCacheOnRetrieveImage() {
+        cleanDefaultCache()
+        let expectation = self.expectation(description: "wait for caching image on retrieve image")
+        let URLString = testKeys[0]
+        _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
+        
+        let url = URL(string: URLString)!
+        
+        self.manager.retrieveImage(with: url, options: [.waitForCache], progressBlock: nil) {
+            image, error, cacheType, imageURL in
+            XCTAssertNotNil(image)
+            XCTAssertEqual(cacheType, .memory)
+            
+            expectation.fulfill()
+        }
+        
+        waitForExpectations(timeout: 5, handler: nil)
+    }
+    
+    func testWaitForCacheOnRetrieveImageWithProcessor() {
+        cleanDefaultCache()
+        let expectation = self.expectation(description: "wait for caching image on retrieve image with processor")
+        let URLString = testKeys[0]
+        _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
+        
+        let url = URL(string: URLString)!
+        
+        let p = RoundCornerImageProcessor(cornerRadius: 20)
+        self.manager.retrieveImage(with: url, options: [.processor(p), .waitForCache], progressBlock: nil) {
+            image, error, cacheType, imageURL in
+            XCTAssertNotNil(image)
+            XCTAssertEqual(cacheType, .memory)
+            
+            expectation.fulfill()
+        }
+        
+        waitForExpectations(timeout: 5, handler: nil)
+    }
 
     func testImageShouldOnlyFromMemoryCacheOrRefreshCanBeGotFromMemory() {
         let expectation = self.expectation(description: "only from memory cache or refresh")