-
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
5
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 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
131 changes: 131 additions & 0 deletions
131
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,131 @@ | ||
| package com.runnect.runnect.presentation.countdown | ||
|
|
||
| import androidx.annotation.DrawableRes | ||
| import androidx.compose.animation.core.FastOutSlowInEasing | ||
| import androidx.compose.animation.core.RepeatMode | ||
| import androidx.compose.animation.core.animateFloat | ||
| import androidx.compose.animation.core.infiniteRepeatable | ||
| import androidx.compose.animation.core.rememberInfiniteTransition | ||
| 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.foundation.layout.size | ||
| 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.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 com.runnect.runnect.R | ||
| import com.runnect.runnect.presentation.ui.theme.RunnectTheme | ||
| import com.runnect.runnect.presentation.ui.theme.White | ||
| import kotlinx.coroutines.delay | ||
|
|
||
| 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") | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| fun CountDownRoute( | ||
| onFinished: () -> Unit, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| var currentCount by remember { mutableIntStateOf(CountDownStateMachine.INITIAL_COUNT) } | ||
|
|
||
| LaunchedEffect(currentCount) { | ||
| delay(CountDownStateMachine.TICK_MILLIS) | ||
| val nextCount = CountDownStateMachine.nextCount(currentCount) | ||
| if (nextCount == null) { | ||
| onFinished() | ||
| } else { | ||
| currentCount = nextCount | ||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| CountDownContent( | ||
| count = currentCount, | ||
| modifier = modifier | ||
| ) | ||
| } | ||
|
|
||
| @Composable | ||
| fun CountDownContent( | ||
| count: Int, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| val scale by rememberInfiniteTransition(label = "countDownScale") | ||
| .animateFloat( | ||
| initialValue = 0.4f, | ||
| targetValue = 1f, | ||
| animationSpec = infiniteRepeatable( | ||
| animation = tween( | ||
| durationMillis = CountDownStateMachine.TICK_MILLIS.toInt(), | ||
| easing = FastOutSlowInEasing | ||
| ), | ||
| repeatMode = RepeatMode.Restart | ||
| ), | ||
| label = "countDownNumberScale" | ||
| ) | ||
|
|
||
| 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) | ||
| .size(width = 88.dp, height = 117.dp) | ||
| .scale(scale) | ||
| .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.
28 changes: 28 additions & 0 deletions
28
app/src/test/java/com/runnect/runnect/presentation/countdown/CountDownStateMachineTest.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,28 @@ | ||
| package com.runnect.runnect.presentation.countdown | ||
|
|
||
| import com.runnect.runnect.R | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertNull | ||
| import org.junit.Test | ||
|
|
||
| class CountDownStateMachineTest { | ||
|
|
||
| @Test | ||
| fun `카운트다운은 3에서 시작한다`() { | ||
| assertEquals(3, CountDownStateMachine.INITIAL_COUNT) | ||
| } | ||
|
|
||
| @Test | ||
| fun `카운트다운은 3_2_1 순서로 진행되고 이후 종료된다`() { | ||
| assertEquals(2, CountDownStateMachine.nextCount(3)) | ||
| assertEquals(1, CountDownStateMachine.nextCount(2)) | ||
| assertNull(CountDownStateMachine.nextCount(1)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `카운트다운 숫자에 맞는 drawable을 반환한다`() { | ||
| assertEquals(R.drawable.anim_num3, CountDownStateMachine.numberDrawableRes(3)) | ||
| assertEquals(R.drawable.anim_num2, CountDownStateMachine.numberDrawableRes(2)) | ||
| assertEquals(R.drawable.anim_num1, CountDownStateMachine.numberDrawableRes(1)) | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.