Skip to content
Prev Previous commit
Next Next commit
Test cleanup
Change-Id: I9c77838e006c8d6e45b62117daa7332d34754a4a
  • Loading branch information
JoseAlcerreca committed Nov 6, 2020
commit 73657aa249ea391d1a0c7de8ba542c0c17df3f36
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ import androidx.activity.ComponentActivity
import androidx.compose.runtime.Providers
import androidx.test.platform.app.InstrumentationRegistry
import androidx.ui.test.createAndroidComposeRule
import androidx.ui.test.hasLabel
import androidx.ui.test.hasSubstring
import androidx.ui.test.onNodeWithLabel
import androidx.ui.test.onNodeWithSubstring
import androidx.ui.test.onRoot
import androidx.ui.test.performClick
import androidx.ui.test.printToLog
import com.example.owl.R
import com.example.owl.model.courses
import com.example.owl.ui.fakes.ProvideTestImageLoader
Expand Down Expand Up @@ -83,8 +87,11 @@ class NavigationTest {
// Given the app in the courses screen
startActivity(MainDestinations.Courses.route)

composeTestRule.onRoot().printToLog("jalc")
// Navigate to the first course
composeTestRule.onNodeWithSubstring(courses.first().name).performClick()
composeTestRule.onNode(
hasLabel(getFeaturedCourseLabel()).and(hasSubstring(courses.first().name))
).performClick()

// Assert navigated to the course details
composeTestRule.onNodeWithSubstring(getCourseDesc().take(15)).assertExists()
Expand All @@ -105,6 +112,12 @@ class NavigationTest {
return InstrumentationRegistry.getInstrumentation().targetContext.resources
.getString(R.string.continue_to_courses)
}

private fun getFeaturedCourseLabel(): String {
return InstrumentationRegistry.getInstrumentation().targetContext.resources
.getString(R.string.featured)
}

private fun getCourseDesc(): String {
return InstrumentationRegistry.getInstrumentation().targetContext.resources
.getString(R.string.course_desc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ import androidx.compose.material.icons.rounded.OndemandVideo
import androidx.compose.runtime.Composable
import androidx.compose.ui.Layout
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.accessibilityLabel
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.ui.tooling.preview.Preview
import com.example.owl.R
import com.example.owl.model.Course
import com.example.owl.model.courses
import com.example.owl.ui.common.OutlinedAvatar
Expand Down Expand Up @@ -78,11 +82,15 @@ fun FeaturedCourse(
elevation = OwlTheme.elevations.card,
shape = MaterialTheme.shapes.medium
) {
val featuredString = stringResource(id = R.string.featured)
ConstraintLayout(
modifier = Modifier
.clickable(
onClick = { selectCourse(course.id) }
)
.semantics {
accessibilityLabel = featuredString
}
) {
val (image, avatar, subject, name, steps, icon) = createRefs()
NetworkImage(
Expand Down