Skip to content

Commit

Permalink
feat: 対象の行がクリックされた時の挙動を変更 (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
kokoichi206 committed Dec 5, 2022
1 parent 26fbdce commit b264787
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ class AppEndToEnd {
val searchBar = composeRule.onNodeWithTag(TestTags.SEARCH_BAR)
val recent = composeRule.onNodeWithTag(TestTags.RECENT_SEARCHED)
recent.assertExists()
val searchedResult = composeRule.onNodeWithTag("${TestTags.SEARCH_RECENT_RESULT_PREFIX}_$query")
searchedResult.assertDoesNotExist()
val searchedReflect = composeRule.onNodeWithTag("${TestTags.REFLECT_SEARCH_BAR_PREFIX}_$query")
searchedReflect.assertDoesNotExist()

Expand All @@ -193,7 +191,10 @@ class AppEndToEnd {
recent.assertExists()
// 直近の検索結果に、履歴が表示されていること
searchedReflect.assertExists()
searchedResult.assertTextEquals(query)
composeRule.onNodeWithTag(
testTag = "${TestTags.SEARCH_RECENT_RESULT_PREFIX}_$query",
useUnmergedTree = true,
).assertTextEquals(query)
}

@Test
Expand Down Expand Up @@ -233,6 +234,35 @@ class AppEndToEnd {
searchBar.assertTextEquals(query)
}

@Test
fun `show_recent_searched_name_work_correctly`() {
// Arrange
val query = "show_recent_reflect_correctly_query"
val searchBar = composeRule.onNodeWithTag(TestTags.SEARCH_BAR)
val searchResult = composeRule.onNodeWithTag(TestTags.SEARCH_RESULT)
val searchedRow = composeRule.onNodeWithTag("${TestTags.RECENT_SEARCH_STR_ROW_PREFIX}_$query")
// 検索履歴用意
searchBar.performTextInput(query)
searchBar.performImeAction()
MockGitHubRepositoryImpl.initMock()
// 検索文字列削除
composeRule.onNodeWithTag(TestTags.CANCEL_BUTTON).performClick()

// Act
// 対象の行を押す
searchedRow.performClick()

// Assert
// 検索バーに、期待値通り文言が表示されていること
searchBar.assertTextEquals(query)
// API のレスポンスにより、リストが更新されていること
searchResult.onChildren().assertCountEquals(2)

// API が呼び出されていること
assertEquals(1, MockGitHubRepositoryImpl.counter)
assertEquals(query, MockGitHubRepositoryImpl.passedQuery)
}

@Test
fun `tap_a_repository_navigate_to_detail_screen`() {
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,25 @@ fun MainView(
viewModel.setShowRecent(false)
},
onItemClick = {
// 検索バーに表示
viewModel.setSearchInput(
TextFieldValue(
text = it,
selection = TextRange(it.length),
)
)
// 検索まで行う
viewModel.searchResults(it)
},
onItemReflectClick = {
// 検索バーに表示するだけ
viewModel.setSearchInput(
TextFieldValue(
text = it,
selection = TextRange(it.length),
)
)
}
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fun RecentSearched(
searched: List<String>,
onCloseClick: () -> Unit = {},
onItemClick: (String) -> Unit = {},
onItemReflectClick: (String) -> Unit = {},
) {
val iconColor = Color.Gray.copy(alpha = 0.4f)

Expand Down Expand Up @@ -67,15 +68,20 @@ fun RecentSearched(
onCloseClick()
}
.testTag(TestTags.RECENT_SEARCHED_CLOSE),
contentDescription = "close recent",
contentDescription = "close recent",
tint = Color.White,
)
}
}

items(searched) { str ->
Row(
modifier = Modifier.padding(vertical = 8.dp, horizontal = 16.dp),
modifier = Modifier
.clickable {
onItemClick(str)
}
.padding(vertical = 8.dp, horizontal = 16.dp)
.testTag("${TestTags.RECENT_SEARCH_STR_ROW_PREFIX}_$str"),
verticalAlignment = Alignment.CenterVertically
) {
Text(
Expand All @@ -96,7 +102,7 @@ fun RecentSearched(
.rotate(45f)
.clickable(
onClick = {
onItemClick(str)
onItemReflectClick(str)
},
indication = rememberRipple(bounded = false),
interactionSource = remember { MutableInteractionSource() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ object TestTags {
const val RECENT_SEARCHED = "RECENT_SEARCHED"
const val RECENT_SEARCHED_CLOSE = "RECENT_SEARCHED_CLOSE"
const val SEARCH_RECENT_RESULT_PREFIX = "SEARCH_RECENT_RESULT_PREFIX"
const val RECENT_SEARCH_STR_ROW_PREFIX = "RECENT_SEARCH_STR_ROW_PREFIX"
const val REFLECT_SEARCH_BAR_PREFIX = "REFLECT_SEARCH_BAR_PREFIX"

// In DetailView
Expand Down

0 comments on commit b264787

Please sign in to comment.