Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localize Tic Tac Toe app #52

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ local.properties
_sandbox

# Android Studio captures folder
captures/
captures/
/.kotlin/*
Binary file added .idea/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ dependencies {
implementation(libs.androidx.window)
implementation(libs.materialWindow)
implementation(libs.navigation)
implementation(project(":library:resources"))

ksp(libs.kotlin.inject.ksp)
implementation(libs.kotlin.inject.runtime)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package me.nasrabadiam.tictactoe.game

import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.lifecycle.SavedStateHandle
import me.nasrabadiam.tictactoe.assertPlayersCountEquals
import me.nasrabadiam.tictactoe.clickOnCell
import me.nasrabadiam.tictactoe.game.model.Player
import me.nasrabadiam.tictactoe.game.ui.GameScreen
import me.nasrabadiam.tictactoe.game.ui.GameViewModel
import me.nasrabadiam.tictactoe.ui.GameWindowSizeClass.COMPACT
import me.nasrabadiam.tictactoe.ui.getWindowSizeClass
import org.junit.Rule
import org.junit.Test

Expand All @@ -18,11 +19,19 @@ class GameClickTests {

private val gameUseCase = GameUseCase()
private val gameViewModel = GameViewModel(gameUseCase, SavedStateHandle())
private val windowClass = COMPACT

private fun ComposeContentTestRule.setContent(
viewModel: GameViewModel = gameViewModel
) {
setContent {
val windowSizeClass = getWindowSizeClass()
GameScreen(viewModel, windowSizeClass)
}
}

@Test
fun whenClickOnCellsShouldDrawItem(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

clickOnCell(0, 0)

Expand All @@ -31,7 +40,7 @@ class GameClickTests {

@Test
fun whenClickOnSecondCellShouldChangeTurn(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

clickOnCell(0, 0)
clickOnCell(1, 1)
Expand All @@ -42,7 +51,7 @@ class GameClickTests {

@Test
fun whenClickOnCellThatClickedBeforeShouldDoNothing(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

clickOnCell(0, 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasContentDescription
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.isDisplayed
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.lifecycle.SavedStateHandle
import me.nasrabadiam.tictactoe.DRAW_RESULT_STRING
Expand All @@ -14,7 +15,7 @@ import me.nasrabadiam.tictactoe.clickOnCell
import me.nasrabadiam.tictactoe.game.model.Player
import me.nasrabadiam.tictactoe.game.ui.GameScreen
import me.nasrabadiam.tictactoe.game.ui.GameViewModel
import me.nasrabadiam.tictactoe.ui.GameWindowSizeClass.COMPACT
import me.nasrabadiam.tictactoe.ui.getWindowSizeClass
import org.junit.Rule
import org.junit.Test

Expand All @@ -25,7 +26,15 @@ class GameLogicTests {

private val gameUseCase = GameUseCase()
private val gameViewModel = GameViewModel(gameUseCase, SavedStateHandle())
private val windowClass = COMPACT

private fun ComposeContentTestRule.setContent(
viewModel: GameViewModel = gameViewModel
) {
setContent {
val windowSizeClass = getWindowSizeClass()
GameScreen(viewModel, windowSizeClass)
}
}

/**
* X - M - M
Expand All @@ -34,7 +43,7 @@ class GameLogicTests {
*/
@Test
fun whenXWinsVerticallyShouldShowWinnerAndEndsTheGame(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

val colIndex = 0
clickOnCell(col = colIndex, row = 0) // X
Expand All @@ -57,7 +66,7 @@ class GameLogicTests {
*/
@Test
fun whenXWinsHorizontallyShouldShowWinnerAndEndsTheGame(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

val rowIndex = 0
clickOnCell(col = 0, row = rowIndex) // X
Expand All @@ -80,7 +89,7 @@ class GameLogicTests {
*/
@Test
fun whenXWinsInCrossShouldShowWinnerAndEndsTheGame(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

clickOnCell(col = 0, row = 0) // X
clickOnCell(col = 0, row = 1) // O
Expand All @@ -102,7 +111,7 @@ class GameLogicTests {
*/
@Test
fun whenOWinsVerticallyShouldShowWinnerAndEndsTheGame(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

val colIndex = 2
clickOnCell(col = 0, row = 0) // X
Expand All @@ -126,7 +135,7 @@ class GameLogicTests {
*/
@Test
fun whenOWinsHorizontallyShouldShowWinnerAndEndsTheGame(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

val rowIndex = 1
clickOnCell(col = 0, row = 0) // X
Expand All @@ -150,7 +159,7 @@ class GameLogicTests {
*/
@Test
fun whenOWinsInCrossShouldShowWinnerAndEndsTheGame(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

clickOnCell(col = 0, row = 0) // X
clickOnCell(col = 2, row = 0) // O
Expand All @@ -173,7 +182,7 @@ class GameLogicTests {
*/
@Test
fun whenOAndXDrawShouldShowDrawAndEndsTheGame(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

clickOnCell(col = 0, row = 0) // X
clickOnCell(col = 2, row = 0) // O
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package me.nasrabadiam.tictactoe.game

import androidx.compose.ui.test.assertAny
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onChildren
import androidx.compose.ui.test.onNodeWithContentDescription
Expand All @@ -12,7 +13,7 @@ import me.nasrabadiam.tictactoe.REPLAY_GAME_BUTTON_TEXT
import me.nasrabadiam.tictactoe.clickOnCell
import me.nasrabadiam.tictactoe.game.ui.GameScreen
import me.nasrabadiam.tictactoe.game.ui.GameViewModel
import me.nasrabadiam.tictactoe.ui.GameWindowSizeClass.COMPACT
import me.nasrabadiam.tictactoe.ui.getWindowSizeClass
import org.junit.Rule
import org.junit.Test

Expand All @@ -23,11 +24,19 @@ class GameScoreTests {

private val gameUseCase = GameUseCase()
private val gameViewModel = GameViewModel(gameUseCase, SavedStateHandle())
private val windowClass = COMPACT

private fun ComposeContentTestRule.setContent(
viewModel: GameViewModel = gameViewModel
) {
setContent {
val windowSizeClass = getWindowSizeClass()
GameScreen(viewModel, windowSizeClass)
}
}

@Test
fun whenXWinsOneTimeShouldShowScore1AndO0(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

val rowIndex = 0
clickOnCell(col = 0, row = rowIndex) // X
Expand All @@ -46,7 +55,7 @@ class GameScoreTests {

@Test
fun whenXWinsOneTimeAndOWinsAnotherShouldShowScore1ForXAnd1ForO(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

val rowIndex = 0
clickOnCell(col = 0, row = rowIndex) // X
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.ui.test.assertIsNotDisplayed
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.isDisplayed
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
Expand All @@ -21,7 +22,7 @@ import me.nasrabadiam.tictactoe.game.model.Player
import me.nasrabadiam.tictactoe.game.ui.GameScreen
import me.nasrabadiam.tictactoe.game.ui.GameViewModel
import me.nasrabadiam.tictactoe.getCellTestTag
import me.nasrabadiam.tictactoe.ui.GameWindowSizeClass.COMPACT
import me.nasrabadiam.tictactoe.ui.getWindowSizeClass
import org.junit.Rule
import org.junit.Test

Expand All @@ -32,26 +33,34 @@ class GameTests {

private val gameUseCase = GameUseCase()
private val gameViewModel = GameViewModel(gameUseCase, SavedStateHandle())
private val windowClass = COMPACT

private fun ComposeContentTestRule.setContent(
viewModel: GameViewModel = gameViewModel
) {
setContent {
val windowSizeClass = getWindowSizeClass()
GameScreen(viewModel, windowSizeClass)
}
}

@Test
fun displayGameCells(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()
for (index in 0..DEFAULT_BOARD_CELL_COUNT) {
onNode(hasTestTag(getCellTestTag(index))).isDisplayed()
}
}

@Test
fun displayRestartButton(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

onNodeWithText(RESTART_GAME_BUTTON_TEXT).assertIsDisplayed()
}

@Test
fun displayReplayButtonWhenOneGameFinished(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

onNodeWithText(REPLAY_GAME_BUTTON_TEXT).assertIsNotDisplayed()

Expand All @@ -74,7 +83,7 @@ class GameTests {

@Test
fun restartGameBoardWhenClickOnReplayButton(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

clickOnCell(col = 0, row = 0) // X
clickOnCell(col = 2, row = 0) // O
Expand All @@ -101,7 +110,7 @@ class GameTests {

@Test
fun whenClickOnRestartGameButtonShouldRestartGame(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

clickOnCell(col = 0, row = 0) // X
clickOnCell(col = 2, row = 0) // O
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.nasrabadiam.tictactoe.game

import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
Expand All @@ -10,7 +11,7 @@ import me.nasrabadiam.tictactoe.clickOnCell
import me.nasrabadiam.tictactoe.game.model.Player
import me.nasrabadiam.tictactoe.game.ui.GameScreen
import me.nasrabadiam.tictactoe.game.ui.GameViewModel
import me.nasrabadiam.tictactoe.ui.GameWindowSizeClass.COMPACT
import me.nasrabadiam.tictactoe.ui.getWindowSizeClass
import org.junit.Rule
import org.junit.Test

Expand All @@ -21,11 +22,19 @@ class GameTurnTests {

private val gameUseCase = GameUseCase()
private val gameViewModel = GameViewModel(gameUseCase, SavedStateHandle())
private val windowClass = COMPACT

private fun ComposeContentTestRule.setContent(
viewModel: GameViewModel = gameViewModel
) {
setContent {
val windowSizeClass = getWindowSizeClass()
GameScreen(viewModel, windowSizeClass)
}
}

@Test
fun whenGameStartsXShouldStartTheGame(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

clickOnCell(0, 0)

Expand All @@ -35,7 +44,7 @@ class GameTurnTests {

@Test
fun whenGameDrawsWhoDoesNotPlayThisGameFirstShouldPlayFirst(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

clickOnCell(col = 0, row = 0) // X
clickOnCell(col = 2, row = 0) // O
Expand All @@ -61,7 +70,7 @@ class GameTurnTests {

@Test
fun whenXWinsTheGameShouldStartTheNextGame(): Unit = with(composeRule) {
setContent { GameScreen(gameViewModel, windowClass) }
setContent()

val colIndex = 0

Expand Down
Loading
Loading