mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 02:24:09 +01:00
fix(v2): show TheGamesDB logo on server stats coverage chips (#4866)
This commit is contained in:
@@ -2,17 +2,14 @@ import { mount } from "@vue/test-utils";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createI18n } from "vue-i18n";
|
||||
import type { MetadataCoverageItem } from "@/__generated__/models/MetadataCoverageItem";
|
||||
import type { RegionBreakdownItem } from "@/__generated__/models/RegionBreakdownItem";
|
||||
import enSettings from "@/locales/en_US/settings.json";
|
||||
import storeConfig from "@/stores/config";
|
||||
import type { Platform } from "@/stores/platforms";
|
||||
import storePlatforms from "@/stores/platforms";
|
||||
import PlatformsStatsSection from "./PlatformsStatsSection.vue";
|
||||
|
||||
// The heartbeat store pulls in config + i18n; stub it down to the single
|
||||
// method this component calls.
|
||||
vi.mock("@/stores/heartbeat", () => ({
|
||||
default: () => ({ getMetadataOptionsByPriority: () => [] }),
|
||||
}));
|
||||
|
||||
const push = vi.fn();
|
||||
vi.mock("vue-router", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("vue-router")>()),
|
||||
@@ -55,11 +52,12 @@ function platform(overrides: Partial<Platform> = {}): Platform {
|
||||
|
||||
function mountSection(
|
||||
platforms: Platform[],
|
||||
regionBreakdown: Record<string, { region: string; count: number }[]> = {},
|
||||
regionBreakdown: Record<string, RegionBreakdownItem[]> = {},
|
||||
metadataCoverage: Record<string, MetadataCoverageItem[]> = {},
|
||||
) {
|
||||
storePlatforms().set(platforms);
|
||||
return mount(PlatformsStatsSection, {
|
||||
props: { totalFilesize: 0, metadataCoverage: {}, regionBreakdown },
|
||||
props: { totalFilesize: 0, metadataCoverage, regionBreakdown },
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
stubs: {
|
||||
@@ -87,6 +85,16 @@ function rowCount(wrapper: Section): number {
|
||||
return wrapper.findAll(".r-v2-plat-stats__row").length;
|
||||
}
|
||||
|
||||
function mountCoverage(items: MetadataCoverageItem[]): Section {
|
||||
return mountSection([platform({ id: 1, rom_count: 4 })], {}, { "1": items });
|
||||
}
|
||||
|
||||
function coverageLogos(wrapper: Section): (string | undefined)[] {
|
||||
return wrapper
|
||||
.findAll(".r-v2-plat-stats__coverage img")
|
||||
.map((img) => img.attributes("src"));
|
||||
}
|
||||
|
||||
async function setOrder(wrapper: Section, order: "name" | "size" | "count") {
|
||||
(wrapper.vm as unknown as { orderBy: string }).orderBy = order;
|
||||
await wrapper.vm.$nextTick();
|
||||
@@ -211,6 +219,48 @@ describe("PlatformsStatsSection", () => {
|
||||
expect(push).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("shows the TheGamesDB name and logo on its coverage chip", () => {
|
||||
const chip = mountCoverage([{ source: "tgdb", matched: 2 }]).find(
|
||||
".r-v2-plat-stats__coverage",
|
||||
);
|
||||
|
||||
expect(chip.find("img").attributes("src")).toBe(
|
||||
"/assets/scrappers/tgdb.png",
|
||||
);
|
||||
expect(chip.attributes("title")).toBe("TheGamesDB matches: 2 / 4");
|
||||
expect(chip.text()).toBe("50%");
|
||||
});
|
||||
|
||||
it("orders coverage chips by the configured scan priority", () => {
|
||||
storeConfig().config.SCAN_METADATA_PRIORITY = ["ss", "tgdb", "igdb"];
|
||||
const wrapper = mountCoverage([
|
||||
{ source: "igdb", matched: 2 },
|
||||
{ source: "ss", matched: 3 },
|
||||
{ source: "tgdb", matched: 1 },
|
||||
]);
|
||||
|
||||
expect(coverageLogos(wrapper)).toEqual([
|
||||
"/assets/scrappers/ss.png",
|
||||
"/assets/scrappers/tgdb.png",
|
||||
"/assets/scrappers/igdb.png",
|
||||
]);
|
||||
});
|
||||
|
||||
it("orders sources missing from the scan priority by registry order", () => {
|
||||
storeConfig().config.SCAN_METADATA_PRIORITY = ["ss"];
|
||||
const wrapper = mountCoverage([
|
||||
{ source: "tgdb", matched: 1 },
|
||||
{ source: "igdb", matched: 2 },
|
||||
{ source: "ss", matched: 3 },
|
||||
]);
|
||||
|
||||
expect(coverageLogos(wrapper)).toEqual([
|
||||
"/assets/scrappers/ss.png",
|
||||
"/assets/scrappers/igdb.png",
|
||||
"/assets/scrappers/tgdb.png",
|
||||
]);
|
||||
});
|
||||
|
||||
it("renders one row per platform on initial load", () => {
|
||||
const wrapper = mountSection(duplicateSlugLibrary());
|
||||
expect(rowCount(wrapper)).toBe(6);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
// PlatformsStatsSection — v2-native rebuild of v1
|
||||
// PlatformsStatsSection: v2-native rebuild of v1
|
||||
// `Settings/ServerStats/PlatformsStats.vue`. Per-platform breakdown
|
||||
// rows: icon · name + meta (games count, metadata coverage chips,
|
||||
// region chips with expand/collapse) · size + percentage of total ·
|
||||
@@ -8,7 +8,7 @@
|
||||
// rows use.
|
||||
//
|
||||
// Toolbar mirrors GalleryToolbar's pattern: inline-prefix search on
|
||||
// the left, icon-only segmented sort on the right. No card chrome —
|
||||
// the left, icon-only segmented sort on the right. No card chrome:
|
||||
// this section sits flush in the page; only the Summary section above
|
||||
// keeps a surface.
|
||||
import {
|
||||
@@ -25,7 +25,7 @@ import { useI18n } from "vue-i18n";
|
||||
import { useRouter } from "vue-router";
|
||||
import type { MetadataCoverageItem } from "@/__generated__/models/MetadataCoverageItem";
|
||||
import type { RegionBreakdownItem } from "@/__generated__/models/RegionBreakdownItem";
|
||||
import storeHeartbeat from "@/stores/heartbeat";
|
||||
import storeConfig from "@/stores/config";
|
||||
import storePlatforms from "@/stores/platforms";
|
||||
import { formatBytes, regionToEmoji } from "@/utils";
|
||||
import PlatformIcon from "@/v2/components/shared/PlatformIcon.vue";
|
||||
@@ -33,6 +33,7 @@ import {
|
||||
pendingMorphName,
|
||||
useViewTransition,
|
||||
} from "@/v2/composables/useViewTransition";
|
||||
import { METADATA_SOURCE_INFO } from "@/v2/utils/metadataProviders";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
@@ -49,7 +50,7 @@ const { morphTransition } = useViewTransition();
|
||||
const platformsStore = storePlatforms();
|
||||
// Only platforms that contain games should be displayed
|
||||
const { filledPlatforms } = storeToRefs(platformsStore);
|
||||
const heartbeat = storeHeartbeat();
|
||||
const { config } = storeToRefs(storeConfig());
|
||||
|
||||
type OrderBy = "name" | "size" | "count";
|
||||
const orderBy = ref<OrderBy>("name");
|
||||
@@ -108,25 +109,21 @@ const sortedPlatforms = computed(() => {
|
||||
);
|
||||
});
|
||||
|
||||
const metadataOptions = computed(() =>
|
||||
heartbeat.getMetadataOptionsByPriority(),
|
||||
);
|
||||
|
||||
const sourceInfo = computed(() => {
|
||||
const map: Record<string, { name: string; logo_path: string }> = {};
|
||||
for (const opt of metadataOptions.value) {
|
||||
map[opt.value] = { name: opt.name, logo_path: opt.logo_path };
|
||||
}
|
||||
return map;
|
||||
});
|
||||
|
||||
const orderedCoverageByPlatform = computed(() => {
|
||||
const priority = metadataOptions.value.map((o) => o.value);
|
||||
// Configured scan priority first, then registry order for the rest.
|
||||
const rankBySource = new Map(
|
||||
[
|
||||
...new Set([
|
||||
...(config.value.SCAN_METADATA_PRIORITY ?? []),
|
||||
...METADATA_SOURCE_INFO.keys(),
|
||||
]),
|
||||
].map((source, i) => [source, i]),
|
||||
);
|
||||
const rank = (source: string) =>
|
||||
rankBySource.get(source) ?? rankBySource.size;
|
||||
const result: Record<string, MetadataCoverageItem[]> = {};
|
||||
for (const [id, items] of Object.entries(props.metadataCoverage)) {
|
||||
result[id] = [...items].sort(
|
||||
(a, b) => priority.indexOf(a.source) - priority.indexOf(b.source),
|
||||
);
|
||||
result[id] = [...items].sort((a, b) => rank(a.source) - rank(b.source));
|
||||
}
|
||||
return result;
|
||||
});
|
||||
@@ -267,15 +264,17 @@ function onRowClick(e: MouseEvent, platformId: number): void {
|
||||
class="r-v2-plat-stats__coverage"
|
||||
:title="
|
||||
t('settings.platform-metadata-matches', {
|
||||
source: sourceInfo[item.source]?.name ?? item.source,
|
||||
source:
|
||||
METADATA_SOURCE_INFO.get(item.source)?.name ??
|
||||
item.source,
|
||||
matched: item.matched,
|
||||
total: platform.rom_count,
|
||||
})
|
||||
"
|
||||
>
|
||||
<img
|
||||
v-if="sourceInfo[item.source]?.logo_path"
|
||||
:src="sourceInfo[item.source]?.logo_path"
|
||||
v-if="METADATA_SOURCE_INFO.has(item.source)"
|
||||
:src="`/assets/scrappers/${METADATA_SOURCE_INFO.get(item.source)?.logo}`"
|
||||
class="r-v2-plat-stats__coverage-logo"
|
||||
alt=""
|
||||
/>
|
||||
@@ -355,7 +354,7 @@ function onRowClick(e: MouseEvent, platformId: number): void {
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
/* Search width mirrors GalleryToolbar — bounded so the sort cluster
|
||||
/* Search width mirrors GalleryToolbar, bounded so the sort cluster
|
||||
stays comfortably visible on wide screens but the field collapses
|
||||
gracefully when the panel narrows. */
|
||||
.r-v2-plat-stats__search {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Metadata-provider registry — single source of truth for the small
|
||||
// Metadata-provider registry: single source of truth for the small
|
||||
// provider chips that appear next to a ROM (gallery list rows, scan
|
||||
// rows, future surfaces). One entry per provider gives label + logo
|
||||
// path + (optional) brand-colour background; consumers iterate and
|
||||
@@ -27,9 +27,9 @@ export type ProviderIdKey =
|
||||
export interface MetadataProvider {
|
||||
/** Field on `SimpleRom` that holds this provider's match id. */
|
||||
key: ProviderIdKey;
|
||||
/** Short brand name (e.g. "IGDB") — used as the gallery filter label. */
|
||||
/** Short brand name (e.g. "IGDB"), used as the gallery filter label. */
|
||||
name: string;
|
||||
/** Tooltip text — also serves as the chip's `alt`. */
|
||||
/** Tooltip text, also used as the chip's `alt`. */
|
||||
title: string;
|
||||
/** File under `/assets/scrappers/`. */
|
||||
logo: string;
|
||||
@@ -127,6 +127,18 @@ export const METADATA_PROVIDER_FILTER_OPTIONS: {
|
||||
title: p.name,
|
||||
}));
|
||||
|
||||
/** Name and logo per backend MetadataSource slug, in registry order.
|
||||
* TheGamesDB has no ROM chip, but its ids still count in match stats. */
|
||||
export const METADATA_SOURCE_INFO: ReadonlyMap<
|
||||
string,
|
||||
{ name: string; logo: string }
|
||||
> = new Map([
|
||||
...METADATA_PROVIDERS.map(
|
||||
(p) => [providerSlug(p.key), { name: p.name, logo: p.logo }] as const,
|
||||
),
|
||||
["tgdb", { name: "TheGamesDB", logo: "tgdb.png" }],
|
||||
]);
|
||||
|
||||
/** Returns the providers whose id field is populated on the given ROM. */
|
||||
export function activeProviders(rom: SimpleRom): MetadataProvider[] {
|
||||
return METADATA_PROVIDERS.filter((p) => Boolean(rom[p.key]));
|
||||
|
||||
Reference in New Issue
Block a user