Skip to content

Commit

Permalink
Hide loading indicator on both load error and success
Browse files Browse the repository at this point in the history
  • Loading branch information
TrabelsiAchraf committed Nov 26, 2021
1 parent 463723c commit 4b774e2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
6 changes: 2 additions & 4 deletions EssentialFeediOS/FeedViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ final public class FeedViewController: UITableViewController {
@objc private func load() {
refreshControl?.beginRefreshing()
loader?.load { [weak self] result in
switch result {
case let .success(feed):
if let feed = try? result.get() {
self?.tableModel = feed
self?.tableView.reloadData()
self?.refreshControl?.endRefreshing()
case .failure: break
}
self?.refreshControl?.endRefreshing()
}
}

Expand Down
6 changes: 3 additions & 3 deletions EssentialFeediOSTests/FeedViewControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ final class FeedViewControllerTests: XCTestCase {
XCTAssertTrue(sut.isShowingLoadingIndicator, "Expected loading indicator once view is loaded")

loader.completeFeedLoading(at: 0)
XCTAssertFalse(sut.isShowingLoadingIndicator, "Expected no loading indicator once loading is completed")
XCTAssertFalse(sut.isShowingLoadingIndicator, "Expected no loading indicator once loading completes successfully")

sut.simulateUserInitiatedFeedReload()
XCTAssertTrue(sut.isShowingLoadingIndicator, "Expected loading indicator once user initiates a reload")

loader.completeFeedLoading(at: 1)
XCTAssertFalse(sut.isShowingLoadingIndicator, "Expected no loading indicator once user initiated loading is completed")
loader.completeFeedLoadingWithError(at: 1)
XCTAssertFalse(sut.isShowingLoadingIndicator, "Expected no loading indicator once user initiated loading completes with error")
}

func test_loadFeedCompletion_rendersSuccessfullyLoadedFeed() {
Expand Down

0 comments on commit 4b774e2

Please sign in to comment.