mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 02:22:44 +01:00
Merge pull request #3945 from SaveEditors/fix-empty-platforms-reachable
Show empty platforms in platform index
This commit is contained in:
31
frontend/src/stores/platforms.test.ts
Normal file
31
frontend/src/stores/platforms.test.ts
Normal file
@@ -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]);
|
||||
});
|
||||
});
|
||||
@@ -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<Platform[]> {
|
||||
|
||||
127
frontend/src/v2/views/PlatformsIndex.test.ts
Normal file
127
frontend/src/v2/views/PlatformsIndex.test.ts
Normal file
@@ -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: "<hr />" }),
|
||||
RLetterHeading: defineComponent({
|
||||
props: { label: { type: String, default: "" } },
|
||||
template: "<h2>{{ label }}</h2>",
|
||||
}),
|
||||
RSkeletonBlock: defineComponent({ template: "<div />" }),
|
||||
}));
|
||||
|
||||
vi.mock("@/v2/components/Gallery/GalleryToolbar.vue", () => ({
|
||||
default: defineComponent({ template: "<div />" }),
|
||||
}));
|
||||
|
||||
vi.mock("@/v2/components/Platforms/PlatformListHeader.vue", () => ({
|
||||
default: defineComponent({ template: "<div />" }),
|
||||
}));
|
||||
|
||||
vi.mock("@/v2/components/Platforms/PlatformListRow.vue", () => ({
|
||||
default: defineComponent({
|
||||
props: {
|
||||
displayName: { type: String, default: "" },
|
||||
romCount: { type: Number, default: 0 },
|
||||
},
|
||||
template:
|
||||
'<div class="platform-row">{{ displayName }} {{ romCount }}</div>',
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@/v2/components/Platforms/PlatformTile.vue", () => ({
|
||||
default: defineComponent({
|
||||
props: {
|
||||
displayName: { type: String, default: "" },
|
||||
romCount: { type: Number, default: 0 },
|
||||
},
|
||||
template:
|
||||
'<div class="platform-tile">{{ displayName }} {{ romCount }}</div>',
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@/v2/components/shared/EmptyState.vue", () => ({
|
||||
default: defineComponent({
|
||||
props: { message: { type: String, default: "" } },
|
||||
template: '<div class="empty-state">{{ message }}</div>',
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@/v2/components/shared/IndexShell.vue", () => ({
|
||||
default: defineComponent({
|
||||
template:
|
||||
'<main><slot name="header" /><slot name="toolbar" /><slot name="listHeader" /><slot /></main>',
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@/v2/components/shared/PageHeader.vue", () => ({
|
||||
default: defineComponent({
|
||||
props: {
|
||||
title: { type: String, default: "" },
|
||||
count: { type: Number, default: 0 },
|
||||
},
|
||||
template: "<header>{{ title }} {{ count }}</header>",
|
||||
}),
|
||||
}));
|
||||
|
||||
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");
|
||||
});
|
||||
});
|
||||
@@ -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<number | string, boolean>();
|
||||
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<Platform[]>(() => {
|
||||
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<Platform[]>(() => {
|
||||
);
|
||||
});
|
||||
|
||||
const totalCount = computed(() => filledPlatforms.value.length);
|
||||
const totalCount = computed(() => allPlatforms.value.length);
|
||||
const noResults = computed(
|
||||
() =>
|
||||
!fetchingPlatforms.value &&
|
||||
|
||||
Reference in New Issue
Block a user