Skip to content

Commit

Permalink
Update tests for onlyLoadFirstFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
onevcat committed Feb 10, 2017
1 parent b808515 commit 7090147
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Demo/Kingfisher-macOS-Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ extension ViewController: NSCollectionViewDataSource {
print("\(indexPath.item + 1): Finished")
})

// Set imageView's `animates` to true if you are loading a GIF.
// item.imageView?.animates = true
return item
}
}
6 changes: 3 additions & 3 deletions Sources/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ extension Kingfisher where Base: Image {
}

var scale: CGFloat {
return base.scale
return base.scale
}

var images: [Image]? {
return base.images
return base.images
}

var duration: TimeInterval {
return base.duration
return base.duration
}

fileprivate(set) var imageSource: ImageSource? {
Expand Down
49 changes: 49 additions & 0 deletions Tests/KingfisherTests/ImageViewExtensionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -548,4 +548,53 @@ class ImageViewExtensionTests: XCTestCase {
imageView.kf.setImage(with: url, placeholder: nil, options: [.keepCurrentImageWhileLoading])
XCTAssertEqual(testImage, imageView.image)
}

func testSetGIFImageOnlyFirstFrameThenFullFrames() {
let expectation = self.expectation(description: "wait for downloading image")

let URLString = testKeys[0]

_ = stubRequest("GET", URLString).andReturn(200)?.withBody(NSData(data: testImageGIFData))
let url = URL(string: URLString)!

func loadFullGIFImage() {
var progressBlockIsCalled = false
ImageCache.default.clearMemoryCache()

imageView.kf.setImage(with: url, placeholder: nil, options: [], progressBlock: { (receivedSize, totalSize) -> () in
progressBlockIsCalled = true
XCTAssertTrue(Thread.isMainThread)
}) { (image, error, cacheType, imageURL) -> () in

XCTAssertFalse(progressBlockIsCalled, "progressBlock should not be called since the image is cached.")
XCTAssertNotNil(image, "Downloaded image should exist.")
XCTAssertNotNil(image!.kf.images, "images should exist since we load full GIF.")
XCTAssertEqual(image!.kf.images?.count, 8, "There are 8 frames in total.")

XCTAssert(cacheType == .disk, "We should find it cached in disk")
XCTAssertTrue(Thread.isMainThread)

expectation.fulfill()
}
}

var progressBlockIsCalled = false
imageView.kf.setImage(with: url, placeholder: nil, options: [.onlyLoadFirstFrame], progressBlock: { (receivedSize, totalSize) -> () in
progressBlockIsCalled = true
XCTAssertTrue(Thread.isMainThread)
}) { (image, error, cacheType, imageURL) -> () in
XCTAssertTrue(progressBlockIsCalled, "progressBlock should be called at least once.")
XCTAssertNotNil(image, "Downloaded image should exist.")
XCTAssertNil(image!.kf.images, "images should not exist since we set only load first frame.")

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

loadFullGIFImage()
}


waitForExpectations(timeout: 5, handler: nil)

}
}
5 changes: 4 additions & 1 deletion Tests/KingfisherTests/KingfisherOptionsInfoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class KingfisherOptionsInfoTests: XCTestCase {
XCTAssertEqual(options.callbackDispatchQueue.label, DispatchQueue.main.label)
XCTAssertEqual(options.scaleFactor, 1.0)
XCTAssertFalse(options.keepCurrentImageWhileLoading)
XCTAssertFalse(options.onlyLoadFirstFrame)
}


Expand Down Expand Up @@ -89,7 +90,8 @@ class KingfisherOptionsInfoTests: XCTestCase {
KingfisherOptionsInfoItem.scaleFactor(2.0),
.requestModifier(testModifier),
.processor(processor),
.keepCurrentImageWhileLoading
.keepCurrentImageWhileLoading,
.onlyLoadFirstFrame
]

XCTAssertTrue(options.targetCache === cache)
Expand All @@ -113,6 +115,7 @@ class KingfisherOptionsInfoTests: XCTestCase {
XCTAssertTrue(options.modifier is TestModifier)
XCTAssertEqual(options.processor.identifier, processor.identifier)
XCTAssertTrue(options.keepCurrentImageWhileLoading)
XCTAssertTrue(options.onlyLoadFirstFrame)
}
}

Expand Down

0 comments on commit 7090147

Please sign in to comment.