Refactor Android mock data system and cleanup old sample data - #177
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the Android test/mock grade data setup by centralizing mock report generation, introducing a fake repository/data source for UI/dev usage, and updating unit/UI tests to match the new mock values.
Changes:
- Replaced ad-hoc hardcoded
sampleReport()test builders withMockGradeSystem.generateReport(...)and updated assertions accordingly. - Introduced
FakeData+FakeGradeRepositoryand aGradeRepositoryinterface with a realSchoolGradeRepositoryimplementation, plus a BuildConfig toggle (USE_FAKE_DATA) for switching repositories. - Added Compose preview entry points that render screens using the centralized fake/mock data.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| fix_sync.py | Adds a Python script intended to regex-edit frontend/sync.js. |
| android/app/src/test/java/com/clhs/score/data/GradeAnalysisTest.kt | Migrates tests to MockGradeSystem.generateReport and updates expectations. |
| android/app/src/test/java/com/clhs/score/data/FakeDataTest.kt | Adds test coverage for the new fake/mock data system and fake repository. |
| android/app/src/main/java/com/clhs/score/viewmodel/ScoreViewModel.kt | Updates VM factory to optionally use FakeGradeRepository and uses SchoolGradeRepository otherwise. |
| android/app/src/main/java/com/clhs/score/ui/ScorePreviews.kt | Adds Compose previews driven by fake/mock data scenarios. |
| android/app/src/main/java/com/clhs/score/ui/GradesScreen.kt | Removes unused imports / minor import ordering cleanup. |
| android/app/src/main/java/com/clhs/score/MainActivity.kt | Wires BuildConfig.USE_FAKE_DATA into the VM factory. |
| android/app/src/main/java/com/clhs/score/data/GradeRepository.kt | Introduces GradeRepository interface + SchoolGradeRepository implementation. |
| android/app/src/main/java/com/clhs/score/data/FakeData.kt | Adds centralized fake data, mock report generator, and FakeGradeRepository. |
| android/app/src/androidTest/java/com/clhs/score/ui/ScoreUiTest.kt | Updates UI tests to align with new Intro screen and mock report values. |
| android/app/build.gradle.kts | Adds USE_FAKE_DATA BuildConfig flag and enables BuildConfig generation. |
| AGENTS.md | Documents the fake data system and how to enable it. |
Comments suppressed due to low confidence (1)
android/app/src/main/java/com/clhs/score/data/FakeData.kt:257
FakeGradeRepository.refreshCaptcha()returnscontentType = "image/png"but uses an emptyByteArray(0)forimageBytes, which is not a valid PNG payload. If anything later tries to decode/render this captcha, it can fail; consider returning a small valid placeholder image (or a content type that matches the payload).
override suspend fun refreshCaptcha(): CaptchaChallenge = CaptchaChallenge(
loginToken = "fake-login-token",
shCaptchaGenCode = "fake-captcha",
deviceToken = "fake-device",
cookies = emptyMap(),
imageBytes = ByteArray(0),
contentType = "image/png",
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| yearRank = subjectYearRank, | ||
| yearRankCount = yearRankCount, | ||
| yearTermDisplay = yearTermDisplay, | ||
| flunk = actualScore < 60.0, |
| defaultConfig { | ||
| applicationId = "com.clhs.score" | ||
| minSdk = 29 | ||
| targetSdk = 36 | ||
| versionCode = releaseVersionCode.get() | ||
| versionName = releaseVersionName.get() | ||
|
|
||
| ndk { | ||
| abiFilters += "arm64-v8a" | ||
| } | ||
|
|
||
| testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
| buildConfigField("boolean", "USE_FAKE_DATA", useFakeData.get().toString()) | ||
| } | ||
|
|
||
| buildFeatures { | ||
| compose = true | ||
| buildConfig = true | ||
| } |
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive fake data system for the Android application to facilitate UI development and testing without relying on live APIs. Key changes include refactoring the GradeRepository into an interface, implementing a FakeGradeRepository with a MockGradeSystem for various student scenarios, and adding new Compose previews and unit tests. Feedback was provided regarding the fix_sync.py script, highlighting that using regular expressions for source code modification is fragile and suggesting that such scripts should not be committed to the repository.
I am having trouble creating individual review comments. Click here to see my feedback.
fix_sync.py (1-39)
The addition of this script directly contradicts the pull request description, which states that the "web frontend logic" was "retained untouched". Furthermore, using regular expressions to modify source code is highly fragile and prone to errors if the source file's structure or formatting changes (e.g., unexpected matches with [\s\S]*?). If this is intended to be a one-time cleanup script, it should ideally not be committed to the repository, or at least be replaced with a more robust refactoring tool that understands the language syntax.
Description
Tests