@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,1000 @@
|
|
|
1
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, mock, spyOn, test } from "bun:test";
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { Window } from "happy-dom";
|
|
5
|
+
import { writable } from "svelte/store";
|
|
6
|
+
|
|
7
|
+
import { findSvelte } from "./svelteSsr.helper.js";
|
|
8
|
+
|
|
9
|
+
// TC-30: the engine wiring of PluginBlock, PluginSlot, the views in the pano context and the plugin page.
|
|
10
|
+
//
|
|
11
|
+
// The real files are compiled with the Svelte compiler (server mode) and run against the REAL registry and the
|
|
12
|
+
// REAL plugin API; only the SvelteKit aliases are stubs. The fixtures stand for a plugin (`tst`, three default
|
|
13
|
+
// views, a block, two injections) and for a theme (overrides, a hand-built theme meta).
|
|
14
|
+
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// Stubs of the SvelteKit aliases (bun mocks are process-wide: every stub is a superset of what other suites use)
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
class Redirect {
|
|
20
|
+
constructor(status, location) {
|
|
21
|
+
this.status = status;
|
|
22
|
+
this.location = location;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const pageState = { current: { data: {}, url: new URL("http://localhost/"), params: {} } };
|
|
27
|
+
const pageStore = {
|
|
28
|
+
subscribe(run) {
|
|
29
|
+
run(pageState.current);
|
|
30
|
+
return () => {};
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
mock.module("@sveltejs/kit", () => ({
|
|
35
|
+
redirect: (status, location) => {
|
|
36
|
+
throw new Redirect(status, location);
|
|
37
|
+
},
|
|
38
|
+
error: (status, message) => Object.assign(new Error(`HTTP ${status} ${message ?? ""}`), { status }),
|
|
39
|
+
}));
|
|
40
|
+
mock.module("$app/paths", () => ({ base: "" }));
|
|
41
|
+
mock.module("$app/environment", () => ({ browser: false, dev: false }));
|
|
42
|
+
mock.module("$app/navigation", () => ({
|
|
43
|
+
goto: async () => {},
|
|
44
|
+
invalidate: async () => {},
|
|
45
|
+
invalidateAll: async () => {},
|
|
46
|
+
}));
|
|
47
|
+
mock.module("$app/stores", () => ({ page: pageStore, navigating: writable(null) }));
|
|
48
|
+
mock.module("$pano/lib/services/auth.js", () => ({ sendLogout: async () => {} }));
|
|
49
|
+
mock.module("$pano/lib/components/ToastContainer.svelte", () => ({
|
|
50
|
+
show: async () => {},
|
|
51
|
+
showSuccess: async () => {},
|
|
52
|
+
showError: async () => {},
|
|
53
|
+
limitTitle: (text) => text,
|
|
54
|
+
}));
|
|
55
|
+
const pluginManagerStub = () => ({
|
|
56
|
+
plugins: writable({}),
|
|
57
|
+
registeredPages: {},
|
|
58
|
+
findMatch: () => null,
|
|
59
|
+
});
|
|
60
|
+
mock.module("@panomc/sdk/core/js/PluginManager.js", pluginManagerStub);
|
|
61
|
+
mock.module(new URL("../../../../sdk/core/js/PluginManager.js", import.meta.url).pathname, pluginManagerStub);
|
|
62
|
+
const returnToUtil = await import("../returnTo.util.js");
|
|
63
|
+
mock.module("$pano/lib/returnTo.util.js", () => returnToUtil);
|
|
64
|
+
const sdkPluginApi = await import("../../../../sdk/core/js/PluginAPI.js");
|
|
65
|
+
mock.module("@panomc/sdk/core/js/PluginAPI", () => sdkPluginApi);
|
|
66
|
+
|
|
67
|
+
const registry = await import("../../registry/index.js");
|
|
68
|
+
const { getPanoContext, setPanoContext } = await import("../../../../sdk/src/internal/index.js");
|
|
69
|
+
|
|
70
|
+
const PLUGIN_API_FILE = join(import.meta.dir, "..", "PluginAPI.js");
|
|
71
|
+
// one PluginAPI instance for the test and for the compiled components (they import it as `$pano/lib/PluginAPI.js`)
|
|
72
|
+
const PLUGIN_API_SPEC = `${PLUGIN_API_FILE}?engineWiring`;
|
|
73
|
+
const api = await import(PLUGIN_API_SPEC);
|
|
74
|
+
const { panoApi, init, executeViewLoad } = api;
|
|
75
|
+
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
// A tiny build of .svelte files: server mode, imports rewritten to files
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
|
|
80
|
+
const svelteDir = findSvelte();
|
|
81
|
+
const pkgSrc = join(import.meta.dir, "..", "..");
|
|
82
|
+
|
|
83
|
+
const FIXTURES = {
|
|
84
|
+
"Badge.svelte": `<script>
|
|
85
|
+
let { text = "" } = $props();
|
|
86
|
+
</script>
|
|
87
|
+
<span class="badge">{text}</span>`,
|
|
88
|
+
|
|
89
|
+
"Child.svelte": `<script module>
|
|
90
|
+
import { createViewProxy } from "@panomc/sdk/views";
|
|
91
|
+
import BadgeDefault from "./Badge.svelte";
|
|
92
|
+
|
|
93
|
+
const Badge = createViewProxy("tst:Badge", BadgeDefault);
|
|
94
|
+
</script>
|
|
95
|
+
<script>
|
|
96
|
+
let { label = "" } = $props();
|
|
97
|
+
</script>
|
|
98
|
+
<div class="child-default"><b class="label">{label}</b><Badge text="in-child" /></div>`,
|
|
99
|
+
|
|
100
|
+
"ChildOverride.svelte": `<script module>
|
|
101
|
+
import { createViewProxy } from "@panomc/sdk/views";
|
|
102
|
+
import BadgeDefault from "./Badge.svelte";
|
|
103
|
+
|
|
104
|
+
const Badge = createViewProxy("tst:Badge", BadgeDefault);
|
|
105
|
+
</script>
|
|
106
|
+
<script>
|
|
107
|
+
let { label = "" } = $props();
|
|
108
|
+
</script>
|
|
109
|
+
<div class="child-override"><b class="label">{label}</b><Badge text="in-override" /></div>`,
|
|
110
|
+
|
|
111
|
+
"Home.svelte": `<script module>
|
|
112
|
+
import { createViewProxy } from "@panomc/sdk/views";
|
|
113
|
+
import ChildDefault from "./Child.svelte";
|
|
114
|
+
import BadgeDefault from "./Badge.svelte";
|
|
115
|
+
|
|
116
|
+
const Child = createViewProxy("tst:Child", ChildDefault);
|
|
117
|
+
const Badge = createViewProxy("tst:Badge", BadgeDefault);
|
|
118
|
+
|
|
119
|
+
export async function load() {
|
|
120
|
+
return { title: "from-default-load", pageTitle: "tst.title" };
|
|
121
|
+
}
|
|
122
|
+
</script>
|
|
123
|
+
<script>
|
|
124
|
+
let { title = "" } = $props();
|
|
125
|
+
</script>
|
|
126
|
+
<section class="home-default"><h1>{title}</h1><Child label="one" /><Badge text="page-badge" /></section>`,
|
|
127
|
+
|
|
128
|
+
"HomeOverride.svelte": `<script module>
|
|
129
|
+
import { pluginView } from "$pano/registry/view.js";
|
|
130
|
+
import PluginBlock from "$pano/lib/components/PluginBlock.svelte";
|
|
131
|
+
|
|
132
|
+
const Child = pluginView("tst:Child");
|
|
133
|
+
|
|
134
|
+
// a load exported by an override is ignored (doc 01 section 4, rule 4)
|
|
135
|
+
export async function load() {
|
|
136
|
+
return { title: "from-override-load" };
|
|
137
|
+
}
|
|
138
|
+
</script>
|
|
139
|
+
<script>
|
|
140
|
+
let { title = "" } = $props();
|
|
141
|
+
</script>
|
|
142
|
+
<main class="home-override">
|
|
143
|
+
<h1>{title}</h1>
|
|
144
|
+
<Child label="nested" />
|
|
145
|
+
<div class="four"><PluginBlock id="tst:Grid" limit={4} /></div>
|
|
146
|
+
<div class="eight"><PluginBlock id="tst:Grid" limit={8} /></div>
|
|
147
|
+
</main>`,
|
|
148
|
+
|
|
149
|
+
"Grid.svelte": `<script module>
|
|
150
|
+
export async function load(event, props) {
|
|
151
|
+
globalThis.__engineWiringGridLoads = (globalThis.__engineWiringGridLoads ?? 0) + 1;
|
|
152
|
+
return { items: Array.from({ length: props.limit ?? 0 }, (_, i) => i + 1), fromEvent: event?.marker ?? null };
|
|
153
|
+
}
|
|
154
|
+
</script>
|
|
155
|
+
<script>
|
|
156
|
+
let { items = [], limit = 0 } = $props();
|
|
157
|
+
</script>
|
|
158
|
+
<ul class="grid" data-limit={limit}>{#each items as n (n)}<li>{n}</li>{/each}</ul>`,
|
|
159
|
+
|
|
160
|
+
"NavCart.svelte": `<script module>
|
|
161
|
+
export async function load() {
|
|
162
|
+
globalThis.__engineWiringLoads = (globalThis.__engineWiringLoads ?? 0) + 1;
|
|
163
|
+
return { loaded: true };
|
|
164
|
+
}
|
|
165
|
+
</script>
|
|
166
|
+
<script>
|
|
167
|
+
let { order = "none", data = {} } = $props();
|
|
168
|
+
</script>
|
|
169
|
+
<span class="navcart" data-order={order} data-loaded={String(!!data.loaded)}>cart</span>`,
|
|
170
|
+
|
|
171
|
+
"Promo.svelte": `<span class="promo">promo</span>`,
|
|
172
|
+
|
|
173
|
+
"BlockHost.svelte": `<script>
|
|
174
|
+
import PluginBlock from "$pano/lib/components/PluginBlock.svelte";
|
|
175
|
+
|
|
176
|
+
let { id } = $props();
|
|
177
|
+
</script>
|
|
178
|
+
<PluginBlock {id}>
|
|
179
|
+
{#snippet fallback()}<i class="fb">fallback</i>{/snippet}
|
|
180
|
+
</PluginBlock>`,
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const STUB_MODULES = {
|
|
184
|
+
// the host sidebars and the plugin sidebar are not part of what TC-30 tests
|
|
185
|
+
"sidebars/HomeSidebar.svelte": `export default function HomeSidebar() {}\nexport async function load() {}`,
|
|
186
|
+
"sidebars/ProfileSidebar.svelte": `export default function ProfileSidebar() {}\nexport async function load() {}`,
|
|
187
|
+
"sidebars/PluginSidebar.svelte": `export default function PluginSidebar() {}`,
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
let workDir;
|
|
191
|
+
let compiler;
|
|
192
|
+
let render;
|
|
193
|
+
const emitted = new Map();
|
|
194
|
+
let counter = 0;
|
|
195
|
+
|
|
196
|
+
function firstExisting(base) {
|
|
197
|
+
for (const candidate of [base, `${base}.js`, `${base}.svelte`]) {
|
|
198
|
+
if (existsSync(candidate) && !candidate.endsWith("/")) {
|
|
199
|
+
try {
|
|
200
|
+
readFileSync(candidate);
|
|
201
|
+
return candidate;
|
|
202
|
+
} catch {
|
|
203
|
+
// a directory
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Compiles a .svelte file (and, recursively, the .svelte files it imports) and returns the path of the module. */
|
|
211
|
+
function emit(file, mode = "server") {
|
|
212
|
+
const cacheKey = `${mode}:${file}`;
|
|
213
|
+
if (emitted.has(cacheKey)) return emitted.get(cacheKey);
|
|
214
|
+
|
|
215
|
+
const out = join(workDir, `m${counter++}.mjs`);
|
|
216
|
+
emitted.set(cacheKey, out);
|
|
217
|
+
|
|
218
|
+
const stub = Object.entries(STUB_MODULES).find(([suffix]) => file.endsWith(suffix));
|
|
219
|
+
if (stub) {
|
|
220
|
+
writeFileSync(out, stub[1]);
|
|
221
|
+
return out;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const source = readFileSync(file, "utf-8");
|
|
225
|
+
const { js } = compiler.compile(source, { generate: mode, filename: file.split("/").pop() });
|
|
226
|
+
const from = dirname(file);
|
|
227
|
+
const code = js.code.replace(/(\bfrom\s*|\bimport\s*)(["'])([^"']+)\2/g, (whole, lead, quote, spec) => {
|
|
228
|
+
const target = target_(spec, from, mode);
|
|
229
|
+
return target === spec ? whole : `${lead}${JSON.stringify(target)}`;
|
|
230
|
+
});
|
|
231
|
+
writeFileSync(out, code);
|
|
232
|
+
return out;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function target_(spec, from, mode = "server") {
|
|
236
|
+
if (mode === "client") {
|
|
237
|
+
// the client build runs under bun: the browser entry of Svelte and a stub for the aliases
|
|
238
|
+
if (spec === "svelte") return join(svelteDir, "src", "index-client.js");
|
|
239
|
+
if (spec === "$app/environment") return clientStub("environment", "export const browser = true; export const dev = false;");
|
|
240
|
+
if (spec === "$app/stores") {
|
|
241
|
+
return clientStub("stores", "export const page = { subscribe(run) { run(globalThis.__engineWiringClientPage); return () => {}; } };");
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (spec === "svelte" || spec.startsWith("svelte/")) return spec;
|
|
245
|
+
|
|
246
|
+
if (spec.startsWith("@panomc/")) return Bun.resolveSync(spec, pkgSrc);
|
|
247
|
+
|
|
248
|
+
let base = null;
|
|
249
|
+
if (spec.startsWith("$pano/")) base = join(pkgSrc, spec.slice("$pano/".length));
|
|
250
|
+
else if (spec.startsWith(".")) base = resolve(from, spec);
|
|
251
|
+
if (!base) return spec; // $app/*, @sveltejs/kit: mocked
|
|
252
|
+
|
|
253
|
+
const found = firstExisting(base);
|
|
254
|
+
if (!found) throw new Error(`cannot resolve ${spec} from ${from}`);
|
|
255
|
+
if (found.endsWith(".svelte")) return emit(found, mode);
|
|
256
|
+
return found === PLUGIN_API_FILE ? PLUGIN_API_SPEC : found;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function clientStub(name, source) {
|
|
260
|
+
const file = join(workDir, `client-${name}.mjs`);
|
|
261
|
+
if (!existsSync(file)) writeFileSync(file, source);
|
|
262
|
+
return file;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const fixturePath = (name) => join(workDir, "fixtures", name);
|
|
266
|
+
const realPath = (rel) => join(pkgSrc, rel);
|
|
267
|
+
/** The compiled module of a fixture or of a real engine file. */
|
|
268
|
+
const build = (file) => import(emit(file));
|
|
269
|
+
|
|
270
|
+
const modules = {};
|
|
271
|
+
let PluginBlock;
|
|
272
|
+
let PluginSlot;
|
|
273
|
+
let PageModule;
|
|
274
|
+
|
|
275
|
+
beforeAll(async () => {
|
|
276
|
+
// inside node_modules (git-ignored): bun applies a mock only to importers that can resolve the specifier
|
|
277
|
+
const scratch = join(pkgSrc, "..", "node_modules");
|
|
278
|
+
mkdirSync(scratch, { recursive: true });
|
|
279
|
+
workDir = mkdtempSync(join(scratch, ".tc30-"));
|
|
280
|
+
mkdirSync(join(workDir, "fixtures"));
|
|
281
|
+
for (const [name, source] of Object.entries(FIXTURES)) writeFileSync(fixturePath(name), source);
|
|
282
|
+
|
|
283
|
+
compiler = await import(join(svelteDir, "src", "compiler", "index.js"));
|
|
284
|
+
({ render } = await import(join(svelteDir, "src", "server", "index.js")));
|
|
285
|
+
|
|
286
|
+
for (const name of Object.keys(FIXTURES)) modules[name.replace(".svelte", "")] = await build(fixturePath(name));
|
|
287
|
+
|
|
288
|
+
PluginBlock = (await build(realPath("lib/components/PluginBlock.svelte"))).default;
|
|
289
|
+
PluginSlot = (await build(realPath("lib/components/PluginSlot.svelte"))).default;
|
|
290
|
+
PageModule = await build(realPath("routes/plugin-ui/Page.svelte"));
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
afterAll(() => {
|
|
294
|
+
rmSync(workDir, { recursive: true, force: true });
|
|
295
|
+
registry.resetRegistryForTests();
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
// ---------------------------------------------------------------------------
|
|
299
|
+
// Fixture plugin + theme
|
|
300
|
+
// ---------------------------------------------------------------------------
|
|
301
|
+
|
|
302
|
+
const PLUGIN = "pano-plugin-tst";
|
|
303
|
+
|
|
304
|
+
const viewDef = (name, file, extra = {}) => ({
|
|
305
|
+
name,
|
|
306
|
+
pluginId: PLUGIN,
|
|
307
|
+
contract: 1,
|
|
308
|
+
kind: "component",
|
|
309
|
+
component: async () => modules[file],
|
|
310
|
+
...extra,
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
function registerPlugin() {
|
|
314
|
+
panoApi.views.add([
|
|
315
|
+
viewDef("tst:Home", "Home", { kind: "page", uses: ["tst:Child", "tst:Badge"] }),
|
|
316
|
+
viewDef("tst:Child", "Child", { uses: ["tst:Badge"] }),
|
|
317
|
+
viewDef("tst:Badge", "Badge"),
|
|
318
|
+
viewDef("tst:Grid", "Grid", { block: true }),
|
|
319
|
+
viewDef("tst:NavCart", "NavCart", { inject: [{ slot: "tst:cart-slot", id: "navcart", priority: 20 }] }),
|
|
320
|
+
viewDef("tst:Promo", "Promo", { inject: [{ slot: "tst:cart-slot", id: "promo", priority: 10 }] }),
|
|
321
|
+
]);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const override = (file, extra = {}) => ({ contract: 1, component: async () => modules[file], ...extra });
|
|
325
|
+
|
|
326
|
+
/** What AppLayoutLogics puts into the pano context (`views`). */
|
|
327
|
+
function installViewsContext() {
|
|
328
|
+
setPanoContext({
|
|
329
|
+
views: {
|
|
330
|
+
getOverride: registry.getOverride,
|
|
331
|
+
getDefault: registry.getDefault,
|
|
332
|
+
has: registry.hasView,
|
|
333
|
+
wrap: (_name, component) => component,
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const parse = (html) => {
|
|
339
|
+
const doc = new Window().document;
|
|
340
|
+
doc.body.innerHTML = html;
|
|
341
|
+
return doc.body;
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
const serverEvent = (extra = {}) => ({
|
|
345
|
+
url: new URL("http://localhost/tst"),
|
|
346
|
+
params: {},
|
|
347
|
+
parent: async () => ({}),
|
|
348
|
+
...extra,
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
/** Runs the plugin page load and renders the page the way the route does. */
|
|
352
|
+
async function renderPluginPage(view = "tst:Home") {
|
|
353
|
+
const event = serverEvent({
|
|
354
|
+
parent: async () => ({
|
|
355
|
+
registeredPage: { view, component: () => registry.loadForInjection(view) },
|
|
356
|
+
}),
|
|
357
|
+
});
|
|
358
|
+
const data = await PageModule.load(event);
|
|
359
|
+
|
|
360
|
+
pageState.current = { data, url: event.url, params: {} };
|
|
361
|
+
|
|
362
|
+
const { body } = render(PageModule.default, { props: { data } });
|
|
363
|
+
|
|
364
|
+
return { data, body, root: parse(body) };
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
let warnSpy;
|
|
368
|
+
let errorSpy;
|
|
369
|
+
|
|
370
|
+
beforeEach(async () => {
|
|
371
|
+
registry.resetRegistryForTests();
|
|
372
|
+
await init();
|
|
373
|
+
warnSpy = spyOn(console, "warn").mockImplementation(() => {});
|
|
374
|
+
errorSpy = spyOn(console, "error").mockImplementation(() => {});
|
|
375
|
+
globalThis.__engineWiringLoads = 0;
|
|
376
|
+
globalThis.__engineWiringGridLoads = 0;
|
|
377
|
+
pageState.current = { data: {}, url: new URL("http://localhost/"), params: {} };
|
|
378
|
+
registry.setThemeConfig({});
|
|
379
|
+
registry.setThemeMeta(null);
|
|
380
|
+
registerPlugin();
|
|
381
|
+
installViewsContext();
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
afterEach(async () => {
|
|
385
|
+
warnSpy.mockRestore();
|
|
386
|
+
errorSpy.mockRestore();
|
|
387
|
+
const { context } = getPanoContext();
|
|
388
|
+
delete context.views;
|
|
389
|
+
await init();
|
|
390
|
+
registry.resetRegistryForTests();
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
// ---------------------------------------------------------------------------
|
|
394
|
+
|
|
395
|
+
describe("plugin page (routes/plugin-ui/Page.svelte)", () => {
|
|
396
|
+
test("no override: the default renders, source is default, the load is the default's", async () => {
|
|
397
|
+
const { data, root } = await renderPluginPage();
|
|
398
|
+
|
|
399
|
+
expect(data.viewSource).toBe("default");
|
|
400
|
+
expect(data.props).toEqual({ title: "from-default-load", pageTitle: "tst.title" });
|
|
401
|
+
expect(data.pageTitle).toBe("tst.title");
|
|
402
|
+
expect(root.querySelector("section.home-default h1").textContent).toBe("from-default-load");
|
|
403
|
+
expect(root.querySelector(".home-default .child-default .label").textContent).toBe("one");
|
|
404
|
+
expect(root.querySelectorAll(".child-override").length).toBe(0);
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
test("a default page with a nested override: the override lands in the page, the page's own badge stays after it", async () => {
|
|
408
|
+
registry.setThemeConfig({ views: { "tst:Child": override("ChildOverride") } });
|
|
409
|
+
|
|
410
|
+
const { data, root } = await renderPluginPage();
|
|
411
|
+
|
|
412
|
+
expect(data.viewSource).toBe("default");
|
|
413
|
+
expect(root.querySelectorAll(".child-default").length).toBe(0);
|
|
414
|
+
expect(root.querySelector("section.home-default > .child-override .label").textContent).toBe("one");
|
|
415
|
+
// a default Badge inside the override is the plugin's
|
|
416
|
+
expect(root.querySelector(".child-override .badge").textContent).toBe("in-override");
|
|
417
|
+
expect(root.querySelector("section.home-default > .badge").textContent).toBe("page-badge");
|
|
418
|
+
|
|
419
|
+
const order = [...root.querySelectorAll("section.home-default > *")].map((n) => n.className || n.tagName.toLowerCase());
|
|
420
|
+
expect(order).toEqual(["h1", "child-override", "badge"]);
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
test("an override page with a nested default: native render, the nested default Child is the plugin's", async () => {
|
|
424
|
+
registry.setThemeConfig({ views: { "tst:Home": override("HomeOverride") } });
|
|
425
|
+
registry.setThemeMeta({
|
|
426
|
+
refs: {
|
|
427
|
+
"tst:Home": [{ id: "tst:Child" }, { id: "tst:Grid", props: { limit: 4 } }, { id: "tst:Grid", props: { limit: 8 } }],
|
|
428
|
+
},
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
const { data, root } = await renderPluginPage();
|
|
432
|
+
|
|
433
|
+
expect(data.viewSource).toBe("override");
|
|
434
|
+
expect(root.querySelectorAll(".home-default").length).toBe(0);
|
|
435
|
+
expect(root.querySelector("main.home-override h1").textContent).toBe("from-default-load");
|
|
436
|
+
expect(root.querySelector("main.home-override .child-default .label").textContent).toBe("nested");
|
|
437
|
+
// the default Child renders its own default Badge through the proxy
|
|
438
|
+
expect(root.querySelector("main.home-override .child-default .badge").textContent).toBe("in-child");
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
test("override data equals the default's load; the override's own load is ignored", async () => {
|
|
442
|
+
const plain = await renderPluginPage();
|
|
443
|
+
|
|
444
|
+
registry.setThemeConfig({ views: { "tst:Home": override("HomeOverride") } });
|
|
445
|
+
registry.setThemeMeta({ refs: { "tst:Home": [{ id: "tst:Child" }] } });
|
|
446
|
+
|
|
447
|
+
const overridden = await renderPluginPage();
|
|
448
|
+
|
|
449
|
+
expect(overridden.data.props).toEqual(plain.data.props);
|
|
450
|
+
expect(overridden.data.props.title).not.toBe("from-override-load");
|
|
451
|
+
expect(overridden.data.pageTitle).toBe(plain.data.pageTitle);
|
|
452
|
+
expect(overridden.data.component.load).toBe(plain.data.component.load);
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
test("an override with another contract falls back to the default and renders it bridged (source default)", async () => {
|
|
456
|
+
registry.setThemeConfig({ views: { "tst:Home": override("HomeOverride", { contract: 7 }) } });
|
|
457
|
+
|
|
458
|
+
const { data, root } = await renderPluginPage();
|
|
459
|
+
|
|
460
|
+
expect(data.viewSource).toBe("default");
|
|
461
|
+
expect(root.querySelectorAll(".home-override").length).toBe(0);
|
|
462
|
+
expect(root.querySelector(".home-default")).not.toBeNull();
|
|
463
|
+
expect(registry.getIssues().map((issue) => issue.type)).toContain("CONTRACT_MISMATCH");
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
test("two grids with different limit get different data, each at its own key", async () => {
|
|
467
|
+
registry.setThemeConfig({ views: { "tst:Home": override("HomeOverride") } });
|
|
468
|
+
registry.setThemeMeta({
|
|
469
|
+
refs: { "tst:Home": [{ id: "tst:Grid", props: { limit: 4 } }, { id: "tst:Grid", props: { limit: 8 } }] },
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
const { data, root } = await renderPluginPage();
|
|
473
|
+
|
|
474
|
+
const keys = Object.keys(data).filter((key) => key.startsWith("block:"));
|
|
475
|
+
expect(keys.sort()).toEqual(['block:tst:Grid#{"limit":4}', 'block:tst:Grid#{"limit":8}']);
|
|
476
|
+
expect(data['block:tst:Grid#{"limit":4}'].items).toEqual([1, 2, 3, 4]);
|
|
477
|
+
expect(data['block:tst:Grid#{"limit":8}'].items.length).toBe(8);
|
|
478
|
+
|
|
479
|
+
expect(root.querySelectorAll(".four .grid li").length).toBe(4);
|
|
480
|
+
expect(root.querySelectorAll(".eight .grid li").length).toBe(8);
|
|
481
|
+
expect(root.querySelector(".four .grid").getAttribute("data-limit")).toBe("4");
|
|
482
|
+
expect(root.querySelector(".eight .grid").getAttribute("data-limit")).toBe("8");
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
test("a view the registry does not know is a 404, not a crash on a missing module", async () => {
|
|
486
|
+
const event = serverEvent({
|
|
487
|
+
parent: async () => ({ registeredPage: { view: "ghost:Page", component: async () => null } }),
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
await expect(PageModule.load(event)).rejects.toMatchObject({ status: 404 });
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
test("a page registered with a component (no view) keeps working: no registry, source default", async () => {
|
|
494
|
+
const event = serverEvent({
|
|
495
|
+
parent: async () => ({
|
|
496
|
+
registeredPage: { component: async () => ({ default: () => {}, load: async () => ({ x: 1 }) }) },
|
|
497
|
+
}),
|
|
498
|
+
});
|
|
499
|
+
const data = await PageModule.load(event);
|
|
500
|
+
|
|
501
|
+
expect(data.viewSource).toBe("default");
|
|
502
|
+
expect(data.props).toEqual({ x: 1 });
|
|
503
|
+
expect(Object.keys(data).filter((key) => key.startsWith("block:"))).toEqual([]);
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
describe("PluginBlock", () => {
|
|
508
|
+
const renderBlock = (props, data = {}) => {
|
|
509
|
+
pageState.current = { data, url: new URL("http://localhost/"), params: {} };
|
|
510
|
+
return parse(render(PluginBlock, { props }).body);
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
test("reads the data of its own placement from $page.data, props win over data", async () => {
|
|
514
|
+
await registry.preloadViews(["tst:Grid"]);
|
|
515
|
+
|
|
516
|
+
const root = renderBlock(
|
|
517
|
+
{ id: "tst:Grid", limit: 2 },
|
|
518
|
+
{ 'block:tst:Grid#{"limit":2}': { items: ["a", "b"], limit: 99 }, 'block:tst:Grid#{"limit":3}': { items: ["x"] } },
|
|
519
|
+
);
|
|
520
|
+
|
|
521
|
+
expect([...root.querySelectorAll("li")].map((li) => li.textContent)).toEqual(["a", "b"]);
|
|
522
|
+
expect(root.querySelector(".grid").getAttribute("data-limit")).toBe("2");
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
test("the key is missing: it renders with its props only (the browser load happens after mount)", async () => {
|
|
526
|
+
await registry.preloadViews(["tst:Grid"]);
|
|
527
|
+
|
|
528
|
+
const root = renderBlock({ id: "tst:Grid", limit: 3 });
|
|
529
|
+
|
|
530
|
+
expect(root.querySelector(".grid").getAttribute("data-limit")).toBe("3");
|
|
531
|
+
expect(root.querySelectorAll("li").length).toBe(0);
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
test("prefers the override, falls back to the default", async () => {
|
|
535
|
+
registry.setThemeConfig({ views: { "tst:Child": override("ChildOverride") } });
|
|
536
|
+
await registry.preloadViews(["tst:Child"]);
|
|
537
|
+
|
|
538
|
+
expect(renderBlock({ id: "tst:Child", label: "x" }).querySelector(".child-override .label").textContent).toBe("x");
|
|
539
|
+
|
|
540
|
+
registry.setThemeConfig({});
|
|
541
|
+
await registry.preloadViews(["tst:Child"]);
|
|
542
|
+
|
|
543
|
+
expect(renderBlock({ id: "tst:Child", label: "y" }).querySelector(".child-default .label").textContent).toBe("y");
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
test("an unknown id renders nothing, or the fallback snippet", async () => {
|
|
547
|
+
expect(renderBlock({ id: "nope:Missing" }).querySelectorAll("*").length).toBe(0);
|
|
548
|
+
|
|
549
|
+
const host = await build(fixturePath("BlockHost.svelte"));
|
|
550
|
+
const root = parse(render(host.default, { props: { id: "nope:Missing" } }).body);
|
|
551
|
+
|
|
552
|
+
expect(root.querySelector("i.fb").textContent).toBe("fallback");
|
|
553
|
+
|
|
554
|
+
// a known id never shows the fallback
|
|
555
|
+
await registry.preloadViews(["tst:Badge"]);
|
|
556
|
+
const known = parse(render(host.default, { props: { id: "tst:Badge", text: "t" } }).body);
|
|
557
|
+
|
|
558
|
+
expect(known.querySelector("i.fb")).toBeNull();
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
test("goes through views.wrap of the pano context when it is set", async () => {
|
|
562
|
+
await registry.preloadViews(["tst:Badge"]);
|
|
563
|
+
const calls = [];
|
|
564
|
+
setPanoContext({
|
|
565
|
+
views: {
|
|
566
|
+
...getPanoContext().context.views,
|
|
567
|
+
wrap: (name, component, source) => {
|
|
568
|
+
calls.push([name, source]);
|
|
569
|
+
return component;
|
|
570
|
+
},
|
|
571
|
+
},
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
renderBlock({ id: "tst:Badge", text: "w" });
|
|
575
|
+
|
|
576
|
+
expect(calls).toEqual([["tst:Badge", "default"]]);
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
describe("PluginSlot", () => {
|
|
581
|
+
const SLOT = "tst:cart-slot";
|
|
582
|
+
|
|
583
|
+
async function renderSlot(props = {}) {
|
|
584
|
+
await executeViewLoad(SLOT, serverEvent());
|
|
585
|
+
return parse(render(PluginSlot, { props: { id: SLOT, ...props } }).body);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
test("renders the injected views in priority order, with the slot's props", async () => {
|
|
589
|
+
const root = await renderSlot({ props: { order: "o-7" } });
|
|
590
|
+
|
|
591
|
+
expect([...root.querySelectorAll("span")].map((n) => n.className)).toEqual(["navcart", "promo"]);
|
|
592
|
+
expect(root.querySelector(".navcart").getAttribute("data-order")).toBe("o-7");
|
|
593
|
+
// the injected view's own load ran and reached it as data
|
|
594
|
+
expect(root.querySelector(".navcart").getAttribute("data-loaded")).toBe("true");
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
test("filter keeps the items it accepts", async () => {
|
|
598
|
+
const root = await renderSlot({ filter: (item) => item.id === "promo" });
|
|
599
|
+
|
|
600
|
+
expect([...root.querySelectorAll("span")].map((n) => n.className)).toEqual(["promo"]);
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
test("an empty or unknown slot renders nothing", async () => {
|
|
604
|
+
pageState.current = { data: {}, url: new URL("http://localhost/"), params: {} };
|
|
605
|
+
|
|
606
|
+
expect(parse(render(PluginSlot, { props: { id: "tst:empty" } }).body).querySelectorAll("*").length).toBe(0);
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
test("a claimed injection is absent from its slot and its load never runs; claims:false keeps it", async () => {
|
|
610
|
+
// the theme places tst:NavCart itself (the scan found a literal id)
|
|
611
|
+
registry.setThemeMeta({ claims: ["tst:NavCart"] });
|
|
612
|
+
|
|
613
|
+
const claimed = await renderSlot();
|
|
614
|
+
|
|
615
|
+
expect(claimed.querySelector(".navcart")).toBeNull();
|
|
616
|
+
expect(claimed.querySelector(".promo")).not.toBeNull();
|
|
617
|
+
expect(globalThis.__engineWiringLoads).toBe(0);
|
|
618
|
+
|
|
619
|
+
// an explicit false keeps the automatic copy
|
|
620
|
+
registry.setThemeConfig({ claims: { "tst:NavCart": false } });
|
|
621
|
+
registry.setThemeMeta({ claims: ["tst:NavCart"] });
|
|
622
|
+
|
|
623
|
+
const kept = await renderSlot();
|
|
624
|
+
|
|
625
|
+
expect(kept.querySelector(".navcart")).not.toBeNull();
|
|
626
|
+
expect(globalThis.__engineWiringLoads).toBe(1);
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
test("an overridden but unclaimed injection needs nothing: the slot renders the override", async () => {
|
|
630
|
+
registry.setThemeConfig({
|
|
631
|
+
views: {
|
|
632
|
+
"tst:Promo": override("ChildOverride"),
|
|
633
|
+
},
|
|
634
|
+
});
|
|
635
|
+
await registry.preloadViews(["tst:Promo"]);
|
|
636
|
+
|
|
637
|
+
const root = await renderSlot();
|
|
638
|
+
|
|
639
|
+
expect(root.querySelector(".promo")).toBeNull();
|
|
640
|
+
expect(root.querySelector(".child-override")).not.toBeNull();
|
|
641
|
+
});
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
describe("the SDK exports both components", () => {
|
|
645
|
+
test("components/theme.js exports PluginBlock and PluginSlot from the pano context", () => {
|
|
646
|
+
const source = readFileSync(join(import.meta.dir, "..", "..", "..", "..", "sdk", "src", "components", "theme.js"), "utf-8");
|
|
647
|
+
|
|
648
|
+
expect(source).toContain("export const PluginBlock = components.PluginBlock;");
|
|
649
|
+
expect(source).toContain("export const PluginSlot = components.PluginSlot;");
|
|
650
|
+
});
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
// ---------------------------------------------------------------------------
|
|
654
|
+
// PluginBlock in the browser (client build, happy-dom): the load after mount
|
|
655
|
+
// ---------------------------------------------------------------------------
|
|
656
|
+
|
|
657
|
+
describe("PluginBlock in the browser", () => {
|
|
658
|
+
const dom = new Window();
|
|
659
|
+
const DOM_GLOBALS = [
|
|
660
|
+
"window", "document", "navigator", "Node", "Element", "HTMLElement", "HTMLTemplateElement", "HTMLInputElement",
|
|
661
|
+
"HTMLSelectElement", "HTMLTextAreaElement", "HTMLFormElement", "HTMLImageElement", "HTMLIFrameElement",
|
|
662
|
+
"HTMLMediaElement", "ShadowRoot", "Text", "Comment", "DocumentFragment", "Event", "CustomEvent", "MouseEvent",
|
|
663
|
+
"KeyboardEvent", "InputEvent", "MutationObserver", "getComputedStyle", "requestAnimationFrame",
|
|
664
|
+
"cancelAnimationFrame", "customElements",
|
|
665
|
+
];
|
|
666
|
+
const saved = new Map();
|
|
667
|
+
let clientSvelte;
|
|
668
|
+
let ClientBlock;
|
|
669
|
+
let clientGrid;
|
|
670
|
+
|
|
671
|
+
beforeAll(async () => {
|
|
672
|
+
for (const key of DOM_GLOBALS) {
|
|
673
|
+
saved.set(key, Object.getOwnPropertyDescriptor(globalThis, key));
|
|
674
|
+
const value = key === "window" ? dom : dom[key];
|
|
675
|
+
if (value === undefined) continue;
|
|
676
|
+
Object.defineProperty(globalThis, key, {
|
|
677
|
+
value: typeof value === "function" && !/^[A-Z]/.test(key) ? value.bind(dom) : value,
|
|
678
|
+
configurable: true,
|
|
679
|
+
writable: true,
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
clientSvelte = await import(join(svelteDir, "src", "index-client.js"));
|
|
684
|
+
ClientBlock = (await import(emit(realPath("lib/components/PluginBlock.svelte"), "client"))).default;
|
|
685
|
+
clientGrid = await import(emit(fixturePath("Grid.svelte"), "client"));
|
|
686
|
+
});
|
|
687
|
+
|
|
688
|
+
afterAll(() => {
|
|
689
|
+
for (const key of DOM_GLOBALS) {
|
|
690
|
+
const was = saved.get(key);
|
|
691
|
+
if (was) Object.defineProperty(globalThis, key, was);
|
|
692
|
+
else delete globalThis[key];
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
const registerClientGrid = () =>
|
|
697
|
+
registry.registerViews([viewDef("tst:Grid", "Grid", { block: true, component: async () => clientGrid })]);
|
|
698
|
+
|
|
699
|
+
async function mountBlock(props, data = {}) {
|
|
700
|
+
globalThis.__engineWiringClientPage = {
|
|
701
|
+
data,
|
|
702
|
+
url: new URL("http://localhost/"),
|
|
703
|
+
params: {},
|
|
704
|
+
route: { id: "/" },
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
const target = dom.document.createElement("div");
|
|
708
|
+
dom.document.body.appendChild(target);
|
|
709
|
+
|
|
710
|
+
const instance = clientSvelte.mount(ClientBlock, { target, props });
|
|
711
|
+
clientSvelte.flushSync();
|
|
712
|
+
// the load runs in an async effect: give it a few turns
|
|
713
|
+
for (let i = 0; i < 5; i++) {
|
|
714
|
+
await new Promise((done) => setTimeout(done, 0));
|
|
715
|
+
clientSvelte.flushSync();
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
return { target, instance };
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
test("the key is missing: the view's load runs once after mount with the literal props, and the data shows up", async () => {
|
|
722
|
+
registerClientGrid();
|
|
723
|
+
await registry.preloadViews(["tst:Grid"]);
|
|
724
|
+
|
|
725
|
+
const { target, instance } = await mountBlock({ id: "tst:Grid", limit: 3 });
|
|
726
|
+
|
|
727
|
+
expect(globalThis.__engineWiringGridLoads).toBe(1);
|
|
728
|
+
expect(target.querySelectorAll("li").length).toBe(3);
|
|
729
|
+
expect(target.querySelector(".grid").getAttribute("data-limit")).toBe("3");
|
|
730
|
+
|
|
731
|
+
clientSvelte.unmount(instance);
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
test("the key is there: no load in the browser, the page data is used", async () => {
|
|
735
|
+
registerClientGrid();
|
|
736
|
+
await registry.preloadViews(["tst:Grid"]);
|
|
737
|
+
|
|
738
|
+
const { target, instance } = await mountBlock(
|
|
739
|
+
{ id: "tst:Grid", limit: 2 },
|
|
740
|
+
{ 'block:tst:Grid#{"limit":2}': { items: ["a", "b"] } },
|
|
741
|
+
);
|
|
742
|
+
|
|
743
|
+
expect(globalThis.__engineWiringGridLoads).toBe(0);
|
|
744
|
+
expect([...target.querySelectorAll("li")].map((li) => li.textContent)).toEqual(["a", "b"]);
|
|
745
|
+
|
|
746
|
+
clientSvelte.unmount(instance);
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
test("a view that was not preloaded is resolved after mount", async () => {
|
|
750
|
+
registerClientGrid();
|
|
751
|
+
|
|
752
|
+
const { target, instance } = await mountBlock({ id: "tst:Grid", limit: 1 }, { 'block:tst:Grid#{"limit":1}': { items: ["z"] } });
|
|
753
|
+
|
|
754
|
+
expect(target.querySelector(".grid")).not.toBeNull();
|
|
755
|
+
expect([...target.querySelectorAll("li")].map((li) => li.textContent)).toEqual(["z"]);
|
|
756
|
+
|
|
757
|
+
clientSvelte.unmount(instance);
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
test("a view that is not a block is rendered but its load is not called in the browser (CX-03)", async () => {
|
|
761
|
+
registry.registerViews([viewDef("tst:Grid", "Grid", { component: async () => clientGrid })]);
|
|
762
|
+
await registry.preloadViews(["tst:Grid"]);
|
|
763
|
+
|
|
764
|
+
expect(registry.describeView("tst:Grid").block).toBe(false);
|
|
765
|
+
|
|
766
|
+
const { target, instance } = await mountBlock({ id: "tst:Grid", limit: 3 });
|
|
767
|
+
|
|
768
|
+
expect(globalThis.__engineWiringGridLoads).toBe(0);
|
|
769
|
+
expect(target.querySelector(".grid")).not.toBeNull();
|
|
770
|
+
expect(target.querySelectorAll("li").length).toBe(0);
|
|
771
|
+
|
|
772
|
+
clientSvelte.unmount(instance);
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
test("an unknown id stays empty and loads nothing", async () => {
|
|
776
|
+
const { target, instance } = await mountBlock({ id: "nope:Missing" });
|
|
777
|
+
|
|
778
|
+
expect(target.querySelectorAll("*").length).toBe(0);
|
|
779
|
+
expect(globalThis.__engineWiringGridLoads).toBe(0);
|
|
780
|
+
|
|
781
|
+
clientSvelte.unmount(instance);
|
|
782
|
+
});
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
// ---------------------------------------------------------------------------
|
|
786
|
+
// AppLayoutLogics: the pano context and the theme setup
|
|
787
|
+
// ---------------------------------------------------------------------------
|
|
788
|
+
|
|
789
|
+
describe("AppLayoutLogics wiring", () => {
|
|
790
|
+
const logicsFile = join(import.meta.dir, "..", "ui-logics", "layout-logics", "AppLayoutLogics.js");
|
|
791
|
+
|
|
792
|
+
/** names that must be real objects, not call-me stubs */
|
|
793
|
+
const VALUES = {
|
|
794
|
+
languageStuff: () => ({ init: async () => "lang", activateLanguage() {} }),
|
|
795
|
+
avatarVersion: () => writable(null),
|
|
796
|
+
initialized: () => writable(true),
|
|
797
|
+
_: () => writable((key) => key),
|
|
798
|
+
};
|
|
799
|
+
|
|
800
|
+
globalThis.__engineWiringLogics = {
|
|
801
|
+
stubs(name) {
|
|
802
|
+
if (name in VALUES) return VALUES[name]();
|
|
803
|
+
const fn = async () => ({});
|
|
804
|
+
fn.stubName = name;
|
|
805
|
+
return fn;
|
|
806
|
+
},
|
|
807
|
+
destroyers: [],
|
|
808
|
+
contexts: new Map(),
|
|
809
|
+
bound: [],
|
|
810
|
+
createThemeHost: Object.assign(() => ({}), { stubName: "createThemeHost" }),
|
|
811
|
+
themeHostFactory: Object.assign(() => ({}), { stubName: "themeHostFactory" }),
|
|
812
|
+
};
|
|
813
|
+
const shared = globalThis.__engineWiringLogics;
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* AppLayoutLogics.js with every import replaced by a stub except the registry, the route config, the plugin API,
|
|
817
|
+
* the SDK context and the stores, which stay real. `browser` is a constant of the build.
|
|
818
|
+
*/
|
|
819
|
+
function buildLogics({ browser }) {
|
|
820
|
+
const keep = new Map([
|
|
821
|
+
["$pano/registry/index.js", join(pkgSrc, "registry", "index.js")],
|
|
822
|
+
["$pano/registry/routes.js", join(pkgSrc, "registry", "routes.js")],
|
|
823
|
+
["$pano/lib/PluginAPI", PLUGIN_API_SPEC],
|
|
824
|
+
["@panomc/sdk/internal", Bun.resolveSync("@panomc/sdk/internal", pkgSrc)],
|
|
825
|
+
["svelte/store", "svelte/store"],
|
|
826
|
+
["$app/stores", "$app/stores"],
|
|
827
|
+
["$app/paths", "$app/paths"],
|
|
828
|
+
["@sveltejs/kit", "@sveltejs/kit"],
|
|
829
|
+
["$app/navigation", "$app/navigation"],
|
|
830
|
+
]);
|
|
831
|
+
const declare = (what, from) => {
|
|
832
|
+
const lines = [];
|
|
833
|
+
const text = what.trim();
|
|
834
|
+
const star = text.match(/\*\s+as\s+(\w+)/);
|
|
835
|
+
const named = text.match(/\{([\s\S]*)\}/);
|
|
836
|
+
const first = text.replace(/\{[\s\S]*\}/, "").replace(/\*\s+as\s+\w+/, "").replace(/,/g, "").trim();
|
|
837
|
+
if (first) lines.push(`const ${first} = __s.stubs(${JSON.stringify(first)});`);
|
|
838
|
+
if (star) lines.push(`const ${star[1]} = __s.stubs(${JSON.stringify(star[1])});`);
|
|
839
|
+
if (named) {
|
|
840
|
+
for (const part of named[1].split(",")) {
|
|
841
|
+
const name = part.trim().split(/\s+as\s+/).pop();
|
|
842
|
+
if (name) lines.push(`const ${name} = __s.stubs(${JSON.stringify(name)});`);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
if (from === "svelte") {
|
|
846
|
+
return [
|
|
847
|
+
"const onDestroy = (fn) => __s.destroyers.push(fn);",
|
|
848
|
+
"const onMount = () => {};",
|
|
849
|
+
"const setContext = (key, value) => __s.contexts.set(key, value);",
|
|
850
|
+
].join("\n");
|
|
851
|
+
}
|
|
852
|
+
if (from === "$pano/lib/controllerHost") {
|
|
853
|
+
return [
|
|
854
|
+
"const createThemeHost = __s.createThemeHost;",
|
|
855
|
+
"const themeHostFactory = __s.themeHostFactory;",
|
|
856
|
+
"const bindControllerSession = (session) => { __s.bound.push(session); return () => {}; };",
|
|
857
|
+
].join("\n");
|
|
858
|
+
}
|
|
859
|
+
if (from === "$app/environment") return `const browser = ${browser}; const dev = false;`;
|
|
860
|
+
return lines.join("\n");
|
|
861
|
+
};
|
|
862
|
+
|
|
863
|
+
let code = readFileSync(logicsFile, "utf-8");
|
|
864
|
+
code = code.replace(/import\s+([\s\S]*?)\s+from\s+["']([^"']+)["'];?/g, (whole, what, from) => {
|
|
865
|
+
if (keep.has(from)) return `import ${what} from ${JSON.stringify(keep.get(from))};`;
|
|
866
|
+
return declare(what, from);
|
|
867
|
+
});
|
|
868
|
+
// side-effect-only imports (none today) and the shared handle
|
|
869
|
+
code = `const __s = globalThis.__engineWiringLogics;\n${code}`;
|
|
870
|
+
|
|
871
|
+
const out = join(workDir, `logics${counter++}.mjs`);
|
|
872
|
+
writeFileSync(out, code);
|
|
873
|
+
return import(out);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
const processEvent = () => ({
|
|
877
|
+
data: {
|
|
878
|
+
user: null,
|
|
879
|
+
csrfToken: "t",
|
|
880
|
+
siteInfo: { locale: "en", themeSettings: {} },
|
|
881
|
+
apiUrlEnv: null,
|
|
882
|
+
panoWebsiteUrlEnv: null,
|
|
883
|
+
avatarVersionDate: "v=1",
|
|
884
|
+
},
|
|
885
|
+
parent: async () => ({}),
|
|
886
|
+
url: new URL("http://localhost/"),
|
|
887
|
+
});
|
|
888
|
+
|
|
889
|
+
const hostFactory = () => globalThis.__PANO_CONTROLLERS__?.hostFactory;
|
|
890
|
+
const pins = () => globalThis.__PANO_CONTROLLERS__?.pins;
|
|
891
|
+
|
|
892
|
+
beforeEach(() => {
|
|
893
|
+
shared.destroyers.length = 0;
|
|
894
|
+
shared.contexts.clear();
|
|
895
|
+
shared.bound.length = 0;
|
|
896
|
+
globalThis.__PANO_CONTROLLERS__ = undefined;
|
|
897
|
+
});
|
|
898
|
+
|
|
899
|
+
test("the source puts views, routes and both components into the pano context and keeps the old keys", () => {
|
|
900
|
+
const source = readFileSync(logicsFile, "utf-8");
|
|
901
|
+
|
|
902
|
+
expect(source).toMatch(/views:\s*{\s*getOverride,\s*getDefault,\s*has:\s*hasView,\s*wrap:\s*wrapView,\s*wrapInjected:\s*wrapInjectedView,?\s*}/);
|
|
903
|
+
expect(source).toMatch(/routes:\s*{\s*resolve:\s*route,?\s*}/);
|
|
904
|
+
expect(source).toContain("PluginBlock,");
|
|
905
|
+
expect(source).toContain("PluginSlot,");
|
|
906
|
+
// the old context components are all still there
|
|
907
|
+
for (const name of ["Date", "Pagination", "NoContent", "PageActions", "PageTitle", "PlayerHead", "Toast", "Sidebar", "ViewComponent", "Hook"]) {
|
|
908
|
+
expect(source).toMatch(new RegExp(`\\b${name}\\b`));
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
|
|
912
|
+
test("processLoad: views, routes and components land in the pano context; setup is done once", async () => {
|
|
913
|
+
registry.setThemeConfig({ routes: { rename: { "/store": "/shop" } }, controllers: { "tst/cart": 2 } });
|
|
914
|
+
|
|
915
|
+
const logics = await buildLogics({ browser: false });
|
|
916
|
+
await logics.processLoad(processEvent());
|
|
917
|
+
|
|
918
|
+
const { context } = getPanoContext();
|
|
919
|
+
|
|
920
|
+
expect(context.views.getOverride).toBe(registry.getOverride);
|
|
921
|
+
expect(context.views.getDefault).toBe(registry.getDefault);
|
|
922
|
+
expect(context.views.has).toBe(registry.hasView);
|
|
923
|
+
// wrap is the identity for now
|
|
924
|
+
const Component = () => {};
|
|
925
|
+
expect(context.views.wrap("tst:Home", Component, "default")).toBe(Component);
|
|
926
|
+
expect(context.routes.resolve).toBe(registry.route);
|
|
927
|
+
expect(context.routes.resolve("/store")).toBe("/shop");
|
|
928
|
+
expect(context.routes.resolve("/other")).toBe("/other");
|
|
929
|
+
expect(context.components.PluginBlock.stubName).toBe("PluginBlock");
|
|
930
|
+
expect(context.components.PluginSlot.stubName).toBe("PluginSlot");
|
|
931
|
+
// the old keys survive
|
|
932
|
+
expect(context.components.Hook.stubName).toBe("Hook");
|
|
933
|
+
expect(context.components.Date).toBeDefined();
|
|
934
|
+
expect(context.utils.api).toBeDefined();
|
|
935
|
+
|
|
936
|
+
// The registry hands the bare request event to the factory, so the engine registers themeHostFactory (which
|
|
937
|
+
// wraps it for createThemeHost), not createThemeHost itself.
|
|
938
|
+
expect(hostFactory()).toBe(shared.themeHostFactory);
|
|
939
|
+
expect(pins()).toEqual({ "tst/cart": 2 });
|
|
940
|
+
|
|
941
|
+
// a second load (a navigation) does not reset the host factory again
|
|
942
|
+
const host = {};
|
|
943
|
+
globalThis.__PANO_CONTROLLERS__.browserHost = host;
|
|
944
|
+
await logics.processLoad(processEvent());
|
|
945
|
+
expect(globalThis.__PANO_CONTROLLERS__.browserHost).toBe(host);
|
|
946
|
+
});
|
|
947
|
+
|
|
948
|
+
test("a theme without the virtual module gets an empty theme meta", async () => {
|
|
949
|
+
registry.setThemeMeta({ refs: { x: [{ id: "a:B" }] }, claims: ["a:B"] });
|
|
950
|
+
registry.setThemeConfig({});
|
|
951
|
+
|
|
952
|
+
const logics = await buildLogics({ browser: false });
|
|
953
|
+
await logics.processLoad(processEvent());
|
|
954
|
+
|
|
955
|
+
expect(registry.getThemeMeta()).toEqual({ refs: {}, claims: [], homePages: {} });
|
|
956
|
+
});
|
|
957
|
+
|
|
958
|
+
test("virtual:pano-theme-meta, when it resolves, becomes the theme meta", async () => {
|
|
959
|
+
mock.module("virtual:pano-theme-meta", () => ({
|
|
960
|
+
default: { refs: { "tst:Home": [{ id: "tst:Grid", props: { limit: 4 } }] }, claims: ["tst:NavCart"], homePages: {} },
|
|
961
|
+
}));
|
|
962
|
+
|
|
963
|
+
registry.setThemeConfig({});
|
|
964
|
+
const logics = await buildLogics({ browser: false });
|
|
965
|
+
await logics.processLoad(processEvent());
|
|
966
|
+
|
|
967
|
+
expect(registry.getThemeMeta().refs).toEqual({ "tst:Home": [{ id: "tst:Grid", props: { limit: 4 } }] });
|
|
968
|
+
expect(registry.getClaims().has("tst:NavCart")).toBe(true);
|
|
969
|
+
});
|
|
970
|
+
|
|
971
|
+
test("init binds the controller session in the browser only", async () => {
|
|
972
|
+
registry.setThemeConfig({});
|
|
973
|
+
const data = (await (await buildLogics({ browser: false })).processLoad(processEvent()));
|
|
974
|
+
|
|
975
|
+
const server = await buildLogics({ browser: false });
|
|
976
|
+
server.init(data);
|
|
977
|
+
expect(shared.bound.length).toBe(0);
|
|
978
|
+
|
|
979
|
+
const client = await buildLogics({ browser: true });
|
|
980
|
+
const had = { window: globalThis.window, document: globalThis.document };
|
|
981
|
+
globalThis.document = { visibilityState: "hidden", addEventListener() {}, removeEventListener() {} };
|
|
982
|
+
globalThis.window = { setTimeout, clearTimeout };
|
|
983
|
+
let result;
|
|
984
|
+
try {
|
|
985
|
+
result = client.init(data);
|
|
986
|
+
} finally {
|
|
987
|
+
for (const [key, value] of Object.entries(had)) {
|
|
988
|
+
if (value === undefined) delete globalThis[key];
|
|
989
|
+
else globalThis[key] = value;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
expect(shared.bound.length).toBe(1);
|
|
994
|
+
// the very session store the layout hands to its children
|
|
995
|
+
expect(shared.bound[0]).toBe(result.session);
|
|
996
|
+
expect(shared.contexts.get("session")).toBe(result.session);
|
|
997
|
+
// and it is released with the layout
|
|
998
|
+
expect(shared.destroyers.length).toBeGreaterThan(0);
|
|
999
|
+
});
|
|
1000
|
+
});
|