From 07b193c3ffde726b13c9dde73bb2e8ea7ab9a60a Mon Sep 17 00:00:00 2001 From: Sam Dornan Date: Sun, 15 Nov 2026 17:26:10 -0600 Subject: [PATCH] fix(frontend): follow bottom-nav taps made while a view transition runs (#5605) --- .../src/components/AppShell/BottomNav.test.ts | 81 ++++++++++++++++++- .../src/components/AppShell/BottomNav.vue | 53 ++++++++++-- frontend/src/test-utils/viewTransition.ts | 10 +++ 3 files changed, 135 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/AppShell/BottomNav.test.ts b/frontend/src/components/AppShell/BottomNav.test.ts index 008321a68..2d0fd1d18 100644 --- a/frontend/src/components/AppShell/BottomNav.test.ts +++ b/frontend/src/components/AppShell/BottomNav.test.ts @@ -1,7 +1,12 @@ import { mount } from "@vue/test-utils"; -import { describe, expect, it, vi } from "vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; import { defineComponent, ref } from "vue"; +import { + popEscapable, + pushEscapable, +} from "@/lib/overlays/RDialog/escapeStack"; import { dropSupersededSkip, isTransitionSkipped } from "@/plugins/transition"; +import { stubActiveViewTransition } from "@/test-utils/viewTransition"; import BottomNav from "./BottomNav.vue"; type Target = { fullPath: string }; @@ -10,11 +15,13 @@ const hooks: { after: ((to: Target) => void) | null; onError: ((error: unknown, to: Target) => void) | null; } = { before: null, after: null, onError: null }; +const pushed: string[] = []; vi.mock("vue-i18n"); vi.mock("vue-router", () => ({ useRoute: () => ({ path: "/collections" }), useRouter: () => ({ + push: (to: string) => pushed.push(to), beforeEach: (fn: (to: Target) => void) => { hooks.before = fn; return () => {}; @@ -46,10 +53,28 @@ const RouterLink = defineComponent({ }); function mountNav() { - return mount(BottomNav, { global: { stubs: { RouterLink } } }); + return mount(BottomNav, { + attachTo: document.body, + global: { stubs: { RouterLink } }, + }); +} + +// Taps on where a view transition sends them, at the centre of `el`. +function tapRootOver(el: Element | undefined) { + vi.spyOn(el!, "getBoundingClientRect").mockReturnValue( + new DOMRect(100, 700, 80, 52), + ); + document.documentElement.dispatchEvent( + new MouseEvent("click", { bubbles: true, clientX: 140, clientY: 726 }), + ); } describe("BottomNav", () => { + afterEach(() => { + delete (document as { activeViewTransition?: unknown }) + .activeViewTransition; + }); + it("uses the filled glyph on every tab", () => { const wrapper = mountNav(); const icons = wrapper.findAll(".r-icon").map((i) => i.classes()); @@ -190,4 +215,56 @@ describe("BottomNav", () => { expect(tabs[2]?.classes()).toContain("r-segmented-control__btn--active"); }); + + it("follows a tab tap that a running view transition sent to ", async () => { + const wrapper = mountNav(); + const tabs = wrapper.findAll(".r-segmented-control__btn"); + const skipTransition = stubActiveViewTransition(); + pushed.length = 0; + + tapRootOver(tabs[1]?.element); + await wrapper.vm.$nextTick(); + + expect(skipTransition).toHaveBeenCalledOnce(); + expect(pushed).toEqual(["/platforms"]); + expect(isTransitionSkipped({ fullPath: "/platforms" })).toBe(true); + expect(tabs[1]?.classes()).toContain("r-segmented-control__btn--active"); + dropSupersededSkip({ fullPath: "/elsewhere" }); + wrapper.unmount(); + }); + + it("ignores a tap on outside every tab", () => { + const wrapper = mountNav(); + const skipTransition = stubActiveViewTransition(); + pushed.length = 0; + + document.documentElement.dispatchEvent( + new MouseEvent("click", { bubbles: true, clientX: 5, clientY: 5 }), + ); + + expect(skipTransition).not.toHaveBeenCalled(); + expect(pushed).toEqual([]); + wrapper.unmount(); + }); + + it("leaves a tap over a tab to the overlay covering the bar", () => { + const wrapper = mountNav(); + const tabs = wrapper.findAll(".r-segmented-control__btn"); + const skipTransition = stubActiveViewTransition(); + const panel = document.createElement("div"); + const sheet = { close: vi.fn(), persistent: true, panel: () => panel }; + pushEscapable(sheet); + pushed.length = 0; + + try { + tapRootOver(tabs[1]?.element); + } finally { + popEscapable(sheet); + } + + expect(pushed).toEqual([]); + expect(skipTransition).not.toHaveBeenCalled(); + expect(sheet.close).not.toHaveBeenCalled(); + wrapper.unmount(); + }); }); diff --git a/frontend/src/components/AppShell/BottomNav.vue b/frontend/src/components/AppShell/BottomNav.vue index 43133ecb3..b84df8e80 100644 --- a/frontend/src/components/AppShell/BottomNav.vue +++ b/frontend/src/components/AppShell/BottomNav.vue @@ -1,6 +1,7 @@