Skip to content

Commit

Permalink
Write tests for the view on map feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrocalles committed Jun 2, 2024
1 parent ae88b4d commit 9e7085d
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.swent.echo.compose.components

import androidx.activity.compose.setContent
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
Expand All @@ -10,9 +11,13 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.github.swent.echo.MainActivity
import com.github.swent.echo.data.SAMPLE_EVENTS
import com.github.swent.echo.ui.navigation.NavigationActions
import com.github.swent.echo.viewmodels.HomeScreenViewModel
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import io.mockk.every
import io.mockk.mockk
import io.mockk.spyk
import kotlinx.coroutines.flow.MutableStateFlow
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand All @@ -31,7 +36,6 @@ class HomeScreenTest {
@Before
fun setUp() {
hiltRule.inject()

navActions = mockk(relaxed = true)
composeTestRule.activity.setContent {
HomeScreen(
Expand Down Expand Up @@ -150,4 +154,25 @@ class HomeScreenTest {
composeTestRule.onNodeWithTag("mapViewWrapper").assertExists()
}
}

@Test
fun shouldShowMapWhenViewOnMapIsCalled() {
val event = SAMPLE_EVENTS[0]
composeTestRule.activity.setContent {
val homeScreenViewModel: HomeScreenViewModel = hiltViewModel()
val mockedHomeScreenViewModel = spyk<HomeScreenViewModel>(homeScreenViewModel)
every { mockedHomeScreenViewModel.displayEventList } returns
MutableStateFlow(listOf(event))
HomeScreen(
homeScreenViewModel = mockedHomeScreenViewModel,
navActions = navActions,
themeViewModel = hiltViewModel()
)
}
composeTestRule.onNodeWithTag("list_map_mode_button").performClick()
composeTestRule.onNodeWithTag("list_event_item_${event.eventId}").performClick()
composeTestRule.onNodeWithTag("view_on_map_${event.eventId}").performClick()
composeTestRule.onNodeWithTag("mapViewWrapper").assertIsDisplayed()
composeTestRule.onNodeWithTag("event_info_sheet").assertIsDisplayed()
}
}

0 comments on commit 9e7085d

Please sign in to comment.