fix+refactor+docs: P0–P3 todo list items
P0 fixes: - Register WinSummaryPlugin, SelectionPlugin, CardAnimationPlugin in main.rs (all three were exported but never wired — features silently did nothing) - game_state::draw(): increment move_count on waste→stock recycle, not just on normal draws; add move_count_increments_on_recycle regression test P1 fixes: - solitaire_server/Cargo.toml: remove duplicate dev-dependencies (solitaire_sync, uuid, chrono, jsonwebtoken were in both sections) P2 — input_plugin refactor: - Split 198-line handle_keyboard() into three focused systems under 110 lines each: handle_keyboard_core (U/N/Z/D/Space), handle_keyboard_hint (H), handle_keyboard_forfeit (G) - Introduce KeyboardConfirmState resource to share countdown timers across systems - Add three new unit tests: all_hints_suggests_draw_*, all_hints_is_empty_when_truly_stuck, new_game_confirm_window_is_positive P2 — achievement predicate tests (solitaire_core): - Add 10 direct unit tests for speed_demon, lightning, no_undo, high_scorer, on_a_roll, comeback predicates (previously only covered via check_achievements()) - 141 core tests now passing P2 — server tests: - solitaire_server/src/sync.rs: 4 unit tests for merge logic (no DB required) - solitaire_server/src/leaderboard.rs: 2 unit tests for entry shape and sort order P3 — documentation: - Add struct-level /// to 12 Plugin structs (ChallengePlugin, CursorPlugin, AnimationPlugin, HelpPlugin, PausePlugin, AudioPlugin, DailyChallengePlugin, HudPlugin, LeaderboardPlugin, OnboardingPlugin, TimeAttackPlugin, WeeklyGoalsPlugin) - Add field-level /// to Card, Pile, Deck, GameState, AchievementContext, AchievementDef - Add /// to WeeklyGoalKind, WeeklyGoalDef, WeeklyGoalContext, StatsExt::update_on_win card_animation module (new files from previous session): - chain.rs, diagnostics.rs, tuning.rs, updated interaction.rs/animation.rs/mod.rs/lib.rs - Remove unused HOVER_SCALE_DEFAULT / DRAG_LIFT_SCALE_DEFAULT / HOVER_LERP_SPEED_DEFAULT constants - Add handle_touch_stock_tap so touch users can draw from the stock pile Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -152,3 +152,71 @@ pub async fn opt_in(
|
||||
|
||||
Ok(Json(serde_json::json!({ "ok": true })))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Tests — data shape and display-name logic; no database required
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use chrono::Utc;
|
||||
use solitaire_sync::LeaderboardEntry;
|
||||
|
||||
/// Helper that constructs a `LeaderboardEntry` with the given display name
|
||||
/// and best score. `best_time_secs` is left as `None`.
|
||||
fn entry(display_name: &str, best_score: Option<i32>) -> LeaderboardEntry {
|
||||
LeaderboardEntry {
|
||||
display_name: display_name.to_string(),
|
||||
best_score,
|
||||
best_time_secs: None,
|
||||
recorded_at: Utc::now(),
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// 1. A LeaderboardEntry always carries a non-empty display_name.
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn leaderboard_entry_has_display_name() {
|
||||
let e = entry("Alice", Some(4_500));
|
||||
assert!(
|
||||
!e.display_name.is_empty(),
|
||||
"display_name must not be empty for a valid leaderboard entry"
|
||||
);
|
||||
assert_eq!(e.display_name, "Alice");
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// 2. A Vec of entries sorts by best_score descending (matching the SQL
|
||||
// ORDER BY used in get_leaderboard).
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn leaderboard_entries_sorted_by_score_descending() {
|
||||
let mut entries = vec![
|
||||
entry("Charlie", Some(1_200)),
|
||||
entry("Alice", Some(8_000)),
|
||||
entry("Bob", Some(3_500)),
|
||||
entry("Dave", None), // no score — should rank last
|
||||
];
|
||||
|
||||
// Mirrors the SQL sort:
|
||||
// CASE WHEN best_score IS NULL THEN 1 ELSE 0 END ASC,
|
||||
// best_score DESC
|
||||
entries.sort_by(|a, b| {
|
||||
let a_null = a.best_score.is_none() as u8;
|
||||
let b_null = b.best_score.is_none() as u8;
|
||||
a_null
|
||||
.cmp(&b_null)
|
||||
.then_with(|| b.best_score.cmp(&a.best_score))
|
||||
});
|
||||
|
||||
// Scored entries first, in descending order.
|
||||
assert_eq!(entries[0].display_name, "Alice", "highest scorer must be first");
|
||||
assert_eq!(entries[1].display_name, "Bob", "second-highest scorer must be second");
|
||||
assert_eq!(entries[2].display_name, "Charlie", "lowest scorer must be third");
|
||||
// Null-score entry sinks to the bottom.
|
||||
assert_eq!(entries[3].display_name, "Dave", "entry with no score must rank last");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user