You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.8 KiB
69 lines
1.8 KiB
import { describe, expect, it } from "vitest";
|
|
import {
|
|
isChajiaModuleId,
|
|
moduleToHubRoute,
|
|
parseChajiaPostMessage,
|
|
} from "@/lib/embed/host-bridge";
|
|
|
|
describe("host-bridge postMessage protocol", () => {
|
|
it("parse 合法信封", () => {
|
|
const msg = parseChajiaPostMessage({
|
|
source: "chajia",
|
|
version: 1,
|
|
type: "chajia:fill",
|
|
module: "MS_GUEST",
|
|
request_id: "r1",
|
|
payload: { form: { pallet_count: 2 } },
|
|
});
|
|
expect(msg?.type).toBe("chajia:fill");
|
|
expect(msg?.module).toBe("MS_GUEST");
|
|
expect(msg?.request_id).toBe("r1");
|
|
});
|
|
|
|
it("拒绝非 chajia 来源", () => {
|
|
expect(
|
|
parseChajiaPostMessage({ source: "other", version: 1, type: "chajia:fill" }),
|
|
).toBeNull();
|
|
});
|
|
|
|
it("moduleToHubRoute 四模块", () => {
|
|
expect(moduleToHubRoute("MS_GUEST")).toEqual({
|
|
provider: "mothership",
|
|
mode: "anon",
|
|
});
|
|
expect(moduleToHubRoute("MS_LOGGED_IN")).toEqual({
|
|
provider: "mothership",
|
|
mode: "login",
|
|
});
|
|
expect(moduleToHubRoute("FLOCK_GUEST")).toEqual({
|
|
provider: "flock",
|
|
mode: "anon",
|
|
});
|
|
expect(moduleToHubRoute("FLOCK_LOGGED_IN")).toEqual({
|
|
provider: "flock",
|
|
mode: "login",
|
|
});
|
|
});
|
|
|
|
it("parse 宿主 scroll-quotes", () => {
|
|
const msg = parseChajiaPostMessage({
|
|
source: "chajia",
|
|
version: 1,
|
|
type: "chajia:scroll-quotes",
|
|
});
|
|
expect(msg?.type).toBe("chajia:scroll-quotes");
|
|
});
|
|
|
|
it("parse iframe scroll-top", () => {
|
|
const msg = parseChajiaPostMessage({
|
|
source: "chajia",
|
|
version: 1,
|
|
type: "chajia:scroll-top",
|
|
module: "MS_LOGGED_IN",
|
|
payload: { reason: "logged-in-details" },
|
|
});
|
|
expect(msg?.type).toBe("chajia:scroll-top");
|
|
expect(msg?.module).toBe("MS_LOGGED_IN");
|
|
});
|
|
});
|