mirror of
https://github.com/rommapp/romm.git
synced 2026-12-02 18:18:47 +01:00
pr-ready step 3: simplify save/state stories
- Provide the app event bus in the Storybook preview, like the app does, instead of per story. - Drop SaveDataTab's mount gate: useSubtabQuery follows the route, and the meta play already waits for the subtab. Share mine/theirs filters. - Let AssetChips and AssetActions stories render from args. - Drop the single-caller withScreenshots flag and the unused STORY_NOW export, and route the static strip tile query through the plays module. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import "@mdi/font/css/materialdesignicons.css";
|
||||
import { withThemeByClassName } from "@storybook/addon-themes";
|
||||
import { setup, type Preview } from "@storybook/vue3-vite";
|
||||
import mitt from "mitt";
|
||||
import { createPinia } from "pinia";
|
||||
import { createMemoryHistory, createRouter } from "vue-router";
|
||||
import { createVuetify } from "vuetify";
|
||||
@@ -10,6 +11,7 @@ import storePermissions from "../src/stores/permissions";
|
||||
import "../src/styles/common.css";
|
||||
import "../src/styles/fonts.css";
|
||||
import { dark, light } from "../src/styles/themes";
|
||||
import type { Events } from "../src/types/emitter";
|
||||
import { installBreakpointAttribute } from "../src/v2/composables/useBreakpoint";
|
||||
import { ChromeLabelsKey } from "../src/v2/lib/a11y/chromeLabels";
|
||||
import "../src/v2/styles/global.css";
|
||||
@@ -41,6 +43,8 @@ setup((app) => {
|
||||
// Stories exercise the same injected-label path as the app, so a
|
||||
// primitive rendering an un-translated label fails here too.
|
||||
app.provide(ChromeLabelsKey, createChromeLabels());
|
||||
// Snackbar and confirm composables inject the app-wide event bus.
|
||||
app.provide("emitter", mitt<Events>());
|
||||
// A catch-all router so primitives that render real `<router-link>`s
|
||||
// (RBtn / RListItem / RMenuItem with `to`) resolve a proper `href`
|
||||
// instead of crashing on `router.resolve`. Any string path resolves.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
||||
import { expect, within } from "storybook/test";
|
||||
import { makeSave, makeState } from "@/v2/utils/saveStates.fixtures";
|
||||
import { downloadButtons } from "@/v2/utils/saveStates.plays";
|
||||
import AssetActions from "./AssetActions.vue";
|
||||
|
||||
const meta: Meta<typeof AssetActions> = {
|
||||
@@ -27,19 +28,13 @@ type Story = StoryObj<typeof AssetActions>;
|
||||
|
||||
export const OwnSave: Story = {
|
||||
name: "Own · save",
|
||||
render: () => ({
|
||||
components: { AssetActions },
|
||||
setup() {
|
||||
return { asset: makeSave(1, "autosave", 1) };
|
||||
},
|
||||
template: `<AssetActions :asset="asset" type="save" own />`,
|
||||
}),
|
||||
args: { asset: makeSave(1, "autosave", 1), type: "save", own: true },
|
||||
play: async ({ canvasElement, step }) => {
|
||||
const ui = within(canvasElement);
|
||||
await step(
|
||||
"own save gets download, edit, favorite and delete",
|
||||
async () => {
|
||||
expect(ui.getByRole("button", { name: /^Download /i })).toBeTruthy();
|
||||
expect(downloadButtons(canvasElement)).toHaveLength(1);
|
||||
expect(ui.getByRole("button", { name: "Edit save" })).toBeTruthy();
|
||||
expect(
|
||||
ui.getByRole("button", { name: "Add to favorites" }),
|
||||
@@ -52,13 +47,11 @@ export const OwnSave: Story = {
|
||||
|
||||
export const OwnFavoriteState: Story = {
|
||||
name: "Own · favorite state",
|
||||
render: () => ({
|
||||
components: { AssetActions },
|
||||
setup() {
|
||||
return { asset: makeState({ id: 2, is_favorite: true }) };
|
||||
},
|
||||
template: `<AssetActions :asset="asset" type="state" own />`,
|
||||
}),
|
||||
args: {
|
||||
asset: makeState({ id: 2, is_favorite: true }),
|
||||
type: "state",
|
||||
own: true,
|
||||
},
|
||||
play: async ({ canvasElement, step }) => {
|
||||
const ui = within(canvasElement);
|
||||
await step("favorite state offers to remove it", async () => {
|
||||
@@ -73,28 +66,21 @@ export const OwnFavoriteState: Story = {
|
||||
|
||||
export const OwnFavoriting: Story = {
|
||||
name: "Own · favoriting",
|
||||
render: () => ({
|
||||
components: { AssetActions },
|
||||
setup() {
|
||||
return { asset: makeSave(3, "speedrun", 3) };
|
||||
},
|
||||
template: `<AssetActions :asset="asset" type="save" own favoriting />`,
|
||||
}),
|
||||
args: {
|
||||
asset: makeSave(3, "speedrun", 3),
|
||||
type: "save",
|
||||
own: true,
|
||||
favoriting: true,
|
||||
},
|
||||
};
|
||||
|
||||
export const Community: Story = {
|
||||
name: "Community · download only",
|
||||
render: () => ({
|
||||
components: { AssetActions },
|
||||
setup() {
|
||||
return { asset: makeState({ id: 4 }) };
|
||||
},
|
||||
template: `<AssetActions :asset="asset" type="state" />`,
|
||||
}),
|
||||
args: { asset: makeState({ id: 4 }), type: "state" },
|
||||
play: async ({ canvasElement, step }) => {
|
||||
const ui = within(canvasElement);
|
||||
await step("community item is download-only", async () => {
|
||||
expect(ui.getByRole("button", { name: /^Download /i })).toBeTruthy();
|
||||
expect(downloadButtons(canvasElement)).toHaveLength(1);
|
||||
expect(ui.queryByRole("button", { name: /^Edit /i })).toBeNull();
|
||||
expect(ui.queryByRole("button", { name: /favorites$/i })).toBeNull();
|
||||
expect(ui.queryByRole("button", { name: /^Delete /i })).toBeNull();
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
||||
import mitt from "mitt";
|
||||
import { expect, waitFor, within } from "storybook/test";
|
||||
import { provide, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import type { DetailedRomSchema } from "@/__generated__";
|
||||
import storeAuth from "@/stores/auth";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import { userFixture } from "@/utils/user.fixtures";
|
||||
import {
|
||||
mixedCommunitySaves,
|
||||
@@ -25,6 +22,12 @@ interface StoryArgs {
|
||||
rom: DetailedRomSchema;
|
||||
}
|
||||
|
||||
const MY_USER_ID = userFixture().id;
|
||||
const mine = <T extends { user_id: number }>(xs: T[]) =>
|
||||
xs.filter((x) => x.user_id === MY_USER_ID);
|
||||
const theirs = <T extends { user_id: number }>(xs: T[]) =>
|
||||
xs.filter((x) => x.user_id !== MY_USER_ID);
|
||||
|
||||
const MINE_HEADING: Record<Subtab, string> = {
|
||||
saves: "My saves",
|
||||
states: "My states",
|
||||
@@ -53,14 +56,11 @@ const meta: Meta<StoryArgs> = {
|
||||
render: (args) => ({
|
||||
components: { SaveDataTab },
|
||||
setup() {
|
||||
provide("emitter", mitt<Events>());
|
||||
storeAuth().setCurrentUser(userFixture({ username: "player" }));
|
||||
// SaveDataTab reads `?subtab=` during setup, so mount it after navigating.
|
||||
const ready = ref(false);
|
||||
void useRouter()
|
||||
.replace({ query: { tab: "save-data", subtab: args.subtab } })
|
||||
.then(() => (ready.value = true));
|
||||
return { rom: args.rom, ready };
|
||||
void useRouter().replace({
|
||||
query: { tab: "save-data", subtab: args.subtab },
|
||||
});
|
||||
return { rom: args.rom };
|
||||
},
|
||||
template: `
|
||||
<div style="
|
||||
@@ -70,12 +70,11 @@ const meta: Meta<StoryArgs> = {
|
||||
padding: var(--r-space-4);
|
||||
background: var(--r-color-bg);
|
||||
">
|
||||
<SaveDataTab v-if="ready" :rom="rom" style="height: min(720px, 85vh);" />
|
||||
<SaveDataTab :rom="rom" style="height: min(720px, 85vh);" />
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
// The mount lands after navigating, so every story waits for it before the
|
||||
// a11y scan runs.
|
||||
// Navigation is async, so every story waits for the subtab before the a11y scan.
|
||||
play: async ({ canvasElement, args }) => {
|
||||
await waitForSubtab(canvasElement, args.subtab);
|
||||
},
|
||||
@@ -109,9 +108,8 @@ export const StatesFull: Story = {
|
||||
export const SavesEmptyMine: Story = {
|
||||
name: "Saves · empty mine",
|
||||
args: {
|
||||
subtab: "saves",
|
||||
rom: storyDetailedRom({
|
||||
all_user_saves: mixedCommunitySaves().filter((s) => s.user_id !== 1),
|
||||
all_user_saves: theirs(mixedCommunitySaves()),
|
||||
}),
|
||||
},
|
||||
play: async ({ canvasElement, step }) => {
|
||||
@@ -127,7 +125,7 @@ export const StatesEmptyMine: Story = {
|
||||
args: {
|
||||
subtab: "states",
|
||||
rom: storyDetailedRom({
|
||||
all_user_states: mixedCommunityStates().filter((s) => s.user_id !== 1),
|
||||
all_user_states: theirs(mixedCommunityStates()),
|
||||
}),
|
||||
},
|
||||
};
|
||||
@@ -135,9 +133,8 @@ export const StatesEmptyMine: Story = {
|
||||
export const SavesMineOnly: Story = {
|
||||
name: "Saves · mine only (no community)",
|
||||
args: {
|
||||
subtab: "saves",
|
||||
rom: storyDetailedRom({
|
||||
all_user_saves: mixedCommunitySaves().filter((s) => s.user_id === 1),
|
||||
all_user_saves: mine(mixedCommunitySaves()),
|
||||
}),
|
||||
},
|
||||
};
|
||||
@@ -147,7 +144,7 @@ export const StatesMineOnly: Story = {
|
||||
args: {
|
||||
subtab: "states",
|
||||
rom: storyDetailedRom({
|
||||
all_user_states: mixedCommunityStates().filter((s) => s.user_id === 1),
|
||||
all_user_states: mine(mixedCommunityStates()),
|
||||
}),
|
||||
},
|
||||
};
|
||||
@@ -155,7 +152,6 @@ export const StatesMineOnly: Story = {
|
||||
export const CompletelyEmpty: Story = {
|
||||
name: "Empty · no saves or states",
|
||||
args: {
|
||||
subtab: "saves",
|
||||
rom: storyDetailedRom({ all_user_saves: [], all_user_states: [] }),
|
||||
},
|
||||
};
|
||||
@@ -163,11 +159,8 @@ export const CompletelyEmpty: Story = {
|
||||
export const SingleCommunitySave: Story = {
|
||||
name: "Saves · single community save",
|
||||
args: {
|
||||
subtab: "saves",
|
||||
rom: storyDetailedRom({
|
||||
all_user_saves: mixedCommunitySaves()
|
||||
.filter((s) => s.user_id !== 1)
|
||||
.slice(0, 1),
|
||||
all_user_saves: theirs(mixedCommunitySaves()).slice(0, 1),
|
||||
}),
|
||||
},
|
||||
};
|
||||
@@ -177,9 +170,7 @@ export const SingleCommunityState: Story = {
|
||||
args: {
|
||||
subtab: "states",
|
||||
rom: storyDetailedRom({
|
||||
all_user_states: mixedCommunityStates()
|
||||
.filter((s) => s.user_id !== 1)
|
||||
.slice(0, 1),
|
||||
all_user_states: theirs(mixedCommunityStates()).slice(0, 1),
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -22,13 +22,7 @@ type Story = StoryObj<typeof AssetChips>;
|
||||
|
||||
export const Default: Story = {
|
||||
name: "Emulator + size",
|
||||
render: () => ({
|
||||
components: { AssetChips },
|
||||
setup() {
|
||||
return { asset: makeSave(1, "main_quest", 2) };
|
||||
},
|
||||
template: `<AssetChips :asset="asset" />`,
|
||||
}),
|
||||
args: { asset: makeSave(1, "main_quest", 2) },
|
||||
play: async ({ canvasElement, step }) => {
|
||||
await step("emulator tag and formatted size render", async () => {
|
||||
const ui = within(canvasElement);
|
||||
@@ -45,33 +39,15 @@ export const Latest: Story = {
|
||||
expect(within(canvasElement).getByText("Latest")).toBeTruthy();
|
||||
});
|
||||
},
|
||||
render: () => ({
|
||||
components: { AssetChips },
|
||||
setup() {
|
||||
return { asset: makeSave(1, "autosave", 1) };
|
||||
},
|
||||
template: `<AssetChips :asset="asset" latest />`,
|
||||
}),
|
||||
args: { asset: makeSave(1, "autosave", 1), latest: true },
|
||||
};
|
||||
|
||||
export const NoEmulator: Story = {
|
||||
name: "No emulator on asset",
|
||||
render: () => ({
|
||||
components: { AssetChips },
|
||||
setup() {
|
||||
return { asset: makeSave(1, null, 5, { emulator: null }) };
|
||||
},
|
||||
template: `<AssetChips :asset="asset" />`,
|
||||
}),
|
||||
args: { asset: makeSave(1, null, 5, { emulator: null }) },
|
||||
};
|
||||
|
||||
export const HideEmulatorChip: Story = {
|
||||
name: "showEmulator false",
|
||||
render: () => ({
|
||||
components: { AssetChips },
|
||||
setup() {
|
||||
return { asset: makeSave(1, "main_quest", 2) };
|
||||
},
|
||||
template: `<AssetChips :asset="asset" :show-emulator="false" />`,
|
||||
}),
|
||||
args: { asset: makeSave(1, "main_quest", 2), showEmulator: false },
|
||||
};
|
||||
|
||||
@@ -10,7 +10,11 @@ import {
|
||||
mixedCommunityStates,
|
||||
screenshotFixture,
|
||||
} from "@/v2/utils/saveStates.fixtures";
|
||||
import { downloadButtons, stripTiles } from "@/v2/utils/saveStates.plays";
|
||||
import {
|
||||
downloadButtons,
|
||||
manageStripTiles,
|
||||
stripTiles,
|
||||
} from "@/v2/utils/saveStates.plays";
|
||||
import AssetStrip from "./AssetStrip.vue";
|
||||
|
||||
const meta: Meta<typeof AssetStrip> = {
|
||||
@@ -121,7 +125,7 @@ export const ManyStatesList: Story = {
|
||||
export const StatesNoScreenshots: Story = {
|
||||
name: "States · 6 without screenshots",
|
||||
render: () => {
|
||||
const states = manyStates(6, false);
|
||||
const states = manyStates(6).map((s) => ({ ...s, screenshot: null }));
|
||||
return selectableStrip(states, states[2].id);
|
||||
},
|
||||
};
|
||||
@@ -247,9 +251,7 @@ export const ManageFlowGrouped: Story = {
|
||||
expect(ui.getByRole("button", { name: /snes9x/i })).toBeTruthy();
|
||||
});
|
||||
await step("static tiles host per-item actions", async () => {
|
||||
const staticTiles = canvasElement.querySelectorAll(
|
||||
".r-asset-strip__tile--static",
|
||||
);
|
||||
const staticTiles = manageStripTiles(canvasElement);
|
||||
expect(staticTiles.length).toBeGreaterThan(0);
|
||||
expect(downloadButtons(canvasElement).length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ import type {
|
||||
import { saveFixture, stateFixture } from "@/utils/assets.fixtures";
|
||||
import { makeDetailedRom } from "@/utils/rom.fixtures";
|
||||
|
||||
export const STORY_NOW = new Date("2026-05-25T20:00:00Z").getTime();
|
||||
const STORY_NOW = new Date("2026-05-25T20:00:00Z").getTime();
|
||||
const HOUR = 3600 * 1000;
|
||||
const WRITTEN_AT = "2026-05-13T22:08:00Z";
|
||||
|
||||
@@ -134,7 +134,7 @@ const stateShots: { color: string; label: string }[] = [
|
||||
{ color: "5a5a0a", label: "Tower" },
|
||||
];
|
||||
|
||||
export function manyStates(n: number, withScreenshots = true): StateSchema[] {
|
||||
export function manyStates(n: number): StateSchema[] {
|
||||
const deltas = [
|
||||
2 * 3600,
|
||||
5 * 3600,
|
||||
@@ -158,12 +158,10 @@ export function manyStates(n: number, withScreenshots = true): StateSchema[] {
|
||||
file_size_bytes: 256 * 1024 + i * 73 * 1024,
|
||||
created_at: at,
|
||||
updated_at: at,
|
||||
screenshot: withScreenshots
|
||||
? screenshotFixture(
|
||||
`https://placehold.co/640x360/${shot.color}/ffffff?text=${shot.label}`,
|
||||
i + 1,
|
||||
)
|
||||
: null,
|
||||
screenshot: screenshotFixture(
|
||||
`https://placehold.co/640x360/${shot.color}/ffffff?text=${shot.label}`,
|
||||
i + 1,
|
||||
),
|
||||
emulator: i % 3 === 0 ? "snes9x" : i % 3 === 1 ? "mesen" : null,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,6 +19,12 @@ export function stripTiles(root: HTMLElement): HTMLElement[] {
|
||||
return Array.from(root.querySelectorAll<HTMLElement>(".r-asset-strip__tile"));
|
||||
}
|
||||
|
||||
export function manageStripTiles(root: HTMLElement): HTMLElement[] {
|
||||
return Array.from(
|
||||
root.querySelectorAll<HTMLElement>(".r-asset-strip__tile--static"),
|
||||
);
|
||||
}
|
||||
|
||||
export function downloadButtons(root: HTMLElement) {
|
||||
return within(root).getAllByRole("button", { name: /^Download /i });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user