web: WebViewModelFactory takes WebStores; search test seam
- Commit
6046b8fb6934406d957acef7686272849ca96684- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 13:42 UTC (29 days ago)
- Parents
43df41d
WebViewModelFactory now depends on the WebStores interface (added for the view model in the previous task) instead of the concrete WebRepository, so tests can build view models from in-memory stores. WebSearchRepository gains an internal searchOverride test seam, never set in production, so the search-results pages can be driven deterministically in unit tests instead of depending on live network failure timing against api.maproj.org. (cherry picked from commit 782a2b7b6f09a0357c6604f0df0db5ca169fb3e7)
Diff
web/src/main/java/com/vayunmathur/web/data/WebSearchRepository.kt
diff --git a/web/src/main/java/com/vayunmathur/web/data/WebSearchRepository.kt b/web/src/main/java/com/vayunmathur/web/data/WebSearchRepository.ktindex 48748cfbd1..670ba9aaef 100644--- a/web/src/main/java/com/vayunmathur/web/data/WebSearchRepository.kt+++ b/web/src/main/java/com/vayunmathur/web/data/WebSearchRepository.kt@@ -16,6 +16,13 @@ object WebSearchRepository { const val BASE_URL = "https://api.maproj.org/api/search" + /**+ * Test seam: when set, [search] delegates here instead of the network.+ * Production never sets it; unit tests use it to drive the search pages+ * deterministically (no live api.maproj.org in the test environment).+ */+ internal var searchOverride: (suspend (query: String, kind: WebSearchKind, safeSearch: Boolean, page: Int) -> WebSearchResponse)? = null+ /** * Runs one search. `safeSearch=true` (parental supervision switch) maps to * the server's strict mode; otherwise moderate. Throws IOException on@@ -29,6 +36,7 @@ object WebSearchRepository { safeSearch: Boolean = false, page: Int = 1, ): WebSearchResponse {+ searchOverride?.let { return it(query, kind, safeSearch, page) } val url = Urls.appendQuery( BASE_URL, mapOf(
web/src/main/java/com/vayunmathur/web/platform/WebViewModelFactory.kt
diff --git a/web/src/main/java/com/vayunmathur/web/platform/WebViewModelFactory.kt b/web/src/main/java/com/vayunmathur/web/platform/WebViewModelFactory.ktindex 1c271a18e2..970bea826e 100644--- a/web/src/main/java/com/vayunmathur/web/platform/WebViewModelFactory.kt+++ b/web/src/main/java/com/vayunmathur/web/platform/WebViewModelFactory.kt@@ -2,10 +2,10 @@ package com.vayunmathur.web.platform import android.content.Context import com.vayunmathur.web.data.ShieldSetting-import com.vayunmathur.web.data.WebRepository+import com.vayunmathur.web.data.WebStores class WebViewModelFactory(- private val repository: WebRepository,+ private val repository: WebStores, private val context: Context, private val windowId: String = WebViewModel.DEFAULT_WINDOW_ID, private val incognito: Boolean = false,