Files
persionalBrand/apps/admin/test/template-preview.test.mjs

34 lines
1.2 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import { templatePreviewUrl } from "../src/lib/template-preview.ts";
test("template preview URL is resolved from one shared deployment address", () => {
const url = templatePreviewUrl(
"brand-a",
"profile",
"https://preview.example.test/app/",
"https://admin.example.test",
"/pages/profile/index",
);
assert.equal(
url,
"https://preview.example.test/app/?editor=1&parentOrigin=https%3A%2F%2Fadmin.example.test&brand=brand-a#/pages/profile/index",
);
});
test("the shared same-origin preview address is the default", () => {
assert.equal(
templatePreviewUrl("brand-a", "home", undefined),
"http://localhost:3002/?editor=1&brand=brand-a#/pages/home/index",
);
assert.equal(templatePreviewUrl("brand-a", "home", "{"), undefined);
assert.equal(templatePreviewUrl("brand-a", "home", "not a URL"), undefined);
});
test("same-origin static preview uses its explicit entry document", () => {
assert.equal(
templatePreviewUrl("brand-a", "home", "/template-preview/index.html", "http://localhost:3005"),
"http://localhost:3005/template-preview/index.html?editor=1&parentOrigin=http%3A%2F%2Flocalhost%3A3005&brand=brand-a#/pages/home/index",
);
});