Skip to content

Commit

Permalink
[CT-46] 리뷰 반영: 어떤 테스트를 하는지 조금 더 알기 쉽게 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
nosorae committed Jul 2, 2024
1 parent 8339665 commit d6c8c60
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class HomeViewHomeModelTest {
// }

@Test
fun success_data_corresponds_to_ui_state() =
fun test_datasource_data_to_ui_state_mapping() =
runTest {
chartTrainerPreferencesDataSource.apply {
updateUser(
Expand Down Expand Up @@ -197,7 +197,7 @@ class HomeViewHomeModelTest {
}

@Test
fun bottom_button_state_is_keep_going_game_when_last_chart_game_id_is_not_null() =
fun test_bottom_button_state_is_keep_going_game_or_quit_when_last_chart_game_id_is_not_null() =
runTest {
val lastChartGameId = 1L
chartTrainerPreferencesDataSource.updateLastChartGameId(lastChartGameId)
Expand All @@ -215,7 +215,7 @@ class HomeViewHomeModelTest {
}

@Test
fun bottom_button_state_is_new_game_when_last_chart_game_id_is_null() =
fun test_bottom_button_state_is_new_game_when_last_chart_game_id_is_null() =
runTest {
chartTrainerPreferencesDataSource.clearLastChartGameId()

Expand All @@ -228,10 +228,10 @@ class HomeViewHomeModelTest {
}

@Test
fun navigation_to_new_chart_game_when_click_start_chart_game() =
fun test_navigation_to_new_chart_game_when_click_start_chart_game() =
runTest {
viewModel.screenEvent.test {
viewModel.handleUserAction(userAction = HomeScreenUserAction.ClickStartChartGame)
viewModel.onUserAction(userAction = HomeScreenUserAction.ClickStartChartGame)

assertEquals(
HomeScreenEvent.NavigateToChartGameScreen(chartGameId = null),
Expand All @@ -241,10 +241,10 @@ class HomeViewHomeModelTest {
}

@Test
fun navigation_to_existing_chart_game_when_click_keep_going_chart_game() =
fun test_navigation_to_existing_chart_game_when_click_keep_going_chart_game() =
runTest {
viewModel.screenEvent.test {
viewModel.handleUserAction(
viewModel.onUserAction(
userAction = HomeScreenUserAction.ClickKeepGoingChartGame(
lastChartGameId = 1L
)
Expand All @@ -258,9 +258,9 @@ class HomeViewHomeModelTest {
}

@Test
fun bottom_button_state_is_new_game_when_click_quit_in_progress_chart_game() =
fun test_bottom_button_state_is_new_game_when_click_quit_in_progress_chart_game() =
runTest {
viewModel.handleUserAction(
viewModel.onUserAction(
userAction = HomeScreenUserAction.ClickQuitInProgressChartGame(
lastChartGameId = 1L
)
Expand All @@ -275,9 +275,9 @@ class HomeViewHomeModelTest {
}

@Test
fun commission_rate_setting_dialog_is_shown_when_click_commission_rate() =
fun test_commission_rate_setting_dialog_is_shown_when_click_commission_rate() =
runTest {
viewModel.handleUserAction(userAction = HomeScreenUserAction.ClickCommissionRate)
viewModel.onUserAction(userAction = HomeScreenUserAction.ClickCommissionRate)

viewModel.screenState.test {
assertEquals(
Expand All @@ -288,9 +288,9 @@ class HomeViewHomeModelTest {
}

@Test
fun commission_rate_ui_is_updated_when_update_with_valid_value() =
fun test_commission_rate_ui_is_updated_when_update_with_valid_value() =
runTest {
viewModel.handleUserAction(
viewModel.onUserAction(
userAction = HomeScreenUserAction.UpdateCommissionRate("123")
)

Expand All @@ -305,10 +305,10 @@ class HomeViewHomeModelTest {
}

@Test
fun commission_rate_setting_error_is_shown_when_update_with_invalid_value() =
fun test_commission_rate_setting_error_is_shown_when_update_with_invalid_value() =
runTest {
viewModel.screenEvent.test {
viewModel.handleUserAction(
viewModel.onUserAction(
userAction = HomeScreenUserAction.UpdateCommissionRate("invalid number")
)

Expand All @@ -320,9 +320,9 @@ class HomeViewHomeModelTest {
}

@Test
fun total_turn_setting_dialog_is_shown_when_click_total_turn() =
fun test_total_turn_setting_dialog_is_shown_when_click_total_turn() =
runTest {
viewModel.handleUserAction(
viewModel.onUserAction(
userAction = HomeScreenUserAction.ClickTotalTurn
)

Expand All @@ -335,9 +335,9 @@ class HomeViewHomeModelTest {
}

@Test
fun total_turn_ui_is_updated_when_update_with_valid_value() =
fun test_total_turn_ui_is_updated_when_update_with_valid_value() =
runTest {
viewModel.handleUserAction(
viewModel.onUserAction(
userAction = HomeScreenUserAction.UpdateTotalTurn("60")
)

Expand All @@ -352,10 +352,10 @@ class HomeViewHomeModelTest {
}

@Test
fun total_turn_setting_error_is_shown_when_update_with_not_number_value() =
fun test_total_turn_setting_error_is_shown_when_update_with_not_number_value() =
runTest {
viewModel.screenEvent.test {
viewModel.handleUserAction(
viewModel.onUserAction(
userAction = HomeScreenUserAction.UpdateTotalTurn("not number")
)

Expand All @@ -367,12 +367,12 @@ class HomeViewHomeModelTest {
}

@Test
fun total_turn_setting_error_is_shown_when_update_with_smaller_than_min_value() =
fun test_total_turn_setting_error_is_shown_when_update_with_smaller_than_min_value() =
runTest {
val invalidValue = Random.nextInt(until = MIN_TOTAL_TURN)

viewModel.screenEvent.test {
viewModel.handleUserAction(
viewModel.onUserAction(
userAction = HomeScreenUserAction.UpdateTotalTurn("$invalidValue")
)

Expand All @@ -384,12 +384,12 @@ class HomeViewHomeModelTest {
}

@Test
fun total_turn_setting_error_is_shown_when_update_with_bigger_than_max_value() =
fun test_total_turn_setting_error_is_shown_when_update_with_bigger_than_max_value() =
runTest {
val invalidValue = Random.nextInt(from = MAX_TOTAL_TURN + 1, until = Int.MAX_VALUE)

viewModel.screenEvent.test {
viewModel.handleUserAction(
viewModel.onUserAction(
userAction = HomeScreenUserAction.UpdateTotalTurn("$invalidValue")
)

Expand All @@ -401,10 +401,10 @@ class HomeViewHomeModelTest {
}

@Test
fun tick_unit_setting_dialog_is_shown_when_click_tick_unit() =
fun test_tick_unit_setting_dialog_is_shown_when_click_tick_unit() =
runTest {
val existingValue = viewModel.screenState.value.settingInfoUi.tickUnit
viewModel.handleUserAction(
viewModel.onUserAction(
userAction = HomeScreenUserAction.ClickTickUnit
)

Expand All @@ -419,9 +419,9 @@ class HomeViewHomeModelTest {
}

@Test
fun tick_unit_ui_is_updated_when_click_update_tick_unit() =
fun test_tick_unit_ui_is_updated_when_click_update_tick_unit() =
runTest {
viewModel.handleUserAction(
viewModel.onUserAction(
userAction = HomeScreenUserAction.UpdateTickUnit(
newValue = TickUnit.HOUR
)
Expand All @@ -438,10 +438,10 @@ class HomeViewHomeModelTest {
}

@Test
fun navigation_to_chart_game_history_when_click_chart_game_history_button() =
fun test_navigation_to_chart_game_history_when_click_chart_game_history_button() =
runTest {
viewModel.screenEvent.test {
viewModel.handleUserAction(
viewModel.onUserAction(
userAction = HomeScreenUserAction.ClickChartGameHistory
)

Expand All @@ -453,9 +453,9 @@ class HomeViewHomeModelTest {
}

@Test
fun setting_dialog_is_dismissed_when_user_dismiss_dialog() =
fun test_setting_dialog_is_dismissed_when_user_dismiss_dialog() =
runTest {
viewModel.handleUserAction(
viewModel.onUserAction(
userAction = HomeScreenUserAction.DismissDialog
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fun HomeScreenRoute(
HomeScreen(
screenState = screenState,
onUserAction = { userAction ->
viewModel.handleUserAction(userAction = userAction)
viewModel.onUserAction(userAction = userAction)
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ class HomeViewModel @Inject constructor(
}.launchIn(viewModelScope)
}

fun handleUserAction(userAction: HomeScreenUserAction) =
fun onUserAction(userAction: HomeScreenUserAction) = handleUserAction(userAction = userAction)

private fun handleUserAction(userAction: HomeScreenUserAction) =
viewModelScope.launch {
when (userAction) {
is HomeScreenUserAction.ClickStartChartGame -> {
Expand Down

0 comments on commit d6c8c60

Please sign in to comment.