refactor(routes): move shared pages to global scope
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
buildGlobalPageUrl,
|
||||
resolveGlobalRouteContext,
|
||||
resolveGlobalRouteContextValue,
|
||||
} from "../global-route-context";
|
||||
import { ROUTES } from "../routes";
|
||||
|
||||
describe("global route context", () => {
|
||||
it("preserves a known character chat as the return target", () => {
|
||||
const context = resolveGlobalRouteContext("/characters/maya/chat");
|
||||
|
||||
expect(context).toMatchObject({
|
||||
characterSlug: "maya",
|
||||
chatUrl: "/characters/maya/chat",
|
||||
splashUrl: "/characters/maya/splash",
|
||||
});
|
||||
expect(context.sidebarUrl).toBe(
|
||||
"/sidebar?returnTo=%2Fcharacters%2Fmaya%2Fchat",
|
||||
);
|
||||
expect(context.feedbackUrl).toBe(
|
||||
"/feedback?returnTo=%2Fcharacters%2Fmaya%2Fchat",
|
||||
);
|
||||
expect(context.coinsRulesUrl).toBe(
|
||||
"/coins-rules?returnTo=%2Fcharacters%2Fmaya%2Fchat",
|
||||
);
|
||||
});
|
||||
|
||||
it("uses only the first repeated return target", () => {
|
||||
expect(
|
||||
resolveGlobalRouteContextValue([
|
||||
"/characters/nayeli/chat",
|
||||
"/characters/maya/chat",
|
||||
]),
|
||||
).toBe("/characters/nayeli/chat");
|
||||
});
|
||||
|
||||
it.each([
|
||||
undefined,
|
||||
null,
|
||||
"",
|
||||
"https://example.com/characters/maya/chat",
|
||||
"//example.com/characters/maya/chat",
|
||||
"/characters/unknown/chat",
|
||||
"/characters/maya/private-room",
|
||||
"/characters/maya/chat?image=1",
|
||||
])("falls back to Elio for an invalid return target", (value) => {
|
||||
expect(resolveGlobalRouteContextValue(value)).toBe(
|
||||
"/characters/elio/chat",
|
||||
);
|
||||
});
|
||||
|
||||
it("sanitizes return targets when building a global page url", () => {
|
||||
expect(buildGlobalPageUrl(ROUTES.sidebar, "https://example.com")).toBe(
|
||||
"/sidebar?returnTo=%2Fcharacters%2Felio%2Fchat",
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user