-
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.
Merge remote-tracking branch 'origin/main' into kb-android-backgrounding
- Loading branch information
Showing
20 changed files
with
543 additions
and
59 deletions.
There are no files selected for viewing
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
104 changes: 104 additions & 0 deletions
104
...src/androidTest/java/com/mbta/tid/mbta_app/android/onboarding/OnboardingScreenViewTest.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,104 @@ | ||
package com.mbta.tid.mbta_app.android.onboarding | ||
|
||
import android.location.Location | ||
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.rule.GrantPermissionRule | ||
import com.mbta.tid.mbta_app.android.location.MockLocationDataManager | ||
import com.mbta.tid.mbta_app.model.OnboardingScreen | ||
import com.mbta.tid.mbta_app.repositories.MockSettingsRepository | ||
import com.mbta.tid.mbta_app.repositories.Settings | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertTrue | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class OnboardingScreenViewTest { | ||
@get:Rule val composeTestRule = createComposeRule() | ||
|
||
// We can't easily mock the permission request, so we grant the permission eagerly. | ||
@get:Rule | ||
val runtimePermissionRule = | ||
GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION) | ||
|
||
@Test | ||
fun testLocationFlow() { | ||
var advanced = false | ||
val locationDataManager = MockLocationDataManager(Location("mock")) | ||
composeTestRule.setContent { | ||
OnboardingScreenView( | ||
screen = OnboardingScreen.Location, | ||
advance = { advanced = true }, | ||
locationDataManager = locationDataManager, | ||
) | ||
} | ||
|
||
composeTestRule | ||
.onNodeWithText( | ||
"We use your location to show you nearby transit options.", | ||
substring = true | ||
) | ||
.assertIsDisplayed() | ||
composeTestRule.onNodeWithText("Continue").performClick() | ||
|
||
composeTestRule.waitForIdle() | ||
assertTrue(advanced) | ||
} | ||
|
||
@Test | ||
fun testHideMapsFlow() { | ||
var savedSetting = false | ||
val settingsRepo = | ||
MockSettingsRepository( | ||
settings = mapOf(Settings.HideMaps to false), | ||
onSaveSettings = { | ||
assertEquals(mapOf(Settings.HideMaps to true), it) | ||
savedSetting = true | ||
} | ||
) | ||
var advanced = false | ||
composeTestRule.setContent { | ||
OnboardingScreenView( | ||
screen = OnboardingScreen.HideMaps, | ||
advance = { advanced = true }, | ||
locationDataManager = MockLocationDataManager(Location("mock")), | ||
settingsRepository = settingsRepo | ||
) | ||
} | ||
composeTestRule | ||
.onNodeWithText( | ||
"When using TalkBack, we can skip reading out maps to keep you focused on transit information." | ||
) | ||
.assertIsDisplayed() | ||
composeTestRule.onNodeWithText("Show maps").assertIsDisplayed() | ||
composeTestRule.onNodeWithText("Hide maps").performClick() | ||
|
||
composeTestRule.waitForIdle() | ||
assertTrue(savedSetting) | ||
assertTrue(advanced) | ||
} | ||
|
||
@Test | ||
fun testFeedbackFlow() { | ||
var advanced = false | ||
composeTestRule.setContent { | ||
OnboardingScreenView( | ||
screen = OnboardingScreen.Feedback, | ||
advance = { advanced = true }, | ||
locationDataManager = MockLocationDataManager(Location("mock")), | ||
) | ||
} | ||
composeTestRule | ||
.onNodeWithText( | ||
"MBTA Go is in the early stages! We want your feedback" + | ||
" as we continue making improvements and adding new features." | ||
) | ||
.assertIsDisplayed() | ||
composeTestRule.onNodeWithText("Get started").performClick() | ||
|
||
composeTestRule.waitForIdle() | ||
assertTrue(advanced) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
androidApp/src/androidTest/java/com/mbta/tid/mbta_app/android/pages/OnboardingPageTest.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,51 @@ | ||
package com.mbta.tid.mbta_app.android.pages | ||
|
||
import android.location.Location | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performClick | ||
import com.mbta.tid.mbta_app.android.location.MockLocationDataManager | ||
import com.mbta.tid.mbta_app.model.OnboardingScreen | ||
import com.mbta.tid.mbta_app.repositories.MockOnboardingRepository | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertTrue | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class OnboardingPageTest { | ||
@get:Rule val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun testFlow() { | ||
val completedScreens = mutableSetOf<OnboardingScreen>() | ||
val onboardingRepository = | ||
MockOnboardingRepository( | ||
pendingOnboarding = OnboardingScreen.entries, | ||
onMarkComplete = completedScreens::add | ||
) | ||
var finished = false | ||
|
||
composeTestRule.setContent { | ||
OnboardingPage( | ||
screens = OnboardingScreen.entries, | ||
locationDataManager = MockLocationDataManager(Location("mock")), | ||
onFinish = { finished = true }, | ||
onboardingRepository = onboardingRepository, | ||
skipLocationDialogue = true, | ||
) | ||
} | ||
|
||
composeTestRule.onNodeWithText("Continue").performClick() | ||
composeTestRule.waitUntil { completedScreens.size == 1 } | ||
assertEquals(1, completedScreens.size) | ||
|
||
composeTestRule.onNodeWithText("Show maps").performClick() | ||
composeTestRule.waitUntil { completedScreens.size == 2 } | ||
assertEquals(2, completedScreens.size) | ||
|
||
composeTestRule.onNodeWithText("Get started").performClick() | ||
composeTestRule.waitUntil { completedScreens.size == 3 } | ||
assertEquals(OnboardingScreen.entries.toSet(), completedScreens) | ||
assertTrue(finished) | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
androidApp/src/main/java/com/mbta/tid/mbta_app/android/ContentViewModel.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,31 @@ | ||
package com.mbta.tid.mbta_app.android | ||
|
||
import androidx.lifecycle.ViewModel | ||
import com.mbta.tid.mbta_app.model.OnboardingScreen | ||
import com.mbta.tid.mbta_app.repositories.IOnboardingRepository | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.launch | ||
|
||
class ContentViewModel(private val onboardingRepository: IOnboardingRepository) : ViewModel() { | ||
private val _pendingOnboarding: MutableStateFlow<List<OnboardingScreen>?> = | ||
MutableStateFlow(null) | ||
val pendingOnboarding: StateFlow<List<OnboardingScreen>?> = _pendingOnboarding | ||
|
||
init { | ||
loadPendingOnboarding() | ||
} | ||
|
||
fun loadPendingOnboarding() { | ||
CoroutineScope(Dispatchers.IO).launch { | ||
val data = onboardingRepository.getPendingOnboarding() | ||
_pendingOnboarding.value = data | ||
} | ||
} | ||
|
||
fun clearPendingOnboarding() { | ||
_pendingOnboarding.value = emptyList() | ||
} | ||
} |
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
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
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
Oops, something went wrong.