This commit is contained in:
Vadim Bulavin 2017-11-02 15:29:29 +02:00
Родитель 06d37ab702
Коммит a2ce0df087
9 изменённых файлов: 71 добавлений и 10 удалений

Просмотреть файл

@ -74,6 +74,14 @@ extension SearchPresenter: SearchPeopleModuleOutput, SearchTopicsModuleOutput {
func didSelectHashtag(_ hashtag: Hashtag) {
view.search(hashtag: hashtag)
}
func didStartLoadingSearchTopicsQuery() {
view.setTopicsLayoutFlipEnabled(false)
}
func didLoadSearchTopicsQuery() {
view.setTopicsLayoutFlipEnabled(true)
}
}
extension SearchPresenter: SearchModuleInput {

Просмотреть файл

@ -138,6 +138,10 @@ extension SearchViewController: SearchViewInput {
func search(hashtag: Hashtag) {
searchSelectedText(hashtag)
}
func setTopicsLayoutFlipEnabled(_ isEnabled: Bool) {
feedLayoutButton.isEnabled = isEnabled
}
}
extension SearchViewController: UISearchBarDelegate {

Просмотреть файл

@ -16,4 +16,6 @@ protocol SearchViewInput: class {
func setLayoutAsset(_ asset: Asset)
func search(hashtag: Hashtag)
func setTopicsLayoutFlipEnabled(_ isEnabled: Bool)
}

Просмотреть файл

@ -9,4 +9,8 @@ protocol SearchTopicsModuleOutput: class {
func didFailToLoadSearchQuery(_ error: Error)
func didSelectHashtag(_ hashtag: Hashtag)
func didStartLoadingSearchTopicsQuery()
func didLoadSearchTopicsQuery()
}

Просмотреть файл

@ -63,8 +63,13 @@ extension SearchTopicsPresenter: FeedModuleOutput {
return true
}
func didUpdateFeed() {
func didStartRefreshingData() {
moduleOutput?.didStartLoadingSearchTopicsQuery()
}
func didFinishRefreshingData(_ error: Error?) {
view.setIsEmpty(feedModule.isEmpty)
moduleOutput?.didLoadSearchTopicsQuery()
}
}

Просмотреть файл

@ -47,14 +47,24 @@ class MockSearchView: SearchViewInput {
setLayoutAssetReceivedAsset = asset
}
// MARK: - search
//MARK: - search
var searchHashtagCalled = false
var searchHashtagInputHashtag: Hashtag?
var searchHashtagReceivedHashtag: Hashtag?
func search(hashtag: Hashtag) {
searchHashtagCalled = true
searchHashtagInputHashtag = hashtag
searchHashtagReceivedHashtag = hashtag
}
//MARK: - setTopicsLayoutFlipEnabled
var setTopicsLayoutFlipEnabledCalled = false
var setTopicsLayoutFlipEnabledReceivedIsEnabled: Bool?
func setTopicsLayoutFlipEnabled(_ isEnabled: Bool) {
setTopicsLayoutFlipEnabledCalled = true
setTopicsLayoutFlipEnabledReceivedIsEnabled = isEnabled
}
}

Просмотреть файл

@ -153,7 +153,7 @@ class SearchPresenterTests: XCTestCase {
let hashtag = UUID().uuidString
sut.didSelectHashtag(hashtag)
XCTAssertTrue(view.searchHashtagCalled)
XCTAssertEqual(view.searchHashtagInputHashtag, hashtag)
XCTAssertEqual(view.searchHashtagReceivedHashtag, hashtag)
}
private func makePeopleTab() -> SearchTabInfo {
@ -180,7 +180,7 @@ class SearchPresenterTests: XCTestCase {
XCTAssertEqual(view.setupInitialStateReceivedTab, topicsTab)
XCTAssertTrue(view.searchHashtagCalled)
XCTAssertEqual(view.searchHashtagInputHashtag, "1")
XCTAssertEqual(view.searchHashtagReceivedHashtag, "1")
}
func testSearchHashtagAfterViewIsReadyAndPeopleTabSelected() {
@ -200,6 +200,18 @@ class SearchPresenterTests: XCTestCase {
XCTAssertEqual(view.switchTabsToFromReceivedArguments?.tab, topicsTab)
XCTAssertTrue(view.searchHashtagCalled)
XCTAssertEqual(view.searchHashtagInputHashtag, "1")
XCTAssertEqual(view.searchHashtagReceivedHashtag, "1")
}
func testStartLoadingTopicsQuery() {
sut.didStartLoadingSearchTopicsQuery()
XCTAssertTrue(view.setTopicsLayoutFlipEnabledCalled)
XCTAssertEqual(view.setTopicsLayoutFlipEnabledReceivedIsEnabled, false)
}
func testFinishLoadingTopicsQuery() {
sut.didLoadSearchTopicsQuery()
XCTAssertTrue(view.setTopicsLayoutFlipEnabledCalled)
XCTAssertEqual(view.setTopicsLayoutFlipEnabledReceivedIsEnabled, true)
}
}

Просмотреть файл

@ -26,4 +26,20 @@ class MockSearchTopicsModuleOutput: SearchTopicsModuleOutput {
didSelectHashtagCalled = true
didSelectHashtagReceivedHashtag = hashtag
}
//MARK: - didStartLoadingSearchTopicsQuery
var didStartLoadingSearchTopicsQueryCalled = false
func didStartLoadingSearchTopicsQuery() {
didStartLoadingSearchTopicsQueryCalled = true
}
//MARK: - didLoadSearchTopicsQuery
var didLoadSearchTopicsQueryCalled = false
func didLoadSearchTopicsQuery() {
didLoadSearchTopicsQueryCalled = true
}
}

Просмотреть файл

@ -66,7 +66,7 @@ class SearchTopicsPresenterTests: XCTestCase {
XCTAssertEqual(view.setupInitialStateWithReceivedFeedViewController, feedViewController)
}
func testThatItSetsViewIsEmptyWhenFeedIsUpdated() {
func testThatItSetsViewIsEmptyWhenFeedFinishesRefreshing() {
testThatItSetsViewIsEmptyWhenFeedIsUpdated(feedIsEmpty: true, isViewExpectedToBeEmpty: true)
testThatItSetsViewIsEmptyWhenFeedIsUpdated(feedIsEmpty: false, isViewExpectedToBeEmpty: false)
@ -77,7 +77,7 @@ class SearchTopicsPresenterTests: XCTestCase {
feedModule.isEmpty = feedIsEmpty
// when
sut.didUpdateFeed()
sut.didFinishRefreshingData(APIError.unknown)
// then
XCTAssertTrue(view.setIsEmptyCalled)