Skip to content

Commit

Permalink
GuessTheTheme + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz Lindner committed Jan 22, 2024
1 parent ceee469 commit e9ae13a
Show file tree
Hide file tree
Showing 74 changed files with 1,749 additions and 92 deletions.
353 changes: 353 additions & 0 deletions .idea/androidTestResultsUserPreferences.xml

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.boozeblaster.minigames.common

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import com.boozeblaster.models.Player
import org.junit.Rule
import org.junit.Test

class HighestBidderTest {

@get:Rule
val testComposableRule = createComposeRule()

private val highestBidder = HighestBidder(pointsToGet = 4)
private val player = Player(name = "John")

@Test
fun testHighestBidderShowsBid() {
testComposableRule.setContent {
highestBidder.DisplayContent(player = player, callback = { /*TODO*/ }, versusPlayer = null)
}

testComposableRule.onNodeWithText("Current Bid:").assertIsDisplayed()
}

@Test
fun testHighestBidderShowsCorrectPoints() {
testComposableRule.setContent {
highestBidder.DisplayContent(player = player, callback = { /*TODO*/ }, versusPlayer = null)
}

testComposableRule.onNodeWithText("4 points can be snatched!").assertIsDisplayed()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.boozeblaster.minigames.common

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.boozeblaster.models.Player
import org.junit.Rule
import org.junit.Test

class NeverHaveIEverTest {

@get:Rule
val testComposableRule = createComposeRule()

private val neverHaveIEver = NeverHaveIEver(statement = "Smoked a Beer")
private val player = Player(name = "John")

@Test
fun testNeverHaveIEverDisplaysText() {
testComposableRule.setContent {
neverHaveIEver.DisplayContent(player = player, callback = { }, versusPlayer = null)
}

testComposableRule.onNodeWithText("Never Have I Ever").assertIsDisplayed()
}

@Test
fun testNeverHaveIEverDisplaysCorrectStatement() {
testComposableRule.setContent {
neverHaveIEver.DisplayContent(player = player, callback = { }, versusPlayer = null)
}

testComposableRule.onNodeWithText("Smoked a Beer").assertIsDisplayed()
}

@Test
fun testNeverHaveIEverAsksForConfirmation() {
testComposableRule.setContent {
neverHaveIEver.DisplayContent(player = player, callback = { }, versusPlayer = null)
}

testComposableRule.onNodeWithText("Check").performClick()
testComposableRule.onNodeWithText("Confirm").assertIsDisplayed()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.boozeblaster.minigames.common

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import org.junit.Rule
import org.junit.Test

class WhoInThisRoomTest {

@get:Rule
val testComposableRule = createComposeRule()

private val whoInThisRoom = WhoInThisRoom(statement = "Has the most rizz")

@Test
fun testWhoInThisRoomDisplaysStatement() {
testComposableRule.setContent {
whoInThisRoom.DisplayContent(player = null, callback = { }, versusPlayer = null)
}

testComposableRule.onNodeWithText("Has the most rizz").assertIsDisplayed()
}

@Test
fun testWhoInThisRoomDisplaysCorrectText() {
testComposableRule.setContent {
whoInThisRoom.DisplayContent(player = null, callback = { }, versusPlayer = null)
}

testComposableRule.onNodeWithText("Who In This Room?").assertIsDisplayed()
}

@Test
fun testWhoInThisRoomCanPickPlayers() {
testComposableRule.setContent {
whoInThisRoom.DisplayContent(player = null, callback = { }, versusPlayer = null)
}

testComposableRule.onNodeWithText("Select Players").assertIsDisplayed()
}

@Test
fun testWhoInThisRoomCannotContinueWithoutPickingPlayers() {
testComposableRule.setContent {
whoInThisRoom.DisplayContent(player = null, callback = { }, versusPlayer = null)
}

testComposableRule.onNodeWithText("Continue").assertIsNotEnabled()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.boozeblaster.minigames.individual

import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import com.boozeblaster.minigames.individual.FactOrFiction
import com.boozeblaster.models.Player
import org.junit.Rule
import org.junit.Test

class FactOrFictionTest {

@get:Rule
val testComposableRule = createComposeRule()

@Test
fun testFactOrFictionDisplay() {
val question = "Is the sky blue?"
val isCorrect = true

testComposableRule.setContent {
FactOrFiction(question = question, isCorrect = isCorrect)
.DisplayContent(player = Player(name = "TestPlayer"), callback = { }, versusPlayer = null)
}

testComposableRule.onNodeWithText(question).assertIsDisplayed()

testComposableRule.onNodeWithText("Wrong").assertIsDisplayed()
.assertHasClickAction()
.performClick()

testComposableRule.onNodeWithText("Right").assertIsDisplayed()
.assertHasClickAction()
.performClick()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.boozeblaster.minigames.individual

import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.boozeblaster.enums.ButtonType
import com.boozeblaster.enums.Genre
import com.boozeblaster.minigames.individual.GuessTheLyrics
import com.boozeblaster.models.Player
import com.boozeblaster.models.Song
import com.boozeblaster.utils.GenrePicker
import org.junit.Rule
import org.junit.Test

class GuessTheLyricsTest {

@get:Rule
val testComposableRule = createComposeRule()

@Test
fun testGuessTheLyricsDisplay() {
val song = Song("TestSong", "TestArtist", genre = Genre.ROCK)
val lyrics = "These are the lyrics to be displayed."
val lyricsCompletion = "These are the lyrics to be displayed."

val guessTheLyrics = GuessTheLyrics(song = song, lyrics = lyrics, lyricsCompletion = lyricsCompletion)

testComposableRule.setContent {
guessTheLyrics.DisplayContent(player = Player(name = "TestPlayer"), callback = { }, versusPlayer = null)
}

testComposableRule.onNodeWithText(song.getSongName()).assertTextEquals(song.getSongName())

testComposableRule.onNodeWithText(song.getArtistName()).assertTextEquals(song.getArtistName())

testComposableRule.onNodeWithText(lyrics).assertTextEquals(lyrics)

testComposableRule.onNodeWithText("Show Solution").assertIsDisplayed().performClick()

testComposableRule.onNodeWithText("Correct").assertIsDisplayed()
.assertHasClickAction()

testComposableRule.onNodeWithText("Partially Correct").assertIsDisplayed()
.assertHasClickAction()

testComposableRule.onNodeWithText("Wrong").assertIsDisplayed()
.assertHasClickAction()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.boozeblaster.minigames.individual

import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.boozeblaster.enums.ButtonType
import com.boozeblaster.minigames.individual.GuessTheSong
import com.boozeblaster.models.Player
import com.boozeblaster.models.Song
import com.boozeblaster.utils.GenrePicker
import com.boozeblaster.R
import com.boozeblaster.enums.Genre
import kotlinx.coroutines.delay
import org.junit.Rule
import org.junit.Test

class GuessTheSongTest {

@get:Rule
val testComposableRule = createComposeRule()

@Test
fun testGuessTheSongDisplay() {
val song = Song("TestSong", "TestArtist", genre = Genre.ROCK)
val resid = R.raw.waka_waka
val duration = 1000L

val guessTheSong = GuessTheSong(song = song, resid = resid, duration = duration)

testComposableRule.setContent {
guessTheSong.DisplayContent(player = Player(name = "TestPlayer"), callback = { }, versusPlayer = null)
LaunchedEffect(Unit) {
delay(2000)
testComposableRule.onNodeWithText("Show Solution").assertIsDisplayed().performClick()

testComposableRule.onNodeWithText(song.getSongName()).assertTextEquals(song.getSongName())

testComposableRule.onNodeWithText(song.getArtistName()).assertTextEquals(song.getArtistName())

testComposableRule.onNodeWithText("Got Both").assertIsDisplayed()
.assertHasClickAction()

testComposableRule.onNodeWithText("One Correct").assertIsDisplayed()
.assertHasClickAction()

testComposableRule.onNodeWithText("Wrong").assertIsDisplayed()
.assertHasClickAction()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.boozeblaster.minigames.individual

import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.boozeblaster.enums.ButtonType
import com.boozeblaster.minigames.individual.GuessTheTheme
import com.boozeblaster.models.Player
import com.boozeblaster.R
import kotlinx.coroutines.delay
import org.junit.Rule
import org.junit.Test

class GuessTheThemeTest {

@get:Rule
val testComposableRule = createComposeRule()

@Test
fun testGuessTheThemeDisplay() {
val name = "TestTheme"
val resid = R.raw.ghostbusters
val duration = 1000L

val guessTheTheme = GuessTheTheme(name = name, resid = resid, duration = duration)

testComposableRule.setContent {
guessTheTheme.DisplayContent(
player = Player(name = "TestPlayer"),
callback = { },
versusPlayer = null
)
LaunchedEffect(Unit) {
delay(2000)
testComposableRule.onNodeWithText(name).assertTextEquals(name)

testComposableRule.onNodeWithText("Show Solution").assertIsDisplayed().performClick()

testComposableRule.onNodeWithText("Correct").assertIsDisplayed()
.assertHasClickAction()

testComposableRule.onNodeWithText("Almost").assertIsDisplayed()
.assertHasClickAction()

testComposableRule.onNodeWithText("Wrong").assertIsDisplayed()
.assertHasClickAction()
}
}
}
}
Loading

0 comments on commit e9ae13a

Please sign in to comment.