2020-03-24 18:47:35 +08:00
|
|
|
import XCTest
|
|
|
|
import SwiftUI
|
|
|
|
import ViewInspector
|
|
|
|
@testable import SDWebImageSwiftUI
|
|
|
|
|
|
|
|
class ImageManagerTests: XCTestCase {
|
|
|
|
|
|
|
|
override func setUp() {
|
|
|
|
super.setUp()
|
|
|
|
// Put setup code here. This method is called before the invocation of each test method in the class.
|
|
|
|
}
|
|
|
|
|
|
|
|
override func tearDown() {
|
|
|
|
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
|
|
|
super.tearDown()
|
|
|
|
}
|
|
|
|
|
|
|
|
func testImageManager() throws {
|
|
|
|
let expectation = self.expectation(description: "ImageManager usage with Combine")
|
|
|
|
let imageUrl = URL(string: "https://via.placeholder.com/500x500.jpg")
|
2022-09-20 20:26:35 +08:00
|
|
|
let imageManager = ImageManager()
|
2021-02-23 16:19:55 +08:00
|
|
|
imageManager.setOnSuccess { image, cacheType, data in
|
2020-03-24 18:47:35 +08:00
|
|
|
XCTAssertNotNil(image)
|
|
|
|
expectation.fulfill()
|
|
|
|
}
|
|
|
|
imageManager.setOnFailure { error in
|
|
|
|
XCTFail()
|
|
|
|
}
|
|
|
|
imageManager.setOnProgress { receivedSize, expectedSize in
|
|
|
|
|
|
|
|
}
|
2022-09-20 20:26:35 +08:00
|
|
|
imageManager.load(url: imageUrl)
|
2020-03-24 18:47:35 +08:00
|
|
|
XCTAssertNotNil(imageManager.currentOperation)
|
|
|
|
let sub = imageManager.objectWillChange
|
|
|
|
.subscribe(on: RunLoop.main)
|
|
|
|
.receive(on: RunLoop.main)
|
|
|
|
.sink { value in
|
|
|
|
print(value)
|
|
|
|
}
|
|
|
|
sub.cancel()
|
2022-09-22 16:06:07 +08:00
|
|
|
self.waitForExpectations(timeout: 10, handler: nil)
|
2020-03-24 18:47:35 +08:00
|
|
|
}
|
|
|
|
}
|