Skip to content

Commit

Permalink
Fix broken tests due to hardcoding offline imagery option.
Browse files Browse the repository at this point in the history
  • Loading branch information
sufyanAbbasi committed Feb 28, 2024
1 parent 6482cea commit 55ebcd2
Showing 1 changed file with 15 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ import com.google.android.ground.ui.common.Navigator
import com.sharedtest.FakeData
import com.squareup.picasso.Picasso
import dagger.hilt.android.testing.HiltAndroidTest
import javax.inject.Inject
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.advanceUntilIdle
import org.hamcrest.CoreMatchers.not
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.ParameterizedRobolectricTestRunner
import org.robolectric.RobolectricTestRunner
import javax.inject.Inject

abstract class AbstractHomeScreenFragmentTest : BaseHiltTest() {

@Inject lateinit var localSurveyStore: LocalSurveyStore
@Inject
lateinit var localSurveyStore: LocalSurveyStore
private lateinit var fragment: HomeScreenFragment
private var initializedPicasso = false

Expand Down Expand Up @@ -119,7 +119,8 @@ abstract class AbstractHomeScreenFragmentTest : BaseHiltTest() {
@RunWith(RobolectricTestRunner::class)
class HomeScreenFragmentTest : AbstractHomeScreenFragmentTest() {

@Inject lateinit var surveyRepository: SurveyRepository
@Inject
lateinit var surveyRepository: SurveyRepository

private val surveyWithoutBasemap: Survey =
Survey(
Expand All @@ -134,27 +135,17 @@ class HomeScreenFragmentTest : AbstractHomeScreenFragmentTest() {
private val surveyWithTileSources: Survey =
surveyWithoutBasemap.copy(
tileSources =
listOf(
TileSource("http://google.com", TileSource.Type.MOG_COLLECTION),
),
listOf(
TileSource("http://google.com", TileSource.Type.MOG_COLLECTION),
),
id = "SURVEY_WITH_TILE_SOURCES"
)

@Test
fun offlineMapImageryMenuIsDisabledWhenActiveSurveyHasNoBasemap() = runWithTestDispatcher {
fun `offline map imagery menu is always enabled`() = runWithTestDispatcher {
surveyRepository.selectedSurveyId = surveyWithoutBasemap.id
advanceUntilIdle()

openDrawer()
onView(withId(R.id.nav_offline_areas)).check(matches(not(isEnabled())))
}

@Test
fun offlineMapImageryMenuIsEnabledWhenActiveSurveyHasBasemap() = runWithTestDispatcher {
localSurveyStore.insertOrUpdateSurvey(surveyWithTileSources)
surveyRepository.selectedSurveyId = surveyWithTileSources.id
advanceUntilIdle()

openDrawer()
onView(withId(R.id.nav_offline_areas)).check(matches(isEnabled()))
}
Expand All @@ -171,8 +162,11 @@ class NavigationDrawerItemClickTest(
private val testLabel: String
) : AbstractHomeScreenFragmentTest() {

@Inject lateinit var navigator: Navigator
@Inject lateinit var surveyRepository: SurveyRepository
@Inject
lateinit var navigator: Navigator

@Inject
lateinit var surveyRepository: SurveyRepository

@Test
fun clickDrawerMenuItem() = runWithTestDispatcher {
Expand Down Expand Up @@ -219,19 +213,12 @@ class NavigationDrawerItemClickTest(
true,
"Clicking 'sync status' should navigate to fragment"
),
arrayOf(
"Offline map imagery",
TEST_SURVEY_WITHOUT_OFFLINE_TILES,
null,
false,
"Clicking 'offline map imagery' when survey doesn't have offline tiles should do nothing"
),
arrayOf(
"Offline map imagery",
TEST_SURVEY_WITH_OFFLINE_TILES,
HomeScreenFragmentDirections.showOfflineAreas(),
true,
"Clicking 'offline map imagery' when survey has offline tiles should navigate to fragment"
"Clicking 'offline map imagery' should navigate to fragment"
),
arrayOf(
"Settings",
Expand Down

0 comments on commit 55ebcd2

Please sign in to comment.