-
Notifications
You must be signed in to change notification settings - Fork 0
[Test] HomeViewModel 테스트 코드 작성 #238
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b0866cb
refactor/#235: 일정 화면 Pager 상태 관리 로직을 SchedulePagerState로 분리
DongChyeon 4186833
chore/#237: core:testing 모듈 설정
DongChyeon 6fe8092
test/#237: 테스트용 Fake Data 추가
DongChyeon 09a1fa9
test/#237: 테스트용 Fake Repository 추가
DongChyeon 3af3373
test/#237: 테스트용 MainDispatcherRule 추가
DongChyeon 65cf5ff
test/#237: HomeViewModel 주요 로직 검증 테스트 케이스 작성
DongChyeon f5b64cb
chore/#237: testImplementation, implementation 분리
DongChyeon 22a2a71
chore/#237: core-testing 모듈의 의존성을 api로 변경
DongChyeon 1b7c62f
chore/#237: kotlinx-coroutines 1.8.1 롤백
DongChyeon 02ffc5e
chore/#237: agp 8.13.0 -> 8.7.3 롤백
DongChyeon b9e776f
refactor/#237: ScheduleTestData 함수들을 프로퍼티로 변경
DongChyeon ff1ccb1
test/#237: Fake Repository API 호출 횟수 추적 로직 제거
DongChyeon e19e4cc
test/#237: Repository 메서드 호출 횟수 검증 로직을 제거하고 UI State 검증으로 대체
DongChyeon 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
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
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
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 @@ | ||
| /build |
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,8 @@ | ||
| plugins { | ||
| id("yapp.kotlin.library") | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(projects.core.dataApi) | ||
| implementation(projects.core.model) | ||
| } | ||
DongChyeon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
21 changes: 21 additions & 0 deletions
21
core/testing/src/main/java/com/yapp/testing/MainDispatcherRule.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,21 @@ | ||
| package com.yapp.testing | ||
|
|
||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
| import kotlinx.coroutines.test.TestDispatcher | ||
| import kotlinx.coroutines.test.UnconfinedTestDispatcher | ||
| import kotlinx.coroutines.test.resetMain | ||
| import kotlinx.coroutines.test.setMain | ||
| import org.junit.rules.TestWatcher | ||
| import org.junit.runner.Description | ||
|
|
||
| class MainDispatcherRule @OptIn(ExperimentalCoroutinesApi::class) constructor( | ||
| private val testDispatcher: TestDispatcher = UnconfinedTestDispatcher() | ||
| ) : TestWatcher() { | ||
| @OptIn(ExperimentalCoroutinesApi::class) | ||
| override fun starting(description: Description?) = Dispatchers.setMain(testDispatcher) | ||
|
|
||
| @OptIn(ExperimentalCoroutinesApi::class) | ||
| override fun finished(description: Description?) = Dispatchers.resetMain() | ||
DongChyeon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| } | ||
41 changes: 41 additions & 0 deletions
41
core/testing/src/main/java/com/yapp/testing/data/AttendanceTestData.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,41 @@ | ||
| @file:Suppress("MagicNumber") | ||
|
|
||
| package com.yapp.testing.data | ||
|
|
||
| import com.yapp.model.AttendStatistics | ||
| import com.yapp.model.AttendanceHistory | ||
| import com.yapp.model.AttendanceHistoryList | ||
| import com.yapp.model.AttendanceStatus | ||
|
|
||
| object AttendanceTestData { | ||
| fun attendanceStatistics(): AttendStatistics = AttendStatistics( | ||
| totalSessionCount = 12, | ||
| remainingSessionCount = 4, | ||
| sessionProgressRate = 0.66, | ||
| attendancePoint = 200, | ||
| attendanceCount = 7, | ||
| lateCount = 2, | ||
| absenceCount = 1, | ||
| latePassCount = 1 | ||
| ) | ||
|
|
||
| fun attendanceHistory(): AttendanceHistoryList = AttendanceHistoryList( | ||
| histories = listOf( | ||
| AttendanceHistory( | ||
| name = "5주차 전체 세션", | ||
| checkedInAt = "2024-05-11T13:05:00+09:00", | ||
| attendanceStatus = AttendanceStatus.ATTENDED | ||
| ), | ||
| AttendanceHistory( | ||
| name = "4주차 전체 세션", | ||
| checkedInAt = "2024-05-04T13:20:00+09:00", | ||
| attendanceStatus = AttendanceStatus.LATE | ||
| ), | ||
| AttendanceHistory( | ||
| name = "3주차 전체 세션", | ||
| checkedInAt = null, | ||
| attendanceStatus = AttendanceStatus.ABSENT | ||
| ) | ||
| ) | ||
| ) | ||
| } |
5 changes: 5 additions & 0 deletions
5
core/testing/src/main/java/com/yapp/testing/data/OperationsTestData.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,5 @@ | ||
| package com.yapp.testing.data | ||
|
|
||
| object OperationsTestData { | ||
| fun positionConfigs(): List<String> = listOf("기획", "디자인", "iOS", "안드로이드", "서버") | ||
| } |
155 changes: 155 additions & 0 deletions
155
core/testing/src/main/java/com/yapp/testing/data/ScheduleTestData.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,155 @@ | ||
| @file:Suppress("MagicNumber") | ||
|
|
||
| package com.yapp.testing.data | ||
|
|
||
| import com.yapp.model.AttendanceStatus | ||
| import com.yapp.model.DateGroupedSchedule | ||
| import com.yapp.model.HomeSession | ||
| import com.yapp.model.HomeSessionList | ||
| import com.yapp.model.NoticeInfo | ||
| import com.yapp.model.NoticeType | ||
| import com.yapp.model.ScheduleInfo | ||
| import com.yapp.model.ScheduleList | ||
| import com.yapp.model.ScheduleProgressPhase | ||
| import com.yapp.model.ScheduleType | ||
| import com.yapp.model.SessionDetailInfo | ||
| import com.yapp.model.SessionProgressPhase | ||
| import com.yapp.model.SessionType | ||
| import com.yapp.model.UpcomingSessionInfo | ||
| import com.yapp.model.UpcomingSessionNotice | ||
| import java.time.LocalDateTime | ||
|
|
||
| object ScheduleTestData { | ||
| fun homeSessionList(): HomeSessionList = HomeSessionList( | ||
| sessions = listOf( | ||
| HomeSession( | ||
| id = "session-1", | ||
| name = "디자인 공유 세션", | ||
| place = "판교 스테이션", | ||
| date = "2024-05-18", | ||
| dayOfWeek = "토", | ||
| relativeDays = 2, | ||
| startTime = "13:00", | ||
| endTime = "16:00", | ||
| progressPhase = SessionProgressPhase.PENDING, | ||
| attendanceStatus = null | ||
| ), | ||
| HomeSession( | ||
| id = "session-2", | ||
| name = "모바일 개발 세션", | ||
| place = "강남 스튜디오", | ||
| date = "2024-05-11", | ||
| dayOfWeek = "토", | ||
| relativeDays = -5, | ||
| startTime = "14:00", | ||
| endTime = "18:00", | ||
| progressPhase = SessionProgressPhase.DONE, | ||
| attendanceStatus = AttendanceStatus.ATTENDED | ||
| ) | ||
| ), | ||
| upcomingSessionId = "session-upcoming", | ||
| upcomingNotice = notices() | ||
| ) | ||
|
|
||
| fun scheduleList(): ScheduleList = ScheduleList( | ||
| dates = listOf( | ||
| DateGroupedSchedule( | ||
| date = "2024-05-18", | ||
| isToday = false, | ||
| dayOfTheWeek = "토", | ||
| schedules = listOf( | ||
| ScheduleInfo( | ||
| id = "schedule-1", | ||
| name = "전체 세션", | ||
| place = "판교 스테이션", | ||
| date = "2024-05-18", | ||
| endDate = null, | ||
| startDayOfWeek = "토", | ||
| endDayOfWeek = null, | ||
| time = "13:00", | ||
| endTime = "16:00", | ||
| scheduleType = ScheduleType.SESSION, | ||
| sessionType = SessionType.OFFLINE, | ||
| scheduleProgressPhase = ScheduleProgressPhase.PENDING, | ||
| attendanceStatus = null, | ||
| ) | ||
| ) | ||
| ), | ||
| DateGroupedSchedule( | ||
| date = "2024-05-11", | ||
| isToday = true, | ||
| dayOfTheWeek = "토", | ||
| schedules = listOf( | ||
| ScheduleInfo( | ||
| id = "schedule-2", | ||
| name = "운영 회의", | ||
| place = "온라인", | ||
| date = "2024-05-11", | ||
| endDate = null, | ||
| startDayOfWeek = "토", | ||
| endDayOfWeek = null, | ||
| time = "10:00", | ||
| endTime = "11:00", | ||
| scheduleType = ScheduleType.TASK, | ||
| sessionType = SessionType.ONLINE, | ||
| scheduleProgressPhase = ScheduleProgressPhase.ONGOING, | ||
| attendanceStatus = AttendanceStatus.ATTENDED, | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| fun upcomingSessionInfo(): UpcomingSessionInfo = UpcomingSessionInfo( | ||
| sessionId = "session-upcoming", | ||
| name = "안드로이드 심화 세션", | ||
| startDate = "2024-05-25", | ||
| startDayOfTheWeek = "토", | ||
| endDate = "2024-05-25", | ||
| endDayOfTheWeek = "토", | ||
| startTime = "13:00", | ||
| endTime = "17:00", | ||
| location = "홍대 스튜디오", | ||
| remainingDays = 7, | ||
| canCheckIn = false, | ||
| status = null, | ||
| progressPhase = SessionProgressPhase.PENDING, | ||
| notices = listOf( | ||
| UpcomingSessionNotice( | ||
| id = "upcoming-notice-1", | ||
| title = "입실은 12시 30분부터 가능합니다." | ||
| ), | ||
| UpcomingSessionNotice( | ||
| id = "upcoming-notice-2", | ||
| title = "간단한 간식이 제공됩니다." | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| fun sessionDetailInfo(): SessionDetailInfo = SessionDetailInfo( | ||
| id = "session-1", | ||
| progressPhase = SessionProgressPhase.PENDING, | ||
| title = "전체 세션", | ||
| startDateTime = LocalDateTime.of(2024, 5, 18, 13, 0), | ||
| endDateTime = LocalDateTime.of(2024, 5, 18, 16, 30), | ||
| place = "판교 스테이션", | ||
| address = "경기도 성남시 판교로 242", | ||
| latitude = 37.4018, | ||
| longitude = 127.1087, | ||
| notices = notices() | ||
| ) | ||
|
|
||
| private fun notices(): List<NoticeInfo> = listOf( | ||
| NoticeInfo( | ||
| id = "notice-1", | ||
| writerName = "운영국", | ||
| writerId = "operation-1", | ||
| writerPosition = "운영", | ||
| writerGeneration = 15, | ||
| createdAt = "2024-05-01T10:00:00+09:00", | ||
| title = "세션 안내", | ||
| content = "이번 주 세션은 판교 스테이션에서 진행됩니다.", | ||
| noticeType = NoticeType.SESSION | ||
| ) | ||
| ) | ||
| } |
29 changes: 29 additions & 0 deletions
29
core/testing/src/main/java/com/yapp/testing/repository/FakeAttendanceRepository.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,29 @@ | ||
| package com.yapp.testing.repository | ||
|
|
||
| import com.yapp.dataapi.AttendanceRepository | ||
| import com.yapp.model.AttendStatistics | ||
| import com.yapp.model.AttendanceHistoryList | ||
| import com.yapp.model.AttendanceInfo | ||
| import com.yapp.testing.data.AttendanceTestData | ||
|
|
||
| class FakeAttendanceRepository( | ||
| var attendStatistics: AttendStatistics = AttendanceTestData.attendanceStatistics(), | ||
| var attendanceHistoryList: AttendanceHistoryList = AttendanceTestData.attendanceHistory(), | ||
| var postAttendanceResult: Result<Unit> = Result.success(Unit) | ||
| ) : AttendanceRepository { | ||
|
|
||
| val postedAttendances: MutableList<AttendanceInfo> = mutableListOf() | ||
|
|
||
| override suspend fun getAttendanceStatistics(): AttendStatistics = attendStatistics | ||
|
|
||
| override suspend fun getAttendanceHistory(): AttendanceHistoryList = attendanceHistoryList | ||
|
|
||
| override suspend fun postAttendance(attendance: AttendanceInfo) { | ||
| postedAttendances += attendance | ||
| postAttendanceResult.getOrThrow() | ||
| } | ||
|
|
||
| fun clearPostedAttendances() { | ||
| postedAttendances.clear() | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
core/testing/src/main/java/com/yapp/testing/repository/FakeOperationsRepository.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,43 @@ | ||
| package com.yapp.testing.repository | ||
|
|
||
| import com.yapp.dataapi.OperationsRepository | ||
| import com.yapp.testing.data.OperationsTestData | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
|
|
||
| class FakeOperationsRepository( | ||
| initialPositions: List<String> = OperationsTestData.positionConfigs(), | ||
| var usageInquiryLink: String = "https://example.com/inquiry", | ||
| var termsOfServiceLink: String = "https://example.com/terms", | ||
| var privacyPolicyLink: String = "https://example.com/privacy", | ||
| var basicRuleLink: String = "https://example.com/rules", | ||
| var storedAppVersion: String = "1.0.0", | ||
| var forceUpdateRequired: Boolean = false | ||
| ) : OperationsRepository { | ||
DongChyeon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| private val positionConfigs = MutableStateFlow(initialPositions) | ||
| var basicRuleRequestCount: Int = 0 | ||
| private set | ||
|
|
||
| override fun getPositionConfigs(): Flow<List<String>> = positionConfigs | ||
|
|
||
| override suspend fun getUsageInquiryLink(): String = usageInquiryLink | ||
|
|
||
| override suspend fun getTermsOfServiceLink(): String = termsOfServiceLink | ||
|
|
||
| override suspend fun getPrivacyPolicyLink(): String = privacyPolicyLink | ||
|
|
||
| override suspend fun getBasicRuleLink(): String { | ||
| basicRuleRequestCount++ | ||
| return basicRuleLink | ||
| } | ||
|
|
||
| override fun getAppVersion(): String = storedAppVersion | ||
|
|
||
| override suspend fun isForceUpdateRequired(): Boolean = forceUpdateRequired | ||
|
|
||
| fun emitPositionConfigs(configs: List<String>) { | ||
| positionConfigs.value = configs | ||
| } | ||
| } | ||
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.