google-developer-training / basic-android-kotlin-compose-training-unscramble

Apache License 2.0
102 stars 141 forks source link

Android Basics: Viewmodel and State in Compose #24

Open myhency opened 2 years ago

myhency commented 2 years ago
@Test
fun gameViewModel_Initialization_FirstWordLoaded() {
    val currentGameUiState = viewModel.uiState.value
    val unScrambledWord = getUnscrambledWord(currentGameUiState.currentScrambledWord)

}

To verify the state is correct, add the assertTrue() functions to assert that the currentWordCount property is set to 1, and the score property is set to 0. Add assertFalse() functions to verify that the isGuessedWordWrong property is false and that the isGameOver property is set to false.

@Test
fun gameViewModel_Initialization_FirstWordLoaded() {
    val gameUiState = viewModel.uiState.value
    val unScrambledWord = getUnscrambledWord(gameUiState.currentScrambledWord)

    // Assert that current word is scrambled.
    assertNotEquals(unScrambledWord, gameUiState.currentScrambledWord)
    // Assert that current word count is set to 1.
    assertTrue(gameUiState.currentWordCount == 1)
    // Assert that initially the score is 0.
    assertTrue(gameUiState.score == 0)
    // Assert that the wrong word guessed is false.
    assertFalse(gameUiState.isGuessedWordWrong)
    // Assert that game is not over.
    assertFalse(gameUiState.isGameOver)
}

This part, I see the variable name suddenly changed from currentGameUiState to gameUiState.

osuleymanova commented 1 year ago

Duplicate of #19, #12, #4.