From 5cffecf13565d129ae39cc0ca6add3624978f9fd Mon Sep 17 00:00:00 2001 From: Sam Dornan Date: Mon, 9 Nov 2026 07:59:21 -0600 Subject: [PATCH] test(frontend): add BottomNav stories (#5528) --- .../components/AppShell/BottomNav.stories.ts | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 frontend/src/components/AppShell/BottomNav.stories.ts diff --git a/frontend/src/components/AppShell/BottomNav.stories.ts b/frontend/src/components/AppShell/BottomNav.stories.ts new file mode 100644 index 000000000..175cd4234 --- /dev/null +++ b/frontend/src/components/AppShell/BottomNav.stories.ts @@ -0,0 +1,109 @@ +import type { Decorator, Meta, StoryObj } from "@storybook/vue3-vite"; +import { expect, userEvent, waitFor, within } from "storybook/test"; +import { onMounted, onUnmounted } from "vue"; +import { useRouter } from "vue-router"; +import BottomNav from "./BottomNav.vue"; + +// A colourful backdrop so the glass blur and saturation have something to show. +const backdrop: Decorator = () => ({ + template: ` +
+
+
+
+
+
+ +
`, +}); + +function atRoute(path: string): Decorator { + return () => ({ + setup() { + const router = useRouter(); + onMounted(() => router.push(path)); + }, + template: "", + }); +} + +const reducedMotion: Decorator = () => ({ + setup() { + const html = document.documentElement; + onMounted(() => html.classList.add("r-reduced-motion")); + onUnmounted(() => html.classList.remove("r-reduced-motion")); + }, + template: "", +}); + +const meta: Meta = { + title: "AppShell/BottomNav", + component: BottomNav, + decorators: [backdrop], + parameters: { layout: "fullscreen" }, + globals: { viewport: { value: "rommPhoneXs" } }, +}; + +export default meta; +type Story = StoryObj; + +const tab = (canvasElement: HTMLElement, name: string) => + within(canvasElement).getByRole("link", { name }); + +export const Default: Story = { + decorators: [atRoute("/")], + play: async ({ canvasElement, step }) => { + await step("Home is active and shows its filled glyph", async () => { + await waitFor(() => + expect(tab(canvasElement, "Home")).toHaveClass( + "r-segmented-control__btn--active", + ), + ); + await expect( + tab(canvasElement, "Home").querySelector(".mdi-home"), + ).not.toBeNull(); + }); + + await step("Tapping Collections moves the selection", async () => { + await userEvent.click(tab(canvasElement, "Collections")); + await waitFor(() => + expect(tab(canvasElement, "Collections")).toHaveClass( + "r-segmented-control__btn--active", + ), + ); + await expect( + tab(canvasElement, "Collections").querySelector(".mdi-bookmark"), + ).not.toBeNull(); + await expect( + tab(canvasElement, "Home").querySelector(".mdi-home-outline"), + ).not.toBeNull(); + }); + }, +}; + +export const PlatformsActive: Story = { + decorators: [atRoute("/platforms")], +}; + +export const Light: Story = { + decorators: [atRoute("/")], + globals: { theme: "light" }, +}; + +export const SmallPhone: Story = { + decorators: [atRoute("/search")], + globals: { viewport: { value: "mobile1" } }, +}; + +export const KeyboardFocus: Story = { + decorators: [atRoute("/")], + globals: { input: "key" }, + play: async ({ canvasElement }) => { + tab(canvasElement, "Platforms").focus(); + await expect(tab(canvasElement, "Platforms")).toHaveFocus(); + }, +}; + +export const ReducedMotion: Story = { + decorators: [reducedMotion, atRoute("/")], +};