Skip to content

Refactor Android mock data system and cleanup old sample data - #177

Merged
alvin000009238 merged 4 commits into
mainfrom
feature/refactor-mock-data
May 21, 2026
Merged

Refactor Android mock data system and cleanup old sample data#177
alvin000009238 merged 4 commits into
mainfrom
feature/refactor-mock-data

Conversation

@alvin000009238

Copy link
Copy Markdown
Owner

Description

  • Removed outdated and inconsistent hardcoded sampleReport functions in Android tests.
  • Transitioned ScoreUiTest.kt and GradeAnalysisTest.kt to fully use MockGradeSystem.generateReport.
  • Updated test assertions to align with the new mock data values.
  • Retained the current web frontend logic untouched.

Tests

  • All 31 tests in .\gradlew.bat test are passing.

Copilot AI review requested due to automatic review settings May 21, 2026 12:16
@alvin000009238
alvin000009238 merged commit 5d12122 into main May 21, 2026
1 check passed
@alvin000009238
alvin000009238 deleted the feature/refactor-mock-data branch May 21, 2026 12:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 with MockGradeSystem.generateReport(...) and updated assertions accordingly.
  • Introduced FakeData + FakeGradeRepository and a GradeRepository interface with a real SchoolGradeRepository implementation, 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() returns contentType = "image/png" but uses an empty ByteArray(0) for imageBytes, 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,
Comment on lines 32 to 50
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
}

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

high

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants