Skip to content

Commit

Permalink
Fix quick settings back press (#129)
Browse files Browse the repository at this point in the history
* Fix quick settings back press

* Update TestTags.kt
  • Loading branch information
davidjiagoogle committed Mar 4, 2024
1 parent 6c9df56 commit 9127847
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import androidx.test.rule.GrantPermissionRule
import androidx.test.uiautomator.UiDevice
import com.google.jetpackcamera.feature.preview.ui.CAPTURE_BUTTON
import com.google.jetpackcamera.feature.preview.ui.FLIP_CAMERA_BUTTON
import com.google.jetpackcamera.feature.preview.ui.QUICK_SETTINGS_BUTTON
import com.google.jetpackcamera.feature.preview.ui.QUICK_SETTINGS_RATIO_1_1_BUTTON
import com.google.jetpackcamera.feature.preview.ui.QUICK_SETTINGS_RATIO_BUTTON
import com.google.jetpackcamera.feature.preview.ui.SETTINGS_BUTTON
import com.google.jetpackcamera.settings.ui.BACK_BUTTON
import org.junit.Rule
Expand Down Expand Up @@ -104,6 +107,59 @@ class NavigationTest {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).assertExists()
}

@Test
fun backFromQuickSettings_returnToPreview() = runScenarioTest<MainActivity> {
// Wait for the capture button to be displayed
composeTestRule.waitUntil {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}

// Navigate to the quick settings screen
composeTestRule.onNodeWithTag(QUICK_SETTINGS_BUTTON)
.assertExists()
.performClick()

// Wait for the quick settings to be displayed
composeTestRule.waitUntil {
composeTestRule.onNodeWithTag(QUICK_SETTINGS_RATIO_BUTTON).isDisplayed()
}

// Press the device's back button
uiDevice.pressBack()

// Assert we're on PreviewScreen by finding the capture button
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).assertExists()
}

@Test
fun backFromQuickSettingsExpended_returnToQuickSettings() = runScenarioTest<MainActivity> {
// Wait for the capture button to be displayed
composeTestRule.waitUntil {
composeTestRule.onNodeWithTag(CAPTURE_BUTTON).isDisplayed()
}

// Navigate to the quick settings screen
composeTestRule.onNodeWithTag(QUICK_SETTINGS_BUTTON)
.assertExists()
.performClick()

// Navigate to the expanded quick settings ratio screen
composeTestRule.onNodeWithTag(QUICK_SETTINGS_RATIO_BUTTON)
.assertExists()
.performClick()

// Wait for the 1:1 ratio button to be displayed
composeTestRule.waitUntil {
composeTestRule.onNodeWithTag(QUICK_SETTINGS_RATIO_1_1_BUTTON).isDisplayed()
}

// Press the device's back button
uiDevice.pressBack()

// Assert we're on quick settings by finding the ratio button
composeTestRule.onNodeWithTag(QUICK_SETTINGS_RATIO_BUTTON).assertExists()
}

private inline fun <reified T : Activity> runScenarioTest(
crossinline block: ActivityScenario<T>.() -> Unit
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ package com.google.jetpackcamera.feature.preview.ui
const val CAPTURE_BUTTON = "CaptureButton"
const val SETTINGS_BUTTON = "SettingsButton"
const val FLIP_CAMERA_BUTTON = "FlipCameraButton"
const val QUICK_SETTINGS_BUTTON = "QuickSettingDropDown"
const val QUICK_SETTINGS_RATIO_BUTTON = "QuickSetAspectRatio"
const val QUICK_SETTINGS_RATIO_1_1_BUTTON = "QuickSetAspectRatio1:1"
3 changes: 3 additions & 0 deletions feature/quicksettings/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ dependencies {
implementation(libs.compose.ui.tooling.preview)
debugImplementation(libs.compose.ui.tooling)

// Compose - Activity
implementation(libs.androidx.activity.compose)

// Compose - Testing
androidTestImplementation(libs.compose.junit)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.jetpackcamera.feature.quicksettings

import androidx.activity.compose.BackHandler
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
Expand Down Expand Up @@ -81,6 +82,13 @@ fun QuickSettingsScreenOverlay(
)

if (isOpen) {
val onBack = {
when (shouldShowQuickSetting) {
IsExpandedQuickSetting.NONE -> toggleIsOpen()
else -> shouldShowQuickSetting = IsExpandedQuickSetting.NONE
}
}
BackHandler(onBack = onBack)
Column(
modifier =
modifier
Expand Down

0 comments on commit 9127847

Please sign in to comment.