-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Overlay and Navigation tests for the Interaction design
- Loading branch information
1 parent
86914b7
commit d1f29f2
Showing
18 changed files
with
147 additions
and
77 deletions.
There are no files selected for viewing
147 changes: 147 additions & 0 deletions
147
...ion/src/testDebug/kotlin/com/android/designcompose/testapp/validation/InteractionTests.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,147 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* 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.designcompose.testapp.validation | ||
|
||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.test.ExperimentalTestApi | ||
import androidx.compose.ui.test.hasText | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.onRoot | ||
import androidx.compose.ui.test.performClick | ||
import androidx.compose.ui.test.performTouchInput | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.android.designcompose.TestUtils | ||
import com.android.designcompose.test.internal.captureRootRoboImage | ||
import com.android.designcompose.test.internal.designComposeRoborazziRule | ||
import com.android.designcompose.testapp.common.InterFontTestRule | ||
import com.android.designcompose.testapp.validation.examples.InteractionTest | ||
import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.annotation.Config | ||
import org.robolectric.annotation.GraphicsMode | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@GraphicsMode(GraphicsMode.Mode.NATIVE) | ||
@Config(qualifiers = RobolectricDeviceQualifiers.SmallPhone) | ||
class InteractionTests { | ||
@get:Rule val clearStateTestRule = TestUtils.ClearStateTestRule() | ||
@get:Rule val composeTestRule = createComposeRule() | ||
@get:Rule val roborazziRule = designComposeRoborazziRule(javaClass.simpleName) | ||
@get:Rule val interFontRule = InterFontTestRule() | ||
|
||
@Before | ||
fun setup() { | ||
with(composeTestRule) { setContent { InteractionTest() } } | ||
} | ||
|
||
@OptIn(ExperimentalTestApi::class) | ||
@Test | ||
fun whilePressedTimeoutTimesOut() { | ||
with(composeTestRule) { | ||
onNodeWithText("Triggers").performClick() | ||
onNodeWithText("While Pressed").performClick() | ||
onNodeWithText("Timeouts").performClick() | ||
captureRootRoboImage("whilePressed-start") | ||
|
||
onNodeWithText("idle").performTouchInput { down(Offset.Zero) } | ||
onNodeWithText("pressed").assertExists() | ||
captureRootRoboImage("whilePressed-pressed") | ||
|
||
waitUntilDoesNotExist(hasText("pressed"), 1000) | ||
onNodeWithText("timeout").assertExists() | ||
captureRootRoboImage("whilePressed-timedOut") | ||
|
||
onRoot().performTouchInput { cancel() } | ||
onNodeWithText("idle").assertExists() | ||
captureRootRoboImage("whilePressed-final") | ||
} | ||
} | ||
|
||
@Test | ||
fun overlayPositionsTests() { | ||
with(composeTestRule) { | ||
onNodeWithText("Overlay Tests").performClick() | ||
onNodeWithText("Overlay Positions").performClick() | ||
captureRootRoboImage("overlay-positions-start") | ||
|
||
// Test Top Left | ||
onNodeWithText("Top Left").assertDoesNotExist() | ||
onNodeWithText("TL").performClick() | ||
onNodeWithText("Top Left").assertExists() | ||
captureRootRoboImage("overlay-positions-tl") | ||
|
||
// Close the overlay. Need to use the unmerged tree to click the node | ||
onNodeWithText("Click To Close", useUnmergedTree = true).performClick() | ||
onNodeWithText("Top Left").assertDoesNotExist() | ||
captureRootRoboImage("overlay-positions-tl-final") | ||
|
||
// Test Top Right | ||
onNodeWithText("Top Right").assertDoesNotExist() | ||
onNodeWithText("TR").performClick() | ||
onNodeWithText("Top Right").assertExists() | ||
captureRootRoboImage("overlay-positions-tr") | ||
onNodeWithText("Click To Close", useUnmergedTree = true).performClick() | ||
onNodeWithText("Top Right").assertDoesNotExist() | ||
captureRootRoboImage("overlay-positions-tr-final") | ||
|
||
// Test Manual | ||
onNodeWithText("Manual").assertDoesNotExist() | ||
onNodeWithText("M").performClick() | ||
onNodeWithText("Manual").assertExists() | ||
captureRootRoboImage("overlay-positions-manual") | ||
onNodeWithText("Click To Close", useUnmergedTree = true).performClick() | ||
onNodeWithText("Manual").assertDoesNotExist() | ||
captureRootRoboImage("overlay-positions-manual-final") | ||
} | ||
} | ||
|
||
@Test | ||
fun navigationTests() { | ||
with(composeTestRule) { | ||
onNodeWithText("Navigation Tests").performClick() | ||
captureRootRoboImage("navigation-start") | ||
|
||
// Initial state | ||
onNodeWithText("Navigation #1").assertExists() | ||
|
||
onNodeWithText("Nav 2").performClick() | ||
onNodeWithText("Navigation #2").assertExists() | ||
onNodeWithText("Navigation #1").assertDoesNotExist() | ||
captureRootRoboImage("navigation-nav2") | ||
|
||
onNodeWithText("Nav 1").performClick() | ||
onNodeWithText("Navigation #1").assertExists() | ||
onNodeWithText("Navigation #2").assertDoesNotExist() | ||
captureRootRoboImage("navigation-nav1") | ||
|
||
// Test the back button | ||
onNodeWithText("<--").performClick() | ||
onNodeWithText("Navigation #2").assertExists() | ||
onNodeWithText("Navigation #1").assertDoesNotExist() | ||
captureRootRoboImage("navigation-back1") | ||
|
||
onNodeWithText("<--").performClick() | ||
onNodeWithText("Navigation #1").assertExists() | ||
onNodeWithText("Navigation #2").assertDoesNotExist() | ||
captureRootRoboImage("navigation-back2") | ||
} | ||
} | ||
} |
77 changes: 0 additions & 77 deletions
77
.../src/testDebug/kotlin/com/android/designcompose/testapp/validation/InteractionTriggers.kt
This file was deleted.
Oops, something went wrong.
Binary file added
BIN
+13.6 KB
...-tests/validation/src/testDebug/roborazzi/InteractionTests/navigation-back1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.8 KB
...-tests/validation/src/testDebug/roborazzi/InteractionTests/navigation-back2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.8 KB
...n-tests/validation/src/testDebug/roborazzi/InteractionTests/navigation-nav1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+13.6 KB
...n-tests/validation/src/testDebug/roborazzi/InteractionTests/navigation-nav2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.8 KB
...-tests/validation/src/testDebug/roborazzi/InteractionTests/navigation-start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.39 KB
...ion/src/testDebug/roborazzi/InteractionTests/overlay-positions-manual-final.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.2 KB
...alidation/src/testDebug/roborazzi/InteractionTests/overlay-positions-manual.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.39 KB
...validation/src/testDebug/roborazzi/InteractionTests/overlay-positions-start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.39 KB
...idation/src/testDebug/roborazzi/InteractionTests/overlay-positions-tl-final.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.9 KB
...ts/validation/src/testDebug/roborazzi/InteractionTests/overlay-positions-tl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.39 KB
...idation/src/testDebug/roborazzi/InteractionTests/overlay-positions-tr-final.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+20 KB
...ts/validation/src/testDebug/roborazzi/InteractionTests/overlay-positions-tr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file renamed
BIN
+7.29 KB
...nteractionTriggers/whilePressed-final.png → ...i/InteractionTests/whilePressed-final.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file renamed
BIN
+8.11 KB
...eractionTriggers/whilePressed-pressed.png → ...InteractionTests/whilePressed-pressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file renamed
BIN
+7.29 KB
...nteractionTriggers/whilePressed-start.png → ...i/InteractionTests/whilePressed-start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file renamed
BIN
+8.67 KB
...ractionTriggers/whilePressed-timedOut.png → ...nteractionTests/whilePressed-timedOut.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.