Created
August 30, 2022 16:34
-
-
Save yschimke/777b5f089ce0fff689dcceae362973de to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
* Copyright 2022 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 | |
* | |
* https://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.google.android.horologist.audio.ui | |
import android.content.res.Configuration | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.CompositionLocalProvider | |
import androidx.compose.runtime.getValue | |
import androidx.compose.runtime.mutableStateOf | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.platform.LocalConfiguration | |
import androidx.compose.ui.platform.testTag | |
import androidx.compose.ui.test.assertContentDescriptionEquals | |
import androidx.compose.ui.test.assertHasClickAction | |
import androidx.compose.ui.test.assertIsDisplayed | |
import androidx.compose.ui.test.assertTextContains | |
import androidx.compose.ui.test.assertTextEquals | |
import androidx.compose.ui.test.junit4.createComposeRule | |
import androidx.compose.ui.test.onChild | |
import androidx.compose.ui.test.onNodeWithContentDescription | |
import androidx.compose.ui.test.onNodeWithTag | |
import androidx.compose.ui.test.onNodeWithText | |
import androidx.test.filters.MediumTest | |
import androidx.wear.compose.material.Scaffold | |
import androidx.wear.compose.material.TimeSource | |
import androidx.wear.compose.material.TimeText | |
import com.google.android.horologist.audio.AudioOutput | |
import com.google.android.horologist.audio.VolumeState | |
import com.google.android.horologist.test.toolbox.matchers.assertHasClickLabel | |
import com.google.android.horologist.test.toolbox.matchers.assertHasStateDescription | |
import org.junit.Rule | |
import org.junit.Test | |
@MediumTest | |
class VolumeScreenA11yTest { | |
@get:Rule | |
val composeTestRule = createComposeRule() | |
@Test | |
fun testSquareTimeText() { | |
composeTestRule.setContent { | |
TimeText(round = false) | |
} | |
composeTestRule.onNodeWithTag("timeText") | |
.assertIsDisplayed() | |
.onChild() | |
.assertTextEquals("10:10") | |
} | |
@Test | |
fun testRoundTimeText() { | |
composeTestRule.setContent { | |
TimeText(round = true) | |
} | |
// composeTestRule.onNodeWithText("10:10").assertExists() | |
composeTestRule.onNodeWithContentDescription("10:10").assertExists() | |
} | |
@Composable | |
private fun TimeText(round: Boolean) { | |
val configuration = | |
LocalConfiguration.current.let { | |
Configuration(it).apply { | |
screenLayout = | |
if (round) { | |
(screenLayout or Configuration.SCREENLAYOUT_ROUND_YES) | |
} else { | |
(screenLayout and Configuration.SCREENLAYOUT_ROUND_YES.inv()) | |
} | |
} | |
} | |
CompositionLocalProvider(LocalConfiguration provides configuration) { | |
Scaffold(timeText = { | |
TimeText( | |
modifier = Modifier.testTag("timeText"), | |
timeSource = object : TimeSource { | |
override val currentTime: String | |
@Composable get() = "10:10" | |
} | |
) | |
}) { | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment