Skip to content

Commit

Permalink
test: add RandomViewModelImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
ksnd committed May 13, 2023
1 parent 05b0d6e commit f882656
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package kosenda.makecolor.feature.viewmodel

import androidx.compose.ui.graphics.Color
import com.google.common.truth.Truth.assertThat
import kosenda.makecolor.core.domain.UpdateOtherColorUseCase
import kosenda.makecolor.core.model.data.RandomType
import kosenda.makecolor.core.util.colorToRGB
import kosenda.makecolor.core.util.rgbToColorData
import org.junit.Test

class RandomViewModelImplTest {

private val viewModel = RandomViewModelImpl(
updateOtherColorUseCase = UpdateOtherColorUseCase(),
)

@Test
fun updateColorData_newColor_updatedUiState() {
// 色の更新ができることを確認
val isRed = viewModel.uiState.value.colorData == rgbToColorData(colorToRGB(Color.Red))
val newColor = if (isRed) Color.Blue else Color.Red
assertThat(viewModel.uiState.value.colorData)
.isNotEqualTo(rgbToColorData(colorToRGB(newColor)))
viewModel.updateColorData(color = newColor)
assertThat(viewModel.uiState.value.colorData)
.isEqualTo(rgbToColorData(colorToRGB(newColor)))
}

@Test
fun updateRandomType_everyIndex_updatedUiState() {
// ランダムの種類の更新ができることを確認
viewModel.updateRandomType(index = RandomType.PASTEL.index)
assertThat(viewModel.uiState.value.selectRandomType).isEqualTo(RandomType.PASTEL)
viewModel.updateRandomType(index = RandomType.BLACK_AND_WHITE.index)
assertThat(viewModel.uiState.value.selectRandomType).isEqualTo(RandomType.BLACK_AND_WHITE)
viewModel.updateRandomType(index = RandomType.VIVID.index)
assertThat(viewModel.uiState.value.selectRandomType).isEqualTo(RandomType.VIVID)
viewModel.updateRandomType(index = RandomType.NOT_SPECIFIED.index)
assertThat(viewModel.uiState.value.selectRandomType).isEqualTo(RandomType.NOT_SPECIFIED)
}

@Test
fun outputRandomColors_once_updatedUiState() {
// ランダムの色の出力ができることを確認
val originRandomRGBColors = viewModel.uiState.value.randomRGBColors
viewModel.outputRandomColors()
assertThat(viewModel.uiState.value.randomRGBColors).isNotEqualTo(originRandomRGBColors)
}
}

0 comments on commit f882656

Please sign in to comment.