mirror of
https://github.com/nextcloud/android.git
synced 2024-11-22 21:25:35 +03:00
Unified search: fix existing tests to make CI happy
Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
73e4f3cf05
commit
c3a1656781
3 changed files with 66 additions and 146 deletions
|
@ -24,24 +24,22 @@ package com.owncloud.android.ui.fragment
|
|||
|
||||
import com.owncloud.android.lib.common.SearchResult
|
||||
import com.owncloud.android.lib.common.SearchResultEntry
|
||||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import com.owncloud.android.ui.unifiedsearch.IUnifiedSearchRepository
|
||||
import com.owncloud.android.ui.unifiedsearch.SearchOnProviderTask
|
||||
import com.owncloud.android.ui.unifiedsearch.UnifiedSearchViewModel
|
||||
import com.owncloud.android.ui.unifiedsearch.ProviderID
|
||||
import com.owncloud.android.ui.unifiedsearch.UnifiedSearchResult
|
||||
|
||||
class UnifiedSearchLocalRepository : IUnifiedSearchRepository {
|
||||
override fun refresh() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
class UnifiedSearchFakeRepository : IUnifiedSearchRepository {
|
||||
|
||||
override fun startLoading() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun loadMore(query: String, vm: UnifiedSearchViewModel) {
|
||||
val result = SearchOnProviderTask.Result(
|
||||
true,
|
||||
SearchResult(
|
||||
override fun queryAll(
|
||||
query: String,
|
||||
onResult: (UnifiedSearchResult) -> Unit,
|
||||
onError: (Throwable) -> Unit,
|
||||
onFinished: (Boolean) -> Unit
|
||||
) {
|
||||
val result = UnifiedSearchResult(
|
||||
provider = "files",
|
||||
success = true,
|
||||
result = SearchResult(
|
||||
"files",
|
||||
false,
|
||||
listOf(
|
||||
|
@ -63,8 +61,46 @@ class UnifiedSearchLocalRepository : IUnifiedSearchRepository {
|
|||
)
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
onResult(result)
|
||||
onFinished(true)
|
||||
}
|
||||
|
||||
override fun queryProvider(
|
||||
query: String,
|
||||
provider: ProviderID,
|
||||
cursor: Int?,
|
||||
onResult: (UnifiedSearchResult) -> Unit,
|
||||
onError: (Throwable) -> Unit,
|
||||
onFinished: (Boolean) -> Unit
|
||||
) {
|
||||
val result = UnifiedSearchResult(
|
||||
provider = provider,
|
||||
success = true,
|
||||
result = SearchResult(
|
||||
provider,
|
||||
false,
|
||||
listOf(
|
||||
SearchResultEntry(
|
||||
"thumbnailUrl",
|
||||
"Test",
|
||||
"in Files",
|
||||
"http://localhost/nc/index.php/apps/files/?dir=/Files&scrollto=Test",
|
||||
"icon",
|
||||
false
|
||||
),
|
||||
SearchResultEntry(
|
||||
"thumbnailUrl",
|
||||
"Test1",
|
||||
"in Folder",
|
||||
"http://localhost/nc/index.php/apps/files/?dir=/folder&scrollto=test1.txt",
|
||||
"icon",
|
||||
false
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
vm.onSearchResult(result)
|
||||
Log_OC.d(this, "loadMore")
|
||||
}
|
||||
}
|
|
@ -25,8 +25,8 @@ import androidx.test.internal.runner.junit4.statement.UiThreadStatement
|
|||
import com.nextcloud.client.TestActivity
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.common.SearchResult
|
||||
import com.owncloud.android.lib.common.SearchResultEntry
|
||||
import com.owncloud.android.ui.unifiedsearch.UnifiedSearchSection
|
||||
import com.owncloud.android.ui.unifiedsearch.UnifiedSearchViewModel
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
@ -47,26 +47,26 @@ class UnifiedSearchFragmentIT : AbstractIT() {
|
|||
|
||||
UiThreadStatement.runOnUiThread {
|
||||
sut.onSearchResultChanged(
|
||||
mutableListOf(
|
||||
SearchResult(
|
||||
"Files",
|
||||
false,
|
||||
listOf(
|
||||
listOf(
|
||||
UnifiedSearchSection(
|
||||
providerID = "files",
|
||||
name = "Files",
|
||||
entries = listOf(
|
||||
SearchResultEntry(
|
||||
"thumbnailUrl",
|
||||
"Test",
|
||||
"in /Files/",
|
||||
"resourceUrl",
|
||||
"in Files",
|
||||
"http://localhost/nc/index.php/apps/files/?dir=/Files&scrollto=Test",
|
||||
"icon",
|
||||
false
|
||||
)
|
||||
)
|
||||
),
|
||||
hasMoreResults = false
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
longSleep()
|
||||
shortSleep()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -74,7 +74,7 @@ class UnifiedSearchFragmentIT : AbstractIT() {
|
|||
val activity = testActivityRule.launchActivity(null)
|
||||
val sut = UnifiedSearchFragment.newInstance(null)
|
||||
val testViewModel = UnifiedSearchViewModel()
|
||||
val localRepository = UnifiedSearchLocalRepository()
|
||||
val localRepository = UnifiedSearchFakeRepository()
|
||||
testViewModel.setRepository(localRepository)
|
||||
|
||||
val ocFile = OCFile("/folder/test1.txt").apply {
|
||||
|
@ -92,7 +92,6 @@ class UnifiedSearchFragmentIT : AbstractIT() {
|
|||
sut.setViewModel(testViewModel)
|
||||
sut.vm.startLoading("test")
|
||||
}
|
||||
|
||||
longSleep()
|
||||
shortSleep()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,115 +0,0 @@
|
|||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Chris Narkiewicz
|
||||
* Copyright (C) 2020 Chris Narkiewicz <hello@ezaquarii.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.owncloud.android.ui.fragment
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import com.owncloud.android.lib.resources.activities.model.Activity
|
||||
|
||||
class UnifiedSearchTestViewModel : ViewModel() {
|
||||
|
||||
val activities: MutableLiveData<List<Activity>> = MutableLiveData<List<Activity>>(emptyList())
|
||||
val error: MutableLiveData<String> = MutableLiveData<String>("")
|
||||
val query: MutableLiveData<String> = MutableLiveData()
|
||||
private var loadingStarted: Boolean = false
|
||||
private var last: Int = -1
|
||||
|
||||
fun refresh() {
|
||||
last = -1
|
||||
activities.value = emptyList()
|
||||
loadMore()
|
||||
}
|
||||
|
||||
fun startLoading(query: String) {
|
||||
if (!loadingStarted) {
|
||||
loadingStarted = true
|
||||
this.query.value = query
|
||||
loadMore()
|
||||
}
|
||||
}
|
||||
|
||||
fun loadMore() {
|
||||
Log_OC.d(this, "loadMore")
|
||||
// if (isLoading.value != true) {
|
||||
// val client = clientFactory.createNextcloudClient(currentUser.user)
|
||||
// val task = SearchOnProviderTask("test", "files", client)
|
||||
// runner.postQuickTask(task, onResult = this::onSearchResult, onError = this::onError)
|
||||
// isLoading.value = true
|
||||
// }
|
||||
}
|
||||
|
||||
// fun openFile(fileUrl: String) {
|
||||
// if (isLoading.value == false) {
|
||||
// (isLoading as MutableLiveData).value = true
|
||||
// val user = currentUser.user
|
||||
// val task = GetRemoteFileTask(
|
||||
// context,
|
||||
// fileUrl,
|
||||
// clientFactory.create(currentUser.user),
|
||||
// FileDataStorageManager(user.toPlatformAccount(), contentResolver),
|
||||
// user
|
||||
// )
|
||||
// runner.postQuickTask(task, onResult = this::onFileRequestResult)
|
||||
// }
|
||||
// }
|
||||
|
||||
fun clearError() {
|
||||
error.value = ""
|
||||
}
|
||||
|
||||
private fun onError(error: Throwable) {
|
||||
Log_OC.d("Unified Search", "Error: " + error.stackTrace)
|
||||
}
|
||||
|
||||
// private fun onSearchResult(result: SearchOnProviderTask.Result) {
|
||||
// isLoading.value = false
|
||||
//
|
||||
// if (result.success) {
|
||||
// // activities.value = result.searchResult.entries
|
||||
// } else {
|
||||
// error.value = resources.getString(R.string.search_error)
|
||||
// }
|
||||
//
|
||||
// Log_OC.d("Unified Search", "Success: " + result.success)
|
||||
// Log_OC.d("Unified Search", "Size: " + result.searchResult.entries.size)
|
||||
// }
|
||||
|
||||
// private fun onActivitiesRequestResult(result: GetActivityListTask.Result) {
|
||||
// isLoading.value = false
|
||||
// if (result.success) {
|
||||
// val existingActivities = activities.value ?: emptyList()
|
||||
// val newActivities = listOf(existingActivities, result.activities).flatten()
|
||||
// last = result.last
|
||||
// activities.value = newActivities
|
||||
// } else {
|
||||
// error.value = resources.getString(R.string.activities_error)
|
||||
// }
|
||||
// }
|
||||
|
||||
// private fun onFileRequestResult(result: GetRemoteFileTask.Result) {
|
||||
// (isLoading as MutableLiveData).value = false
|
||||
// if (result.success) {
|
||||
// (file as MutableLiveData).value = result.file
|
||||
// } else {
|
||||
// (file as MutableLiveData).value = null
|
||||
// }
|
||||
// }
|
||||
}
|
Loading…
Reference in a new issue