Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuhiro4949 committed Dec 19, 2019
1 parent 03851b8 commit f4872b1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
6 changes: 3 additions & 3 deletions PagingKit/PagingContentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public class PagingContentViewController: UIViewController {
/// - Parameter page: An index to show after reloading.
public func reloadData(with page: Int? = nil, completion: (() -> Void)? = nil) {
removeAll()
appearanceHandler.preReload(at: leftSidePageIndex)
let preferredPage = page ?? leftSidePageIndex
leftSidePageIndex = preferredPage
initialLoad(with: preferredPage)
Expand All @@ -175,8 +176,7 @@ public class PagingContentViewController: UIViewController {
},
completion: { [weak self] _ in
self?.scroll(to: preferredPage, needsCallAppearance: false, animated: false) { _ in
self?.cachedViewControllers[preferredPage]?.beginAppearanceTransition(true, animated: false)
self?.cachedViewControllers[preferredPage]?.endAppearanceTransition()
self?.appearanceHandler.postReload(at: preferredPage)
completion?()
}
}
Expand All @@ -189,7 +189,7 @@ public class PagingContentViewController: UIViewController {
/// - page: A index defining an content of the content view controller.
/// - animated: true if the scrolling should be animated, false if it should be immediate.
public func scroll(to page: Int, animated: Bool, completion: ((Bool) -> Void)? = nil) {
scroll(to: page, needsCallAppearance: false, animated: animated, completion: completion)
scroll(to: page, needsCallAppearance: true, animated: animated, completion: completion)
}


Expand Down
35 changes: 35 additions & 0 deletions PagingKitTests/PagingContentViewControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,41 @@ extension PagingContentViewControllerTests {

wait(for: [expectation], timeout: 0.2)
}

func test_promgrammaticScrolling_Apperance() {
let expectation = XCTestExpectation(description: "finish reloadData")
let dataSource = PagingContentVcDataSourceSpy()
pagingContentViewController?.dataSource = dataSource
pagingContentViewController?.loadViewIfNeeded()
pagingContentViewController?.reloadData(with: 3) { [unowned self] in
self.pagingContentViewController?.scroll(to: 4, animated: false)

XCTAssertEqual(self.contentAppearanceHandler.beginDragging_args, 3)

expectation.fulfill()
}

wait(for: [expectation], timeout: 0.2)
}

func test_reload() {
let expectation = XCTestExpectation(description: "finish reloadData")
let dataSource = PagingContentVcDataSourceSpy()
pagingContentViewController?.dataSource = dataSource
pagingContentViewController?.loadViewIfNeeded()
pagingContentViewController?.reloadData(with: 3) { [unowned self] in
self.pagingContentViewController?.reloadData(with: 4, completion: {

XCTAssertEqual(self.contentAppearanceHandler.preReload_args, 3)
XCTAssertEqual(self.contentAppearanceHandler.postReload_ags, 4)

})

expectation.fulfill()
}

wait(for: [expectation], timeout: 0.2)
}
}


Expand Down

0 comments on commit f4872b1

Please sign in to comment.