Skip to content

Commit

Permalink
screenshot race conditions controlled
Browse files Browse the repository at this point in the history
  • Loading branch information
Javier Manrique committed Nov 2, 2024
1 parent 40e4f1a commit 0edfef0
Show file tree
Hide file tree
Showing 39 changed files with 60 additions and 13 deletions.
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.
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.
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.
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.
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.
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.
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 @@ -4,7 +4,6 @@ import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.semantics.getOrNull
import androidx.compose.ui.test.SemanticsNodeInteraction
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.onChild
import androidx.compose.ui.test.onChildAt
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
Expand All @@ -16,12 +15,16 @@ import androidx.compose.ui.test.swipeLeft
import androidx.compose.ui.test.swipeUp
import com.jmp.commons.utils.test.TestUtils.waitUntil
import com.jmp.examsfeature.presentation.list.screens.ExamsScreenTestTags.CLOSE_FILTER_TEXTBOX_BUTTON
import com.jmp.examsfeature.presentation.list.screens.ExamsScreenTestTags.EMPTY_EXAMS_LOTTIE_COMPOSITION_LOADED_SEMANTICS
import com.jmp.examsfeature.presentation.list.screens.ExamsScreenTestTags.EMPTY_EXAMS_SCREEN_LOTTIE
import com.jmp.examsfeature.presentation.list.screens.ExamsScreenTestTags.EXAMS_LIST
import com.jmp.examsfeature.presentation.list.screens.ExamsScreenTestTags.EXAMS_SCREEN
import com.jmp.examsfeature.presentation.list.screens.ExamsScreenTestTags.EXAM_ROW_IMAGE
import com.jmp.examsfeature.presentation.list.screens.ExamsScreenTestTags.EXAM_ROW_IMAGE_LOADED_SEMANTICS
import com.jmp.examsfeature.presentation.list.screens.ExamsScreenTestTags.FILTER_TEXT_BOX
import com.jmp.examsfeature.presentation.list.screens.ExamsScreenTestTags.QUOTES_CAROUSEL
import com.jmp.examsfeature.presentation.list.screens.ExamsScreenTestTags.QUOTES_CAROUSEL_ERROR_PLACEHOLDER
import com.jmp.onboardingfeature.OnboardingCarouselScreenTestTags.ONBOARDING_LOTTIE_COMPOSITION_LOADED_SEMANTICS
import com.jmp.xtudent.core.TestUtils.waitForNode
import com.jmp.xtudent.features.exams.creation.screen.ExamCreationScreen
import com.jmp.xtudent.features.exams.detail.screen.ExamDetailScreen
Expand All @@ -36,6 +39,7 @@ class ExamsScreen(
init {
composeTestRule.apply {
waitForNode(EXAMS_SCREEN)
waitForIdle()
}
}

Expand Down Expand Up @@ -135,9 +139,18 @@ class ExamsScreen(
composeTestRule
.onNodeWithTag(EMPTY_EXAMS_SCREEN_LOTTIE)
.fetchSemanticsNode()
.config
.getOrNull(SemanticsProperties.ProgressBarRangeInfo)
?.current != 0f
.config.getOrNull(SemanticsProperties.ContentDescription)
?.contains(EMPTY_EXAMS_LOTTIE_COMPOSITION_LOADED_SEMANTICS) == true
}
}

fun waitUntilExamImageIsLoaded() {
waitUntil {
composeTestRule
.onNodeWithTag(EXAM_ROW_IMAGE)
.fetchSemanticsNode()
.config.getOrNull(SemanticsProperties.ContentDescription)
?.contains(EXAM_ROW_IMAGE_LOADED_SEMANTICS) == true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ open class ExamsScreenTest : UiTest() {
mockExamsScenario.givenThatThereIsOneExam()

onExamsScreen()
.waitUntilExamImageIsLoaded()

compareScreenshot(composeRule)
}
Expand All @@ -51,6 +52,7 @@ open class ExamsScreenTest : UiTest() {
mockExamsScenario.givenThatThereAreSeveralExams()

onExamsScreen()
.waitUntilExamImageIsLoaded()

compareScreenshot(composeRule)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import com.jmp.commons.utils.test.TestUtils.waitUntil
import com.jmp.examsfeature.presentation.list.screens.ExamsScreenTestTags.EMPTY_EXAMS_SCREEN_LOTTIE
import com.jmp.onboardingfeature.OnboardingCarouselScreenTestTags.FIRST_ONBOARDING_LOTTIE
import com.jmp.onboardingfeature.OnboardingCarouselScreenTestTags.ONBOARDING_LOTTIE_COMPOSITION_LOADED_SEMANTICS
import com.jmp.onboardingfeature.OnboardingCarouselScreenTestTags.NEXT_BUTTON
import com.jmp.onboardingfeature.OnboardingCarouselScreenTestTags.ONBOARDING_SCREEN_NAME
import com.jmp.onboardingfeature.OnboardingCarouselScreenTestTags.SECOND_ONBOARDING_LOTTIE
Expand Down Expand Up @@ -60,9 +60,8 @@ open class OnboardingCarouselScreen(
composeTestRule
.onNodeWithTag(testTag)
.fetchSemanticsNode()
.config
.getOrNull(SemanticsProperties.ProgressBarRangeInfo)
?.current != 0f
.config.getOrNull(SemanticsProperties.ContentDescription)
?.contains(ONBOARDING_LOTTIE_COMPOSITION_LOADED_SEMANTICS) == true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,23 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.AsyncImage
import com.jmp.examsfeature.presentation.R
import com.jmp.examsfeature.presentation.list.screens.ExamsScreenTestTags.EXAM_ROW_IMAGE
import com.jmp.examsfeature.presentation.list.screens.ExamsScreenTestTags.EXAM_ROW_IMAGE_LOADED_SEMANTICS

@Composable
fun ExamRowItemHeader(
Expand All @@ -31,13 +38,22 @@ fun ExamRowItemHeader(
questionCount: Int,
imageRes: Int
) {
val imageLoaded = remember { mutableStateOf(false) }
Row(modifier = modifier) {
Card(shape = CircleShape) {
AsyncImage(
modifier = Modifier.size(40.dp),
modifier = Modifier
.size(40.dp)
.testTag(EXAM_ROW_IMAGE)
.semantics {
if (imageLoaded.value) {
contentDescription = EXAM_ROW_IMAGE_LOADED_SEMANTICS
}
},
contentScale = ContentScale.Crop,
model = imageRes,
contentDescription = null
contentDescription = null,
onSuccess = { imageLoaded.value = true }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
Expand All @@ -23,6 +25,7 @@ import com.airbnb.lottie.compose.LottieCompositionSpec
import com.airbnb.lottie.compose.LottieConstants
import com.airbnb.lottie.compose.rememberLottieComposition
import com.jmp.examsfeature.presentation.R
import com.jmp.examsfeature.presentation.list.screens.ExamsScreenTestTags.EMPTY_EXAMS_LOTTIE_COMPOSITION_LOADED_SEMANTICS
import com.jmp.examsfeature.presentation.list.screens.ExamsScreenTestTags.EMPTY_EXAMS_SCREEN_LOTTIE

@Composable
Expand All @@ -38,7 +41,10 @@ fun EmptyExamsScreen(modifier: Modifier = Modifier) {
modifier = Modifier
.size(280.dp)
.align(Alignment.CenterHorizontally)
.testTag(EMPTY_EXAMS_SCREEN_LOTTIE),
.testTag(EMPTY_EXAMS_SCREEN_LOTTIE)
.semantics {
contentDescription = EMPTY_EXAMS_LOTTIE_COMPOSITION_LOADED_SEMANTICS
},
composition = composition,
iterations = LottieConstants.IterateForever,
contentScale = ContentScale.Fit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ object ExamsScreenTestTags {
const val ERROR_MAIN_SCREEN = "error_main_screen"
const val EXAMS_LIST = "exams_list"
const val EMPTY_EXAMS_SCREEN_LOTTIE = "empty_exams_screen_lottie"
const val EMPTY_EXAMS_LOTTIE_COMPOSITION_LOADED_SEMANTICS = "empty_exams_screen_lottie_loaded"
const val EXAM_ROW_IMAGE = "exam_row_image"
const val EXAM_ROW_IMAGE_LOADED_SEMANTICS = "exam_row_image_loaded"
const val QUOTES_CAROUSEL = "quotes_carousel"
const val QUOTES_CAROUSEL_ERROR_PLACEHOLDER = "quotes_carousel_error_placeholder"
const val FILTER_TEXT_BOX = "filter_text_box"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ object OnboardingCarouselScreenTestTags {
const val FIRST_ONBOARDING_LOTTIE = "first_onboarding_lottie"
const val SECOND_ONBOARDING_LOTTIE = "second_onboarding_lottie"
const val THIRD_ONBOARDING_LOTTIE = "third_onboarding_lottie"
const val ONBOARDING_LOTTIE_COMPOSITION_LOADED_SEMANTICS = "onboarding_lottie_composition_loaded_semantics"
const val NEXT_BUTTON = "next_button"
const val SKIP_BUTTON = "skip_button"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.Dp
import com.airbnb.lottie.compose.LottieAnimation
import com.airbnb.lottie.compose.LottieCompositionSpec
import com.airbnb.lottie.compose.LottieConstants
import com.airbnb.lottie.compose.rememberLottieComposition
import com.jmp.onboardingfeature.OnboardingCarouselScreenTestTags.ONBOARDING_LOTTIE_COMPOSITION_LOADED_SEMANTICS

@Composable
fun OnboardingScreenImage(
Expand All @@ -28,8 +31,12 @@ fun OnboardingScreenImage(
LottieAnimation(
modifier = Modifier
.size(size)
.testTag(lottieTestTag
),
.testTag(lottieTestTag)
.semantics {
composition?.let {
contentDescription = ONBOARDING_LOTTIE_COMPOSITION_LOADED_SEMANTICS
}
},
composition = composition,
iterations = LottieConstants.IterateForever,
contentScale = contentScale,
Expand Down

0 comments on commit 0edfef0

Please sign in to comment.