-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testing for fully implemented search components, fix bug in debounce
- Loading branch information
1 parent
31b0300
commit c79a45c
Showing
4 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
androidApp/src/androidTest/java/com/mbta/tid/mbta_app/android/search/SearchBarOverlayTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.mbta.tid.mbta_app.android.search | ||
|
||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.focus.FocusRequester | ||
import androidx.compose.ui.test.ExperimentalTestApi | ||
import androidx.compose.ui.test.hasText | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performClick | ||
import androidx.compose.ui.test.performTextInput | ||
import androidx.compose.ui.test.requestFocus | ||
import com.mbta.tid.mbta_app.model.RouteType | ||
import com.mbta.tid.mbta_app.model.SearchResults | ||
import com.mbta.tid.mbta_app.model.StopResult | ||
import com.mbta.tid.mbta_app.model.StopResultRoute | ||
import com.mbta.tid.mbta_app.model.response.ApiResult | ||
import com.mbta.tid.mbta_app.repositories.ISearchResultRepository | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.koin.compose.KoinContext | ||
import org.koin.dsl.koinApplication | ||
import org.koin.dsl.module | ||
import org.koin.test.KoinTest | ||
|
||
@ExperimentalTestApi | ||
@ExperimentalMaterial3Api | ||
class SearchBarOverlayTest : KoinTest { | ||
val koinApplication = koinApplication { | ||
modules( | ||
module { | ||
single<ISearchResultRepository> { | ||
object : ISearchResultRepository { | ||
override suspend fun getSearchResults( | ||
query: String | ||
): ApiResult<SearchResults>? { | ||
return ApiResult.Ok( | ||
SearchResults( | ||
routes = emptyList(), | ||
stops = | ||
listOf( | ||
StopResult( | ||
id = "stopId", | ||
rank = 2, | ||
name = "stopName", | ||
zone = "stopZone", | ||
isStation = false, | ||
routes = | ||
listOf( | ||
StopResultRoute( | ||
type = RouteType.BUS, | ||
icon = "routeIcon", | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
) | ||
} | ||
|
||
@get:Rule var composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun testSearchBarOverlayBehavesCorrectly() = runTest { | ||
val navigated = mutableStateOf(false) | ||
|
||
composeTestRule.setContent { | ||
KoinContext(koinApplication.koin) { | ||
val focusRequester = remember { FocusRequester() } | ||
SearchBarOverlay( | ||
onStopNavigation = { navigated.value = true }, | ||
currentNavEntry = null, | ||
inputFieldFocusRequester = focusRequester, | ||
) { | ||
Text("Content") | ||
} | ||
} | ||
} | ||
|
||
composeTestRule.onNodeWithText("Content").assertExists() | ||
val searchNode = composeTestRule.onNodeWithText("Search by stop") | ||
searchNode.assertExists() | ||
searchNode.requestFocus() | ||
composeTestRule.awaitIdle() | ||
|
||
searchNode.performTextInput("sto") | ||
composeTestRule.waitUntilAtLeastOneExists(hasText("stopName")) | ||
composeTestRule.onNodeWithText("stopName").performClick() | ||
composeTestRule.waitUntil { navigated.value } | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
androidApp/src/androidTest/java/com/mbta/tid/mbta_app/android/state/GetSearchResultTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.mbta.tid.mbta_app.android.state | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import com.mbta.tid.mbta_app.model.RouteType | ||
import com.mbta.tid.mbta_app.model.SearchResults | ||
import com.mbta.tid.mbta_app.model.StopResult | ||
import com.mbta.tid.mbta_app.model.StopResultRoute | ||
import com.mbta.tid.mbta_app.model.response.ApiResult | ||
import com.mbta.tid.mbta_app.repositories.ISearchResultRepository | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class GetSearchResultTest { | ||
val searchResults = | ||
SearchResults( | ||
routes = emptyList(), | ||
stops = | ||
listOf( | ||
StopResult( | ||
id = "stopId", | ||
rank = 2, | ||
name = "stopName", | ||
zone = "stopZone", | ||
isStation = false, | ||
routes = | ||
listOf( | ||
StopResultRoute( | ||
type = RouteType.BUS, | ||
icon = "routeIcon", | ||
) | ||
) | ||
) | ||
) | ||
) | ||
|
||
@get:Rule val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun testSearchResults() = runTest { | ||
var actualSearchResultsViewModel: SearchResultsViewModel? = null | ||
|
||
composeTestRule.setContent { | ||
actualSearchResultsViewModel = | ||
getSearchResultsVm( | ||
object : ISearchResultRepository { | ||
override suspend fun getSearchResults( | ||
query: String | ||
): ApiResult<SearchResults>? { | ||
return ApiResult.Ok(searchResults) | ||
} | ||
} | ||
) | ||
} | ||
|
||
composeTestRule.waitUntil { actualSearchResultsViewModel != null } | ||
|
||
actualSearchResultsViewModel?.getSearchResults("query") | ||
|
||
composeTestRule.waitUntil { actualSearchResultsViewModel?.searchResults?.value != null } | ||
|
||
assert(actualSearchResultsViewModel?.searchResults?.value == searchResults) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters