-
Notifications
You must be signed in to change notification settings - Fork 1
CountDownActivity Compose 전환 및 테스트 추가 #403
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
Open
unam98
wants to merge
4
commits into
develop
Choose a base branch
from
feature/countdown-compose-tdd-migration
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
app/src/androidTest/java/com/runnect/runnect/presentation/countdown/CountDownScreenTest.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package com.runnect.runnect.presentation.countdown | ||
|
|
||
| import androidx.compose.ui.test.assertContentDescriptionEquals | ||
| import androidx.compose.ui.test.assertIsDisplayed | ||
| import androidx.compose.ui.test.junit4.createComposeRule | ||
| import androidx.compose.ui.test.onNodeWithTag | ||
| import androidx.compose.ui.test.onNodeWithText | ||
| import com.runnect.runnect.presentation.ui.theme.RunnectTheme | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
|
|
||
| class CountDownScreenTest { | ||
|
|
||
| @get:Rule | ||
| val composeTestRule = createComposeRule() | ||
|
|
||
| @Test | ||
| fun 카운트다운_배경_숫자_안내문구가_노출된다() { | ||
| composeTestRule.setContent { | ||
| RunnectTheme { | ||
| CountDownContent(count = 3) | ||
| } | ||
| } | ||
|
|
||
| composeTestRule.onNodeWithTag(CountDownScreenTestTags.BACKGROUND).assertIsDisplayed() | ||
| composeTestRule.onNodeWithTag(CountDownScreenTestTags.NUMBER) | ||
| .assertIsDisplayed() | ||
| .assertContentDescriptionEquals("3") | ||
| composeTestRule.onNodeWithText("잠시 후 러닝을 시작합니다").assertIsDisplayed() | ||
| } | ||
|
|
||
| @Test | ||
| fun 카운트다운이_끝나면_완료_콜백이_호출된다() { | ||
| var finishedCount = 0 | ||
| composeTestRule.mainClock.autoAdvance = false | ||
|
|
||
| composeTestRule.setContent { | ||
| RunnectTheme { | ||
| CountDownRoute( | ||
| onFinished = { finishedCount += 1 } | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| composeTestRule.waitForIdle() | ||
| repeat(3) { | ||
| composeTestRule.mainClock.advanceTimeBy(CountDownStateMachine.TICK_MILLIS) | ||
| composeTestRule.waitForIdle() | ||
| } | ||
| composeTestRule.waitUntil(timeoutMillis = 5_000L) { | ||
| finishedCount == 1 | ||
| } | ||
|
|
||
| assertEquals(1, finishedCount) | ||
| } | ||
| } | ||
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
147 changes: 147 additions & 0 deletions
147
app/src/main/java/com/runnect/runnect/presentation/countdown/CountDownScreen.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| package com.runnect.runnect.presentation.countdown | ||
|
|
||
| import androidx.annotation.DrawableRes | ||
| import androidx.compose.animation.core.Animatable | ||
| import androidx.compose.animation.core.Easing | ||
| import androidx.compose.animation.core.tween | ||
| import androidx.compose.foundation.Image | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.foundation.layout.offset | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.LaunchedEffect | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableIntStateOf | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.draw.scale | ||
| import androidx.compose.ui.layout.ContentScale | ||
| import androidx.compose.ui.platform.testTag | ||
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.lifecycle.Lifecycle | ||
| import androidx.lifecycle.compose.LocalLifecycleOwner | ||
| import androidx.lifecycle.repeatOnLifecycle | ||
| import com.runnect.runnect.R | ||
| import com.runnect.runnect.presentation.ui.theme.RunnectTheme | ||
| import com.runnect.runnect.presentation.ui.theme.White | ||
| import kotlinx.coroutines.delay | ||
| import kotlin.math.PI | ||
| import kotlin.math.cos | ||
|
|
||
| object CountDownScreenTestTags { | ||
| const val BACKGROUND = "count_down_background" | ||
| const val NUMBER = "count_down_number" | ||
| const val DESCRIPTION = "count_down_description" | ||
| } | ||
|
|
||
| object CountDownStateMachine { | ||
| const val INITIAL_COUNT = 3 | ||
| private const val LAST_VISIBLE_COUNT = 1 | ||
| const val TICK_MILLIS = 1_000L | ||
|
|
||
| fun nextCount(currentCount: Int): Int? = | ||
| if (currentCount > LAST_VISIBLE_COUNT) currentCount - 1 else null | ||
|
|
||
| @DrawableRes | ||
| fun numberDrawableRes(count: Int): Int = when (count) { | ||
| 3 -> R.drawable.anim_num3 | ||
| 2 -> R.drawable.anim_num2 | ||
| 1 -> R.drawable.anim_num1 | ||
| else -> error("Unsupported countdown number: $count") | ||
| } | ||
| } | ||
|
|
||
| object CountDownAnimationSpec { | ||
| const val INITIAL_SCALE = 0.4f | ||
| const val TARGET_SCALE = 1f | ||
|
|
||
| val AccelerateDecelerateEasing = Easing { fraction -> | ||
| (cos((fraction + 1f) * PI).toFloat() / 2f) + 0.5f | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| fun CountDownRoute( | ||
| onFinished: () -> Unit, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| var currentCount by remember { mutableIntStateOf(CountDownStateMachine.INITIAL_COUNT) } | ||
| var isFinished by remember { mutableStateOf(false) } | ||
| val lifecycle = LocalLifecycleOwner.current.lifecycle | ||
|
|
||
| LaunchedEffect(lifecycle) { | ||
| lifecycle.repeatOnLifecycle(Lifecycle.State.RESUMED) { | ||
| while (!isFinished) { | ||
| delay(CountDownStateMachine.TICK_MILLIS) | ||
| val nextCount = CountDownStateMachine.nextCount(currentCount) | ||
| if (nextCount == null) { | ||
| isFinished = true | ||
| onFinished() | ||
| } else { | ||
| currentCount = nextCount | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| CountDownContent( | ||
| count = currentCount, | ||
| modifier = modifier | ||
| ) | ||
| } | ||
|
|
||
| @Composable | ||
| fun CountDownContent( | ||
| count: Int, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| val scale = remember { Animatable(CountDownAnimationSpec.INITIAL_SCALE) } | ||
|
|
||
| LaunchedEffect(count) { | ||
| scale.snapTo(CountDownAnimationSpec.INITIAL_SCALE) | ||
| scale.animateTo( | ||
| targetValue = CountDownAnimationSpec.TARGET_SCALE, | ||
| animationSpec = tween( | ||
| durationMillis = CountDownStateMachine.TICK_MILLIS.toInt(), | ||
| easing = CountDownAnimationSpec.AccelerateDecelerateEasing | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| Box( | ||
| modifier = modifier.fillMaxSize() | ||
| ) { | ||
| Image( | ||
| painter = painterResource(R.drawable.star_background), | ||
| contentDescription = null, | ||
| contentScale = ContentScale.Crop, | ||
| modifier = Modifier | ||
| .fillMaxSize() | ||
| .testTag(CountDownScreenTestTags.BACKGROUND) | ||
| ) | ||
| Image( | ||
| painter = painterResource(CountDownStateMachine.numberDrawableRes(count)), | ||
| contentDescription = count.toString(), | ||
| modifier = Modifier | ||
| .align(Alignment.BottomCenter) | ||
| .offset(y = (-350).dp) | ||
| .scale(scale.value) | ||
| .testTag(CountDownScreenTestTags.NUMBER) | ||
| ) | ||
| Text( | ||
| text = stringResource(R.string.count_down_desc), | ||
| style = RunnectTheme.textStyle.medium15, | ||
| color = White, | ||
| modifier = Modifier | ||
| .align(Alignment.BottomCenter) | ||
| .offset(y = (-280).dp) | ||
| .testTag(CountDownScreenTestTags.DESCRIPTION) | ||
| ) | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Avoid hard-coding localized UI copy in the assertion.
This makes the test locale-dependent even though
CountDownContentalready exposes aDESCRIPTIONtag and reads fromR.string.count_down_desc. Assert via the tag plus the string resource instead.Suggested change
📝 Committable suggestion
🤖 Prompt for AI Agents