diff --git a/frontend/src/stores/platforms.test.ts b/frontend/src/stores/platforms.test.ts new file mode 100644 index 000000000..5e3ff6eec --- /dev/null +++ b/frontend/src/stores/platforms.test.ts @@ -0,0 +1,31 @@ +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.allPlatforms).toEqual([filled, empty]); + expect(store.filledPlatforms).toEqual([filled]); + }); +}); diff --git a/frontend/src/stores/platforms.ts b/frontend/src/stores/platforms.ts index ac576e65d..64f26ac2c 100644 --- a/frontend/src/stores/platforms.ts +++ b/frontend/src/stores/platforms.ts @@ -38,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 new file mode 100644 index 000000000..3eb467a10 --- /dev/null +++ b/frontend/src/v2/views/PlatformsIndex.test.ts @@ -0,0 +1,127 @@ +/* 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"; +import { defineComponent, ref } from "vue"; +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: { type: String, default: "" } }, + 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: { type: String, default: "" }, + romCount: { type: Number, default: 0 }, + }, + template: + '
{{ displayName }} {{ romCount }}
', + }), +})); + +vi.mock("@/v2/components/Platforms/PlatformTile.vue", () => ({ + default: defineComponent({ + props: { + displayName: { type: String, default: "" }, + romCount: { type: Number, default: 0 }, + }, + template: + '
{{ displayName }} {{ romCount }}
', + }), +})); + +vi.mock("@/v2/components/shared/EmptyState.vue", () => ({ + default: defineComponent({ + props: { message: { type: String, default: "" } }, + template: '
{{ message }}
', + }), +})); + +vi.mock("@/v2/components/shared/IndexShell.vue", () => ({ + default: defineComponent({ + template: + '
', + }), +})); + +vi.mock("@/v2/components/shared/PageHeader.vue", () => ({ + default: defineComponent({ + props: { + title: { type: String, default: "" }, + count: { type: Number, default: 0 }, + }, + 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..5ceb2796e 100644 --- a/frontend/src/v2/views/PlatformsIndex.vue +++ b/frontend/src/v2/views/PlatformsIndex.vue @@ -41,7 +41,7 @@ import { useWrapGridNav } from "@/v2/composables/useWrapGridNav"; const { t } = useI18n(); const platformsStore = storePlatforms(); -const { filledPlatforms, fetchingPlatforms } = storeToRefs(platformsStore); +const { allPlatforms, fetchingPlatforms } = storeToRefs(platformsStore); const { groupBy, layout } = useGalleryMode(); useGalleryViewModeUrl(); @@ -61,7 +61,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 allPlatforms.value) map.set(p.id, fn(p.slug)); return map; }); @@ -201,8 +201,8 @@ onMounted(() => { const filtered = computed(() => { const term = searchTerm.value.trim().toLowerCase(); - if (!term) return filledPlatforms.value; - return filledPlatforms.value.filter((p) => + if (!term) return allPlatforms.value; + return allPlatforms.value.filter((p) => p.display_name.toLowerCase().includes(term), ); }); @@ -222,7 +222,7 @@ const sortedForList = computed(() => { ); }); -const totalCount = computed(() => filledPlatforms.value.length); +const totalCount = computed(() => allPlatforms.value.length); const noResults = computed( () => !fetchingPlatforms.value &&