Update NameWithIcon

The `NameWithIcon()` function had a `platform` parameter that was immediately overwritten by `platform = None` and never used (dead code). The function mixed data lookup (database queries via IDs) with rendering, making it untestable.

**Fix**: Refactored `NameWithIcon()` to follow the `LinkedPurchase` pattern — accepts model objects (`Game`, `Session`) instead of IDs. Extracted `_resolve_name_with_icon()` helper for testable computation logic (name resolution, platform extraction, link creation). Fixed bug where `platform` was not extracted when `session` parameter was passed. Removed dead `platform` parameter from the public API. Updated all 3 production call sites (already using model objects). Added 10 unit tests for `_resolve_name_with_icon()` covering session override, custom names, linkify behavior, platform resolution, and edge cases. Updated 6 integration tests to use model-based parameters.
This commit is contained in:
2026-05-12 10:05:15 +02:00
parent eae020fd34
commit 1a4e51c95a
5 changed files with 157 additions and 38 deletions
+2 -4
View File
@@ -104,7 +104,7 @@ def list_games(request: HttpRequest, search_string: str = "") -> HttpResponse:
],
"rows": [
[
NameWithIcon(game_id=game.pk),
NameWithIcon(game=game),
PopoverTruncated(
game.sort_name
if game.sort_name is not None and game.name != game.sort_name
@@ -308,9 +308,7 @@ def view_game(request: HttpRequest, game_id: int) -> HttpResponse:
"columns": ["Game", "Date", "Duration", "Actions"],
"rows": [
[
NameWithIcon(
session_id=session.pk,
),
NameWithIcon(session=session),
f"{local_strftime(session.timestamp_start)}{f'{local_strftime(session.timestamp_end, timeformat)}' if session.timestamp_end else ''}",
session.duration_formatted_with_mark,
render_to_string(