Add Unit Tests for v3 Layer and All GetX Controllers

未關閉
#619 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

@srykaran 已經在處理了。

開始於 2026年3月13日。

評估

難度
5/5
預估耗時
一週以上
新手友好度
35/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
dart, flutter

研究方向

從 pubspec.yaml 以及 test/api_service_test.dart 和 test/models/json/task_test.dart 中現有的模式開始。在 test/v3/ 和 test/modules/controllers/ 下新增列出的 helpers 和 tests,然後先執行 build_runner 和兩個指定範圍的 flutter test 指令,再執行完整測試套件。完成標準是全部 12 個 v3 tests 和 14 個 controller tests 均通過,並涵蓋指定的狀態、變更和邊界情況。

由索引模型根據 Issue 內容生成。

描述

Summary

The project has 91+ existing tests covering utilities, JSON models, routes, and tour UI — but the v3 data layer (12 files) and all 14 GetX controllers have zero unit test coverage. These are the most critical parts of the codebase: v3 contains the task database, network sync, and core models, while controllers hold all business logic and state management.

Motivation
  • Controllers are the sole owners of business logic per the GetX architecture contract — regressions here break the entire UI silently
  • The v3 layer handles live task data sync; bugs here cause data loss
  • No test infrastructure exists yet for either layer, making refactors risky

Scope
Phase 1 — Test Infrastructure
  • Add test/v3/helpers.dart — shared setup for sqflite FFI, SharedPreferences mock, binding init
  • Add test/modules/controllers/helpers.dart — GetX test mode setup (Get.testMode = true, Get.reset())
  • Run build_runner to regenerate mocks
Phase 2 — V3 Unit Tests (12 files)

Models (test/v3/models/)

  • test/v3/models/task_test.dart — Task fromJson/toJson, null fields, edge cases
  • test/v3/models/annotation_test.dart — Annotation serialization
  • test/v3/models/task_for_replica_test.dart — TaskForReplica model

Database (test/v3/db/)

  • test/v3/db/task_database_test.dart — open, CRUD operations (sqflite FFI)
  • test/v3/db/update_test.dart — migration/update logic

Network (test/v3/net/)

  • test/v3/net/add_task_test.dart
  • test/v3/net/complete_test.dart
  • test/v3/net/delete_test.dart
  • test/v3/net/fetch_test.dart
  • test/v3/net/modify_test.dart
  • test/v3/net/origin_test.dart

Champion (test/v3/champion/)

  • test/v3/champion/replica_test.dart — sync logic with mocked DB and origin
Phase 3 — Controller Unit Tests (14 files in test/modules/controllers/)
  • home_controller_test.dart — filterTasks, updateTags, reactive state, search
  • splash_controller_test.dart — init flow, navigation state
  • taskc_details_controller_test.dart — task init from args, field mutation, save
  • settings_controller_test.dart — language change, directory pick, theme
  • widget_controller_test.dart
  • logs_controller_test.dart
  • about_controller_test.dart
  • detail_route_controller_test.dart
  • manage_task_server_controller_test.dart — server add/remove, connection test
  • reports_controller_test.dart
  • profile_controller_test.dart
  • permission_controller_test.dart
  • onboarding_controller_test.dart
  • manage_task_champion_creds_controller_test.dart

Acceptance Criteria
  • flutter test test/v3/ passes with all 12 v3 tests green
  • flutter test test/modules/controllers/ passes with all 14 controller tests green
  • flutter test full suite passes without regression
  • Each controller test covers: onInit state, at least 2 state-mutating methods, and error/edge cases
Implementation Notes
  • No new pub dependencies needed — mockito and sqflite_ffi are already in pubspec.yaml
  • Reference existing patterns in test/api_service_test.dart (mock setup) and test/models/json/task_test.dart (model tests)
  • All 14 controllers extend GetxController — use Get.testMode = true per test group
  • v3 net tests should mock http.Client via @GenerateMocks([http.Client])
Labels

testing good first issue help wanted v3 controllers

主要語言
Dart
星號
246
分支
184
PR 合併指標
30 天內沒有已合併 PR

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

CCExtractor/taskwarrior-flutter 的其他 Issue

查看 CCExtractor/taskwarrior-flutter 的全部 Issue

相似的 Issue

更多 Dart Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。