@panomc/theme-core 1.0.0-dev.60 → 1.0.0-dev.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/css/pano-fallback-legacy.css +12381 -0
- package/assets/css/pano-fallback.css +3222 -0
- package/bin/__tests__/check/fixtures/plugin-contracts/market/controllers.json +4 -0
- package/bin/__tests__/check/fixtures/plugin-contracts/market/views.json +67 -0
- package/bin/__tests__/check/fixtures/routes.json +5 -0
- package/bin/__tests__/check/helpers.js +55 -0
- package/bin/__tests__/check/overrides.test.js +287 -0
- package/bin/__tests__/check/theme.test.js +332 -0
- package/bin/__tests__/cli/accept-and-list.test.js +159 -0
- package/bin/__tests__/cli/config-edit.test.js +213 -0
- package/bin/__tests__/cli/contracts-pull.test.js +187 -0
- package/bin/__tests__/cli/core-meta.test.js +305 -0
- package/bin/__tests__/cli/eject-view.test.js +356 -0
- package/bin/__tests__/cli/helpers.js +258 -0
- package/bin/__tests__/scaffold/scaffold.test.js +84 -0
- package/bin/bundle-internal-libs.js +14 -2
- package/bin/check.js +1150 -213
- package/bin/contracts.js +1643 -0
- package/bin/generate-contract.js +378 -0
- package/bin/generate-licenses.js +14 -2
- package/bin/generate-runtime-shims.js +27 -9
- package/bin/new.js +101 -2
- package/bin/package-zip.js +16 -2
- package/bin/sync.js +360 -7
- package/bin/theme-core.js +65 -107
- package/lang/en-US.json +1 -0
- package/lang/ru.json +1 -0
- package/lang/tr.json +1 -0
- package/package.json +8 -9
- package/skin-contract.json +864 -19
- package/src/kit/__tests__/hooks-server-fetch.test.js +56 -0
- package/src/kit/__tests__/route-map.test.js +154 -0
- package/src/kit/__tests__/theme-meta.test.js +249 -0
- package/src/kit/hooks-client.js +3 -0
- package/src/kit/hooks-server.js +79 -21
- package/src/kit/route-map.js +300 -0
- package/src/kit/specifiers.js +3 -62
- package/src/kit/svelte-config.js +3 -0
- package/src/kit/theme-meta.js +405 -0
- package/src/kit/vite-config.js +156 -12
- package/src/lib/NotificationManager.js +18 -0
- package/src/lib/PluginAPI.js +313 -9
- package/src/lib/Store.js +18 -5
- package/src/lib/__tests__/avatarVersion.test.js +25 -0
- package/src/lib/__tests__/check.test.js +201 -0
- package/src/lib/__tests__/controllerHost.test.js +363 -0
- package/src/lib/__tests__/cx03.test.js +245 -0
- package/src/lib/__tests__/engineBoot.test.js +151 -0
- package/src/lib/__tests__/engineParts.helper.js +284 -0
- package/src/lib/__tests__/engineParts.test.js +179 -0
- package/src/lib/__tests__/engineSidebars.helper.js +353 -0
- package/src/lib/__tests__/engineSidebars.test.js +273 -0
- package/src/lib/__tests__/engineStyles.test.js +227 -0
- package/src/lib/__tests__/engineWiring.test.js +1000 -0
- package/src/lib/__tests__/fallbackStyles.test.js +1254 -0
- package/src/lib/__tests__/fixtures/Probe.svelte +5 -0
- package/src/lib/__tests__/fixtures/engine-parts.ssr.json +29 -0
- package/src/lib/__tests__/fixtures/engine-sidebars.ssr.json +16 -0
- package/src/lib/__tests__/home.test.js +563 -0
- package/src/lib/__tests__/injectedScope.test.js +490 -0
- package/src/lib/__tests__/languageConcurrency.test.js +55 -0
- package/src/lib/__tests__/languageLayers.test.js +286 -0
- package/src/lib/__tests__/pageHead.test.js +167 -0
- package/src/lib/__tests__/pageMeta.util.test.js +216 -0
- package/src/lib/__tests__/pageTitle.util.test.js +96 -0
- package/src/lib/__tests__/pluginApiViews.test.js +529 -0
- package/src/lib/__tests__/plugins.test.js +53 -0
- package/src/lib/__tests__/profileNav.util.test.js +145 -0
- package/src/lib/__tests__/registryReady.test.js +26 -0
- package/src/lib/__tests__/returnTo.util.test.js +294 -0
- package/src/lib/__tests__/routeConfig.test.js +361 -0
- package/src/lib/__tests__/sidebarSpec.util.test.js +152 -0
- package/src/lib/__tests__/skinContract.test.js +558 -0
- package/src/lib/__tests__/svelteSsr.helper.js +68 -0
- package/src/lib/__tests__/tc03.test.js +427 -0
- package/src/lib/__tests__/tc11.test.js +184 -0
- package/src/lib/__tests__/translationLayers.test.js +161 -0
- package/src/lib/avatarVersion.js +39 -0
- package/src/lib/components/Breadcrumb.svelte +9 -40
- package/src/lib/components/Date.svelte +1 -1
- package/src/lib/components/DefaultToast.svelte +13 -3
- package/src/lib/components/FallbackLinks.svelte +28 -0
- package/src/lib/components/FallbackScope.svelte +24 -0
- package/src/lib/components/Footer.svelte +8 -8
- package/src/lib/components/Header.svelte +3 -3
- package/src/lib/components/Hook.svelte +12 -1
- package/src/lib/components/LoginFormBody.svelte +5 -5
- package/src/lib/components/Main.svelte +22 -47
- package/src/lib/components/Navbar.svelte +30 -29
- package/src/lib/components/NoContent.svelte +2 -2
- package/src/lib/components/NotificationContainer.svelte +31 -82
- package/src/lib/components/OnlineAdmins.svelte +3 -2
- package/src/lib/components/PageActions.svelte +1 -1
- package/src/lib/components/PageHead.svelte +50 -0
- package/src/lib/components/PageTitle.svelte +2 -2
- package/src/lib/components/Pagination.svelte +6 -6
- package/src/lib/components/PlayerHead.svelte +4 -4
- package/src/lib/components/PluginBlock.svelte +132 -0
- package/src/lib/components/PluginSlot.svelte +40 -0
- package/src/lib/components/Post.svelte +13 -230
- package/src/lib/components/Posts.svelte +7 -14
- package/src/lib/components/RegisterForm.svelte +12 -11
- package/src/lib/components/Sidebar.svelte +9 -7
- package/src/lib/components/TicketRow.svelte +8 -48
- package/src/lib/components/TicketStatus.svelte +10 -16
- package/src/lib/components/Tickets.svelte +8 -30
- package/src/lib/components/Toast.svelte +16 -14
- package/src/lib/components/ToastContainer.svelte +16 -9
- package/src/lib/components/ViewComponent.svelte +13 -1
- package/src/lib/components/modals/CloseTicketConfirmModal.svelte +15 -46
- package/src/lib/components/modals/ConfirmRemoveAllNotificationsModal.svelte +17 -39
- package/src/lib/components/modals/LogoutSessionConfirmModal.svelte +12 -30
- package/src/lib/components/sidebars/HomeSidebar.svelte +33 -284
- package/src/lib/components/sidebars/PlayerDetailSidebar.svelte +14 -63
- package/src/lib/components/sidebars/PluginSidebar.svelte +21 -0
- package/src/lib/components/sidebars/ProfileNavCard.svelte +24 -0
- package/src/lib/components/sidebars/ProfileSidebar.svelte +44 -84
- package/src/lib/components/sidebars/SupportSidebar.svelte +19 -22
- package/src/lib/components/sidebars/TicketCreateAndDetailSidebar.svelte +23 -35
- package/src/lib/components/sidebars/profileNav.util.js +105 -0
- package/src/lib/components/sidebars/sidebarSpec.util.js +92 -0
- package/src/lib/controllerHost.js +261 -0
- package/src/lib/fallbackStyles.js +317 -0
- package/src/lib/home.js +202 -0
- package/src/lib/language.util.js +70 -37
- package/src/lib/layouts/AppLayout.svelte +16 -8
- package/src/lib/layouts/AuthLayout.svelte +6 -4
- package/src/lib/layouts/MainLayout.svelte +17 -12
- package/src/lib/layouts/ProfileLayout.svelte +6 -4
- package/src/lib/layouts/ThemeSettingsLayout.svelte +6 -4
- package/src/lib/layouts/TicketsLayout.svelte +6 -5
- package/src/lib/pageMeta.util.js +212 -0
- package/src/lib/pageShape.js +33 -0
- package/src/lib/pageTitle.util.js +32 -0
- package/src/lib/pages/ActivateEmailPage.svelte +2 -7
- package/src/lib/pages/ConfirmNewEmailPage.svelte +2 -7
- package/src/lib/pages/ErrorPage.svelte +5 -2
- package/src/lib/pages/HomePage.svelte +31 -8
- package/src/lib/pages/LoginPage.svelte +38 -41
- package/src/lib/pages/NotificationsPage.svelte +2 -7
- package/src/lib/pages/PlayerDetailPage.svelte +2 -7
- package/src/lib/pages/PostDetailPage.svelte +2 -7
- package/src/lib/pages/PreviewPostPage.svelte +2 -7
- package/src/lib/pages/RegisterPage.svelte +10 -13
- package/src/lib/pages/RenewPasswordPage.svelte +2 -7
- package/src/lib/pages/ResetPasswordPage.svelte +2 -7
- package/src/lib/pages/RulesPage.svelte +3 -8
- package/src/lib/pages/SupportPage.svelte +2 -7
- package/src/lib/pages/ThemeSettingsPage.svelte +2 -7
- package/src/lib/pages/profile/ProfilePage.svelte +2 -7
- package/src/lib/pages/profile/SettingsPage.svelte +2 -7
- package/src/lib/pages/profile/TicketsPage.svelte +2 -7
- package/src/lib/pages/ticket/CreateTicketPage.svelte +2 -7
- package/src/lib/pages/ticket/TicketDetailPage.svelte +2 -7
- package/src/lib/plugins.js +61 -0
- package/src/lib/returnTo.util.js +116 -0
- package/src/lib/services/auth.js +11 -11
- package/src/lib/services/posts.js +21 -10
- package/src/lib/services/profile.js +5 -5
- package/src/lib/services/theme-setting.js +1 -1
- package/src/lib/services/tickets.js +36 -15
- package/src/lib/siteRealtime.js +55 -8
- package/src/lib/themePageLoad.js +38 -0
- package/src/lib/translationLayers.js +144 -0
- package/src/lib/ui-logics/layout-logics/AppLayoutLogics.js +160 -6
- package/src/lib/ui-logics/layout-logics/AuthLayoutLogics.js +3 -2
- package/src/lib/ui-logics/layout-logics/ProfileLayoutLogics.js +3 -2
- package/src/lib/ui-logics/layout-logics/TicketsLayoutLogics.js +3 -2
- package/src/lib/ui-logics/page-logics/ActiveEmailPageLogics.js +4 -4
- package/src/lib/ui-logics/page-logics/ConfirmNewEmailPageLogics.js +4 -4
- package/src/lib/ui-logics/page-logics/CreateTicketPageLogics.js +5 -5
- package/src/lib/ui-logics/page-logics/HomePageLogics.js +5 -3
- package/src/lib/ui-logics/page-logics/NotificationsPageLogics.js +40 -16
- package/src/lib/ui-logics/page-logics/PlayerDetailPageLogics.js +3 -3
- package/src/lib/ui-logics/page-logics/PostDetailPageLogics.js +3 -3
- package/src/lib/ui-logics/page-logics/PreviewPostPageLogics.js +1 -1
- package/src/lib/ui-logics/page-logics/RenewPasswordPageLogics.js +4 -4
- package/src/lib/ui-logics/page-logics/ResetPasswordPageLogics.js +6 -6
- package/src/lib/ui-logics/page-logics/SettingsPageLogics.js +8 -8
- package/src/lib/ui-logics/page-logics/TicketDetailPageLogics.js +3 -3
- package/src/lib/ui-logics/page-logics/TicketsPageLogics.js +5 -3
- package/src/lib/views/ActivateEmailView.samples.js +22 -0
- package/src/lib/views/ActivateEmailView.svelte +4 -4
- package/src/lib/views/AppLayoutView.samples.js +17 -0
- package/src/lib/views/AppLayoutView.svelte +1 -1
- package/src/lib/views/AuthLayoutView.samples.js +4 -0
- package/src/lib/views/AuthLayoutView.svelte +1 -1
- package/src/lib/views/Breadcrumb.samples.js +15 -0
- package/src/lib/views/CloseTicketConfirmModal.samples.js +12 -0
- package/src/lib/views/ConfirmNewEmailView.samples.js +22 -0
- package/src/lib/views/ConfirmNewEmailView.svelte +4 -4
- package/src/lib/views/ConfirmRemoveAllNotificationsModal.samples.js +9 -0
- package/src/lib/views/CreateTicketView.samples.js +21 -0
- package/src/lib/views/CreateTicketView.svelte +5 -5
- package/src/lib/views/Date.samples.js +9 -0
- package/src/lib/views/DefaultToast.samples.js +7 -0
- package/src/lib/views/ErrorView.samples.js +8 -0
- package/src/lib/views/ErrorView.svelte +4 -2
- package/src/lib/views/Footer.samples.js +8 -0
- package/src/lib/views/Header.samples.js +8 -0
- package/src/lib/views/HomeSidebar.samples.js +59 -0
- package/src/lib/views/HomeView.samples.js +34 -0
- package/src/lib/views/HomeView.svelte +14 -6
- package/src/lib/views/LoginFormBody.samples.js +8 -0
- package/src/lib/views/LoginView.samples.js +50 -0
- package/src/lib/views/LoginView.svelte +24 -22
- package/src/lib/views/LogoutSessionConfirmModal.samples.js +8 -0
- package/src/lib/views/Main.samples.js +23 -0
- package/src/lib/views/MainLayoutView.svelte +3 -4
- package/src/lib/views/Navbar.samples.js +8 -0
- package/src/lib/views/NoContent.samples.js +7 -0
- package/src/lib/views/NotificationContainer.samples.js +25 -0
- package/src/lib/views/NotificationsView.samples.js +36 -0
- package/src/lib/views/NotificationsView.svelte +21 -12
- package/src/lib/views/PageActions.samples.js +7 -0
- package/src/lib/views/PageTitle.samples.js +8 -0
- package/src/lib/views/Pagination.samples.js +7 -0
- package/src/lib/views/PlayerDetailSidebar.samples.js +35 -0
- package/src/lib/views/PlayerDetailView.samples.js +8 -0
- package/src/lib/views/PlayerDetailView.svelte +3 -3
- package/src/lib/views/PlayerHead.samples.js +8 -0
- package/src/lib/views/Post.samples.js +10 -0
- package/src/lib/views/PostDetailView.samples.js +28 -0
- package/src/lib/views/PostDetailView.svelte +24 -16
- package/src/lib/views/Posts.samples.js +9 -0
- package/src/lib/views/PreviewPostView.samples.js +20 -0
- package/src/lib/views/PreviewPostView.svelte +10 -10
- package/src/lib/views/ProfileLayoutView.samples.js +4 -0
- package/src/lib/views/ProfileSidebar.samples.js +33 -0
- package/src/lib/views/ProfileView.samples.js +29 -0
- package/src/lib/views/ProfileView.svelte +2 -2
- package/src/lib/views/RegisterForm.samples.js +7 -0
- package/src/lib/views/RegisterView.samples.js +28 -0
- package/src/lib/views/RegisterView.svelte +5 -3
- package/src/lib/views/RenewPasswordView.samples.js +24 -0
- package/src/lib/views/RenewPasswordView.svelte +6 -6
- package/src/lib/views/ResetPasswordView.samples.js +24 -0
- package/src/lib/views/ResetPasswordView.svelte +3 -3
- package/src/lib/views/RulesView.samples.js +14 -0
- package/src/lib/views/RulesView.svelte +3 -3
- package/src/lib/views/SettingsView.svelte +48 -17
- package/src/lib/views/Sidebar.samples.js +7 -0
- package/src/lib/views/SupportSidebar.samples.js +24 -0
- package/src/lib/views/SupportView.samples.js +16 -0
- package/src/lib/views/SupportView.svelte +8 -6
- package/src/lib/views/ThemeSettingsLayoutView.samples.js +9 -0
- package/src/lib/views/ThemeSettingsLayoutView.svelte +1 -1
- package/src/lib/views/ThemeSettingsView.svelte +89 -89
- package/src/lib/views/TicketCreateAndDetailSidebar.samples.js +33 -0
- package/src/lib/views/TicketDetailView.samples.js +34 -0
- package/src/lib/views/TicketDetailView.svelte +17 -15
- package/src/lib/views/TicketRow.samples.js +10 -0
- package/src/lib/views/TicketStatus.samples.js +8 -0
- package/src/lib/views/Tickets.samples.js +9 -0
- package/src/lib/views/TicketsLayoutView.samples.js +4 -0
- package/src/lib/views/TicketsView.samples.js +23 -0
- package/src/lib/views/TicketsView.svelte +11 -9
- package/src/lib/views/Toast.samples.js +9 -0
- package/src/lib/views/ToastContainer.samples.js +8 -0
- package/src/lib/views/parts/Breadcrumb.svelte +53 -0
- package/src/lib/views/parts/CloseTicketConfirmModal.svelte +63 -0
- package/src/lib/views/parts/ConfirmRemoveAllNotificationsModal.svelte +55 -0
- package/src/lib/views/parts/DefaultToast.svelte +22 -0
- package/src/lib/views/parts/HomeSidebar.svelte +334 -0
- package/src/lib/views/parts/LogoutSessionConfirmModal.svelte +46 -0
- package/src/lib/views/parts/Main.svelte +71 -0
- package/src/lib/views/parts/NotificationContainer.svelte +109 -0
- package/src/lib/views/parts/PlayerDetailSidebar.svelte +81 -0
- package/src/lib/views/parts/Post.svelte +255 -0
- package/src/lib/views/parts/Posts.svelte +25 -0
- package/src/lib/views/parts/ProfileSidebar.svelte +115 -0
- package/src/lib/views/parts/Sidebar.svelte +19 -0
- package/src/lib/views/parts/SupportSidebar.svelte +34 -0
- package/src/lib/views/parts/TicketCreateAndDetailSidebar.svelte +51 -0
- package/src/lib/views/parts/TicketRow.svelte +63 -0
- package/src/lib/views/parts/TicketStatus.svelte +24 -0
- package/src/lib/views/parts/Tickets.svelte +45 -0
- package/src/lib/views/parts/Toast.svelte +27 -0
- package/src/lib/views/parts/ToastContainer.svelte +17 -0
- package/src/lib/views/parts/engine-views.generated.js +63 -0
- package/src/lib/views/parts/publicHref.js +18 -0
- package/src/lib/views/parts/ticketStatuses.js +7 -0
- package/src/plugin-engine/__tests__/engine.test.js +161 -0
- package/src/plugin-engine/engine.js +80 -12
- package/src/registry/__tests__/registry.test.js +510 -0
- package/src/registry/__tests__/view.test.js +52 -0
- package/src/registry/index.js +700 -51
- package/src/registry/routes.js +62 -0
- package/src/registry/view.js +69 -0
- package/src/routes/RootLayout.svelte +24 -1
- package/src/routes/catalogue/List.svelte +163 -0
- package/src/routes/catalogue/Stage.svelte +355 -0
- package/src/routes/catalogue/__tests__/browserSafe.test.js +13 -0
- package/src/routes/catalogue/__tests__/catalogue.test.js +539 -0
- package/src/routes/catalogue/catalogue.js +129 -0
- package/src/routes/catalogue/deps.js +147 -0
- package/src/routes/catalogue/engineSamples.js +63 -0
- package/src/routes/catalogue/fixtures.js +77 -0
- package/src/routes/catalogue/list.js +37 -0
- package/src/routes/catalogue/model.js +286 -0
- package/src/routes/catalogue/stage.js +69 -0
- package/src/routes/catalogue/views-json.js +24 -0
- package/src/routes/plugin-ui/Layout.svelte +29 -4
- package/src/routes/plugin-ui/Page.svelte +86 -31
- package/src/routes/plugin-ui/load.js +173 -0
- package/src/routes/plugins-client-file.js +8 -3
- package/src/routes/plugins-ui-file.js +60 -0
- package/src/routes/root-layout-load.js +59 -2
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { afterAll, describe, expect, mock, test } from "bun:test";
|
|
2
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, existsSync, writeFileSync, readdirSync } from "node:fs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
|
|
7
|
+
// TC-39: the four text layers through loadLanguage (doc 03 section 5.3) with a stubbed fetch, and
|
|
8
|
+
// `theme-core sync` writing lang/<locale>.plugins.json and the engine stylesheets (section 5.1,
|
|
9
|
+
// 4.2, 4.6). Also that the bins find hoisted packages in a Bun workspace.
|
|
10
|
+
|
|
11
|
+
mock.module("$app/paths", () => ({ base: "" }));
|
|
12
|
+
mock.module("$app/environment", () => ({ browser: false, dev: false }));
|
|
13
|
+
|
|
14
|
+
/** What the stubbed translations API answers; each test sets it. */
|
|
15
|
+
let apiAnswer = { result: "ok", data: {}, meta: {} };
|
|
16
|
+
|
|
17
|
+
mock.module("$pano/lib/api.util.js", () => ({
|
|
18
|
+
default: {
|
|
19
|
+
get: async ({ path }) => {
|
|
20
|
+
if (path === "/api/locales") return { result: "ok", data: [{ code: "tr", name: "Turkce" }] };
|
|
21
|
+
return apiAnswer;
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
// a fresh instance, so the api stub above is the one it is bound to
|
|
27
|
+
const { loadLanguage } = await import("../language.util.js?layers");
|
|
28
|
+
const { _, locale } = await import("svelte-i18n");
|
|
29
|
+
const { get } = await import("svelte/store");
|
|
30
|
+
|
|
31
|
+
const KEY = "plugins.pano-plugin-market.theme.store.title";
|
|
32
|
+
const tree = (value) => ({ theme: { store: { title: value } } });
|
|
33
|
+
|
|
34
|
+
const json = (body, status = 200) => ({ ok: status === 200, status, json: async () => body });
|
|
35
|
+
|
|
36
|
+
/** event.fetch answering the two theme-api files; `plugins: null` = the third file is a 404 */
|
|
37
|
+
function eventFor({ theme = {}, plugins = null } = {}) {
|
|
38
|
+
const urls = [];
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
urls,
|
|
42
|
+
fetch: async (url) => {
|
|
43
|
+
urls.push(String(url));
|
|
44
|
+
if (String(url).endsWith(".plugins.json")) {
|
|
45
|
+
return plugins === null ? json({ error: "Language file not found" }, 404) : json(plugins);
|
|
46
|
+
}
|
|
47
|
+
return json(theme);
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function shown(event, key = KEY) {
|
|
53
|
+
await loadLanguage({ code: "tr", name: "Turkce" }, event);
|
|
54
|
+
locale.set("tr");
|
|
55
|
+
|
|
56
|
+
return get(_)(key);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
describe("loadLanguage merges the text layers", () => {
|
|
60
|
+
test("worked example of doc 03 section 5.3", async () => {
|
|
61
|
+
apiAnswer = { result: "ok", data: { plugins: { "pano-plugin-market": tree("Mağaza") } }, meta: {} };
|
|
62
|
+
expect(await shown(eventFor())).toBe("Mağaza");
|
|
63
|
+
|
|
64
|
+
expect(await shown(eventFor({ plugins: { market: tree("Dükkan") } }))).toBe("Dükkan");
|
|
65
|
+
|
|
66
|
+
apiAnswer = {
|
|
67
|
+
result: "ok",
|
|
68
|
+
data: { plugins: { "pano-plugin-market": tree("Market") } },
|
|
69
|
+
meta: { pluginAdminKeys: { "pano-plugin-market": ["theme.store.title"] } },
|
|
70
|
+
};
|
|
71
|
+
expect(await shown(eventFor({ plugins: { market: tree("Dükkan") } }))).toBe("Market");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("fetches the third file in the same call, from the same base", async () => {
|
|
75
|
+
apiAnswer = { result: "ok", data: {}, meta: {} };
|
|
76
|
+
const event = eventFor();
|
|
77
|
+
await shown(event);
|
|
78
|
+
|
|
79
|
+
expect(event.urls.sort()).toEqual(["/theme-api/languages/tr.json", "/theme-api/languages/tr.plugins.json"]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("a missing or failing third file is {}: the plugin text and the theme file still show", async () => {
|
|
83
|
+
apiAnswer = { result: "ok", data: { plugins: { "pano-plugin-market": tree("Mağaza") } }, meta: {} };
|
|
84
|
+
|
|
85
|
+
expect(await shown(eventFor({ theme: { greeting: "merhaba" }, plugins: null }), "greeting")).toBe("merhaba");
|
|
86
|
+
expect(await shown(eventFor({ plugins: null }))).toBe("Mağaza");
|
|
87
|
+
|
|
88
|
+
const broken = {
|
|
89
|
+
fetch: async (url) => {
|
|
90
|
+
if (String(url).endsWith(".plugins.json")) throw new Error("network");
|
|
91
|
+
return json({});
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
expect(await shown(broken)).toBe("Mağaza");
|
|
95
|
+
|
|
96
|
+
const badBody = {
|
|
97
|
+
fetch: async (url) =>
|
|
98
|
+
String(url).endsWith(".plugins.json") ? { ok: true, status: 200, json: async () => { throw new Error("bad json"); } } : json({}),
|
|
99
|
+
};
|
|
100
|
+
expect(await shown(badBody)).toBe("Mağaza");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("the dictionary is flat: a plugin id with a dot resolves, core keys keep working", async () => {
|
|
104
|
+
apiAnswer = {
|
|
105
|
+
result: "ok",
|
|
106
|
+
data: { plugins: { "acme.shop": { theme: { title: "Acme" } } }, custom: { key: "admin value" } },
|
|
107
|
+
meta: {},
|
|
108
|
+
};
|
|
109
|
+
const event = eventFor({ theme: { nav: { home: "Ana sayfa" }, custom: { key: "theme value" } } });
|
|
110
|
+
|
|
111
|
+
expect(await shown(event, "plugins.acme.shop.theme.title")).toBe("Acme");
|
|
112
|
+
expect(get(_)("nav.home")).toBe("Ana sayfa");
|
|
113
|
+
expect(get(_)("custom.key")).toBe("admin value");
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("a failed translations API answer leaves the theme file and the theme's plugin files", async () => {
|
|
117
|
+
apiAnswer = { result: "error" };
|
|
118
|
+
const event = eventFor({ theme: { greeting: "merhaba" }, plugins: { "pano-plugin-market": tree("Dükkan") } });
|
|
119
|
+
await loadLanguage({ code: "tr" }, event);
|
|
120
|
+
|
|
121
|
+
expect(get(_)("greeting")).toBe("merhaba");
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// ---------------------------------------------------------------------------
|
|
126
|
+
// sync.js and the bins on fixture themes
|
|
127
|
+
// ---------------------------------------------------------------------------
|
|
128
|
+
|
|
129
|
+
const pkgDir = join(import.meta.dir, "..", "..", "..");
|
|
130
|
+
const syncJs = join(pkgDir, "bin", "sync.js");
|
|
131
|
+
const bundleJs = join(pkgDir, "bin", "bundle-internal-libs.js");
|
|
132
|
+
|
|
133
|
+
const roots = [];
|
|
134
|
+
afterAll(() => {
|
|
135
|
+
for (const root of roots) rmSync(root, { recursive: true, force: true });
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
function put(root, files) {
|
|
139
|
+
for (const [path, content] of Object.entries(files)) {
|
|
140
|
+
mkdirSync(dirname(join(root, path)), { recursive: true });
|
|
141
|
+
writeFileSync(join(root, path), content);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const sdkStub = (root) =>
|
|
146
|
+
put(root, {
|
|
147
|
+
"node_modules/@panomc/sdk/package.json": JSON.stringify({ name: "@panomc/sdk", version: "0.0.0" }),
|
|
148
|
+
"node_modules/@panomc/sdk/core/css/pano-tokens.css": ":root{--pano-color-primary:#123456}\n",
|
|
149
|
+
"node_modules/@fortawesome/fontawesome-free/package.json": JSON.stringify({ name: "@fortawesome/fontawesome-free", version: "6.0.0" }),
|
|
150
|
+
"node_modules/@fortawesome/fontawesome-free/css/all.min.css": ".fa{}\n",
|
|
151
|
+
"node_modules/@fortawesome/fontawesome-free/webfonts/fa.woff2": "font",
|
|
152
|
+
"node_modules/bootstrap/package.json": JSON.stringify({ name: "bootstrap", version: "5.3.0" }),
|
|
153
|
+
"node_modules/bootstrap/dist/js/bootstrap.bundle.min.js": "/* bootstrap */\n",
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
function makeTheme(files = {}, { workspace = false } = {}) {
|
|
157
|
+
const base = mkdtempSync(join(tmpdir(), "theme-core-tc39-"));
|
|
158
|
+
roots.push(base);
|
|
159
|
+
|
|
160
|
+
const dir = workspace ? join(base, "themes", "fixture") : base;
|
|
161
|
+
mkdirSync(dir, { recursive: true });
|
|
162
|
+
// hoisted: the packages sit at the workspace root, not in the theme's own node_modules
|
|
163
|
+
sdkStub(base);
|
|
164
|
+
put(dir, { "package.json": JSON.stringify({ name: "pano-fixture-theme" }), ...files });
|
|
165
|
+
|
|
166
|
+
return dir;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function run(script, cwd) {
|
|
170
|
+
const proc = Bun.spawnSync([process.execPath, script], { cwd, stdout: "pipe", stderr: "pipe" });
|
|
171
|
+
|
|
172
|
+
return { code: proc.exitCode, out: proc.stdout.toString() + proc.stderr.toString() };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const read = (dir, path) => readFileSync(join(dir, path), "utf-8");
|
|
176
|
+
|
|
177
|
+
describe("sync: lang/<locale>.plugins.json", () => {
|
|
178
|
+
const files = {
|
|
179
|
+
"lang-overrides/tr.json": JSON.stringify({ own: { key: "x" } }),
|
|
180
|
+
"lang-overrides/plugins/market/tr.json": JSON.stringify(tree("Dükkan")),
|
|
181
|
+
"lang-overrides/plugins/market/en-US.json": JSON.stringify(tree("Shop")),
|
|
182
|
+
"lang-overrides/plugins/pano-plugin-wiki/tr.json": JSON.stringify({ title: "Wiki" }),
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
test("one file per locale with a plugin file, keyed by folder; lang/<locale>.json stays free of plugin text", () => {
|
|
186
|
+
const dir = makeTheme(files);
|
|
187
|
+
const result = run(syncJs, dir);
|
|
188
|
+
expect(result.code).toBe(0);
|
|
189
|
+
|
|
190
|
+
expect(JSON.parse(read(dir, "lang/tr.plugins.json"))).toEqual({
|
|
191
|
+
"pano-plugin-wiki": { title: "Wiki" },
|
|
192
|
+
market: tree("Dükkan"),
|
|
193
|
+
});
|
|
194
|
+
expect(JSON.parse(read(dir, "lang/en-US.plugins.json"))).toEqual({ market: tree("Shop") });
|
|
195
|
+
expect(existsSync(join(dir, "lang", "de.plugins.json"))).toBe(false);
|
|
196
|
+
|
|
197
|
+
const own = JSON.parse(read(dir, "lang/tr.json"));
|
|
198
|
+
expect(own.own).toEqual({ key: "x" });
|
|
199
|
+
expect(JSON.stringify(own)).not.toContain("Dükkan");
|
|
200
|
+
// the "plugins" folder is not a locale
|
|
201
|
+
expect(existsSync(join(dir, "lang", "plugins.json"))).toBe(false);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("a theme without plugin files writes none, and a removed source removes the stale file", () => {
|
|
205
|
+
const dir = makeTheme({ "lang-overrides/tr.json": "{}" });
|
|
206
|
+
expect(run(syncJs, dir).code).toBe(0);
|
|
207
|
+
expect(readdirSync(join(dir, "lang")).filter((f) => f.endsWith(".plugins.json"))).toEqual([]);
|
|
208
|
+
|
|
209
|
+
put(dir, { "lang-overrides/plugins/market/tr.json": JSON.stringify(tree("Dükkan")) });
|
|
210
|
+
expect(run(syncJs, dir).code).toBe(0);
|
|
211
|
+
expect(existsSync(join(dir, "lang", "tr.plugins.json"))).toBe(true);
|
|
212
|
+
|
|
213
|
+
rmSync(join(dir, "lang-overrides", "plugins"), { recursive: true });
|
|
214
|
+
expect(run(syncJs, dir).code).toBe(0);
|
|
215
|
+
expect(existsSync(join(dir, "lang", "tr.plugins.json"))).toBe(false);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test("a plugin file that is not a JSON object stops the sync with the file name", () => {
|
|
219
|
+
const dir = makeTheme({ "lang-overrides/plugins/market/tr.json": "[1]" });
|
|
220
|
+
const result = run(syncJs, dir);
|
|
221
|
+
|
|
222
|
+
expect(result.code).not.toBe(0);
|
|
223
|
+
expect(result.out).toContain("lang-overrides/plugins/market/tr.json");
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe("sync: engine stylesheets", () => {
|
|
228
|
+
test("pano-tokens.css and the FontAwesome sheet (as pano-fallback-icons.css) are copied, and refreshed when they change", () => {
|
|
229
|
+
const dir = makeTheme();
|
|
230
|
+
expect(run(syncJs, dir).code).toBe(0);
|
|
231
|
+
|
|
232
|
+
expect(read(dir, "static/assets/css/pano-tokens.css")).toContain("--pano-color-primary:#123456");
|
|
233
|
+
expect(read(dir, "static/assets/css/pano-fallback-icons.css")).toBe(".fa{}\n");
|
|
234
|
+
expect(existsSync(join(dir, "static/assets/webfonts/fa.woff2"))).toBe(true);
|
|
235
|
+
|
|
236
|
+
writeFileSync(join(dir, "node_modules/@panomc/sdk/core/css/pano-tokens.css"), ":root{--pano-color-primary:#abcdef}\n");
|
|
237
|
+
expect(run(syncJs, dir).code).toBe(0);
|
|
238
|
+
expect(read(dir, "static/assets/css/pano-tokens.css")).toContain("#abcdef");
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test("a source that does not exist is skipped without an error", () => {
|
|
242
|
+
const dir = makeTheme();
|
|
243
|
+
rmSync(join(dir, "node_modules"), { recursive: true, force: true });
|
|
244
|
+
|
|
245
|
+
expect(run(syncJs, dir).code).toBe(0);
|
|
246
|
+
// the sheets that live in the engine package itself are still copied; the one that comes from the missing sdk is
|
|
247
|
+
// skipped. The icon sheet follows the engine's own FontAwesome dependency (sync falls back to it when the theme has
|
|
248
|
+
// no copy), so it exists exactly when the engine can resolve the package.
|
|
249
|
+
let engineHasFontAwesome = true;
|
|
250
|
+
try {
|
|
251
|
+
createRequire(syncJs).resolve("@fortawesome/fontawesome-free/package.json");
|
|
252
|
+
} catch {
|
|
253
|
+
engineHasFontAwesome = false;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
expect(existsSync(join(dir, "static/assets/css/pano-fallback.css"))).toBe(true);
|
|
257
|
+
expect(existsSync(join(dir, "static/assets/css/pano-tokens.css"))).toBe(false);
|
|
258
|
+
expect(existsSync(join(dir, "static/assets/css/pano-fallback-icons.css"))).toBe(engineHasFontAwesome);
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
describe("bins inside a workspace (hoisted node_modules)", () => {
|
|
263
|
+
test("sync finds the sdk and FontAwesome at the workspace root", () => {
|
|
264
|
+
const dir = makeTheme({}, { workspace: true });
|
|
265
|
+
expect(existsSync(join(dir, "node_modules"))).toBe(false);
|
|
266
|
+
|
|
267
|
+
expect(run(syncJs, dir).code).toBe(0);
|
|
268
|
+
expect(existsSync(join(dir, "static/assets/css/pano-tokens.css"))).toBe(true);
|
|
269
|
+
expect(existsSync(join(dir, "static/assets/css/pano-fallback-icons.css"))).toBe(true);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test("bundle-internal-libs finds Bootstrap at the workspace root", () => {
|
|
273
|
+
const dir = makeTheme({}, { workspace: true });
|
|
274
|
+
const result = run(bundleJs, dir);
|
|
275
|
+
|
|
276
|
+
expect(result.code).toBe(0);
|
|
277
|
+
expect(result.out).toContain("Copied Bootstrap bundle");
|
|
278
|
+
const hash = readdirSync(join(dir, "static", "lib"))[0];
|
|
279
|
+
expect(read(dir, `static/lib/${hash}/bootstrap/bootstrap.bundle.min.js`)).toContain("bootstrap");
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
test("bundle-internal-libs in a theme with its own node_modules behaves as before", () => {
|
|
283
|
+
const dir = makeTheme();
|
|
284
|
+
expect(run(bundleJs, dir).out).toContain("Copied Bootstrap bundle");
|
|
285
|
+
});
|
|
286
|
+
});
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
|
|
7
|
+
const lib = join(import.meta.dir, "..");
|
|
8
|
+
const routes = join(lib, "..", "routes", "plugin-ui");
|
|
9
|
+
const read = (...parts) => readFileSync(join(...parts), "utf-8");
|
|
10
|
+
|
|
11
|
+
// svelte is a peer of the theme (not installed in this repo): use it from the repo, or from the
|
|
12
|
+
// vanilla-theme checkout next to it when present. Without any, only the source assertions run.
|
|
13
|
+
function findSvelte() {
|
|
14
|
+
for (const from of [import.meta.dir, join(import.meta.dir, "../../../../../../themes/vanilla-theme/package.json")]) {
|
|
15
|
+
try {
|
|
16
|
+
const req = createRequire(from);
|
|
17
|
+
return join(req.resolve("svelte/package.json"), "..");
|
|
18
|
+
} catch {
|
|
19
|
+
// try the next location
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const svelteDir = findSvelte();
|
|
26
|
+
|
|
27
|
+
describe("page head plumbing (TC-2 / TC-3 wiring)", () => {
|
|
28
|
+
test("MainLayoutView no longer emits the description tag but keeps keywords", () => {
|
|
29
|
+
const source = read(lib, "views", "MainLayoutView.svelte");
|
|
30
|
+
|
|
31
|
+
expect(source).not.toMatch(/name\s*=\s*["']description["']/);
|
|
32
|
+
expect(source).toContain('name="keywords"');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("meta is lifted to page.data by the plugin page load (load.js) and Layout.svelte", () => {
|
|
36
|
+
for (const file of ["load.js", "Layout.svelte"]) {
|
|
37
|
+
expect(read(routes, file)).toMatch(
|
|
38
|
+
/\["pageTitle", "breadcrumbs", "sidebar", "sidebarProps", "meta"\]/,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("AppLayout mounts PageHead with meta, siteInfo, url and the resolved title", () => {
|
|
44
|
+
const source = read(lib, "layouts", "AppLayout.svelte");
|
|
45
|
+
|
|
46
|
+
expect(source).toMatch(/<PageHead[\s\S]*?meta=\{\$page\.data\?\.meta\}/);
|
|
47
|
+
expect(source).toContain("siteInfo={$session.siteInfo}");
|
|
48
|
+
expect(source).toContain("url={$page.url}");
|
|
49
|
+
expect(source).toContain("resolvePageTitle($pageTitle, $_).title");
|
|
50
|
+
// before the layout view, so its tags come first
|
|
51
|
+
expect(source.indexOf("<PageHead")).toBeLessThan(source.indexOf("<svelte:component"));
|
|
52
|
+
// the document title honours `raw` through the shared helper
|
|
53
|
+
expect(source).toMatch(/getTitle[\s\S]*resolvePageTitle\(pt, \$_\)/);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("Main skips the visible title when hidden and uses the shared helper", () => {
|
|
57
|
+
const source = read(lib, "components", "Main.svelte");
|
|
58
|
+
const part = read(lib, "views", "parts", "Main.svelte");
|
|
59
|
+
|
|
60
|
+
expect(source).toContain("resolvePageTitle($pageTitle, $_)");
|
|
61
|
+
expect(part).toContain("!resolvedTitle.hidden");
|
|
62
|
+
expect(source + part).not.toMatch(/\$_\(\$pageTitle/);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("PageHead emits the JSON-LD script with a split closing tag", () => {
|
|
66
|
+
const source = read(lib, "components", "PageHead.svelte");
|
|
67
|
+
|
|
68
|
+
expect(source).toContain("'</' + 'script>'");
|
|
69
|
+
expect(source).not.toContain("</script>\n {/if}");
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe.skipIf(!svelteDir)("PageHead server render", () => {
|
|
74
|
+
async function renderHead(props) {
|
|
75
|
+
const compiler = await import(join(svelteDir, "src", "compiler", "index.js"));
|
|
76
|
+
const source = read(lib, "components", "PageHead.svelte");
|
|
77
|
+
const { js } = compiler.compile(source, { generate: "server", filename: "PageHead.svelte" });
|
|
78
|
+
|
|
79
|
+
// The engine alias points at this checkout; svelte resolves through a symlinked node_modules.
|
|
80
|
+
const code = js.code.replace(
|
|
81
|
+
'"$pano/lib/pageMeta.util.js"',
|
|
82
|
+
JSON.stringify(join(lib, "pageMeta.util.js")),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const dir = mkdtempSync(join(tmpdir(), "pagehead-"));
|
|
86
|
+
mkdirSync(join(dir, "node_modules"));
|
|
87
|
+
symlinkSync(svelteDir, join(dir, "node_modules", "svelte"), "dir");
|
|
88
|
+
const file = join(dir, "PageHead.mjs");
|
|
89
|
+
writeFileSync(file, code);
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const { default: Component } = await import(file);
|
|
93
|
+
const { render } = await import(join(dir, "node_modules", "svelte", "src", "server", "index.js"));
|
|
94
|
+
|
|
95
|
+
return render(Component, { props }).head;
|
|
96
|
+
} finally {
|
|
97
|
+
rmSync(dir, { recursive: true, force: true });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const siteInfo = {
|
|
102
|
+
websiteName: "My Server",
|
|
103
|
+
websiteDescription: "Site description",
|
|
104
|
+
websiteUrl: "https://pano.example",
|
|
105
|
+
};
|
|
106
|
+
const url = new URL("https://127.0.0.1:3000/store/p");
|
|
107
|
+
const count = (html, needle) => html.split(needle).length - 1;
|
|
108
|
+
|
|
109
|
+
test("a page without meta emits exactly one description (the site-wide one) and no optional tags", async () => {
|
|
110
|
+
const head = await renderHead({ meta: undefined, siteInfo, url, title: "Store" });
|
|
111
|
+
|
|
112
|
+
expect(count(head, 'name="description"')).toBe(1);
|
|
113
|
+
expect(head).toContain('content="Site description"');
|
|
114
|
+
expect(head).toContain('property="og:title" content="Store"');
|
|
115
|
+
expect(head).toContain('property="og:url" content="https://pano.example/store/p"');
|
|
116
|
+
expect(head).toContain('name="twitter:card" content="summary"');
|
|
117
|
+
expect(head).not.toContain("og:image");
|
|
118
|
+
expect(head).not.toContain("canonical");
|
|
119
|
+
expect(head).not.toContain('name="robots"');
|
|
120
|
+
expect(head).not.toContain("ld+json");
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("a page with meta emits one description, og:image, canonical, referrer and JSON-LD", async () => {
|
|
124
|
+
const head = await renderHead({
|
|
125
|
+
meta: {
|
|
126
|
+
description: "Buy the thing",
|
|
127
|
+
image: "/img/a.png",
|
|
128
|
+
imageAlt: "A thing",
|
|
129
|
+
canonical: "/store/p",
|
|
130
|
+
robots: "noindex, evil",
|
|
131
|
+
referrer: "no-referrer",
|
|
132
|
+
type: "product",
|
|
133
|
+
jsonLd: { "@type": "Product", name: "</script><script>alert(1)</script>" },
|
|
134
|
+
},
|
|
135
|
+
siteInfo,
|
|
136
|
+
url,
|
|
137
|
+
title: "Store",
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
expect(count(head, 'name="description"')).toBe(1);
|
|
141
|
+
expect(head).toContain('content="Buy the thing"');
|
|
142
|
+
expect(head).toContain('property="og:image" content="https://pano.example/img/a.png"');
|
|
143
|
+
expect(head).toContain('property="og:image:alt" content="A thing"');
|
|
144
|
+
expect(head).toContain('rel="canonical" href="https://pano.example/store/p"');
|
|
145
|
+
expect(head).toContain('name="robots" content="noindex"');
|
|
146
|
+
expect(head).toContain('name="referrer" content="no-referrer"');
|
|
147
|
+
expect(head).toContain('property="og:type" content="product"');
|
|
148
|
+
expect(head).toContain('name="twitter:card" content="summary_large_image"');
|
|
149
|
+
|
|
150
|
+
// exactly one JSON-LD script and the payload cannot close it early
|
|
151
|
+
expect(count(head, '<script type="application/ld+json">')).toBe(1);
|
|
152
|
+
expect(count(head, "</script>")).toBe(1);
|
|
153
|
+
expect(head).toContain("\\u003c/script>");
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test("meta values are attribute-escaped", async () => {
|
|
157
|
+
const head = await renderHead({
|
|
158
|
+
meta: { description: 'a" onload="alert(1)', title: '"><script>x</script>' },
|
|
159
|
+
siteInfo,
|
|
160
|
+
url,
|
|
161
|
+
title: "T",
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
expect(head).not.toContain('onload="alert(1)"');
|
|
165
|
+
expect(head).not.toContain("<script>x</script>");
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { normalizePageMeta } from "../pageMeta.util.js";
|
|
3
|
+
|
|
4
|
+
const SITE = {
|
|
5
|
+
websiteName: "My Server",
|
|
6
|
+
websiteDescription: "The site-wide description",
|
|
7
|
+
websiteUrl: "https://pano.example/",
|
|
8
|
+
};
|
|
9
|
+
const URL_ = new URL("https://127.0.0.1:3000/store/product?x=1");
|
|
10
|
+
|
|
11
|
+
const run = (meta, extra = {}) =>
|
|
12
|
+
normalizePageMeta(meta, { siteInfo: SITE, url: URL_, title: "Product", ...extra });
|
|
13
|
+
|
|
14
|
+
describe("normalizePageMeta (TC-2)", () => {
|
|
15
|
+
test("description: whitespace collapsed, trimmed, cut to 300", () => {
|
|
16
|
+
expect(run({ description: " a \n\t b c " }).description).toBe("a b c");
|
|
17
|
+
|
|
18
|
+
const long = run({ description: "x".repeat(500) }).description;
|
|
19
|
+
expect(long).toHaveLength(300);
|
|
20
|
+
|
|
21
|
+
expect(run({ description: "w ".repeat(400) }).description.length).toBeLessThanOrEqual(300);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("empty / non-string description falls back to the site-wide description", () => {
|
|
25
|
+
for (const description of ["", " \n ", 5, null, {}, undefined]) {
|
|
26
|
+
const out = run({ description });
|
|
27
|
+
expect(out.description).toBe("The site-wide description");
|
|
28
|
+
expect(out.ogDescription).toBe("The site-wide description");
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("relative image is made absolute with websiteUrl (no double slash)", () => {
|
|
33
|
+
expect(run({ image: "/img/a.png" }).ogImage).toBe("https://pano.example/img/a.png");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("relative image uses url.origin when websiteUrl is empty", () => {
|
|
37
|
+
const out = run({ image: "/img/a.png" }, { siteInfo: { ...SITE, websiteUrl: "" } });
|
|
38
|
+
expect(out.ogImage).toBe("https://127.0.0.1:3000/img/a.png");
|
|
39
|
+
expect(out.twitterCard).toBe("summary_large_image");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("a websiteUrl that is not http(s) is ignored in favour of url.origin", () => {
|
|
43
|
+
const out = run({ image: "/a.png" }, { siteInfo: { ...SITE, websiteUrl: "javascript:alert(1)" } });
|
|
44
|
+
expect(out.ogImage).toBe("https://127.0.0.1:3000/a.png");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("absolute http(s) image kept; every other image is dropped", () => {
|
|
48
|
+
expect(run({ image: "https://cdn.example/a.png" }).ogImage).toBe("https://cdn.example/a.png");
|
|
49
|
+
expect(run({ image: "http://cdn.example/a.png" }).ogImage).toBe("http://cdn.example/a.png");
|
|
50
|
+
|
|
51
|
+
for (const image of [
|
|
52
|
+
"javascript:alert(1)",
|
|
53
|
+
"data:image/png;base64,AAAA",
|
|
54
|
+
"//evil.example/a.png",
|
|
55
|
+
"/\\evil.example/a.png",
|
|
56
|
+
"relative/a.png",
|
|
57
|
+
"ftp://x/a.png",
|
|
58
|
+
"",
|
|
59
|
+
42,
|
|
60
|
+
null,
|
|
61
|
+
]) {
|
|
62
|
+
const out = run({ image });
|
|
63
|
+
expect(out.ogImage).toBeNull();
|
|
64
|
+
expect(out.twitterCard).toBe("summary");
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("imageAlt: kept with an image, cut to 200, null without an image", () => {
|
|
69
|
+
expect(run({ image: "/a.png", imageAlt: "x".repeat(300) }).ogImageAlt).toHaveLength(200);
|
|
70
|
+
expect(run({ image: "/a.png", imageAlt: " a b " }).ogImageAlt).toBe("a b");
|
|
71
|
+
expect(run({ image: "/a.png" }).ogImageAlt).toBeNull();
|
|
72
|
+
expect(run({ imageAlt: "alt" }).ogImageAlt).toBeNull();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("canonical: site-relative path accepted and made absolute", () => {
|
|
76
|
+
const out = run({ canonical: "/store/product/42?ref=a#frag" });
|
|
77
|
+
expect(out.canonical).toBe("https://pano.example/store/product/42?ref=a");
|
|
78
|
+
expect(out.ogUrl).toBe(out.canonical);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("canonical: absolute URL with the site's origin accepted", () => {
|
|
82
|
+
expect(run({ canonical: "https://pano.example/store/p" }).canonical).toBe(
|
|
83
|
+
"https://pano.example/store/p",
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("canonical: foreign origin / unsafe values are dropped (ogUrl falls back to the page URL)", () => {
|
|
88
|
+
for (const canonical of [
|
|
89
|
+
"https://evil.example/store/p",
|
|
90
|
+
"http://pano.example/store/p",
|
|
91
|
+
"https://pano.example.evil.example/",
|
|
92
|
+
"//evil.example/x",
|
|
93
|
+
"/\\evil.example",
|
|
94
|
+
"/.//evil.example",
|
|
95
|
+
"javascript:alert(1)",
|
|
96
|
+
"relative",
|
|
97
|
+
"/a\nb",
|
|
98
|
+
"",
|
|
99
|
+
7,
|
|
100
|
+
]) {
|
|
101
|
+
const out = run({ canonical });
|
|
102
|
+
expect(out.canonical).toBeNull();
|
|
103
|
+
expect(out.ogUrl).toBe("https://pano.example/store/product");
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("auth paths are allowed as canonical (no auth-page guard)", () => {
|
|
108
|
+
expect(run({ canonical: "/login" }).canonical).toBe("https://pano.example/login");
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("robots: unknown tokens removed, case folded, deduplicated, empty => null", () => {
|
|
112
|
+
expect(run({ robots: "noindex, evil" }).robots).toBe("noindex");
|
|
113
|
+
expect(run({ robots: "NoIndex , NOFOLLOW,noindex" }).robots).toBe("noindex, nofollow");
|
|
114
|
+
expect(run({ robots: "evil, other" }).robots).toBeNull();
|
|
115
|
+
expect(run({ robots: "" }).robots).toBeNull();
|
|
116
|
+
expect(run({ robots: ["noindex"] }).robots).toBeNull();
|
|
117
|
+
expect(run({}).robots).toBeNull();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("type defaults to website; only website, article, product are accepted", () => {
|
|
121
|
+
expect(run({}).ogType).toBe("website");
|
|
122
|
+
expect(run({ type: "article" }).ogType).toBe("article");
|
|
123
|
+
expect(run({ type: "product" }).ogType).toBe("product");
|
|
124
|
+
expect(run({ type: "video.movie" }).ogType).toBe("website");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("referrer: only the three policies, else null", () => {
|
|
128
|
+
expect(run({ referrer: "no-referrer" }).referrer).toBe("no-referrer");
|
|
129
|
+
expect(run({ referrer: "same-origin" }).referrer).toBe("same-origin");
|
|
130
|
+
expect(run({ referrer: "strict-origin-when-cross-origin" }).referrer).toBe(
|
|
131
|
+
"strict-origin-when-cross-origin",
|
|
132
|
+
);
|
|
133
|
+
expect(run({ referrer: "unsafe-url" }).referrer).toBeNull();
|
|
134
|
+
expect(run({ referrer: "origin" }).referrer).toBeNull();
|
|
135
|
+
expect(run({}).referrer).toBeNull();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("jsonLd containing </script> is serialised without a literal <", () => {
|
|
139
|
+
const out = run({
|
|
140
|
+
jsonLd: { "@type": "Product", name: "</script><script>alert(1)</script>", n: "a<b" },
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
expect(out.jsonLd).not.toContain("<");
|
|
144
|
+
expect(out.jsonLd).toContain("\\u003c/script>");
|
|
145
|
+
// still valid JSON that round-trips to the original value
|
|
146
|
+
expect(JSON.parse(out.jsonLd).name).toBe("</script><script>alert(1)</script>");
|
|
147
|
+
expect(JSON.parse(out.jsonLd).n).toBe("a<b");
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test("jsonLd arrays of objects are accepted", () => {
|
|
151
|
+
const out = run({ jsonLd: [{ "@type": "A" }, { "@type": "B" }] });
|
|
152
|
+
expect(JSON.parse(out.jsonLd)).toEqual([{ "@type": "A" }, { "@type": "B" }]);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test("oversize jsonLd is dropped; non-object jsonLd is dropped", () => {
|
|
156
|
+
expect(run({ jsonLd: { d: "x".repeat(20000) } }).jsonLd).toBeNull();
|
|
157
|
+
|
|
158
|
+
// exactly at the limit stays (the object wrapper {"d":""} is 8 chars)
|
|
159
|
+
const atLimit = run({ jsonLd: { d: "x".repeat(16384 - 8) } }).jsonLd;
|
|
160
|
+
expect(atLimit).toHaveLength(16384);
|
|
161
|
+
expect(run({ jsonLd: { d: "x".repeat(16384 - 7) } }).jsonLd).toBeNull();
|
|
162
|
+
|
|
163
|
+
for (const jsonLd of ["string", 5, true, null, undefined, [], [1, 2], [{}, null]]) {
|
|
164
|
+
expect(run({ jsonLd }).jsonLd).toBeNull();
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test("jsonLd that cannot be serialised is dropped instead of throwing", () => {
|
|
169
|
+
const circular = {};
|
|
170
|
+
circular.self = circular;
|
|
171
|
+
expect(run({ jsonLd: circular }).jsonLd).toBeNull();
|
|
172
|
+
expect(run({ jsonLd: { n: 10n } }).jsonLd).toBeNull();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('non-object meta ("x", null, arrays) => site-wide description only', () => {
|
|
176
|
+
for (const meta of ["x", null, undefined, 3, ["description"]]) {
|
|
177
|
+
const out = run(meta);
|
|
178
|
+
expect(out.description).toBe("The site-wide description");
|
|
179
|
+
expect(out.ogDescription).toBe("The site-wide description");
|
|
180
|
+
expect(out.canonical).toBeNull();
|
|
181
|
+
expect(out.ogImage).toBeNull();
|
|
182
|
+
expect(out.robots).toBeNull();
|
|
183
|
+
expect(out.referrer).toBeNull();
|
|
184
|
+
expect(out.jsonLd).toBeNull();
|
|
185
|
+
expect(out.ogType).toBe("website");
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test("og:title defaults to the resolved title, then the site name; meta.title wins", () => {
|
|
190
|
+
expect(run({}).ogTitle).toBe("Product");
|
|
191
|
+
expect(run({ title: "Custom" }).ogTitle).toBe("Custom");
|
|
192
|
+
expect(run({ title: " " }).ogTitle).toBe("Product");
|
|
193
|
+
expect(run({}, { title: "" }).ogTitle).toBe("My Server");
|
|
194
|
+
expect(run({}, { title: undefined }).ogTitle).toBe("My Server");
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test("ogUrl, siteName and twitterCard defaults", () => {
|
|
198
|
+
const out = run({});
|
|
199
|
+
expect(out.ogUrl).toBe("https://pano.example/store/product");
|
|
200
|
+
expect(out.siteName).toBe("My Server");
|
|
201
|
+
expect(out.twitterCard).toBe("summary");
|
|
202
|
+
|
|
203
|
+
const noBase = normalizePageMeta({}, { siteInfo: {}, url: URL_, title: "T" });
|
|
204
|
+
expect(noBase.ogUrl).toBe("https://127.0.0.1:3000/store/product");
|
|
205
|
+
expect(noBase.siteName).toBeNull();
|
|
206
|
+
expect(noBase.description).toBeNull();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test("tolerates missing context entirely", () => {
|
|
210
|
+
const out = normalizePageMeta(undefined);
|
|
211
|
+
expect(out.description).toBeNull();
|
|
212
|
+
expect(out.ogTitle).toBeNull();
|
|
213
|
+
expect(out.ogUrl).toBeNull();
|
|
214
|
+
expect(out.ogType).toBe("website");
|
|
215
|
+
});
|
|
216
|
+
});
|