-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(planet-selection): add unit tests forPlanetSelectionScreen compo…
…sable
- Loading branch information
Showing
2 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
...Test/java/com/github/lookupgroup27/lookup/ui/planetselection/PlanetSelectionScreenTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters