From 3ccd9968fe9fe3c638957bf11ff21352fadea234 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Tue, 28 Jan 2020 18:58:58 +0800 Subject: [PATCH] Update the test case about onViewCreate/onViewUpdate/onViewDestroy --- Tests/AnimatedImageTests.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Tests/AnimatedImageTests.swift b/Tests/AnimatedImageTests.swift index 60136ea..7b8b002 100644 --- a/Tests/AnimatedImageTests.swift +++ b/Tests/AnimatedImageTests.swift @@ -127,6 +127,10 @@ class AnimatedImageTests: XCTestCase { func testAnimatedImageModifier() throws { let expectation = self.expectation(description: "WebImage modifier") let imageUrl = URL(string: "https://assets.sbnation.com/assets/2512203/dogflops.gif") + AnimatedImage.onViewDestroy { view, coordinator in + XCTAssert(view.isKind(of: SDAnimatedImageView.self)) + XCTAssertEqual(coordinator.userInfo?["foo"] as? String, "bar") + } let imageView = AnimatedImage(url: imageUrl, options: [.progressiveLoad], context: [.imageScaleFactor: 1]) let introspectView = imageView .onSuccess { _, _ in @@ -137,6 +141,14 @@ class AnimatedImageTests: XCTestCase { } .onProgress { _, _ in + } + .onViewCreate { view, context in + XCTAssert(view.isKind(of: SDAnimatedImageView.self)) + context.coordinator.userInfo = ["foo" : "bar"] + } + .onViewUpdate { view, context in + XCTAssert(view.isKind(of: SDAnimatedImageView.self)) + XCTAssertEqual(context.coordinator.userInfo?["foo"] as? String, "bar") } .placeholder(WebImage.emptyImage) .indicator(SDWebImageActivityIndicator.medium) @@ -157,6 +169,7 @@ class AnimatedImageTests: XCTestCase { _ = try introspectView.inspect(AnimatedImage.self) ViewHosting.host(view: introspectView) self.waitForExpectations(timeout: 5, handler: nil) + AnimatedImage.onViewDestroy() } // MARK: Helper