From e626c313151523037de85babdf7407e5c0e2ec8c Mon Sep 17 00:00:00 2001 From: SaveEditors Date: Sat, 25 Jul 2026 01:45:47 -0400 Subject: [PATCH 1/3] Show empty platforms in platform index --- frontend/src/stores/platforms.test.ts | 35 ++++++ frontend/src/stores/platforms.ts | 2 + frontend/src/v2/views/PlatformsIndex.test.ts | 124 +++++++++++++++++++ frontend/src/v2/views/PlatformsIndex.vue | 11 +- 4 files changed, 167 insertions(+), 5 deletions(-) create mode 100644 frontend/src/stores/platforms.test.ts create mode 100644 frontend/src/v2/views/PlatformsIndex.test.ts diff --git a/frontend/src/stores/platforms.test.ts b/frontend/src/stores/platforms.test.ts new file mode 100644 index 000000000..26c31625a --- /dev/null +++ b/frontend/src/stores/platforms.test.ts @@ -0,0 +1,35 @@ +import { createPinia, setActivePinia } from "pinia"; +import { beforeEach, describe, expect, it } from "vitest"; +import storePlatforms, { type Platform } from "@/stores/platforms"; + +function platform( + id: number, + displayName: string, + romCount: number, +): Platform { + return { + id, + display_name: displayName, + name: displayName, + slug: displayName.toLowerCase().replaceAll(" ", "-"), + fs_slug: displayName.toLowerCase().replaceAll(" ", "-"), + rom_count: romCount, + } as Platform; +} + +describe("platform store lists", () => { + beforeEach(() => { + setActivePinia(createPinia()); + }); + + it("keeps empty platforms reachable from the Platforms index", () => { + const store = storePlatforms(); + const empty = platform(1, "Game Boy", 0); + const filled = platform(2, "Nintendo 64", 12); + + store.set([filled, empty]); + + expect(store.filledPlatforms).toEqual([filled]); + expect(store.platformIndexPlatforms).toEqual([empty, filled]); + }); +}); diff --git a/frontend/src/stores/platforms.ts b/frontend/src/stores/platforms.ts index ac576e65d..74706f3ff 100644 --- a/frontend/src/stores/platforms.ts +++ b/frontend/src/stores/platforms.ts @@ -20,6 +20,8 @@ export default defineStore("platforms", { all .filter((p) => p.rom_count > 0) .sort((a, b) => a.display_name.localeCompare(b.display_name)), + platformIndexPlatforms: ({ allPlatforms: all }) => + [...all].sort((a, b) => a.display_name.localeCompare(b.display_name)), filteredPlatforms: ({ allPlatforms: all, filterText }) => all .filter( diff --git a/frontend/src/v2/views/PlatformsIndex.test.ts b/frontend/src/v2/views/PlatformsIndex.test.ts new file mode 100644 index 000000000..7790f2238 --- /dev/null +++ b/frontend/src/v2/views/PlatformsIndex.test.ts @@ -0,0 +1,124 @@ +import { mount } from "@vue/test-utils"; +import { createPinia, setActivePinia } from "pinia"; +import { defineComponent, ref } from "vue"; +import { beforeEach, describe, expect, it, vi } from "vitest"; +import storePlatforms, { type Platform } from "@/stores/platforms"; +import PlatformsIndex from "./PlatformsIndex.vue"; + +vi.mock("vue-i18n", () => ({ + useI18n: () => ({ t: (key: string) => key }), +})); + +vi.mock("@v2/lib", () => ({ + RDivider: defineComponent({ template: "
" }), + RLetterHeading: defineComponent({ + props: ["label"], + template: "

{{ label }}

", + }), + RSkeletonBlock: defineComponent({ template: "
" }), +})); + +vi.mock("@/v2/components/Gallery/GalleryToolbar.vue", () => ({ + default: defineComponent({ template: "
" }), +})); + +vi.mock("@/v2/components/Platforms/PlatformListHeader.vue", () => ({ + default: defineComponent({ template: "
" }), +})); + +vi.mock("@/v2/components/Platforms/PlatformListRow.vue", () => ({ + default: defineComponent({ + props: ["displayName", "romCount"], + template: + "
{{ displayName }} {{ romCount }}
", + }), +})); + +vi.mock("@/v2/components/Platforms/PlatformTile.vue", () => ({ + default: defineComponent({ + props: ["displayName", "romCount"], + template: + "
{{ displayName }} {{ romCount }}
", + }), +})); + +vi.mock("@/v2/components/shared/EmptyState.vue", () => ({ + default: defineComponent({ + props: ["message"], + template: "
{{ message }}
", + }), +})); + +vi.mock("@/v2/components/shared/IndexShell.vue", () => ({ + default: defineComponent({ + template: + "
", + }), +})); + +vi.mock("@/v2/components/shared/PageHeader.vue", () => ({ + default: defineComponent({ + props: ["title", "count"], + template: "
{{ title }} {{ count }}
", + }), +})); + +vi.mock("@/v2/composables/useGalleryMode", () => ({ + useGalleryMode: () => ({ + groupBy: ref("none"), + layout: ref("grid"), + }), +})); + +vi.mock("@/v2/composables/useGalleryViewModeUrl", () => ({ + useGalleryViewModeUrl: vi.fn(), +})); + +vi.mock("@/v2/composables/usePlatformPlayable", () => ({ + usePlatformPlayableChecker: () => ({ + isPlayable: ref(() => false), + }), +})); + +vi.mock("@/v2/composables/useTileSearchUrl", () => ({ + useTileSearchUrl: () => ref(""), +})); + +vi.mock("@/v2/composables/useWrapGridNav", () => ({ + useWrapGridNav: vi.fn(), +})); + +function platform( + id: number, + displayName: string, + romCount: number, +): Platform { + return { + id, + display_name: displayName, + name: displayName, + slug: displayName.toLowerCase().replaceAll(" ", "-"), + fs_slug: displayName.toLowerCase().replaceAll(" ", "-"), + rom_count: romCount, + } as Platform; +} + +describe("PlatformsIndex", () => { + beforeEach(() => { + setActivePinia(createPinia()); + }); + + it("renders empty database platforms so they remain reachable", () => { + const platforms = storePlatforms(); + platforms.set([ + platform(2, "Nintendo 64", 12), + platform(1, "Game Boy", 0), + ]); + + const wrapper = mount(PlatformsIndex); + + expect(wrapper.text()).toContain("common.platforms 2"); + expect(wrapper.text()).toContain("Game Boy 0"); + expect(wrapper.text()).toContain("Nintendo 64 12"); + }); +}); diff --git a/frontend/src/v2/views/PlatformsIndex.vue b/frontend/src/v2/views/PlatformsIndex.vue index 2ac07d0db..458835461 100644 --- a/frontend/src/v2/views/PlatformsIndex.vue +++ b/frontend/src/v2/views/PlatformsIndex.vue @@ -41,7 +41,8 @@ import { useWrapGridNav } from "@/v2/composables/useWrapGridNav"; const { t } = useI18n(); const platformsStore = storePlatforms(); -const { filledPlatforms, fetchingPlatforms } = storeToRefs(platformsStore); +const { platformIndexPlatforms, fetchingPlatforms } = + storeToRefs(platformsStore); const { groupBy, layout } = useGalleryMode(); useGalleryViewModeUrl(); @@ -61,7 +62,7 @@ useWrapGridNav(gridRoot, { cellSelector: ".plat-tile" }); const playableById = computed(() => { const fn = isPlayable.value; const map = new Map(); - for (const p of filledPlatforms.value) map.set(p.id, fn(p.slug)); + for (const p of platformIndexPlatforms.value) map.set(p.id, fn(p.slug)); return map; }); @@ -201,8 +202,8 @@ onMounted(() => { const filtered = computed(() => { const term = searchTerm.value.trim().toLowerCase(); - if (!term) return filledPlatforms.value; - return filledPlatforms.value.filter((p) => + if (!term) return platformIndexPlatforms.value; + return platformIndexPlatforms.value.filter((p) => p.display_name.toLowerCase().includes(term), ); }); @@ -222,7 +223,7 @@ const sortedForList = computed(() => { ); }); -const totalCount = computed(() => filledPlatforms.value.length); +const totalCount = computed(() => platformIndexPlatforms.value.length); const noResults = computed( () => !fetchingPlatforms.value && From e9539dadeb045327abb4e9fce0d2d5d690a1c793 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sat, 25 Jul 2026 07:39:54 -0400 Subject: [PATCH 2/3] use allplatforms --- frontend/src/stores/platforms.test.ts | 8 ++------ frontend/src/stores/platforms.ts | 4 +--- frontend/src/v2/views/PlatformsIndex.test.ts | 21 +++++++------------- frontend/src/v2/views/PlatformsIndex.vue | 11 +++++----- 4 files changed, 15 insertions(+), 29 deletions(-) diff --git a/frontend/src/stores/platforms.test.ts b/frontend/src/stores/platforms.test.ts index 26c31625a..5fb7de100 100644 --- a/frontend/src/stores/platforms.test.ts +++ b/frontend/src/stores/platforms.test.ts @@ -2,11 +2,7 @@ import { createPinia, setActivePinia } from "pinia"; import { beforeEach, describe, expect, it } from "vitest"; import storePlatforms, { type Platform } from "@/stores/platforms"; -function platform( - id: number, - displayName: string, - romCount: number, -): Platform { +function platform(id: number, displayName: string, romCount: number): Platform { return { id, display_name: displayName, @@ -29,7 +25,7 @@ describe("platform store lists", () => { store.set([filled, empty]); + expect(store.allPlatforms).toEqual([empty, filled]); expect(store.filledPlatforms).toEqual([filled]); - expect(store.platformIndexPlatforms).toEqual([empty, filled]); }); }); diff --git a/frontend/src/stores/platforms.ts b/frontend/src/stores/platforms.ts index 74706f3ff..64f26ac2c 100644 --- a/frontend/src/stores/platforms.ts +++ b/frontend/src/stores/platforms.ts @@ -20,8 +20,6 @@ export default defineStore("platforms", { all .filter((p) => p.rom_count > 0) .sort((a, b) => a.display_name.localeCompare(b.display_name)), - platformIndexPlatforms: ({ allPlatforms: all }) => - [...all].sort((a, b) => a.display_name.localeCompare(b.display_name)), filteredPlatforms: ({ allPlatforms: all, filterText }) => all .filter( @@ -40,7 +38,7 @@ export default defineStore("platforms", { actions: { _reorder() { this.allPlatforms = uniqBy(this.allPlatforms, "id").sort((a, b) => { - return a.name.localeCompare(b.name); + return a.display_name.localeCompare(b.display_name); }); }, fetchPlatforms(): Promise { diff --git a/frontend/src/v2/views/PlatformsIndex.test.ts b/frontend/src/v2/views/PlatformsIndex.test.ts index 7790f2238..3f33af21a 100644 --- a/frontend/src/v2/views/PlatformsIndex.test.ts +++ b/frontend/src/v2/views/PlatformsIndex.test.ts @@ -1,7 +1,7 @@ import { mount } from "@vue/test-utils"; import { createPinia, setActivePinia } from "pinia"; -import { defineComponent, ref } from "vue"; import { beforeEach, describe, expect, it, vi } from "vitest"; +import { defineComponent, ref } from "vue"; import storePlatforms, { type Platform } from "@/stores/platforms"; import PlatformsIndex from "./PlatformsIndex.vue"; @@ -30,7 +30,7 @@ vi.mock("@/v2/components/Platforms/PlatformListRow.vue", () => ({ default: defineComponent({ props: ["displayName", "romCount"], template: - "
{{ displayName }} {{ romCount }}
", + '
{{ displayName }} {{ romCount }}
', }), })); @@ -38,21 +38,21 @@ vi.mock("@/v2/components/Platforms/PlatformTile.vue", () => ({ default: defineComponent({ props: ["displayName", "romCount"], template: - "
{{ displayName }} {{ romCount }}
", + '
{{ displayName }} {{ romCount }}
', }), })); vi.mock("@/v2/components/shared/EmptyState.vue", () => ({ default: defineComponent({ props: ["message"], - template: "
{{ message }}
", + template: '
{{ message }}
', }), })); vi.mock("@/v2/components/shared/IndexShell.vue", () => ({ default: defineComponent({ template: - "
", + '
', }), })); @@ -88,11 +88,7 @@ vi.mock("@/v2/composables/useWrapGridNav", () => ({ useWrapGridNav: vi.fn(), })); -function platform( - id: number, - displayName: string, - romCount: number, -): Platform { +function platform(id: number, displayName: string, romCount: number): Platform { return { id, display_name: displayName, @@ -110,10 +106,7 @@ describe("PlatformsIndex", () => { it("renders empty database platforms so they remain reachable", () => { const platforms = storePlatforms(); - platforms.set([ - platform(2, "Nintendo 64", 12), - platform(1, "Game Boy", 0), - ]); + platforms.set([platform(2, "Nintendo 64", 12), platform(1, "Game Boy", 0)]); const wrapper = mount(PlatformsIndex); diff --git a/frontend/src/v2/views/PlatformsIndex.vue b/frontend/src/v2/views/PlatformsIndex.vue index 458835461..5ceb2796e 100644 --- a/frontend/src/v2/views/PlatformsIndex.vue +++ b/frontend/src/v2/views/PlatformsIndex.vue @@ -41,8 +41,7 @@ import { useWrapGridNav } from "@/v2/composables/useWrapGridNav"; const { t } = useI18n(); const platformsStore = storePlatforms(); -const { platformIndexPlatforms, fetchingPlatforms } = - storeToRefs(platformsStore); +const { allPlatforms, fetchingPlatforms } = storeToRefs(platformsStore); const { groupBy, layout } = useGalleryMode(); useGalleryViewModeUrl(); @@ -62,7 +61,7 @@ useWrapGridNav(gridRoot, { cellSelector: ".plat-tile" }); const playableById = computed(() => { const fn = isPlayable.value; const map = new Map(); - for (const p of platformIndexPlatforms.value) map.set(p.id, fn(p.slug)); + for (const p of allPlatforms.value) map.set(p.id, fn(p.slug)); return map; }); @@ -202,8 +201,8 @@ onMounted(() => { const filtered = computed(() => { const term = searchTerm.value.trim().toLowerCase(); - if (!term) return platformIndexPlatforms.value; - return platformIndexPlatforms.value.filter((p) => + if (!term) return allPlatforms.value; + return allPlatforms.value.filter((p) => p.display_name.toLowerCase().includes(term), ); }); @@ -223,7 +222,7 @@ const sortedForList = computed(() => { ); }); -const totalCount = computed(() => platformIndexPlatforms.value.length); +const totalCount = computed(() => allPlatforms.value.length); const noResults = computed( () => !fetchingPlatforms.value && From 250e1630e18cf2d05dcfa133c8839a56a65e1774 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sat, 25 Jul 2026 08:06:52 -0400 Subject: [PATCH 3/3] fix fmt --- frontend/src/stores/platforms.test.ts | 2 +- frontend/src/v2/views/PlatformsIndex.test.ts | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/frontend/src/stores/platforms.test.ts b/frontend/src/stores/platforms.test.ts index 5fb7de100..5e3ff6eec 100644 --- a/frontend/src/stores/platforms.test.ts +++ b/frontend/src/stores/platforms.test.ts @@ -25,7 +25,7 @@ describe("platform store lists", () => { store.set([filled, empty]); - expect(store.allPlatforms).toEqual([empty, filled]); + expect(store.allPlatforms).toEqual([filled, empty]); expect(store.filledPlatforms).toEqual([filled]); }); }); diff --git a/frontend/src/v2/views/PlatformsIndex.test.ts b/frontend/src/v2/views/PlatformsIndex.test.ts index 3f33af21a..3eb467a10 100644 --- a/frontend/src/v2/views/PlatformsIndex.test.ts +++ b/frontend/src/v2/views/PlatformsIndex.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable vue/one-component-per-file */ import { mount } from "@vue/test-utils"; import { createPinia, setActivePinia } from "pinia"; import { beforeEach, describe, expect, it, vi } from "vitest"; @@ -12,7 +13,7 @@ vi.mock("vue-i18n", () => ({ vi.mock("@v2/lib", () => ({ RDivider: defineComponent({ template: "
" }), RLetterHeading: defineComponent({ - props: ["label"], + props: { label: { type: String, default: "" } }, template: "

{{ label }}

", }), RSkeletonBlock: defineComponent({ template: "
" }), @@ -28,7 +29,10 @@ vi.mock("@/v2/components/Platforms/PlatformListHeader.vue", () => ({ vi.mock("@/v2/components/Platforms/PlatformListRow.vue", () => ({ default: defineComponent({ - props: ["displayName", "romCount"], + props: { + displayName: { type: String, default: "" }, + romCount: { type: Number, default: 0 }, + }, template: '
{{ displayName }} {{ romCount }}
', }), @@ -36,7 +40,10 @@ vi.mock("@/v2/components/Platforms/PlatformListRow.vue", () => ({ vi.mock("@/v2/components/Platforms/PlatformTile.vue", () => ({ default: defineComponent({ - props: ["displayName", "romCount"], + props: { + displayName: { type: String, default: "" }, + romCount: { type: Number, default: 0 }, + }, template: '
{{ displayName }} {{ romCount }}
', }), @@ -44,7 +51,7 @@ vi.mock("@/v2/components/Platforms/PlatformTile.vue", () => ({ vi.mock("@/v2/components/shared/EmptyState.vue", () => ({ default: defineComponent({ - props: ["message"], + props: { message: { type: String, default: "" } }, template: '
{{ message }}
', }), })); @@ -58,7 +65,10 @@ vi.mock("@/v2/components/shared/IndexShell.vue", () => ({ vi.mock("@/v2/components/shared/PageHeader.vue", () => ({ default: defineComponent({ - props: ["title", "count"], + props: { + title: { type: String, default: "" }, + count: { type: Number, default: 0 }, + }, template: "
{{ title }} {{ count }}
", }), }));