Skip to content
Merged
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
1 change: 1 addition & 0 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ kotlin {
implementation(libs.assertk)
implementation(kotlin("test"))
implementation(libs.androidx.test.runner)
implementation("io.coil-kt.coil3:coil-test:3.3.0")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.randomboxd.feature.random_film.presentation

import android.graphics.Bitmap
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import coil3.ImageLoader
import coil3.SingletonImageLoader
import coil3.annotation.DelicateCoilApi
import coil3.asImage
import coil3.test.FakeImageLoaderEngine
import com.nacchofer31.randomboxd.random_film.presentation.components.FilmPoster
import org.junit.After
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class FilmPosterTest {
@get:Rule
val composeTestRule = createComposeRule()

private val context get() = InstrumentationRegistry.getInstrumentation().targetContext

@After
@OptIn(DelicateCoilApi::class)
fun resetImageLoader() {
SingletonImageLoader.reset()
}

private fun setImageLoader(engine: FakeImageLoaderEngine) {
SingletonImageLoader.setSafe {
ImageLoader.Builder(context).components { add(engine) }.build()
}
}

@Test
fun film_poster_shows_image_with_valid_dimensions() {
val bitmap = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888)
setImageLoader(
FakeImageLoaderEngine
.Builder()
.default(bitmap.asImage())
.build(),
)

composeTestRule.setContent {
FilmPoster(
imageUrl = "https://example.com/poster.jpg",
title = "Test Film",
releaseYear = "2020",
onClick = {},
)
}

composeTestRule.waitForIdle()

composeTestRule.onNodeWithContentDescription("film_image").assertIsDisplayed()
composeTestRule.onNodeWithContentDescription("info_icon").assertIsDisplayed()
}

@Test
fun film_poster_shows_image_with_invalid_dimensions_fallback() {
val bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888)
setImageLoader(
FakeImageLoaderEngine
.Builder()
.default(bitmap.asImage())
.build(),
)

composeTestRule.setContent {
FilmPoster(
imageUrl = "https://example.com/poster.jpg",
title = "Test Film",
releaseYear = "2020",
onClick = {},
)
}

composeTestRule.waitForIdle()

composeTestRule.onNodeWithTag("test-film-poster").assertIsDisplayed()
}

@Test
fun film_poster_click_triggers_callback_on_loaded_image() {
val bitmap = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888)
setImageLoader(
FakeImageLoaderEngine
.Builder()
.default(bitmap.asImage())
.build(),
)

var clicked = false
composeTestRule.setContent {
FilmPoster(
imageUrl = "https://example.com/poster.jpg",
title = "Inception",
releaseYear = "2010",
onClick = { clicked = true },
)
}

composeTestRule.waitForIdle()
composeTestRule.onNodeWithContentDescription("film_image").performClick()

assertTrue(clicked)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.randomboxd.onboarding.presentation

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 androidx.test.ext.junit.runners.AndroidJUnit4
import com.nacchofer31.randomboxd.onboarding.presentation.OnboardingScreen
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class OnboardingScreenTest {
@get:Rule
val composeTestRule = createComposeRule()

@Test
fun onboarding_screen_shows_first_page_on_launch() {
composeTestRule.setContent {
OnboardingScreen(onFinish = {})
}

composeTestRule.onNodeWithText("RandomBoxd").assertIsDisplayed()
composeTestRule.onNodeWithText("Get Started").assertIsDisplayed()
composeTestRule.onNodeWithText("Skip").assertIsDisplayed()
}

@Test
fun onboarding_skip_button_calls_on_finish() {
var finished = false
composeTestRule.setContent {
OnboardingScreen(onFinish = { finished = true })
}

composeTestRule.onNodeWithText("Skip").performClick()

assertTrue(finished)
}

@Test
fun onboarding_next_button_advances_to_second_page() {
composeTestRule.setContent {
OnboardingScreen(onFinish = {})
}

composeTestRule.onNodeWithText("Get Started").performClick()

composeTestRule.onNodeWithText("Random Selection").assertIsDisplayed()
composeTestRule.onNodeWithText("Next").assertIsDisplayed()
}

@Test
fun onboarding_navigates_through_all_pages_to_finish() {
var finished = false
composeTestRule.setContent {
OnboardingScreen(onFinish = { finished = true })
}

// Page 1 → 2
composeTestRule.onNodeWithText("Get Started").performClick()
composeTestRule.waitForIdle()
// Page 2 → 3
composeTestRule.onNodeWithText("Next").performClick()
composeTestRule.waitForIdle()
// Page 3 → 4
composeTestRule.onNodeWithText("Next").performClick()
composeTestRule.waitForIdle()
// Page 4 — last page, skip button should NOT be visible
composeTestRule.onNodeWithText("Start Exploring").assertIsDisplayed()
composeTestRule.onNodeWithText("Start Exploring").performClick()

assertTrue(finished)
}
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ coil-compose-core = { module = "io.coil-kt.coil3:coil-compose-core", version.ref
coil-network-ktor2 = { module = "io.coil-kt.coil3:coil-network-ktor2", version.ref = "coil3" }
coil-network-ktor3 = { module = "io.coil-kt.coil3:coil-network-ktor3", version.ref = "coil3" }
coil-mp = { module = "io.coil-kt.coil3:coil", version.ref = "coil3" }
coil-test = { module = "io.coil-kt.coil3:coil-test", version.ref = "coil3" }
androidx-ui-test-android = { group = "androidx.compose.ui", name = "ui-test-android", version.ref = "uiTestAndroid" }

# Jsoup
Expand Down