@panomc/theme-core 1.0.0-dev.59 → 1.0.0-dev.61
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 +7 -3
- 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 +91 -7
- package/src/kit/route-map.js +300 -0
- package/src/kit/specifiers.js +3 -0
- 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,96 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { resolvePageTitle } from "../pageTitle.util.js";
|
|
3
|
+
|
|
4
|
+
const dict = { "page.home": "Home", "page.hello": "Hello {name}", "page.sub": "Subtitle" };
|
|
5
|
+
// Mimics svelte-i18n: unknown keys come back as the key itself, {name} is interpolated.
|
|
6
|
+
const calls = [];
|
|
7
|
+
const translate = (key, options) => {
|
|
8
|
+
calls.push([key, options]);
|
|
9
|
+
const template = dict[key] ?? key;
|
|
10
|
+
|
|
11
|
+
return template.replace(/\{(\w+)\}/g, (_, name) => options?.values?.[name] ?? `{${name}}`);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
describe("resolvePageTitle (TC-3)", () => {
|
|
15
|
+
test("string key is translated", () => {
|
|
16
|
+
expect(resolvePageTitle("page.home", translate)).toEqual({
|
|
17
|
+
title: "Home",
|
|
18
|
+
subtitle: "",
|
|
19
|
+
hidden: false,
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("object form translates title and subtitle", () => {
|
|
24
|
+
expect(resolvePageTitle({ title: "page.home", subtitle: "page.sub" }, translate)).toEqual({
|
|
25
|
+
title: "Home",
|
|
26
|
+
subtitle: "Subtitle",
|
|
27
|
+
hidden: false,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("raw: title and subtitle are used verbatim, translate is never called", () => {
|
|
32
|
+
calls.length = 0;
|
|
33
|
+
|
|
34
|
+
const out = resolvePageTitle(
|
|
35
|
+
{ title: "page.home", subtitle: "page.sub", raw: true },
|
|
36
|
+
translate,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
expect(out).toEqual({ title: "page.home", subtitle: "page.sub", hidden: false });
|
|
40
|
+
expect(calls).toHaveLength(0);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("raw only counts when it is exactly true", () => {
|
|
44
|
+
expect(resolvePageTitle({ title: "page.home", raw: "yes" }, translate).title).toBe("Home");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("hidden flag is passed through", () => {
|
|
48
|
+
expect(resolvePageTitle({ title: "page.home", hidden: true }, translate)).toEqual({
|
|
49
|
+
title: "Home",
|
|
50
|
+
subtitle: "",
|
|
51
|
+
hidden: true,
|
|
52
|
+
});
|
|
53
|
+
expect(resolvePageTitle({ title: "x", raw: true, hidden: true }, translate).hidden).toBe(true);
|
|
54
|
+
expect(resolvePageTitle({ title: "page.home", hidden: "yes" }, translate).hidden).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("titleValues / subtitleValues are interpolated", () => {
|
|
58
|
+
const out = resolvePageTitle(
|
|
59
|
+
{
|
|
60
|
+
title: "page.hello",
|
|
61
|
+
titleValues: { name: "Steve" },
|
|
62
|
+
subtitle: "page.hello",
|
|
63
|
+
subtitleValues: { name: "Alex" },
|
|
64
|
+
},
|
|
65
|
+
translate,
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
expect(out.title).toBe("Hello Steve");
|
|
69
|
+
expect(out.subtitle).toBe("Hello Alex");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("missing values default to an empty object (as before)", () => {
|
|
73
|
+
calls.length = 0;
|
|
74
|
+
resolvePageTitle({ title: "page.home" }, translate);
|
|
75
|
+
expect(calls[0]).toEqual(["page.home", { values: {} }]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("raw ignores values and does not interpolate", () => {
|
|
79
|
+
const out = resolvePageTitle(
|
|
80
|
+
{ title: "Hello {name}", titleValues: { name: "Steve" }, raw: true },
|
|
81
|
+
translate,
|
|
82
|
+
);
|
|
83
|
+
expect(out.title).toBe("Hello {name}");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("empty / absent parts resolve to empty strings", () => {
|
|
87
|
+
for (const pt of [null, undefined, "", {}, { title: "" }, 5, true]) {
|
|
88
|
+
expect(resolvePageTitle(pt, translate)).toEqual({ title: "", subtitle: "", hidden: false });
|
|
89
|
+
}
|
|
90
|
+
expect(resolvePageTitle({ subtitle: "page.sub" }, translate)).toEqual({
|
|
91
|
+
title: "",
|
|
92
|
+
subtitle: "Subtitle",
|
|
93
|
+
hidden: false,
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, mock, spyOn, test } from "bun:test";
|
|
2
|
+
import { writable } from "svelte/store";
|
|
3
|
+
import { get } from "svelte/store";
|
|
4
|
+
|
|
5
|
+
// The SvelteKit aliases are not installed in this repo: stub what PluginAPI.js and its imports use.
|
|
6
|
+
class Redirect {
|
|
7
|
+
constructor(status, location) {
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.location = location;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const navigations = [];
|
|
13
|
+
// bun mocks are process-wide and a module that is already linked cannot gain exports: every stub below is a
|
|
14
|
+
// superset of what the other suites mock for the same specifier.
|
|
15
|
+
mock.module("@sveltejs/kit", () => ({
|
|
16
|
+
redirect: (status, location) => {
|
|
17
|
+
throw new Redirect(status, location);
|
|
18
|
+
},
|
|
19
|
+
error: (status) => Object.assign(new Error(`HTTP ${status}`), { status }),
|
|
20
|
+
}));
|
|
21
|
+
mock.module("$app/paths", () => ({ base: "" }));
|
|
22
|
+
mock.module("$app/environment", () => ({ browser: false, dev: false }));
|
|
23
|
+
mock.module("$app/navigation", () => ({
|
|
24
|
+
goto: async (url, options) => {
|
|
25
|
+
navigations.push({ url, options });
|
|
26
|
+
},
|
|
27
|
+
invalidate: async () => {},
|
|
28
|
+
invalidateAll: async () => {},
|
|
29
|
+
}));
|
|
30
|
+
// Store.js (a relative import of PluginAPI.js) still reaches for the alias
|
|
31
|
+
const returnToUtil = await import("../returnTo.util.js");
|
|
32
|
+
mock.module("$pano/lib/returnTo.util.js", () => returnToUtil);
|
|
33
|
+
mock.module("$pano/lib/services/auth.js", () => ({ sendLogout: async () => {} }));
|
|
34
|
+
mock.module("$pano/lib/components/ToastContainer.svelte", () => ({
|
|
35
|
+
show: async () => {},
|
|
36
|
+
showSuccess: async () => {},
|
|
37
|
+
showError: async () => {},
|
|
38
|
+
limitTitle: (text) => text,
|
|
39
|
+
}));
|
|
40
|
+
// bun mocks are process-wide: a superset of what the other suites stub for the same file.
|
|
41
|
+
const pluginManagerStub = () => ({
|
|
42
|
+
plugins: writable({}),
|
|
43
|
+
registeredPages: {},
|
|
44
|
+
findMatch: () => null,
|
|
45
|
+
});
|
|
46
|
+
mock.module("@panomc/sdk/core/js/PluginManager.js", pluginManagerStub);
|
|
47
|
+
mock.module(new URL("../../../../sdk/core/js/PluginManager.js", import.meta.url).pathname, pluginManagerStub);
|
|
48
|
+
// (factories return resolved namespaces: a factory that returns a promise can deadlock against the other
|
|
49
|
+
// suites that mock the same specifier)
|
|
50
|
+
const sdkPluginApi = await import("../../../../sdk/core/js/PluginAPI.js");
|
|
51
|
+
mock.module("@panomc/sdk/core/js/PluginAPI", () => sdkPluginApi);
|
|
52
|
+
// PluginAPI imports the engine, the registry and returnTo.util relatively, so this suite runs the REAL ones
|
|
53
|
+
// whatever the other suites mock for the `$pano/...` spelling.
|
|
54
|
+
const registry = await import("../../registry/index.js");
|
|
55
|
+
const { setRouteConfig } = await import("../../registry/routes.js");
|
|
56
|
+
const controllersModule = await import("../../../../sdk/core/js/ControllerRegistry.js");
|
|
57
|
+
// a query makes this instance independent of other suites that import PluginAPI with their own mocks
|
|
58
|
+
const api = await import("../PluginAPI.js?pluginApiViews");
|
|
59
|
+
const { panoApi, init, executeViewLoad, executeHookLoad, THEME_FEATURE_IDS } = api;
|
|
60
|
+
|
|
61
|
+
const pluginManager = await import("@panomc/sdk/core/js/PluginManager.js");
|
|
62
|
+
|
|
63
|
+
const MARKET = "pano-plugin-market";
|
|
64
|
+
const Page = function Page() {};
|
|
65
|
+
const Card = function Card() {};
|
|
66
|
+
const load = async () => ({ products: [1, 2] });
|
|
67
|
+
|
|
68
|
+
const def = (name, over = {}) => ({
|
|
69
|
+
name,
|
|
70
|
+
pluginId: MARKET,
|
|
71
|
+
contract: 1,
|
|
72
|
+
kind: "component",
|
|
73
|
+
component: async () => ({ default: Card, load }),
|
|
74
|
+
...over,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
let errorSpy;
|
|
78
|
+
let warnSpy;
|
|
79
|
+
// bun mocks are process-wide and later-loaded suites replace them: install the two that record behaviour per test
|
|
80
|
+
function installSpies() {
|
|
81
|
+
mock.module("@sveltejs/kit", () => ({
|
|
82
|
+
redirect: (status, location) => {
|
|
83
|
+
throw new Redirect(status, location);
|
|
84
|
+
},
|
|
85
|
+
error: (status) => Object.assign(new Error(`HTTP ${status}`), { status }),
|
|
86
|
+
}));
|
|
87
|
+
mock.module("$app/navigation", () => ({
|
|
88
|
+
goto: async (url, options) => {
|
|
89
|
+
navigations.push({ url, options });
|
|
90
|
+
},
|
|
91
|
+
invalidate: async () => {},
|
|
92
|
+
invalidateAll: async () => {},
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
beforeEach(async () => {
|
|
97
|
+
installSpies();
|
|
98
|
+
registry.resetRegistryForTests();
|
|
99
|
+
await init();
|
|
100
|
+
navigations.length = 0;
|
|
101
|
+
errorSpy = spyOn(console, "error").mockImplementation(() => {});
|
|
102
|
+
warnSpy = spyOn(console, "warn").mockImplementation(() => {});
|
|
103
|
+
registry.setThemeConfig({});
|
|
104
|
+
});
|
|
105
|
+
afterEach(async () => {
|
|
106
|
+
setRouteConfig();
|
|
107
|
+
errorSpy.mockRestore();
|
|
108
|
+
warnSpy.mockRestore();
|
|
109
|
+
await init();
|
|
110
|
+
registry.resetRegistryForTests();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const warnings = () => warnSpy.mock.calls.map((call) => String(call[0]));
|
|
114
|
+
const errors = () => errorSpy.mock.calls.map((call) => String(call[0]));
|
|
115
|
+
|
|
116
|
+
describe("pano.views", () => {
|
|
117
|
+
test("add registers the defaults; has and describe answer for them", () => {
|
|
118
|
+
expect(panoApi.views.has("market:ProductCard")).toBe(false);
|
|
119
|
+
expect(panoApi.views.describe("market:ProductCard")).toBeNull();
|
|
120
|
+
|
|
121
|
+
panoApi.views.add([def("market:ProductCard", { contract: 2 })]);
|
|
122
|
+
|
|
123
|
+
expect(panoApi.views.has("market:ProductCard")).toBe(true);
|
|
124
|
+
// the pluginId spelling is accepted as an alias
|
|
125
|
+
expect(panoApi.views.has(`${MARKET}:ProductCard`)).toBe(true);
|
|
126
|
+
expect(panoApi.views.describe("market:ProductCard")).toEqual({
|
|
127
|
+
contract: 2,
|
|
128
|
+
block: false,
|
|
129
|
+
overridden: false,
|
|
130
|
+
overrideContract: null,
|
|
131
|
+
status: "default",
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("a def whose namespace belongs to another plugin is rejected, and so are its pages and injections", () => {
|
|
136
|
+
panoApi.views.add([def("market:ProductCard")]);
|
|
137
|
+
panoApi.views.add([
|
|
138
|
+
def("market:Intruder", {
|
|
139
|
+
pluginId: "pano-plugin-evil",
|
|
140
|
+
page: { path: "/intruder" },
|
|
141
|
+
inject: [{ slot: "profile-content", id: "intruder" }],
|
|
142
|
+
}),
|
|
143
|
+
]);
|
|
144
|
+
|
|
145
|
+
expect(panoApi.views.has("market:Intruder")).toBe(false);
|
|
146
|
+
expect(panoApi.ui.page.isPluginPage("/intruder")).toBe(false);
|
|
147
|
+
expect(get(panoApi.ui.view.get("profile-content"))).toEqual([]);
|
|
148
|
+
expect(errors().join("\n")).toContain("NAMESPACE_CLASH");
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test("add applies a page: it is registered with the view and a component thunk that keeps the plugin's load", async () => {
|
|
152
|
+
panoApi.views.add([
|
|
153
|
+
def("market:StorePage", {
|
|
154
|
+
kind: "page",
|
|
155
|
+
page: { path: "/store", loginRequired: true },
|
|
156
|
+
home: { label: "Store" },
|
|
157
|
+
component: async () => ({ default: Page, load }),
|
|
158
|
+
}),
|
|
159
|
+
]);
|
|
160
|
+
|
|
161
|
+
expect(panoApi.ui.page.isPluginPage("/store")).toBe(true);
|
|
162
|
+
|
|
163
|
+
const registered = Object.values(pluginManager.registeredPages).find((page) => page.path === "/store");
|
|
164
|
+
expect(registered).toMatchObject({
|
|
165
|
+
path: "/store",
|
|
166
|
+
view: "market:StorePage",
|
|
167
|
+
loginRequired: true,
|
|
168
|
+
home: { label: "Store" },
|
|
169
|
+
pluginId: MARKET,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const module = await registered.component();
|
|
173
|
+
expect(module.default).toBe(Page);
|
|
174
|
+
expect(module.load).toBe(load);
|
|
175
|
+
expect(warnings()).toEqual([]);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test("add applies slot, sidebar and hook injections", async () => {
|
|
179
|
+
panoApi.views.add([
|
|
180
|
+
def("market:NavCart", {
|
|
181
|
+
inject: [
|
|
182
|
+
{ slot: "navbar-right", id: "market-cart", priority: 40 },
|
|
183
|
+
{ sidebar: "home", priority: 5 },
|
|
184
|
+
{ hook: "theme:top", skipLoad: true },
|
|
185
|
+
],
|
|
186
|
+
}),
|
|
187
|
+
]);
|
|
188
|
+
|
|
189
|
+
const [slotItem] = get(panoApi.ui.view.get("navbar-right"));
|
|
190
|
+
expect(slotItem).toMatchObject({ id: "market-cart", priority: 40, view: "market:NavCart" });
|
|
191
|
+
|
|
192
|
+
const [sidebarItem] = get(panoApi.ui.sidebar.get("home"));
|
|
193
|
+
// no explicit id: the view id; a sidebar item gets the prop sidebarId
|
|
194
|
+
expect(sidebarItem).toMatchObject({ id: "market:NavCart", priority: 5, props: { sidebarId: "home" } });
|
|
195
|
+
|
|
196
|
+
const [hookEntry] = get(panoApi.ui.hook.get("theme:top"));
|
|
197
|
+
expect(hookEntry).toMatchObject({ view: "market:NavCart", skipLoad: true, name: "theme:top" });
|
|
198
|
+
|
|
199
|
+
// all three resolve to the default module
|
|
200
|
+
expect((await slotItem.component()).default).toBe(Card);
|
|
201
|
+
expect((await hookEntry.component()).default).toBe(Card);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("an array of slots injects into each", () => {
|
|
205
|
+
panoApi.views.add([def("market:Badge", { inject: [{ slot: ["profile-content", "settings-content"] }] })]);
|
|
206
|
+
|
|
207
|
+
expect(get(panoApi.ui.view.get("profile-content")).length).toBe(1);
|
|
208
|
+
expect(get(panoApi.ui.view.get("settings-content")).length).toBe(1);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
describe("normalizeItem", () => {
|
|
213
|
+
test("a `view` item resolves through the registry and survives a later edit", async () => {
|
|
214
|
+
panoApi.views.add([def("market:ProductCard")]);
|
|
215
|
+
|
|
216
|
+
panoApi.ui.profile.content.edit((items) => {
|
|
217
|
+
items.push({ id: "card", priority: 5, view: "market:ProductCard" });
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
const resolved = await executeViewLoad("profile-content", {});
|
|
221
|
+
expect(resolved).toHaveLength(1);
|
|
222
|
+
// the module is stored on the item, with the plugin's load result as props.data
|
|
223
|
+
expect(typeof resolved[0].component).toBe("object");
|
|
224
|
+
expect(resolved[0].component.default).toBe(Card);
|
|
225
|
+
expect(resolved[0].props.data).toEqual({ products: [1, 2] });
|
|
226
|
+
|
|
227
|
+
// a later edit must not blank the loaded module back into a thunk
|
|
228
|
+
panoApi.ui.profile.content.edit((items) => {
|
|
229
|
+
items.push({ id: "other", priority: 1, component: "local:other" });
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const [card] = get(panoApi.ui.profile.content.get()).filter((item) => item.id === "card");
|
|
233
|
+
expect(typeof card.component).toBe("object");
|
|
234
|
+
expect(card.component.default).toBe(Card);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test("an item whose view changed gets a new component thunk", async () => {
|
|
238
|
+
const Other = function Other() {};
|
|
239
|
+
panoApi.views.add([def("market:A"), def("market:B", { component: async () => ({ default: Other }) })]);
|
|
240
|
+
|
|
241
|
+
const item = { id: "x", view: "market:A" };
|
|
242
|
+
panoApi.ui.profile.content.edit((items) => items.push(item));
|
|
243
|
+
expect((await item.component()).default).toBe(Card);
|
|
244
|
+
|
|
245
|
+
panoApi.ui.profile.content.edit((items) => {
|
|
246
|
+
items[0].view = "market:B";
|
|
247
|
+
});
|
|
248
|
+
expect((await item.component()).default).toBe(Other);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test("a theme override supplies the markup, the default supplies the load", async () => {
|
|
252
|
+
const Override = function Override() {};
|
|
253
|
+
registry.setThemeConfig({
|
|
254
|
+
views: { "market:ProductCard": { contract: 1, component: async () => ({ default: Override, load: () => ({ no: 1 }) }) } },
|
|
255
|
+
});
|
|
256
|
+
panoApi.views.add([def("market:ProductCard")]);
|
|
257
|
+
|
|
258
|
+
panoApi.ui.profile.content.edit((items) => items.push({ id: "card", view: "market:ProductCard" }));
|
|
259
|
+
|
|
260
|
+
const [resolved] = await executeViewLoad("profile-content", {});
|
|
261
|
+
expect(resolved.component.default).toBe(Override);
|
|
262
|
+
expect(resolved.props.data).toEqual({ products: [1, 2] });
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test("an unknown view id drops the item and names the closest registered view", () => {
|
|
266
|
+
panoApi.views.add([def("market:ProductCard"), def("market:Cart")]);
|
|
267
|
+
|
|
268
|
+
panoApi.ui.profile.content.edit((items) => {
|
|
269
|
+
items.push({ id: "typo", view: "market:ProductCrad", pluginId: MARKET });
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
expect(get(panoApi.ui.profile.content.get())).toEqual([]);
|
|
273
|
+
const message = errors().join("\n");
|
|
274
|
+
expect(message).toContain("market:ProductCrad");
|
|
275
|
+
expect(message).toContain("closest registered view: 'market:ProductCard'");
|
|
276
|
+
expect(message).toContain(MARKET);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
test("an unknown view id with nothing registered still drops the item", () => {
|
|
280
|
+
panoApi.ui.view.register({ viewId: "navbar-right", id: "x", view: "market:Nope" });
|
|
281
|
+
|
|
282
|
+
expect(get(panoApi.ui.view.get("navbar-right"))).toEqual([]);
|
|
283
|
+
expect(errors().join("\n")).toContain("market:Nope");
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test("the `component` form without a view is dropped with an error naming the replacement", async () => {
|
|
287
|
+
const component = async () => ({ default: Card, load });
|
|
288
|
+
|
|
289
|
+
for (const id of ["one", "two"]) {
|
|
290
|
+
panoApi.ui.view.register({ viewId: "navbar-right", id, component, pluginId: MARKET });
|
|
291
|
+
}
|
|
292
|
+
panoApi.ui.profile.content.edit((items) => items.push({ id: "three", component, pluginId: MARKET }));
|
|
293
|
+
|
|
294
|
+
expect(await executeViewLoad("navbar-right", {})).toEqual([]);
|
|
295
|
+
expect(await executeViewLoad("profile-content", {})).toEqual([]);
|
|
296
|
+
|
|
297
|
+
const dropped = errors().filter((text) => text.includes("registered with 'component'"));
|
|
298
|
+
expect(dropped).toHaveLength(3);
|
|
299
|
+
expect(dropped[0]).toContain(MARKET);
|
|
300
|
+
expect(dropped[0]).toContain("export const view = { hook: '...' }");
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test("an item with a view and a stray component loads without the component", async () => {
|
|
304
|
+
panoApi.views.add([def("market:A")]);
|
|
305
|
+
panoApi.ui.view.register({
|
|
306
|
+
viewId: "navbar-right",
|
|
307
|
+
id: "both",
|
|
308
|
+
view: "market:A",
|
|
309
|
+
component: async () => ({ default: function Stray() {} }),
|
|
310
|
+
pluginId: MARKET,
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
const [resolved] = await executeViewLoad("navbar-right", {});
|
|
314
|
+
expect(resolved.component.default).toBe(Card);
|
|
315
|
+
expect(warnings().filter((text) => text.includes("registered with 'component'"))).toEqual([]);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test("engine items with a string component are not warned about", () => {
|
|
319
|
+
panoApi.ui.profile.nav.edit((items) => items.push({ id: "profile-nav", component: "local:profile-nav" }));
|
|
320
|
+
|
|
321
|
+
expect(warnings()).toEqual([]);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
test("page.register takes `view`, and drops an unknown view and a bare component", async () => {
|
|
325
|
+
panoApi.views.add([def("market:CartPage")]);
|
|
326
|
+
|
|
327
|
+
panoApi.ui.page.register({ path: "/cart", view: "market:CartPage" });
|
|
328
|
+
panoApi.ui.page.register({ path: "/ghost", view: "market:Ghost" });
|
|
329
|
+
panoApi.ui.page.register({ path: "/old", component: async () => ({ default: Page }) });
|
|
330
|
+
|
|
331
|
+
expect(panoApi.ui.page.isPluginPage("/cart")).toBe(true);
|
|
332
|
+
expect(panoApi.ui.page.isPluginPage("/ghost")).toBe(false);
|
|
333
|
+
expect(panoApi.ui.page.isPluginPage("/old")).toBe(false);
|
|
334
|
+
|
|
335
|
+
const cart = Object.values(pluginManager.registeredPages).find((page) => page.path === "/cart");
|
|
336
|
+
expect((await cart.component()).default).toBe(Card);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
test("the plugin's page object is not mutated", () => {
|
|
340
|
+
panoApi.views.add([def("market:CartPage")]);
|
|
341
|
+
const page = { path: "/cart2", view: "market:CartPage" };
|
|
342
|
+
panoApi.ui.page.register(page);
|
|
343
|
+
|
|
344
|
+
expect(page.component).toBeUndefined();
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
describe("claims: the theme places the view itself", () => {
|
|
349
|
+
async function registerThree() {
|
|
350
|
+
panoApi.views.add([
|
|
351
|
+
def("market:A", { component: async () => ({ default: Card, load: async () => ({ id: "A" }) }) }),
|
|
352
|
+
def("market:NavCart", { component: async () => ({ default: Card, load: async () => ({ id: "NavCart" }) }) }),
|
|
353
|
+
def("market:C", { component: async () => ({ default: Card, load: async () => ({ id: "C" }) }) }),
|
|
354
|
+
]);
|
|
355
|
+
|
|
356
|
+
for (const name of ["A", "NavCart", "C"]) {
|
|
357
|
+
panoApi.ui.hook.register({ name: "theme:top", view: `market:${name}` });
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
test("hook positions stay aligned and the claimed view's load never runs", async () => {
|
|
362
|
+
registry.setThemeMeta({ claims: ["market:NavCart"] });
|
|
363
|
+
await registerThree();
|
|
364
|
+
|
|
365
|
+
const list = get(panoApi.ui.hook.get("theme:top"));
|
|
366
|
+
const props = await executeHookLoad("theme:top", {});
|
|
367
|
+
|
|
368
|
+
expect(list.map((entry) => entry.view)).toEqual(["market:A", "market:C"]);
|
|
369
|
+
expect(props.map((p) => p.id)).toEqual(["A", "C"]);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
test("`claims: { id: false }` keeps the automatic copy", async () => {
|
|
373
|
+
registry.setThemeMeta({ claims: ["market:NavCart"] });
|
|
374
|
+
registry.setThemeConfig({ claims: { "market:NavCart": false } });
|
|
375
|
+
await registerThree();
|
|
376
|
+
|
|
377
|
+
expect(get(panoApi.ui.hook.get("theme:top")).map((entry) => entry.view)).toEqual([
|
|
378
|
+
"market:A",
|
|
379
|
+
"market:NavCart",
|
|
380
|
+
"market:C",
|
|
381
|
+
]);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
test("a claim made with the plugin-id spelling suppresses the item", async () => {
|
|
385
|
+
registry.setThemeMeta({ claims: [`${MARKET}:NavCart`] });
|
|
386
|
+
await registerThree();
|
|
387
|
+
|
|
388
|
+
expect(get(panoApi.ui.hook.get("theme:top")).map((entry) => entry.view)).not.toContain("market:NavCart");
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
test("a slot item is left out of the read and of the load", async () => {
|
|
392
|
+
registry.setThemeMeta({ claims: ["market:NavCart"] });
|
|
393
|
+
panoApi.views.add([
|
|
394
|
+
def("market:NavCart", {
|
|
395
|
+
inject: [{ slot: "navbar-right", id: "market-cart" }],
|
|
396
|
+
component: async () => ({
|
|
397
|
+
default: Card,
|
|
398
|
+
load: async () => {
|
|
399
|
+
throw new Error("must not load");
|
|
400
|
+
},
|
|
401
|
+
}),
|
|
402
|
+
}),
|
|
403
|
+
def("market:Other", { inject: [{ slot: "navbar-right", id: "other" }] }),
|
|
404
|
+
]);
|
|
405
|
+
|
|
406
|
+
expect(get(panoApi.ui.nav.rightComponents.get()).map((item) => item.id)).toEqual(["other"]);
|
|
407
|
+
expect((await executeViewLoad("navbar-right", {})).map((item) => item.id)).toEqual(["other"]);
|
|
408
|
+
expect(warnings().join("\n")).not.toContain("Load failed");
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
describe("init()", () => {
|
|
413
|
+
test("forgets plugin views, controllers, hooks, slots and nav links", async () => {
|
|
414
|
+
panoApi.views.add([def("market:A", { inject: [{ slot: "navbar-right" }] })]);
|
|
415
|
+
panoApi.controllers.register(MARKET, "market", {
|
|
416
|
+
cart: { name: "cart", version: 1, create: () => ({ get: () => ({}), subscribe() {}, actions: {}, destroy() {} }) },
|
|
417
|
+
});
|
|
418
|
+
panoApi.ui.nav.site.editNavLinks((links) => [...links, { id: "l", href: "/store", text: "Store" }]);
|
|
419
|
+
|
|
420
|
+
expect(panoApi.views.has("market:A")).toBe(true);
|
|
421
|
+
expect(panoApi.controllers.has("market/cart")).toBe(true);
|
|
422
|
+
|
|
423
|
+
await init();
|
|
424
|
+
|
|
425
|
+
expect(panoApi.views.has("market:A")).toBe(false);
|
|
426
|
+
expect(panoApi.controllers.has("market/cart")).toBe(false);
|
|
427
|
+
expect(get(panoApi.ui.view.get("navbar-right"))).toEqual([]);
|
|
428
|
+
expect(get(panoApi.ui.nav.site.getNavLinks())).toEqual([]);
|
|
429
|
+
// the same registry the SDK exposes
|
|
430
|
+
expect(panoApi.controllers).toBe(controllersModule.controllers);
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
test("a namespace freed by init() can be taken by another plugin", async () => {
|
|
434
|
+
panoApi.views.add([def("market:A")]);
|
|
435
|
+
await init();
|
|
436
|
+
panoApi.views.add([def("market:A", { pluginId: "pano-plugin-other" })]);
|
|
437
|
+
|
|
438
|
+
expect(panoApi.views.has("market:A")).toBe(true);
|
|
439
|
+
expect(errors().join("\n")).not.toContain("NAMESPACE_CLASH");
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
describe("feature ids", () => {
|
|
444
|
+
test("the new ids are announced", () => {
|
|
445
|
+
for (const id of ["named-views", "plugin-slots", "blocks", "route-map"]) {
|
|
446
|
+
expect(THEME_FEATURE_IDS).toContain(id);
|
|
447
|
+
expect(panoApi.features.has(id)).toBe(true);
|
|
448
|
+
}
|
|
449
|
+
expect(new Set(THEME_FEATURE_IDS).size).toBe(THEME_FEATURE_IDS.length);
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
describe("routes: what plugins are handed goes through route()", () => {
|
|
454
|
+
const rename = { "/store": "/shop", "/store/[slug]": "/shop/[slug]", "/login": "/signin" };
|
|
455
|
+
|
|
456
|
+
test("pano.routes.resolve is route()", () => {
|
|
457
|
+
expect(panoApi.routes.resolve("/store")).toBe("/store");
|
|
458
|
+
|
|
459
|
+
setRouteConfig({ routes: { rename } });
|
|
460
|
+
|
|
461
|
+
expect(panoApi.routes.resolve("/store")).toBe("/shop");
|
|
462
|
+
expect(panoApi.routes.resolve("/store/vip?x=1")).toBe("/shop/vip?x=1");
|
|
463
|
+
expect(panoApi.routes.resolve("/profile")).toBe("/profile");
|
|
464
|
+
expect(panoApi.routes.resolve("https://example.com/store")).toBe("https://example.com/store");
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
test("site nav links are published under the theme's path, once, even when read late", () => {
|
|
468
|
+
panoApi.ui.nav.site.editNavLinks((links) => [...links, { id: "store", href: "/store", text: "Store", priority: 1 }]);
|
|
469
|
+
|
|
470
|
+
expect(get(panoApi.ui.nav.site.getNavLinks())[0].href).toBe("/store");
|
|
471
|
+
|
|
472
|
+
setRouteConfig({ routes: { rename } });
|
|
473
|
+
|
|
474
|
+
const links = get(panoApi.ui.nav.site.getNavLinks());
|
|
475
|
+
expect(links[0].href).toBe("/shop");
|
|
476
|
+
// the stored link is untouched: an edit that runs again cannot map it twice
|
|
477
|
+
panoApi.ui.nav.site.editNavLinks((current) => current);
|
|
478
|
+
expect(get(panoApi.ui.nav.site.getNavLinks())[0].href).toBe("/shop");
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
test("auth.loginUrl and requireLogin follow a renamed login route", async () => {
|
|
482
|
+
expect(panoApi.auth.loginUrl("/store/checkout")).toBe("/login?redirect=%2Fstore%2Fcheckout");
|
|
483
|
+
|
|
484
|
+
setRouteConfig({ routes: { rename } });
|
|
485
|
+
|
|
486
|
+
expect(panoApi.auth.loginUrl("/store/checkout")).toBe("/signin?redirect=%2Fstore%2Fcheckout");
|
|
487
|
+
expect(panoApi.auth.loginUrl()).toBe("/signin");
|
|
488
|
+
|
|
489
|
+
const event = {
|
|
490
|
+
parent: async () => ({ session: { user: null } }),
|
|
491
|
+
url: new URL("https://site.test/cart?x=1"),
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
let thrown;
|
|
495
|
+
try {
|
|
496
|
+
await panoApi.auth.requireLogin(event);
|
|
497
|
+
} catch (e) {
|
|
498
|
+
thrown = e;
|
|
499
|
+
}
|
|
500
|
+
expect(thrown).toBeInstanceOf(Redirect);
|
|
501
|
+
expect(thrown.status).toBe(302);
|
|
502
|
+
expect(thrown.location).toBe("/signin?redirect=%2Fcart%3Fx%3D1");
|
|
503
|
+
|
|
504
|
+
// a logged-in user passes
|
|
505
|
+
await panoApi.auth.requireLogin({ ...event, parent: async () => ({ session: { user: { id: 1 } } }) });
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
test("routedGoto and routedRedirect map site paths only", async () => {
|
|
509
|
+
setRouteConfig({ routes: { rename } });
|
|
510
|
+
|
|
511
|
+
await api.routedGoto("/store", { replaceState: true });
|
|
512
|
+
await api.routedGoto("https://elsewhere.test/store");
|
|
513
|
+
await api.routedGoto("//elsewhere.test/store");
|
|
514
|
+
|
|
515
|
+
expect(navigations).toEqual([
|
|
516
|
+
{ url: "/shop", options: { replaceState: true } },
|
|
517
|
+
{ url: "https://elsewhere.test/store", options: undefined },
|
|
518
|
+
{ url: "//elsewhere.test/store", options: undefined },
|
|
519
|
+
]);
|
|
520
|
+
|
|
521
|
+
expect(() => api.routedRedirect(303, "/store/vip")).toThrow();
|
|
522
|
+
try {
|
|
523
|
+
api.routedRedirect(303, "/store/vip");
|
|
524
|
+
} catch (e) {
|
|
525
|
+
expect(e.location).toBe("/shop/vip");
|
|
526
|
+
expect(e.status).toBe(303);
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { register, reset } from "@panomc/sdk/core/js/ControllerRegistry.js";
|
|
3
|
+
|
|
4
|
+
import { hasPlugin, pluginInfo } from "../plugins.js";
|
|
5
|
+
|
|
6
|
+
const siteInfo = {
|
|
7
|
+
plugins: {
|
|
8
|
+
"pano-plugin-market": { version: "1.4.0", uiHash: "abc", dependencies: [] },
|
|
9
|
+
"acme-shop": { version: null, uiHash: "def", dependencies: ["pano-plugin-market"] },
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
afterEach(() => reset());
|
|
14
|
+
|
|
15
|
+
describe("hasPlugin / pluginInfo", () => {
|
|
16
|
+
test("an installed plugin by full id and by namespace", () => {
|
|
17
|
+
expect(hasPlugin(siteInfo, "pano-plugin-market")).toBe(true);
|
|
18
|
+
expect(hasPlugin(siteInfo, "market")).toBe(true);
|
|
19
|
+
expect(pluginInfo(siteInfo, "market")).toEqual({ version: "1.4.0", uiHash: "abc", dependencies: [] });
|
|
20
|
+
expect(pluginInfo(siteInfo, "pano-plugin-market")?.version).toBe("1.4.0");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("a plugin that is not installed", () => {
|
|
24
|
+
expect(hasPlugin(siteInfo, "pano-plugin-faq")).toBe(false);
|
|
25
|
+
expect(hasPlugin(siteInfo, "faq")).toBe(false);
|
|
26
|
+
expect(pluginInfo(siteInfo, "faq")).toBeNull();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("a namespace registered by a plugin with an own id", () => {
|
|
30
|
+
expect(hasPlugin(siteInfo, "shop")).toBe(false);
|
|
31
|
+
register("acme-shop", "shop", {});
|
|
32
|
+
expect(hasPlugin(siteInfo, "shop")).toBe(true);
|
|
33
|
+
expect(pluginInfo(siteInfo, "shop")?.version).toBeNull();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("no site info yet, an empty map, odd input", () => {
|
|
37
|
+
for (const info of [undefined, null, {}, { plugins: null }, { plugins: {} }]) {
|
|
38
|
+
expect(hasPlugin(info, "pano-plugin-market")).toBe(false);
|
|
39
|
+
expect(pluginInfo(info, "market")).toBeNull();
|
|
40
|
+
}
|
|
41
|
+
expect(hasPlugin(siteInfo, "")).toBe(false);
|
|
42
|
+
expect(hasPlugin(siteInfo, undefined)).toBe(false);
|
|
43
|
+
expect(hasPlugin(siteInfo, "toString")).toBe(false);
|
|
44
|
+
expect(hasPlugin(siteInfo, "constructor")).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("keeps no state between calls (two requests, two site infos)", () => {
|
|
48
|
+
const other = { plugins: {} };
|
|
49
|
+
expect(hasPlugin(siteInfo, "market")).toBe(true);
|
|
50
|
+
expect(hasPlugin(other, "market")).toBe(false);
|
|
51
|
+
expect(hasPlugin(siteInfo, "market")).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
});
|