From 45b558a6afd7eb4a434f5cec9ba88d847d37f89a Mon Sep 17 00:00:00 2001 From: Kenzoud Date: Thu, 19 Dec 2024 13:51:54 +0100 Subject: [PATCH 1/4] fix: set GLSurfaceView to be transparent and place it in the background explicitly in PlanetSurfaceView --- .../lookup/model/planetselection/PlanetSurfaceView.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/model/planetselection/PlanetSurfaceView.kt b/app/src/main/java/com/github/lookupgroup27/lookup/model/planetselection/PlanetSurfaceView.kt index 3f256bba5..53c222d46 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/model/planetselection/PlanetSurfaceView.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/model/planetselection/PlanetSurfaceView.kt @@ -2,6 +2,7 @@ package com.github.lookupgroup27.lookup.model.planetselection import android.annotation.SuppressLint import android.content.Context +import android.graphics.PixelFormat import android.opengl.GLSurfaceView import com.github.lookupgroup27.lookup.model.map.planets.PlanetData @@ -26,6 +27,11 @@ class PlanetSurfaceView(context: Context, private var planet: PlanetData) : GLSu // Render only when the content changes renderMode = RENDERMODE_CONTINUOUSLY + + // Enable transparency + setZOrderOnTop(false) + setZOrderMediaOverlay(false) + holder.setFormat(PixelFormat.TRANSLUCENT) } /** From 5dca02c6826a8ca2a88da6d1fbea1b56be07600a Mon Sep 17 00:00:00 2001 From: Kenzoud Date: Thu, 19 Dec 2024 14:17:23 +0100 Subject: [PATCH 2/4] fix: replace Surface with Scaffold in PlanetSelectionScreen -Use topBar and content slots to better structure components --- .../planetselection/PlanetSelectionScreen.kt | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt index f3f587ae8..d730b0d8d 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt @@ -1,12 +1,13 @@ package com.github.lookupgroup27.lookup.ui.planetselection +import android.annotation.SuppressLint import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material3.Icon import androidx.compose.material3.IconButton -import androidx.compose.material3.Surface +import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.* import androidx.compose.ui.Alignment @@ -32,6 +33,7 @@ import com.github.lookupgroup27.lookup.ui.planetselection.components.PlanetSelec * @param viewModel The ViewModel for the Planet Selection screen. * @param navigationActions The navigation actions to handle screen transitions. */ +@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter") @Composable fun PlanetSelectionScreen( viewModel: PlanetSelectionViewModel = viewModel(), @@ -43,34 +45,29 @@ fun PlanetSelectionScreen( // Reference to the PlanetSurfaceView to update it var planetSurfaceView by remember { mutableStateOf(null) } - Surface( - modifier = Modifier.fillMaxSize(), color = Color.Black // Background color for the screen - ) { + Scaffold( + topBar = { + IconButton( + onClick = { navigationActions.navigateTo(Screen.MENU) }, + modifier = Modifier.padding(16.dp).testTag("go_back_button")) { + Icon( + imageVector = Icons.AutoMirrored.Filled.ArrowBack, + contentDescription = "Back", + tint = Color.White) + } + }, + content = { Column( - modifier = Modifier.fillMaxSize(), + modifier = Modifier.fillMaxSize().background(Color.Black), verticalArrangement = Arrangement.SpaceBetween, horizontalAlignment = Alignment.CenterHorizontally) { + Spacer(modifier = Modifier.height(70.dp)) - // Back Button - IconButton( - onClick = { navigationActions.navigateTo(Screen.MENU) }, - modifier = - Modifier.padding(16.dp) - .align(Alignment.Start) - .testTag("go_back_button_quiz")) { - Icon( - imageVector = Icons.AutoMirrored.Filled.ArrowBack, - contentDescription = "Back", - tint = Color.White) - } - - // Top: Horizontal planet selection PlanetSelectionRow( planets = planets, onPlanetSelected = { viewModel.selectPlanet(it) }) - Spacer(modifier = Modifier.height(40.dp)) + Spacer(modifier = Modifier.height(50.dp)) - // Middle: Planet name Text( text = selectedPlanet.name, color = White, @@ -86,11 +83,11 @@ fun PlanetSelectionScreen( factory = { context -> PlanetSurfaceView(context, selectedPlanet).also { planetSurfaceView = it } }, - modifier = Modifier.fillMaxSize()) + modifier = Modifier.size(600.dp)) } // LaunchedEffect to update the planet when selectedPlanet changes LaunchedEffect(selectedPlanet) { planetSurfaceView?.updatePlanet(selectedPlanet) } } - } + }) } From 8487e36559c2d92ba481778667898325152f2243 Mon Sep 17 00:00:00 2001 From: Kenzoud Date: Thu, 19 Dec 2024 14:42:59 +0100 Subject: [PATCH 3/4] fix: separate PlanetSelectionRow an the text from the OpenGL content (the Planet) --- .../planetselection/PlanetSelectionScreen.kt | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt index d730b0d8d..26d9c2e9f 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt @@ -47,33 +47,33 @@ fun PlanetSelectionScreen( Scaffold( topBar = { - IconButton( - onClick = { navigationActions.navigateTo(Screen.MENU) }, - modifier = Modifier.padding(16.dp).testTag("go_back_button")) { - Icon( - imageVector = Icons.AutoMirrored.Filled.ArrowBack, - contentDescription = "Back", - tint = Color.White) - } + Column(modifier = Modifier.fillMaxSize().background(Color.Transparent)) { + IconButton( + onClick = { navigationActions.navigateTo(Screen.MENU) }, + modifier = Modifier.padding(16.dp).testTag("go_back_button")) { + Icon( + imageVector = Icons.AutoMirrored.Filled.ArrowBack, + contentDescription = "Back", + tint = Color.White) + } + + PlanetSelectionRow(planets = planets, onPlanetSelected = { viewModel.selectPlanet(it) }) + + Spacer(modifier = Modifier.height(50.dp)) + + Text( + text = selectedPlanet.name, + color = White, + fontSize = 50.sp, + fontWeight = FontWeight.Light, + modifier = Modifier.padding(20.dp).align(Alignment.CenterHorizontally)) + } }, content = { Column( modifier = Modifier.fillMaxSize().background(Color.Black), verticalArrangement = Arrangement.SpaceBetween, horizontalAlignment = Alignment.CenterHorizontally) { - Spacer(modifier = Modifier.height(70.dp)) - - PlanetSelectionRow( - planets = planets, onPlanetSelected = { viewModel.selectPlanet(it) }) - - Spacer(modifier = Modifier.height(50.dp)) - - Text( - text = selectedPlanet.name, - color = White, - fontSize = 50.sp, - fontWeight = FontWeight.Light, - modifier = Modifier.padding(20.dp)) // Bottom: Planet renderer Box( From 264724cc6c443f5984087c776bf49f9d201e7ad7 Mon Sep 17 00:00:00 2001 From: Kenzoud Date: Thu, 19 Dec 2024 17:08:47 +0100 Subject: [PATCH 4/4] test(planet-selection): add unit tests forPlanetSelectionScreen composable --- .../PlanetSelectionScreenTest.kt | 79 +++++++++++++++++++ .../planetselection/PlanetSelectionScreen.kt | 5 +- 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreenTest.kt diff --git a/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreenTest.kt b/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreenTest.kt new file mode 100644 index 000000000..295862c1c --- /dev/null +++ b/app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreenTest.kt @@ -0,0 +1,79 @@ +package com.github.lookupgroup27.lookup.ui.planetselection + +import androidx.compose.ui.test.* +import androidx.compose.ui.test.junit4.createComposeRule +import com.github.lookupgroup27.lookup.model.map.planets.PlanetsRepository +import com.github.lookupgroup27.lookup.ui.navigation.NavigationActions +import com.github.lookupgroup27.lookup.ui.navigation.Screen +import io.mockk.* +import org.junit.Before +import org.junit.Rule +import org.junit.Test + +class PlanetSelectionScreenTest { + + @get:Rule val composeTestRule = createComposeRule() + + private lateinit var viewModel: PlanetSelectionViewModel + private lateinit var navigationActions: NavigationActions + private lateinit var planetsRepository: PlanetsRepository + + @Before + fun setUp() { + + planetsRepository = PlanetsRepository(mockk(), mockk(), "") + + // Mock the ViewModel with PlanetsRepository + viewModel = spyk(PlanetSelectionViewModel(planetsRepository)) + + // Mock NavigationActions + navigationActions = mockk(relaxed = true) + } + + @Test + fun testBackButtonNavigatesToMenu() { + composeTestRule.setContent { + PlanetSelectionScreen(viewModel = viewModel, navigationActions = navigationActions) + } + + composeTestRule.onNodeWithTag("go_back_button").performClick() + + verify { navigationActions.navigateTo(Screen.MENU) } + } + + @Test + fun testPlanetSelectionUpdatesPlanetName() { + composeTestRule.setContent { + PlanetSelectionScreen(viewModel = viewModel, navigationActions = navigationActions) + } + + // Select Mars + composeTestRule.onNodeWithContentDescription("Mars button").performClick() + + // Check if the planet name is updated + composeTestRule.onNodeWithTag("planet_name").assertTextEquals("Mars") + } + + @Test + fun testInitialPlanetDisplayedCorrectly() { + composeTestRule.setContent { + PlanetSelectionScreen(viewModel = viewModel, navigationActions = navigationActions) + } + + // Check if the initially selected planet (Moon) is displayed + composeTestRule.onNodeWithTag("planet_name").assertTextEquals("Moon") + } + + @Test + fun testPlanetSurfaceViewUpdatesOnPlanetChange() { + composeTestRule.setContent { + PlanetSelectionScreen(viewModel = viewModel, navigationActions = navigationActions) + } + + // Select Jupiter + composeTestRule.onNodeWithContentDescription("Jupiter button").performClick() + + // Verify if the planet name is updated to Jupiter + composeTestRule.onNodeWithTag("planet_name").assertTextEquals("Jupiter") + } +} diff --git a/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt b/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt index 26d9c2e9f..5c2320c9d 100644 --- a/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt +++ b/app/src/main/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreen.kt @@ -66,7 +66,10 @@ fun PlanetSelectionScreen( color = White, fontSize = 50.sp, fontWeight = FontWeight.Light, - modifier = Modifier.padding(20.dp).align(Alignment.CenterHorizontally)) + modifier = + Modifier.padding(20.dp) + .align(Alignment.CenterHorizontally) + .testTag("planet_name")) } }, content = {