From d96fc4dfeb4e1d2fa6c76cc62d80267e8d48c37f Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Sat, 18 Jun 2016 23:38:58 +0800 Subject: [PATCH] switchToLatest so that the delayed trending code doesn't override the search --- GiphySearch/HomeViewModel.swift | 3 ++- GiphySearchUITests/GiphySearchUITests.swift | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/GiphySearch/HomeViewModel.swift b/GiphySearch/HomeViewModel.swift index 4af7b43..f93806c 100644 --- a/GiphySearch/HomeViewModel.swift +++ b/GiphySearch/HomeViewModel.swift @@ -32,7 +32,8 @@ class HomeViewModel { .switchLatest() isSearching.asObservable() - .flatMap({ $0 ? searching : trending }) + .map({ $0 ? searching : trending }) + .switchLatest() .subscribeNext({[unowned self] in self.giphys.value = $0 }) diff --git a/GiphySearchUITests/GiphySearchUITests.swift b/GiphySearchUITests/GiphySearchUITests.swift index 8229f6e..4657354 100644 --- a/GiphySearchUITests/GiphySearchUITests.swift +++ b/GiphySearchUITests/GiphySearchUITests.swift @@ -31,6 +31,11 @@ class GiphySearchUITests: XCTestCase { func testExample() { // Use recording to get started writing UI tests. // Use XCTAssert and related functions to verify your tests produce the correct results. + + let app = XCUIApplication() + app.searchFields["Search"].tap() + app.typeText("hello\r") + app.buttons["Cancel"].tap() } }