@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,361 @@
|
|
|
1
|
+
import { afterAll, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { findSvelte } from "./svelteSsr.helper.js";
|
|
6
|
+
|
|
7
|
+
// Route config in the engine (TC-12, doc 01 section 9): what `theme-core sync` generates for
|
|
8
|
+
// routes.add / hooks.js, the 308 for a renamed-away path, the 404 for a disabled one, and
|
|
9
|
+
// themePageLoad.
|
|
10
|
+
|
|
11
|
+
mock.module("$app/environment", () => ({ dev: false, browser: false }));
|
|
12
|
+
mock.module("$pano/lib/api.util", () => ({ default: {} }));
|
|
13
|
+
|
|
14
|
+
// Modules the plugin-ui Layout imports.
|
|
15
|
+
mock.module("@sveltejs/kit", () => ({
|
|
16
|
+
error: (status) => Object.assign(new Error(`HTTP ${status}`), { status }),
|
|
17
|
+
redirect: (status, location) => Object.assign(new Error("redirect"), { status, location }),
|
|
18
|
+
}));
|
|
19
|
+
mock.module("$app/paths", () => ({ base: "" }));
|
|
20
|
+
mock.module("$pano/lib/PluginManager.js", () => ({
|
|
21
|
+
registeredPages: { "/store": { name: "store" }, "/store/vip": { name: "vip" }, "/rules": { name: "rules-plugin" } },
|
|
22
|
+
findMatch: (pages, path) => pages[path] ?? null,
|
|
23
|
+
}));
|
|
24
|
+
mock.module("$pano/lib/auth.util.js", () => ({ hasPermission: () => true }));
|
|
25
|
+
mock.module("$pano/lib/returnTo.util.js", () => ({ loginRedirectFor: () => null }));
|
|
26
|
+
mock.module("$pano/registry/routes.js", () => routes);
|
|
27
|
+
for (const name of ["App", "Auth", "Main", "Profile", "ThemeSettings", "Tickets"]) {
|
|
28
|
+
mock.module(`$pano/lib/layouts/${name}Layout.svelte`, () => ({ default: null }));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
const pkgDir = join(import.meta.dir, "..", "..", "..");
|
|
34
|
+
const syncJs = join(pkgDir, "bin", "sync.js");
|
|
35
|
+
|
|
36
|
+
const routes = await import("../../registry/routes.js");
|
|
37
|
+
const { redirectRenamedPath, createThemeHooks } = await import("../../kit/hooks-server.js");
|
|
38
|
+
const registry = await import("../../registry/index.js");
|
|
39
|
+
const { themePageLoad } = await import("../themePageLoad.js");
|
|
40
|
+
|
|
41
|
+
const roots = [];
|
|
42
|
+
afterAll(() => {
|
|
43
|
+
for (const root of roots) rmSync(root, { recursive: true, force: true });
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// sync.js on a fixture theme
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
function makeTheme(config, { files = {} } = {}) {
|
|
51
|
+
const dir = mkdtempSync(join(tmpdir(), "theme-core-routes-"));
|
|
52
|
+
roots.push(dir);
|
|
53
|
+
|
|
54
|
+
writeFileSync(join(dir, "package.json"), JSON.stringify({ name: "pano-fixture-theme" }));
|
|
55
|
+
writeFileSync(join(dir, "theme.config.js"), `export default ${JSON.stringify(config)};\n`);
|
|
56
|
+
|
|
57
|
+
for (const [path, content] of Object.entries({
|
|
58
|
+
"src/pages/StaffTeam.svelte": "<h1>Staff</h1>\n",
|
|
59
|
+
"src/pages/Member.svelte": "<h1>Member</h1>\n",
|
|
60
|
+
...files,
|
|
61
|
+
})) {
|
|
62
|
+
mkdirSync(dirname(join(dir, path)), { recursive: true });
|
|
63
|
+
writeFileSync(join(dir, path), content);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return dir;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function sync(cwd) {
|
|
70
|
+
const proc = Bun.spawnSync([process.execPath, syncJs], { cwd, stdout: "pipe", stderr: "pipe" });
|
|
71
|
+
|
|
72
|
+
return { code: proc.exitCode, out: proc.stdout.toString() + proc.stderr.toString() };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const read = (dir, path) => readFileSync(join(dir, path), "utf-8");
|
|
76
|
+
|
|
77
|
+
describe("sync: routes.add and hooks.js", () => {
|
|
78
|
+
const config = {
|
|
79
|
+
routes: {
|
|
80
|
+
add: { "/staff-team": "./src/pages/StaffTeam.svelte", "/team/[slug]": "./src/pages/Member.svelte" },
|
|
81
|
+
rename: { "/store": "/shop" },
|
|
82
|
+
disable: ["/rules"],
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
test("generates src/hooks.js, a page pair per added route and the plugin UI file route", () => {
|
|
87
|
+
const dir = makeTheme(config);
|
|
88
|
+
const result = sync(dir);
|
|
89
|
+
expect(result.code).toBe(0);
|
|
90
|
+
|
|
91
|
+
const hooks = read(dir, "src/hooks.js");
|
|
92
|
+
expect(hooks).toContain('import themeConfig from "../theme.config.js";');
|
|
93
|
+
expect(hooks).toContain("export const reroute = createReroute(themeConfig);");
|
|
94
|
+
expect(hooks).toContain("setRouteConfig(themeConfig);");
|
|
95
|
+
|
|
96
|
+
const pageJs = read(dir, "src/routes/(theme)/staff-team/+page.js");
|
|
97
|
+
expect(pageJs).toContain('import * as mod from "../../../pages/StaffTeam.svelte";');
|
|
98
|
+
expect(pageJs).toContain('import { themePageLoad } from "$pano/lib/themePageLoad.js";');
|
|
99
|
+
expect(pageJs).toContain('export const load = themePageLoad("route:/staff-team", mod);');
|
|
100
|
+
|
|
101
|
+
const pageSvelte = read(dir, "src/routes/(theme)/staff-team/+page.svelte");
|
|
102
|
+
expect(pageSvelte).toContain('import ThemePage from "../../../pages/StaffTeam.svelte";');
|
|
103
|
+
expect(pageSvelte).toContain("<ThemePage {data} />");
|
|
104
|
+
|
|
105
|
+
expect(read(dir, "src/routes/(theme)/team/[slug]/+page.js")).toContain(
|
|
106
|
+
'themePageLoad("route:/team/[slug]", mod)',
|
|
107
|
+
);
|
|
108
|
+
expect(read(dir, "src/routes/(theme)/team/[slug]/+page.js")).toContain('"../../../../pages/Member.svelte"');
|
|
109
|
+
|
|
110
|
+
expect(read(dir, "src/routes/(theme)/plugins/[pluginId]/resources/plugin-ui/[kind]/[...file]/+server.js")).toContain(
|
|
111
|
+
'export { GET } from "$pano/routes/plugins-ui-file.js";',
|
|
112
|
+
);
|
|
113
|
+
// the existing client file route stays
|
|
114
|
+
expect(existsSync(join(dir, "src/routes/(theme)/plugins/[pluginId]/resources/plugin-ui/client/[fileName]/+server.js"))).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("a second run is stable and dropping an entry removes its generated files", () => {
|
|
118
|
+
const dir = makeTheme(config);
|
|
119
|
+
expect(sync(dir).code).toBe(0);
|
|
120
|
+
|
|
121
|
+
const before = read(dir, "src/routes/(theme)/staff-team/+page.js");
|
|
122
|
+
expect(sync(dir).code).toBe(0);
|
|
123
|
+
expect(read(dir, "src/routes/(theme)/staff-team/+page.js")).toBe(before);
|
|
124
|
+
|
|
125
|
+
writeFileSync(join(dir, "theme.config.js"), `export default { routes: { add: { "/team/[slug]": "./src/pages/Member.svelte" } } };\n`);
|
|
126
|
+
expect(sync(dir).code).toBe(0);
|
|
127
|
+
expect(existsSync(join(dir, "src/routes/(theme)/staff-team"))).toBe(false);
|
|
128
|
+
expect(existsSync(join(dir, "src/routes/(theme)/team/[slug]/+page.js"))).toBe(true);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("a theme without routes gets hooks.js and no extra route", () => {
|
|
132
|
+
const dir = makeTheme({});
|
|
133
|
+
expect(sync(dir).code).toBe(0);
|
|
134
|
+
expect(read(dir, "src/hooks.js")).toContain("createReroute(themeConfig)");
|
|
135
|
+
expect(existsSync(join(dir, "src/routes/(theme)/staff-team"))).toBe(false);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("a hand-written hooks.js is left alone", () => {
|
|
139
|
+
const dir = makeTheme({}, { files: { "src/hooks.js": "export const reroute = () => {};\n" } });
|
|
140
|
+
const result = sync(dir);
|
|
141
|
+
expect(result.code).toBe(0);
|
|
142
|
+
expect(result.out).toContain("hand-written");
|
|
143
|
+
expect(read(dir, "src/hooks.js")).toBe("export const reroute = () => {};\n");
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe("add is an error when it cannot be a new route", () => {
|
|
147
|
+
for (const [label, add, message] of [
|
|
148
|
+
["a live canonical path", { "/rules": "./src/pages/StaffTeam.svelte" }, /already serves/],
|
|
149
|
+
["a live path with other param names", { "/post/[slug]": "./src/pages/StaffTeam.svelte" }, /already serves/],
|
|
150
|
+
["the home path", { "/": "./src/pages/StaffTeam.svelte" }, /already serves/],
|
|
151
|
+
["/posts", { "/posts": "./src/pages/StaffTeam.svelte" }, /reserved/],
|
|
152
|
+
["/__pano*", { "/__pano-x": "./src/pages/StaffTeam.svelte" }, /reserved/],
|
|
153
|
+
["a missing file", { "/staff": "./src/pages/Nope.svelte" }, /does not exist/],
|
|
154
|
+
["an invalid pattern", { "/a/[x]/[x]": "./src/pages/StaffTeam.svelte" }, /twice/],
|
|
155
|
+
]) {
|
|
156
|
+
test(label, () => {
|
|
157
|
+
const dir = makeTheme({ routes: { add } });
|
|
158
|
+
const result = sync(dir);
|
|
159
|
+
expect(result.code).toBe(1);
|
|
160
|
+
expect(result.out).toMatch(message);
|
|
161
|
+
// nothing was written
|
|
162
|
+
expect(existsSync(join(dir, "src/routes"))).toBe(false);
|
|
163
|
+
expect(existsSync(join(dir, "src/hooks.js"))).toBe(false);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
test("a path already published by a rename", () => {
|
|
168
|
+
const dir = makeTheme({
|
|
169
|
+
routes: { rename: { "/store": "/shop" }, add: { "/shop": "./src/pages/StaffTeam.svelte" } },
|
|
170
|
+
});
|
|
171
|
+
const result = sync(dir);
|
|
172
|
+
expect(result.code).toBe(1);
|
|
173
|
+
expect(result.out).toMatch(/renamed route/);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("an invalid rename", () => {
|
|
177
|
+
const dir = makeTheme({ routes: { rename: { "/store/[slug]": "/shop/[id]" } } });
|
|
178
|
+
const result = sync(dir);
|
|
179
|
+
expect(result.code).toBe(1);
|
|
180
|
+
expect(result.out).toMatch(/same params/);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// ---------------------------------------------------------------------------
|
|
186
|
+
// 308 for a renamed-away canonical path
|
|
187
|
+
// ---------------------------------------------------------------------------
|
|
188
|
+
|
|
189
|
+
const themeConfig = {
|
|
190
|
+
routes: {
|
|
191
|
+
rename: { "/store": "/shop", "/store/[slug]": "/shop/[slug]" },
|
|
192
|
+
disable: ["/rules"],
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const get = (path, extra = {}) => ({
|
|
197
|
+
url: new URL(path, "http://localhost"),
|
|
198
|
+
request: { method: "GET" },
|
|
199
|
+
...extra,
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe("hooks-server: renamed-away path", () => {
|
|
203
|
+
beforeEach(() => routes.setRouteConfig(themeConfig));
|
|
204
|
+
|
|
205
|
+
test("the canonical path answers 308 to the public path, query kept", () => {
|
|
206
|
+
const response = redirectRenamedPath(get("/store/vip?ref=1"));
|
|
207
|
+
expect(response.status).toBe(308);
|
|
208
|
+
expect(response.headers.get("location")).toBe("/shop/vip?ref=1");
|
|
209
|
+
|
|
210
|
+
expect(redirectRenamedPath(get("/store")).headers.get("location")).toBe("/shop");
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test("the public path, other paths and a theme without renames pass", () => {
|
|
214
|
+
expect(redirectRenamedPath(get("/shop"))).toBeNull();
|
|
215
|
+
expect(redirectRenamedPath(get("/shop/vip"))).toBeNull();
|
|
216
|
+
expect(redirectRenamedPath(get("/profile"))).toBeNull();
|
|
217
|
+
routes.setRouteConfig({});
|
|
218
|
+
expect(redirectRenamedPath(get("/store"))).toBeNull();
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test("data requests and non-GET methods keep resolving the canonical path", () => {
|
|
222
|
+
expect(redirectRenamedPath(get("/store", { isDataRequest: true }))).toBeNull();
|
|
223
|
+
expect(redirectRenamedPath(get("/store", { request: { method: "POST" } }))).toBeNull();
|
|
224
|
+
expect(redirectRenamedPath(get("/store", { request: { method: "HEAD" } })).status).toBe(308);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test("a swap redirects nothing, a base is kept", () => {
|
|
228
|
+
routes.setRouteConfig({ routes: { rename: { "/a": "/b", "/b": "/a" } } });
|
|
229
|
+
expect(redirectRenamedPath(get("/a"))).toBeNull();
|
|
230
|
+
expect(redirectRenamedPath(get("/b"))).toBeNull();
|
|
231
|
+
|
|
232
|
+
routes.setRouteConfig(themeConfig);
|
|
233
|
+
expect(redirectRenamedPath(get("/base/store"), "/base").headers.get("location")).toBe("/base/shop");
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test("handle() answers the 308 before it resolves anything", async () => {
|
|
237
|
+
const { handle } = createThemeHooks({ internalLibsHash: "h", runtimeShimsHash: "s" });
|
|
238
|
+
let resolved = false;
|
|
239
|
+
|
|
240
|
+
const response = await handle({
|
|
241
|
+
event: { ...get("/store/vip"), cookies: { get: () => undefined }, locals: {} },
|
|
242
|
+
resolve: async () => {
|
|
243
|
+
resolved = true;
|
|
244
|
+
return new Response("page");
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
expect(response.status).toBe(308);
|
|
249
|
+
expect(response.headers.get("location")).toBe("/shop/vip");
|
|
250
|
+
expect(resolved).toBe(false);
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// ---------------------------------------------------------------------------
|
|
255
|
+
// disabled -> 404 in the plugin-ui catch-all (Layout.svelte load)
|
|
256
|
+
// ---------------------------------------------------------------------------
|
|
257
|
+
|
|
258
|
+
const svelteDir = findSvelte();
|
|
259
|
+
|
|
260
|
+
describe.skipIf(!svelteDir)("plugin-ui Layout load", () => {
|
|
261
|
+
/** @type {(event: any) => Promise<any>} */
|
|
262
|
+
let load;
|
|
263
|
+
|
|
264
|
+
beforeEach(async () => {
|
|
265
|
+
if (load) return;
|
|
266
|
+
|
|
267
|
+
const compiler = await import(join(svelteDir, "src", "compiler", "index.js"));
|
|
268
|
+
// Inside the package so `svelte` resolves from the package's own node_modules.
|
|
269
|
+
const dir = mkdtempSync(join(import.meta.dir, ".tmp-routeconfig-"));
|
|
270
|
+
roots.push(dir);
|
|
271
|
+
|
|
272
|
+
const source = readFileSync(join(pkgDir, "src", "routes", "plugin-ui", "Layout.svelte"), "utf-8");
|
|
273
|
+
const { js } = compiler.compile(source, { generate: "server", filename: "Layout.svelte" });
|
|
274
|
+
writeFileSync(join(dir, "Layout.mjs"), js.code);
|
|
275
|
+
|
|
276
|
+
load = (await import(join(dir, "Layout.mjs"))).load;
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
const event = (pathname) => ({
|
|
280
|
+
url: { pathname, search: "" },
|
|
281
|
+
parent: async () => ({ session: { user: null } }),
|
|
282
|
+
params: {},
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
const status = async (pathname) => {
|
|
286
|
+
try {
|
|
287
|
+
await load(event(pathname));
|
|
288
|
+
return 200;
|
|
289
|
+
} catch (e) {
|
|
290
|
+
return e.status;
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
test("a public path is turned into the canonical one before findMatch", async () => {
|
|
295
|
+
routes.setRouteConfig(themeConfig);
|
|
296
|
+
|
|
297
|
+
const output = await load(event("/shop/vip"));
|
|
298
|
+
expect(output.registeredPage.name).toBe("vip");
|
|
299
|
+
expect((await load(event("/shop"))).registeredPage.name).toBe("store");
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
test("a disabled route is a 404 even when a plugin registered it", async () => {
|
|
303
|
+
routes.setRouteConfig(themeConfig);
|
|
304
|
+
|
|
305
|
+
expect(await status("/rules")).toBe(404);
|
|
306
|
+
routes.setRouteConfig({});
|
|
307
|
+
expect(await status("/rules")).toBe(200);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test("/__pano* is never served by a plugin page, unknown paths are 404", async () => {
|
|
311
|
+
routes.setRouteConfig(themeConfig);
|
|
312
|
+
|
|
313
|
+
expect(await status("/__pano-disabled")).toBe(404);
|
|
314
|
+
expect(await status("/__pano/views")).toBe(404);
|
|
315
|
+
expect(await status("/nothing-here")).toBe(404);
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
// ---------------------------------------------------------------------------
|
|
320
|
+
// themePageLoad
|
|
321
|
+
// ---------------------------------------------------------------------------
|
|
322
|
+
|
|
323
|
+
describe("themePageLoad", () => {
|
|
324
|
+
beforeEach(() => registry.resetRegistryForTests());
|
|
325
|
+
|
|
326
|
+
test("the page's own load output, plus the loads of the blocks its closure places", async () => {
|
|
327
|
+
registry.registerViews([
|
|
328
|
+
{
|
|
329
|
+
name: "market:NavCart",
|
|
330
|
+
pluginId: "pano-plugin-market",
|
|
331
|
+
contract: 1,
|
|
332
|
+
block: true,
|
|
333
|
+
component: async () => ({ default: function () {}, load: async (_event, props) => ({ cart: props?.size ?? 0 }) }),
|
|
334
|
+
},
|
|
335
|
+
]);
|
|
336
|
+
registry.setThemeConfig({ views: {} });
|
|
337
|
+
registry.setThemeMeta({
|
|
338
|
+
refs: { "route:/staff-team": [{ id: "market:NavCart", props: { size: 3 } }] },
|
|
339
|
+
claims: [],
|
|
340
|
+
homePages: {},
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
const pageModule = { load: async (event) => ({ title: "Staff", seen: event.params.x }) };
|
|
344
|
+
const load = themePageLoad("route:/staff-team", pageModule);
|
|
345
|
+
const data = await load({ params: { x: "1" } });
|
|
346
|
+
|
|
347
|
+
expect(data.title).toBe("Staff");
|
|
348
|
+
expect(data.seen).toBe("1");
|
|
349
|
+
const blockKeys = Object.keys(data).filter((key) => key.startsWith("block:"));
|
|
350
|
+
expect(blockKeys).toHaveLength(1);
|
|
351
|
+
expect(data[blockKeys[0]]).toEqual({ cart: 3 });
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
test("a page without a load, a thunk module and a failing closure", async () => {
|
|
355
|
+
registry.setThemeConfig({ views: {} });
|
|
356
|
+
|
|
357
|
+
expect(await themePageLoad("route:/plain", { default: function () {} })({ params: {} })).toEqual({});
|
|
358
|
+
expect(await themePageLoad("route:/lazy", async () => ({ load: async () => ({ a: 1 }) }))({ params: {} })).toEqual({ a: 1 });
|
|
359
|
+
expect(await themePageLoad("route:/null", { load: async () => null })({ params: {} })).toEqual({});
|
|
360
|
+
});
|
|
361
|
+
});
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
parseSidebarSpec,
|
|
5
|
+
resolveSidebarSpec,
|
|
6
|
+
SIDEBAR_ID_PATTERN,
|
|
7
|
+
} from "../components/sidebars/sidebarSpec.util.js";
|
|
8
|
+
|
|
9
|
+
describe("parseSidebarSpec (T5 + T8)", () => {
|
|
10
|
+
test("a non-string value is a component (unchanged behaviour)", () => {
|
|
11
|
+
for (const value of [undefined, null, {}, () => {}, 12, class A {}]) {
|
|
12
|
+
expect(parseSidebarSpec(value)).toEqual({ kind: "component" });
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test("home and profile are host sidebars", () => {
|
|
17
|
+
expect(parseSidebarSpec("home")).toEqual({ kind: "host", id: "home" });
|
|
18
|
+
expect(parseSidebarSpec("profile")).toEqual({ kind: "host", id: "profile" });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("plugin:<id> with a valid id is an engine sidebar", () => {
|
|
22
|
+
expect(parseSidebarSpec("plugin:fixture")).toEqual({ kind: "plugin", sidebarId: "fixture" });
|
|
23
|
+
expect(parseSidebarSpec("plugin:market:cart-1")).toEqual({ kind: "plugin", sidebarId: "market:cart-1" });
|
|
24
|
+
expect(parseSidebarSpec("plugin:0a")).toEqual({ kind: "plugin", sidebarId: "0a" });
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("other host ids and malformed plugin ids are invalid", () => {
|
|
28
|
+
for (const value of [
|
|
29
|
+
"player-detail",
|
|
30
|
+
"support",
|
|
31
|
+
"ticket",
|
|
32
|
+
"",
|
|
33
|
+
"Home",
|
|
34
|
+
"plugin:",
|
|
35
|
+
"plugin:Upper",
|
|
36
|
+
"plugin:-lead",
|
|
37
|
+
"plugin::lead",
|
|
38
|
+
"plugin:has space",
|
|
39
|
+
"plugin:a/b",
|
|
40
|
+
"plugin:" + "a".repeat(65),
|
|
41
|
+
" plugin:x",
|
|
42
|
+
]) {
|
|
43
|
+
expect(parseSidebarSpec(value).kind).toBe("invalid");
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("the id pattern accepts 64 characters and rejects 65", () => {
|
|
48
|
+
expect(SIDEBAR_ID_PATTERN.test("a".repeat(64))).toBe(true);
|
|
49
|
+
expect(SIDEBAR_ID_PATTERN.test("a".repeat(65))).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe("resolveSidebarSpec", () => {
|
|
54
|
+
const HomeComponent = { name: "Home" };
|
|
55
|
+
const ProfileComponent = { name: "Profile" };
|
|
56
|
+
const PluginSidebar = { name: "PluginSidebar" };
|
|
57
|
+
const event = { url: new URL("https://pano.example/store") };
|
|
58
|
+
|
|
59
|
+
function setup({ visible = {}, loadResult } = {}) {
|
|
60
|
+
const calls = [];
|
|
61
|
+
const hosts = {
|
|
62
|
+
home: { default: HomeComponent, load: async (e) => calls.push(["home.load", e]) },
|
|
63
|
+
profile: { default: ProfileComponent, load: async (e) => calls.push(["profile.load", e]) },
|
|
64
|
+
};
|
|
65
|
+
const warnings = [];
|
|
66
|
+
const args = {
|
|
67
|
+
event,
|
|
68
|
+
hosts,
|
|
69
|
+
PluginSidebar,
|
|
70
|
+
executeSidebarLoad: async (id, e) => calls.push(["executeSidebarLoad", id, e]),
|
|
71
|
+
countVisible: (id) => visible[id] ?? 0,
|
|
72
|
+
warn: (...a) => warnings.push(a),
|
|
73
|
+
};
|
|
74
|
+
return { args, calls, warnings };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
test("a component value leaves the output unchanged (returns null)", async () => {
|
|
78
|
+
const { args, calls } = setup();
|
|
79
|
+
expect(await resolveSidebarSpec({ ...args, sidebar: HomeComponent })).toBeNull();
|
|
80
|
+
expect(await resolveSidebarSpec({ ...args, sidebar: undefined })).toBeNull();
|
|
81
|
+
expect(calls).toEqual([]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('"profile" runs the host load with the event and returns the host component', async () => {
|
|
85
|
+
const { args, calls } = setup();
|
|
86
|
+
const out = await resolveSidebarSpec({ ...args, sidebar: "profile", sidebarProps: { side: "left" } });
|
|
87
|
+
|
|
88
|
+
expect(out).toEqual({ sidebar: ProfileComponent });
|
|
89
|
+
expect(calls).toEqual([["profile.load", event]]);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('"home" runs the home load', async () => {
|
|
93
|
+
const { args, calls } = setup();
|
|
94
|
+
const out = await resolveSidebarSpec({ ...args, sidebar: "home" });
|
|
95
|
+
|
|
96
|
+
expect(out).toEqual({ sidebar: HomeComponent });
|
|
97
|
+
expect(calls).toEqual([["home.load", event]]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("a host without a load function is still resolved", async () => {
|
|
101
|
+
const { args } = setup();
|
|
102
|
+
args.hosts.home = { default: HomeComponent };
|
|
103
|
+
expect(await resolveSidebarSpec({ ...args, sidebar: "home" })).toEqual({ sidebar: HomeComponent });
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("plugin:<id> with items => PluginSidebar and sidebarProps merged with the id", async () => {
|
|
107
|
+
const { args, calls } = setup({ visible: { fixture: 2 } });
|
|
108
|
+
const out = await resolveSidebarSpec({
|
|
109
|
+
...args,
|
|
110
|
+
sidebar: "plugin:fixture",
|
|
111
|
+
sidebarProps: { side: "left", sidebarId: "ignored" },
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
expect(calls).toEqual([["executeSidebarLoad", "fixture", event]]);
|
|
115
|
+
expect(out).toEqual({ sidebar: PluginSidebar, sidebarProps: { side: "left", sidebarId: "fixture" } });
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("plugin:<id> with items and no sidebarProps", async () => {
|
|
119
|
+
const { args } = setup({ visible: { fixture: 1 } });
|
|
120
|
+
const out = await resolveSidebarSpec({ ...args, sidebar: "plugin:fixture" });
|
|
121
|
+
expect(out).toEqual({ sidebar: PluginSidebar, sidebarProps: { sidebarId: "fixture" } });
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("plugin:<id> with zero visible items => no sidebar (full width)", async () => {
|
|
125
|
+
const { args, calls } = setup({ visible: { fixture: 0 } });
|
|
126
|
+
const out = await resolveSidebarSpec({ ...args, sidebar: "plugin:fixture" });
|
|
127
|
+
|
|
128
|
+
expect(out.sidebar).toBeNull();
|
|
129
|
+
expect(calls).toEqual([["executeSidebarLoad", "fixture", event]]);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("the sidebar load runs before the items are counted", async () => {
|
|
133
|
+
const order = [];
|
|
134
|
+
const { args } = setup();
|
|
135
|
+
args.executeSidebarLoad = async () => order.push("load");
|
|
136
|
+
args.countVisible = () => (order.push("count"), 1);
|
|
137
|
+
await resolveSidebarSpec({ ...args, sidebar: "plugin:x" });
|
|
138
|
+
expect(order).toEqual(["load", "count"]);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("anything else => null sidebar and exactly one console.warn, no loads", async () => {
|
|
142
|
+
for (const value of ["support", "ticket", "player-detail", "plugin:Bad Id", "nonsense"]) {
|
|
143
|
+
const { args, calls, warnings } = setup();
|
|
144
|
+
const out = await resolveSidebarSpec({ ...args, sidebar: value });
|
|
145
|
+
|
|
146
|
+
expect(out.sidebar).toBeNull();
|
|
147
|
+
expect(warnings.length).toBe(1);
|
|
148
|
+
expect(String(warnings[0][0])).toContain(value);
|
|
149
|
+
expect(calls).toEqual([]);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|