mirror of
https://github.com/rommapp/romm.git
synced 2026-11-29 18:11:16 +01:00
Adds a "Tag" gallery filter so a library can be narrowed by the custom tags parsed from filenames (No-Intro / Redump nomenclature, e.g. Proto, Beta, Demo), mirroring the existing data-derived multi-value filters (regions, languages). Closes #3546. Backend: - New `_filter_by_tags` over `Rom.tags` with any/all/none logic; wired through filter_roms, get_roms_scalar, the /roms endpoint (tags + tags_logic), and the unscoped cache gate. - Tags are data-derived, so the selectable list is surfaced via filter_values: added to _collect_filter_values, with_filter_values, get_rom_filters, and RomFiltersDict. - Smart collections apply the criterion via get_smart_collection_roms. Frontend (v1 + v2): - Wired into the galleryFilter store, rom API service, request cache key, both filter drawers, v2 URL persistence, the v2 refetch watcher, and smart-collection serialization/summary + create dialog. - Added the `platform.tag` key to all locales (distinct from the existing `platform.tags` section heading). Tests: - Backend handler (any/all/none + unknown-value), endpoint, filter_values, and smart-collection coverage. - Frontend smartCollectionCriteria serialization/summary coverage. AI assistance: implemented with Claude Code (Anthropic). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
from handler.database import db_collection_handler
|
|
from models.collection import SmartCollection
|
|
from models.user import User
|
|
|
|
|
|
def test_get_smart_collection_roms_normalizes_legacy_selected_status_lists(
|
|
admin_user: User, mocker
|
|
):
|
|
get_roms_scalar = mocker.patch("handler.database.db_rom_handler.get_roms_scalar")
|
|
smart_collection = SmartCollection(
|
|
name="Finished games",
|
|
description="",
|
|
user_id=admin_user.id,
|
|
filter_criteria={"selected_status": ["finished", "completed_100"]},
|
|
)
|
|
|
|
db_collection_handler.get_smart_collection_roms(
|
|
smart_collection, user_id=admin_user.id
|
|
)
|
|
|
|
assert get_roms_scalar.call_args.kwargs["statuses"] == [
|
|
"finished",
|
|
"completed_100",
|
|
]
|
|
|
|
|
|
def test_get_smart_collection_roms_passes_metadata_providers(admin_user: User, mocker):
|
|
get_roms_scalar = mocker.patch("handler.database.db_rom_handler.get_roms_scalar")
|
|
smart_collection = SmartCollection(
|
|
name="IGDB and Moby matches",
|
|
description="",
|
|
user_id=admin_user.id,
|
|
filter_criteria={
|
|
"metadata_providers": ["igdb", "moby"],
|
|
"metadata_providers_logic": "all",
|
|
},
|
|
)
|
|
|
|
db_collection_handler.get_smart_collection_roms(
|
|
smart_collection, user_id=admin_user.id
|
|
)
|
|
|
|
assert get_roms_scalar.call_args.kwargs["metadata_providers"] == ["igdb", "moby"]
|
|
assert get_roms_scalar.call_args.kwargs["metadata_providers_logic"] == "all"
|
|
|
|
|
|
def test_get_smart_collection_roms_passes_tags(admin_user: User, mocker):
|
|
get_roms_scalar = mocker.patch("handler.database.db_rom_handler.get_roms_scalar")
|
|
smart_collection = SmartCollection(
|
|
name="Prototypes and betas",
|
|
description="",
|
|
user_id=admin_user.id,
|
|
filter_criteria={
|
|
"tags": ["Proto", "Beta"],
|
|
"tags_logic": "any",
|
|
},
|
|
)
|
|
|
|
db_collection_handler.get_smart_collection_roms(
|
|
smart_collection, user_id=admin_user.id
|
|
)
|
|
|
|
assert get_roms_scalar.call_args.kwargs["tags"] == ["Proto", "Beta"]
|
|
assert get_roms_scalar.call_args.kwargs["tags_logic"] == "any"
|