Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup a11y tests #2182

Merged
merged 6 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,93 +14,55 @@
* limitations under the License.
*/

@file:Suppress("DEPRECATION")
@file:OptIn(ExperimentalWearFoundationApi::class)

package com.google.android.horologist.composables

import android.app.Application
import android.view.accessibility.AccessibilityManager
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.performClick
import androidx.test.core.app.ApplicationProvider
import androidx.test.filters.FlakyTest
import androidx.wear.compose.foundation.ExperimentalWearFoundationApi
import com.google.android.horologist.screenshots.ScreenshotBaseTest
import com.google.android.horologist.screenshots.ScreenshotTestRule.Companion.screenshotTestRuleParams
import org.junit.Ignore
import com.google.android.horologist.screenshots.rng.WearLegacyA11yTest
import org.junit.Test
import org.robolectric.Shadows
import java.time.LocalDate

@FlakyTest(detail = "https://github.com/google/horologist/issues/1806")
class DatePickerA11yTest : ScreenshotBaseTest(
screenshotTestRuleParams {
screenTimeText = {}
enableA11y = true
},
) {
class DatePickerA11yTest : WearLegacyA11yTest() {
@Test
fun screenshot() {
enableTouchExploration()

screenshotTestRule.setContent {
runScreenTest {
DatePicker(
onDateConfirm = {},
date = LocalDate.of(2022, 4, 25),
)
}

screenshotTestRule.takeScreenshot()
}

@Test
@Ignore("https://github.com/google/horologist/issues/1806")
fun interactionTest() {
enableTouchExploration()

screenshotTestRule.setContent {
runScreenTest {
DatePicker(
onDateConfirm = {},
date = LocalDate.of(2022, 4, 25),
)
}

screenshotTestRule.interact {
onNodeWithContentDescription("Next")
.assertHasClickAction()

waitForIdle()
// onNodeWithContentDescription("Day, 25")
// .assertIsFocused()
}

screenshotTestRule.takeScreenshot()
composeRule.onNodeWithContentDescription("Next")
.assertHasClickAction()
.performClick()

screenshotTestRule.interact {
onNodeWithContentDescription("Next")
.performClick()
captureScreenshot("_2")

waitForIdle()
// waitUntil {
// onNodeWithContentDescription("April")
// .fetchSemanticsNode()
// .config[SemanticsProperties.Focused]
// }
}
composeRule.onNodeWithContentDescription("Next")
.assertHasClickAction()
.performClick()

screenshotTestRule.takeScreenshot()
}
captureScreenshot("_3")

companion object {
fun enableTouchExploration() {
val applicationContext = ApplicationProvider.getApplicationContext<Application>()
val a11yManager = applicationContext.getSystemService(AccessibilityManager::class.java)
val shadow = Shadows.shadowOf(a11yManager)
composeRule.onNodeWithContentDescription("Next")
.assertHasClickAction()
.performClick()

shadow.setEnabled(true)
shadow.setTouchExplorationEnabled(true)
}
captureScreenshot("_3")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,28 @@
* limitations under the License.
*/

@file:Suppress("DEPRECATION")

package com.google.android.horologist.composables

import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.onNodeWithContentDescription
import com.google.android.horologist.screenshots.ScreenshotBaseTest
import com.google.android.horologist.screenshots.ScreenshotTestRule
import com.google.android.horologist.screenshots.rng.WearLegacyA11yTest
import org.junit.Test
import java.time.LocalTime

class TimePicker12hA11yTest : ScreenshotBaseTest(
ScreenshotTestRule.screenshotTestRuleParams {
screenTimeText = {}
enableA11y = true
},
) {
class TimePicker12hA11yTest : WearLegacyA11yTest() {

@Test
fun initial() {
DatePickerA11yTest.enableTouchExploration()
enableTouchExploration()

screenshotTestRule.setContent(takeScreenshot = true) {
runScreenTest {
TimePickerWith12HourClock(
time = LocalTime.of(10, 10, 0),
onTimeConfirm = {},
)
}

screenshotTestRule.interact {
onNodeWithContentDescription("Confirm")
.assertHasClickAction()
}
composeRule.onNodeWithContentDescription("Confirm")
.assertHasClickAction()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,28 @@
* limitations under the License.
*/

@file:Suppress("DEPRECATION")

package com.google.android.horologist.composables

import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.onNodeWithContentDescription
import com.google.android.horologist.screenshots.ScreenshotBaseTest
import com.google.android.horologist.screenshots.ScreenshotTestRule.Companion.screenshotTestRuleParams
import com.google.android.horologist.screenshots.rng.WearLegacyA11yTest
import org.junit.Test
import java.time.LocalTime

class TimePickerA11yTest : ScreenshotBaseTest(
screenshotTestRuleParams {
screenTimeText = {}
enableA11y = true
},
) {
class TimePickerA11yTest : WearLegacyA11yTest() {

@Test
fun initial() {
DatePickerA11yTest.enableTouchExploration()
enableTouchExploration()

screenshotTestRule.setContent {
runScreenTest {
TimePicker(
time = LocalTime.of(10, 10, 0),
onTimeConfirm = {},
)
}

screenshotTestRule.interact {
onNodeWithContentDescription("Confirm")
.assertHasClickAction()
}

screenshotTestRule.takeScreenshot()
composeRule.onNodeWithContentDescription("Confirm")
.assertHasClickAction()
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To test manually.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -14,92 +14,68 @@
* limitations under the License.
*/

@file:Suppress("DEPRECATION")

package com.google.android.horologist.compose.material

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.SemanticsActions
import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.test.SemanticsMatcher.Companion.keyIsDefined
import androidx.compose.ui.test.SemanticsMatcher.Companion.keyNotDefined
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertContentDescriptionEquals
import androidx.compose.ui.test.assertHasClickAction
import com.google.android.horologist.screenshots.ScreenshotBaseTest
import com.google.android.horologist.screenshots.ScreenshotTestRule.Companion.screenshotTestRuleParams
import com.google.android.horologist.screenshots.rng.WearLegacyA11yTest
import org.junit.Test

class ButtonA11yTest : ScreenshotBaseTest(
screenshotTestRuleParams {
enableA11y = true
screenTimeText = {}
},
) {
class ButtonA11yTest : WearLegacyA11yTest() {

@Test
fun default() {
screenshotTestRule.setContent(takeScreenshot = true) {
Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()) {
Button(
imageVector = Icons.Default.Check,
contentDescription = "contentDescription",
onClick = { },
onLongClick = {},
)
}
runComponentTest {
Button(
imageVector = Icons.Default.Check,
contentDescription = "contentDescription",
onClick = { },
onLongClick = {},
)
}

screenshotTestRule.interact {
onNode(keyIsDefined(SemanticsProperties.Role))
.assertHasClickAction()
.assert(keyIsDefined(SemanticsActions.OnLongClick))
.assertContentDescriptionEquals("contentDescription")
}
composeRule.onNode(keyIsDefined(SemanticsProperties.Role))
.assertHasClickAction()
.assert(keyIsDefined(SemanticsActions.OnLongClick))
.assertContentDescriptionEquals("contentDescription")
}

@Test
fun material() {
screenshotTestRule.setContent(takeScreenshot = true) {
Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()) {
Button(
imageVector = Icons.Default.Check,
contentDescription = "contentDescription",
onClick = { },
)
}
runComponentTest {
Button(
imageVector = Icons.Default.Check,
contentDescription = "contentDescription",
onClick = { },
)
}

screenshotTestRule.interact {
onNode(keyIsDefined(SemanticsProperties.Role))
.assertHasClickAction()
.assert(keyNotDefined(SemanticsActions.OnLongClick))
.assertContentDescriptionEquals("contentDescription")
}
composeRule.onNode(keyIsDefined(SemanticsProperties.Role))
.assertHasClickAction()
.assert(keyNotDefined(SemanticsActions.OnLongClick))
.assertContentDescriptionEquals("contentDescription")
}

@Test
fun disabled() {
screenshotTestRule.setContent(takeScreenshot = true) {
Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()) {
Button(
imageVector = Icons.Default.Check,
contentDescription = "contentDescription",
onClick = { },
enabled = false,
)
}
runComponentTest {
Button(
imageVector = Icons.Default.Check,
contentDescription = "contentDescription",
onClick = { },
enabled = false,
)
}

screenshotTestRule.interact {
onNode(keyIsDefined(SemanticsProperties.Role))
.assertHasClickAction()
.assertContentDescriptionEquals("contentDescription")
}
composeRule.onNode(keyIsDefined(SemanticsProperties.Role))
.assertHasClickAction()
.assertContentDescriptionEquals("contentDescription")
}
}
Loading
Loading