Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e501ebc9 authored by Michał Brzeziński's avatar Michał Brzeziński Committed by Android (Google) Code Review
Browse files

Merge "Adding first error state for touchpad tutorial" into main

parents 41f24eeb 07454189
Loading
Loading
Loading
Loading
+111 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.touchpad.tutorial.ui

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.inputdevice.tutorial.ui.composable.TutorialActionState
import com.android.systemui.inputdevice.tutorial.ui.composable.TutorialActionState.Error
import com.android.systemui.inputdevice.tutorial.ui.composable.TutorialActionState.Finished
import com.android.systemui.inputdevice.tutorial.ui.composable.TutorialActionState.InProgress
import com.android.systemui.inputdevice.tutorial.ui.composable.TutorialActionState.InProgressAfterError
import com.android.systemui.inputdevice.tutorial.ui.composable.TutorialActionState.NotStarted
import com.android.systemui.touchpad.tutorial.ui.composable.toGestureUiState
import com.android.systemui.touchpad.tutorial.ui.composable.toTutorialActionState
import com.android.systemui.touchpad.tutorial.ui.gesture.GestureState
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
class StateTransitionsTest : SysuiTestCase() {

    companion object {
        private const val START_MARKER = "startMarker"
        private const val END_MARKER = "endMarker"
        private const val SUCCESS_ANIMATION = 0
    }

    // needed to simulate caching last state as it's used to create new state
    private var lastState: TutorialActionState = NotStarted

    private fun GestureState.toTutorialActionState(): TutorialActionState {
        val newState =
            this.toGestureUiState(
                    progressStartMarker = START_MARKER,
                    progressEndMarker = END_MARKER,
                    successAnimation = SUCCESS_ANIMATION,
                )
                .toTutorialActionState(lastState)
        lastState = newState
        return lastState
    }

    @Test
    fun gestureStateProducesEquivalentTutorialActionStateInHappyPath() {
        val happyPath =
            listOf(
                GestureState.NotStarted,
                GestureState.InProgress(0f),
                GestureState.InProgress(0.5f),
                GestureState.InProgress(1f),
                GestureState.Finished,
            )

        val resultingStates = mutableListOf<TutorialActionState>()
        happyPath.forEach { resultingStates.add(it.toTutorialActionState()) }

        assertThat(resultingStates)
            .containsExactly(
                NotStarted,
                InProgress(0f, START_MARKER, END_MARKER),
                InProgress(0.5f, START_MARKER, END_MARKER),
                InProgress(1f, START_MARKER, END_MARKER),
                Finished(SUCCESS_ANIMATION),
            )
            .inOrder()
    }

    @Test
    fun gestureStateProducesEquivalentTutorialActionStateInErrorPath() {
        val errorPath =
            listOf(
                GestureState.NotStarted,
                GestureState.InProgress(0f),
                GestureState.Error,
                GestureState.InProgress(0.5f),
                GestureState.InProgress(1f),
                GestureState.Finished,
            )

        val resultingStates = mutableListOf<TutorialActionState>()
        errorPath.forEach { resultingStates.add(it.toTutorialActionState()) }

        assertThat(resultingStates)
            .containsExactly(
                NotStarted,
                InProgress(0f, START_MARKER, END_MARKER),
                Error,
                InProgressAfterError(InProgress(0.5f, START_MARKER, END_MARKER)),
                InProgressAfterError(InProgress(1f, START_MARKER, END_MARKER)),
                Finished(SUCCESS_ANIMATION),
            )
            .inOrder()
    }
}
+3 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.testKosmos
import com.android.systemui.touchpad.tutorial.ui.gesture.GestureState.Error
import com.android.systemui.touchpad.tutorial.ui.gesture.GestureState.InProgress
import com.android.systemui.touchpad.tutorial.ui.gesture.GestureState.NotStarted
import com.android.systemui.touchpad.tutorial.ui.gesture.MultiFingerGesture.Companion.SWIPE_DISTANCE
@@ -56,9 +57,9 @@ class HomeGestureRecognizerTest : SysuiTestCase() {
    }

    @Test
    fun doesntTriggerGestureFinished_onGestureSpeedTooSlow() {
    fun triggersError_onGestureSpeedTooSlow() {
        velocityTracker.setVelocity(Velocity(SLOW))
        assertStateAfterEvents(events = ThreeFingerGesture.swipeUp(), expectedState = NotStarted)
        assertStateAfterEvents(events = ThreeFingerGesture.swipeUp(), expectedState = Error)
    }

    @Test
+3 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.testKosmos
import com.android.systemui.touchpad.tutorial.ui.gesture.GestureState.Error
import com.android.systemui.touchpad.tutorial.ui.gesture.GestureState.InProgress
import com.android.systemui.touchpad.tutorial.ui.gesture.GestureState.NotStarted
import com.android.systemui.touchpad.tutorial.ui.gesture.MultiFingerGesture.Companion.SWIPE_DISTANCE
@@ -57,9 +58,9 @@ class RecentAppsGestureRecognizerTest : SysuiTestCase() {
    }

    @Test
    fun doesntTriggerGestureFinished_onGestureSpeedTooHigh() {
    fun triggersError_onGestureSpeedTooHigh() {
        velocityTracker.setVelocity(Velocity(FAST))
        assertStateAfterEvents(events = ThreeFingerGesture.swipeUp(), expectedState = NotStarted)
        assertStateAfterEvents(events = ThreeFingerGesture.swipeUp(), expectedState = Error)
    }

    @Test
+5 −4
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.touchpad.tutorial.ui.gesture
import android.view.MotionEvent
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.touchpad.tutorial.ui.gesture.GestureState.Error
import com.android.systemui.touchpad.tutorial.ui.gesture.GestureState.Finished
import com.android.systemui.touchpad.tutorial.ui.gesture.GestureState.InProgress
import com.android.systemui.touchpad.tutorial.ui.gesture.GestureState.NotStarted
@@ -64,12 +65,12 @@ class ThreeFingerGestureRecognizerTest(
    }

    @Test
    fun doesntTriggerGestureFinished_onGestureDistanceTooShort() {
        assertStateAfterEvents(events = tooShortGesture, expectedState = NotStarted)
    fun triggersGestureError_onGestureDistanceTooShort() {
        assertStateAfterEvents(events = tooShortGesture, expectedState = Error)
    }

    @Test
    fun doesntTriggerGestureFinished_onThreeFingersSwipeInOtherDirections() {
    fun triggersGestureError_onThreeFingersSwipeInOtherDirections() {
        val allThreeFingerGestures =
            listOf(
                ThreeFingerGesture.swipeUp(),
@@ -78,7 +79,7 @@ class ThreeFingerGestureRecognizerTest(
                ThreeFingerGesture.swipeRight(),
            )
        val invalidGestures = allThreeFingerGestures.filter { it.differentFromAnyOf(validGestures) }
        invalidGestures.forEach { assertStateAfterEvents(events = it, expectedState = NotStarted) }
        invalidGestures.forEach { assertStateAfterEvents(events = it, expectedState = Error) }
    }

    @Test
+11 −0
Original line number Diff line number Diff line
@@ -3932,6 +3932,8 @@
    <string name="touchpad_tutorial_recent_apps_gesture_button">View recent apps</string>
    <!-- Label for button finishing touchpad tutorial [CHAR LIMIT=NONE] -->
    <string name="touchpad_tutorial_done_button">Done</string>
    <!-- Screen title after gesture was not done correctly [CHAR LIMIT=NONE] -->
    <string name="gesture_error_title">Try again!</string>
    <!-- BACK GESTURE -->
    <!-- Touchpad back gesture action name in tutorial [CHAR LIMIT=NONE] -->
    <string name="touchpad_back_gesture_action_title">Go back</string>
@@ -3941,6 +3943,8 @@
    <string name="touchpad_back_gesture_success_title">Nice!</string>
    <!-- Text shown to the user after they complete back gesture tutorial [CHAR LIMIT=NONE] -->
    <string name="touchpad_back_gesture_success_body">You completed the go back gesture.</string>
    <!-- Text shown to the user after back gesture was not done correctly [CHAR LIMIT=NONE] -->
    <string name="touchpad_back_gesture_error_body">To go back using your touchpad, swipe left or right using three fingers</string>
    <!-- HOME GESTURE -->
    <!-- Touchpad home gesture action name in tutorial [CHAR LIMIT=NONE] -->
    <string name="touchpad_home_gesture_action_title">Go home</string>
@@ -3950,6 +3954,8 @@
    <string name="touchpad_home_gesture_success_title">Great job!</string>
    <!-- Text shown to the user after they complete home gesture tutorial [CHAR LIMIT=NONE] -->
    <string name="touchpad_home_gesture_success_body">You completed the go home gesture</string>
    <!-- Text shown to the user after home gesture was not done correctly [CHAR LIMIT=NONE] -->
    <string name="touchpad_home_gesture_error_body">Swipe up with three fingers on your touchpad to go to your home screen</string>
    <!-- RECENT APPS GESTURE -->
    <!-- Touchpad recent apps gesture action name in tutorial [CHAR LIMIT=NONE] -->
    <string name="touchpad_recent_apps_gesture_action_title">View recent apps</string>
@@ -3959,6 +3965,8 @@
    <string name="touchpad_recent_apps_gesture_success_title">Great job!</string>
    <!-- Text shown to the user after they complete recent apps gesture tutorial [CHAR LIMIT=NONE] -->
    <string name="touchpad_recent_apps_gesture_success_body">You completed the view recent apps gesture.</string>
    <!-- Text shown to the user after recent gesture was not done correctly [CHAR LIMIT=NONE] -->
    <string name="touchpad_recent_gesture_error_body">To view recent apps, swipe up and hold using three fingers on your touchpad</string>

    <!-- KEYBOARD TUTORIAL-->
    <!-- Action key tutorial title [CHAR LIMIT=NONE] -->
@@ -3969,6 +3977,9 @@
    <string name="tutorial_action_key_success_title">Well done!</string>
    <!-- Text shown to the user after they complete action key tutorial [CHAR LIMIT=NONE] -->
    <string name="tutorial_action_key_success_body">You completed the view all apps gesture</string>
    <!-- Text shown to the user after action key tutorial was not done correctly [CHAR LIMIT=NONE] -->
    <string name="touchpad_action_key_error_body">Press the action key on your keyboard to view all of your apps</string>

    <!-- Content description for the animation playing during the tutorial. The user can click the animation to pause and unpause playback. [CHAR LIMIT=NONE] -->
    <string name="tutorial_animation_content_description">Tutorial animation, click to pause and resume play.</string>

Loading