Skip to content

Commit

Permalink
Add test for resource apis
Browse files Browse the repository at this point in the history
  • Loading branch information
onevcat committed Aug 14, 2015
1 parent 264dbae commit bc6f480
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions KingfisherTests/UIImageViewExtensionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,33 @@ class UIImageViewExtensionTests: XCTestCase {
waitForExpectationsWithTimeout(5, handler: nil)
}

func testImageDownloadWithResourceForImageView() {
let expectation = expectationWithDescription("wait for downloading image")

let URLString = testKeys[0]
stubRequest("GET", URLString).andReturn(200).withBody(testImageData)
let URL = NSURL(string: URLString)!
let resource = Resource(downloadURL: URL)

var progressBlockIsCalled = false

imageView.kf_setImageWithResource(resource, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
progressBlockIsCalled = true
}) { (image, error, cacheType, imageURL) -> () in
expectation.fulfill()

XCTAssert(progressBlockIsCalled, "progressBlock should be called at least once.")
XCTAssert(image != nil, "Downloaded image should exist.")
XCTAssert(image! == testImage, "Downloaded image should be the same as test image.")
XCTAssert(self.imageView.image! == testImage, "Downloaded image should be already set to the image property.")
XCTAssert(self.imageView.kf_webURL == imageURL, "Web URL should equal to the downloaded url.")

XCTAssert(cacheType == .None, "The cache type should be none here. This image was just downloaded.")
}

waitForExpectationsWithTimeout(5, handler: nil)
}

func testImageDownloadCancelForImageView() {
let expectation = expectationWithDescription("wait for downloading image")

Expand Down

0 comments on commit bc6f480

Please sign in to comment.