@panomc/theme-core 1.0.0-dev.60 → 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 +79 -21
- 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,558 @@
|
|
|
1
|
+
import { afterAll, beforeAll, describe, expect, mock, test } from "bun:test";
|
|
2
|
+
import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { readable, writable } from "svelte/store";
|
|
6
|
+
|
|
7
|
+
import { findSvelte, renderPart as renderPartWith } from "./engineParts.helper.js";
|
|
8
|
+
import {
|
|
9
|
+
applyDerived,
|
|
10
|
+
deriveAll,
|
|
11
|
+
engineTableSource,
|
|
12
|
+
generate,
|
|
13
|
+
hooksOf,
|
|
14
|
+
propNamesOf,
|
|
15
|
+
renderedComponents,
|
|
16
|
+
slotPropsOf,
|
|
17
|
+
} from "../../../bin/generate-contract.js";
|
|
18
|
+
import { engineViews } from "../views/parts/engine-views.generated.js";
|
|
19
|
+
|
|
20
|
+
// The registry reads SvelteKit's `dev` flag; the old pre-split modals import the SDK's api util.
|
|
21
|
+
mock.module("$app/environment", () => ({ browser: false, dev: false }));
|
|
22
|
+
mock.module("@panomc/sdk/core/js/api.util", () => ({ default: {}, NETWORK_ERROR: "NETWORK_ERROR", buildQueryParams: () => "" }));
|
|
23
|
+
|
|
24
|
+
const registry = await import("../../registry/index.js");
|
|
25
|
+
|
|
26
|
+
const pkg = join(import.meta.dir, "..", "..", "..");
|
|
27
|
+
const lib = join(pkg, "src", "lib");
|
|
28
|
+
const read = (...parts) => readFileSync(join(...parts), "utf-8");
|
|
29
|
+
const svelteDir = findSvelte();
|
|
30
|
+
|
|
31
|
+
// DefaultToast imports the SDK's html helper by its package name, which the helper's temp folder
|
|
32
|
+
// cannot resolve: hand it the real source as a module-only .svelte file.
|
|
33
|
+
const HTML_UTIL = {
|
|
34
|
+
"@panomc/sdk/core/js/html.util.js": `<script context="module">\n${read(pkg, "..", "sdk", "core", "js", "html.util.js")}\n</script>`,
|
|
35
|
+
};
|
|
36
|
+
const renderPart = (args) => renderPartWith({ ...args, extraSvelte: { ...HTML_UTIL, ...args.extraSvelte } });
|
|
37
|
+
|
|
38
|
+
const contract = JSON.parse(read(pkg, "skin-contract.json"));
|
|
39
|
+
|
|
40
|
+
// name -> folder of its controller (the file themes and plugins import today)
|
|
41
|
+
const SEVEN = {
|
|
42
|
+
Toast: "components",
|
|
43
|
+
DefaultToast: "components",
|
|
44
|
+
ToastContainer: "components",
|
|
45
|
+
NotificationContainer: "components",
|
|
46
|
+
CloseTicketConfirmModal: "components/modals",
|
|
47
|
+
ConfirmRemoveAllNotificationsModal: "components/modals",
|
|
48
|
+
LogoutSessionConfirmModal: "components/modals",
|
|
49
|
+
};
|
|
50
|
+
const EIGHT = ["Main", "Sidebar", "Breadcrumb", "Post", "Posts", "Tickets", "TicketRow", "TicketStatus"];
|
|
51
|
+
const FORMER_REGISTRY_COMPONENTS = [
|
|
52
|
+
"LoginFormBody",
|
|
53
|
+
"RegisterForm",
|
|
54
|
+
"Date",
|
|
55
|
+
"Pagination",
|
|
56
|
+
"NoContent",
|
|
57
|
+
"PageActions",
|
|
58
|
+
"PageTitle",
|
|
59
|
+
"PlayerHead",
|
|
60
|
+
"Navbar",
|
|
61
|
+
"Header",
|
|
62
|
+
"Footer",
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
const normalize = (html) => html.replace(/<!--[\s\S]*?-->/g, "").replace(/svelte-[a-z0-9]{4,8}/g, "svelte-H");
|
|
66
|
+
|
|
67
|
+
describe("engine parts (B): files", () => {
|
|
68
|
+
for (const [name, folder] of Object.entries(SEVEN)) {
|
|
69
|
+
test(`${name} is a controller over views/parts/${name}.svelte`, () => {
|
|
70
|
+
const controller = read(lib, folder, `${name}.svelte`);
|
|
71
|
+
expect(existsSync(join(lib, "views", "parts", `${name}.svelte`))).toBe(true);
|
|
72
|
+
expect(controller).toContain(`getOverride("${name}")`);
|
|
73
|
+
expect(controller).toContain(`$pano/lib/views/parts/${name}.svelte`);
|
|
74
|
+
// the part never imports its own controller
|
|
75
|
+
expect(read(lib, "views", "parts", `${name}.svelte`)).not.toMatch(new RegExp(`import[^;]*/${name}\\.svelte`));
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
test("the stateful controllers keep their module API", () => {
|
|
80
|
+
const exportsOf = (folder, name) =>
|
|
81
|
+
[...read(lib, folder, `${name}.svelte`).matchAll(/export (?:async )?function (\w+)/g)].map((m) => m[1]).sort();
|
|
82
|
+
|
|
83
|
+
expect(exportsOf("components", "ToastContainer")).toEqual(["limitTitle", "show", "showError", "showSuccess"]);
|
|
84
|
+
expect(exportsOf("components", "NotificationContainer")).toEqual(["hide", "show"]);
|
|
85
|
+
expect(exportsOf("components/modals", "CloseTicketConfirmModal")).toEqual(["hide", "onHide", "setCallback", "show"]);
|
|
86
|
+
expect(exportsOf("components/modals", "ConfirmRemoveAllNotificationsModal")).toEqual(["hide", "onHide", "setCallback", "show"]);
|
|
87
|
+
expect(exportsOf("components/modals", "LogoutSessionConfirmModal")).toEqual(["hide", "setCallback", "show"]);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe("skin-contract.json (TC-32)", () => {
|
|
92
|
+
test("the seven parts and the eleven former registry components are component views of contract 1", () => {
|
|
93
|
+
for (const name of [...Object.keys(SEVEN), ...FORMER_REGISTRY_COMPONENTS]) {
|
|
94
|
+
expect(contract.views[name]?.kind).toBe("component");
|
|
95
|
+
// Pagination went to 2 when its page-count prop gained an s (the /api/v1 page shape, TC-42)
|
|
96
|
+
expect(contract.views[name]?.contract).toBe(name === "Pagination" ? 2 : 1);
|
|
97
|
+
}
|
|
98
|
+
// the eight of TC-20 are still there
|
|
99
|
+
for (const name of EIGHT) expect(contract.views[name]?.kind).toBe("component");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("registry_components is the derived list of component views (kept for check / list-views)", () => {
|
|
103
|
+
const components = Object.entries(contract.views)
|
|
104
|
+
.filter(([, v]) => v.kind === "component")
|
|
105
|
+
.map(([name]) => name);
|
|
106
|
+
expect(contract.registry_components).toEqual(components);
|
|
107
|
+
for (const name of FORMER_REGISTRY_COMPONENTS) expect(contract.registry_components).toContain(name);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("every entry carries source, uses, hooks, slotProps, a lock and the props its source declares", () => {
|
|
111
|
+
const derived = deriveAll(contract);
|
|
112
|
+
for (const [name, entry] of Object.entries(contract.views)) {
|
|
113
|
+
expect(typeof entry.source).toBe("string");
|
|
114
|
+
expect(existsSync(join(pkg, entry.source))).toBe(true);
|
|
115
|
+
expect(Array.isArray(entry.uses)).toBe(true);
|
|
116
|
+
expect(Array.isArray(entry.hooks)).toBe(true);
|
|
117
|
+
expect(typeof entry.slotProps).toBe("object");
|
|
118
|
+
expect(entry.locked.contract).toBe(entry.contract);
|
|
119
|
+
expect(Object.keys(entry.props ?? {}).sort()).toEqual(derived[name].props);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("the generated fields and the engine table are current: run `node bin/generate-contract.js` when this fails", () => {
|
|
124
|
+
const { problems, changed } = generate({ check: true });
|
|
125
|
+
expect(problems).toEqual([]);
|
|
126
|
+
expect(changed).toEqual([]);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("the engine table lists every view with its contract and a lazy component", () => {
|
|
130
|
+
expect(Object.keys(engineViews)).toEqual(Object.keys(contract.views));
|
|
131
|
+
for (const [name, entry] of Object.entries(engineViews)) {
|
|
132
|
+
expect(entry.contract).toBe(contract.views[name].contract);
|
|
133
|
+
expect(typeof entry.component).toBe("function");
|
|
134
|
+
expect(entry.uses ?? []).toEqual(contract.views[name].uses);
|
|
135
|
+
}
|
|
136
|
+
expect(engineViews.ToastContainer.uses).toEqual(["DefaultToast"]);
|
|
137
|
+
expect(engineViews.DefaultToast.uses).toEqual(["Toast"]);
|
|
138
|
+
expect(engineViews.Posts.uses).toEqual(["NoContent", "Post"]);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("the table registers with the registry", () => {
|
|
142
|
+
registry.resetRegistryForTests();
|
|
143
|
+
registry.registerEngineViews(engineViews);
|
|
144
|
+
expect(registry.hasView("ToastContainer")).toBe(true);
|
|
145
|
+
expect(registry.hasView("LogoutSessionConfirmModal")).toBe(true);
|
|
146
|
+
expect(registry.hasView("Navbar")).toBe(true);
|
|
147
|
+
registry.resetRegistryForTests();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe("generate-contract.js", () => {
|
|
152
|
+
test("reads props (export let and $props), hooks, slot props and rendered components", () => {
|
|
153
|
+
const source = `<Hook name="page:top" />
|
|
154
|
+
<Child a={1} />
|
|
155
|
+
<slot name="footer" row={x} {y} />
|
|
156
|
+
<slot />
|
|
157
|
+
<script context="module">
|
|
158
|
+
import Dflt from "./Dflt.svelte";
|
|
159
|
+
</script>
|
|
160
|
+
<script>
|
|
161
|
+
import Child from "./Child.svelte";
|
|
162
|
+
import Constant, { K } from "./Constant.svelte";
|
|
163
|
+
export let one;
|
|
164
|
+
export let two = [1, 2], three = 3;
|
|
165
|
+
let { four = 4, five, ...rest } = $props();
|
|
166
|
+
</script>`;
|
|
167
|
+
|
|
168
|
+
expect(propNamesOf(source)).toEqual(["five", "four", "one", "three", "two"]);
|
|
169
|
+
expect(hooksOf(source)).toEqual(["page:top"]);
|
|
170
|
+
expect(slotPropsOf(source)).toEqual({ default: [], footer: ["row", "y"] });
|
|
171
|
+
// Child is placed, Dflt is a module default, Constant is only read from
|
|
172
|
+
expect([...renderedComponents(source)].sort()).toEqual(["Child", "Dflt"]);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe("the contract rule", () => {
|
|
176
|
+
/** @type {string} */
|
|
177
|
+
let dir;
|
|
178
|
+
const part = (props) => `<div>{one}</div>\n<script>\n${props.map((p) => ` export let ${p};`).join("\n")}\n</script>\n`;
|
|
179
|
+
const write = (rel, text) => {
|
|
180
|
+
mkdirSync(join(dir, rel, ".."), { recursive: true });
|
|
181
|
+
writeFileSync(join(dir, rel), text);
|
|
182
|
+
};
|
|
183
|
+
const entry = (props, contractNumber) => ({
|
|
184
|
+
kind: "component",
|
|
185
|
+
contract: contractNumber,
|
|
186
|
+
props: Object.fromEntries(props.map((p) => [p, `${p} prop`])),
|
|
187
|
+
});
|
|
188
|
+
const setContract = (views) => write("skin-contract.json", JSON.stringify({ views }));
|
|
189
|
+
|
|
190
|
+
beforeAll(() => {
|
|
191
|
+
dir = mkdtempSync(join(tmpdir(), "tc32-contract-"));
|
|
192
|
+
write("src/lib/views/parts/Thing.svelte", part(["one"]));
|
|
193
|
+
setContract({ Thing: entry(["one"], 1) });
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
afterAll(() => rmSync(dir, { recursive: true, force: true }));
|
|
197
|
+
|
|
198
|
+
test("a first run fills the generated fields, the lock and the table", () => {
|
|
199
|
+
const { problems, changed } = generate({ dir });
|
|
200
|
+
expect(problems).toEqual([]);
|
|
201
|
+
expect(changed).toContain("skin-contract.json");
|
|
202
|
+
|
|
203
|
+
const written = JSON.parse(read(dir, "skin-contract.json"));
|
|
204
|
+
expect(written.views.Thing.source).toBe("src/lib/views/parts/Thing.svelte");
|
|
205
|
+
expect(written.views.Thing.locked).toEqual({ contract: 1, props: ["one"] });
|
|
206
|
+
expect(read(dir, "src/lib/views/parts/engine-views.generated.js")).toContain('"Thing": { contract: 1, component: () => import("./Thing.svelte") }');
|
|
207
|
+
expect(generate({ dir, check: true })).toEqual({ problems: [], changed: [] });
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test("a prop added to the source but not described fails", () => {
|
|
211
|
+
write("src/lib/views/parts/Thing.svelte", part(["one", "two"]));
|
|
212
|
+
const { problems } = generate({ dir, check: true });
|
|
213
|
+
expect(problems.join("\n")).toMatch(/Thing: .*not described: two/);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test("a described prop without a raised contract fails", () => {
|
|
217
|
+
const written = JSON.parse(read(dir, "skin-contract.json"));
|
|
218
|
+
written.views.Thing.props.two = "two prop";
|
|
219
|
+
writeFileSync(join(dir, "skin-contract.json"), JSON.stringify(written));
|
|
220
|
+
|
|
221
|
+
const { problems } = generate({ dir });
|
|
222
|
+
expect(problems.join("\n")).toMatch(/Thing: the prop set changed \(one -> one, two\) but "contract" is still 1; raise it to 2/);
|
|
223
|
+
// nothing was written on a failed run
|
|
224
|
+
expect(JSON.parse(read(dir, "skin-contract.json")).views.Thing.locked.props).toEqual(["one"]);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test("with the contract raised the run passes and records the new lock", () => {
|
|
228
|
+
const written = JSON.parse(read(dir, "skin-contract.json"));
|
|
229
|
+
written.views.Thing.contract = 2;
|
|
230
|
+
writeFileSync(join(dir, "skin-contract.json"), JSON.stringify(written));
|
|
231
|
+
|
|
232
|
+
const { problems } = generate({ dir });
|
|
233
|
+
expect(problems).toEqual([]);
|
|
234
|
+
expect(JSON.parse(read(dir, "skin-contract.json")).views.Thing.locked).toEqual({ contract: 2, props: ["one", "two"] });
|
|
235
|
+
expect(generate({ dir, check: true })).toEqual({ problems: [], changed: [] });
|
|
236
|
+
expect(read(dir, "src/lib/views/parts/engine-views.generated.js")).toContain("contract: 2");
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test("lowering the contract fails", () => {
|
|
240
|
+
const written = JSON.parse(read(dir, "skin-contract.json"));
|
|
241
|
+
written.views.Thing.contract = 1;
|
|
242
|
+
writeFileSync(join(dir, "skin-contract.json"), JSON.stringify(written));
|
|
243
|
+
expect(generate({ dir, check: true }).problems.join("\n")).toMatch(/Thing: "contract" went down \(2 -> 1\)/);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// ---------------------------------------------------------------------------
|
|
249
|
+
// Default render: the same HTML as before the split. The strings below were rendered from the
|
|
250
|
+
// pre-split sources (git 3fabe70, same helper, same stubs) with the same props. Since TC-57 they also carry
|
|
251
|
+
// the pano-* semantic class tokens (FX-08 proved that stripping them gives the pre-split strings).
|
|
252
|
+
// ---------------------------------------------------------------------------
|
|
253
|
+
|
|
254
|
+
const EXPECTED = {
|
|
255
|
+
"Toast/neutral": "<div id=\"appToast3\" class=\"pano-toast animate__animated animate__bounceInUp toast align-items-center shadow-lg text-bg-tertiary opacity-100 \" role=\"alert\" aria-live=\"assertive\" aria-atomic=\"true\" data-bs-dismiss=\"toast\"><div class=\"toast-body\">msg</div></div>",
|
|
256
|
+
"Toast/success": "<div id=\"appToast4\" class=\"pano-toast animate__animated animate__bounceInUp toast align-items-center shadow-lg text-bg-tertiary opacity-100 text-success\" role=\"alert\" aria-live=\"assertive\" aria-atomic=\"true\" data-bs-dismiss=\"toast\"><div class=\"toast-body\">msg</div></div>",
|
|
257
|
+
"Toast/danger": "<div id=\"appToast5\" class=\"pano-toast animate__animated animate__bounceInUp toast align-items-center shadow-lg text-bg-tertiary opacity-100 text-danger\" role=\"alert\" aria-live=\"assertive\" aria-atomic=\"true\" data-bs-dismiss=\"toast\"><div class=\"toast-body\"><b>m</b></div></div>",
|
|
258
|
+
"Toast/unknown": "<div id=\"appToast6\" class=\"pano-toast animate__animated animate__bounceInUp toast align-items-center shadow-lg text-bg-tertiary opacity-100 \" role=\"alert\" aria-live=\"assertive\" aria-atomic=\"true\" data-bs-dismiss=\"toast\"><div class=\"toast-body\">msg</div></div>",
|
|
259
|
+
"DefaultToast/plain": "<div id=\"appToast1\" class=\"pano-toast animate__animated animate__bounceInUp toast align-items-center shadow-lg text-bg-tertiary opacity-100 \" role=\"alert\" aria-live=\"assertive\" aria-atomic=\"true\" data-bs-dismiss=\"toast\"><div class=\"toast-body\">a.b</div></div>",
|
|
260
|
+
"DefaultToast/values": "<div id=\"appToast2\" class=\"pano-toast animate__animated animate__bounceInUp toast align-items-center shadow-lg text-bg-tertiary opacity-100 text-danger\" role=\"alert\" aria-live=\"assertive\" aria-atomic=\"true\" data-bs-dismiss=\"toast\"><div class=\"toast-body\">a.b{\"name\":\"<i>x</i>\",\"n\":3}</div></div>",
|
|
261
|
+
"ToastContainer/with-toasts": "<div class=\"pano-toast-container toast-container position-fixed bottom-0 start-50 translate-middle-x mb-3\"><div id=\"appToast1\" class=\"pano-toast animate__animated animate__bounceInUp toast align-items-center shadow-lg text-bg-tertiary opacity-100 \" role=\"alert\" aria-live=\"assertive\" aria-atomic=\"true\" data-bs-dismiss=\"toast\"><div class=\"toast-body\">t.one{\"who\":\"<b>w</b>\",\"text\":\"t.one\"}</div></div><div id=\"appToast2\" class=\"pano-toast animate__animated animate__bounceInUp toast align-items-center shadow-lg text-bg-tertiary opacity-100 text-success\" role=\"alert\" aria-live=\"assertive\" aria-atomic=\"true\" data-bs-dismiss=\"toast\"><div class=\"toast-body\">t.two{\"text\":\"t.two\"}</div></div></div>",
|
|
262
|
+
"ToastContainer/empty": "<div class=\"pano-toast-container toast-container position-fixed bottom-0 start-50 translate-middle-x mb-3\"></div>",
|
|
263
|
+
"CloseTicketConfirmModal/default": "<div aria-hidden=\"true\" class=\"pano-close-ticket-confirm-modal modal fade\" id=\"closeTicketConfirmModal\" role=\"dialog\" tabindex=\"-1\"><div class=\"modal-dialog modal-dialog-centered\" role=\"dialog\"><div class=\"modal-content\"><div class=\"pano-close-ticket-confirm-modal__body modal-body text-center\"> <div class=\"pb-3\"><i class=\"fas fa-question-circle fa-3x d-block m-auto text-gray\"></i></div> components.modals.close-ticket-confirm.title</div> <div class=\"pano-close-ticket-confirm-modal__footer modal-footer flex-nowrap\"><button class=\"pano-close-ticket-confirm-modal__action btn btn-link col-6 m-0\" data-bs-dismiss=\"modal\" type=\"button\" aria-disabled=\"false\">buttons.cancel</button> <button class=\"pano-close-ticket-confirm-modal__yes btn btn-danger col-6 m-0\" type=\"button\" aria-disabled=\"false\">buttons.yes</button></div></div></div></div>",
|
|
264
|
+
"ConfirmRemoveAllNotificationsModal/default": "<div aria-hidden=\"true\" class=\"pano-confirm-remove-all-notifications-modal modal fade\" id=\"confirmDeleteAllNotifications\" role=\"dialog\" tabindex=\"-1\"><div class=\"modal-dialog modal-dialog-centered\" role=\"dialog\"><div class=\"modal-content\"><div class=\"pano-confirm-remove-all-notifications-modal__body modal-body text-center\"><div class=\"pb-3\"><i class=\"fas fa-question-circle fa-3x d-block m-auto text-gray\"></i></div> components.modals.confirm-remove-all-notifications.title</div> <div class=\"pano-confirm-remove-all-notifications-modal__footer modal-footer flex-nowrap\"><button class=\"pano-confirm-remove-all-notifications-modal__action btn btn-link col-6 m-0\" type=\"button\">buttons.cancel</button> <button class=\"pano-confirm-remove-all-notifications-modal__yes btn btn-danger col-6 m-0\" type=\"button\">buttons.yes</button></div></div></div></div>",
|
|
265
|
+
"LogoutSessionConfirmModal/default": "<div aria-hidden=\"true\" class=\"pano-logout-session-confirm-modal modal fade\" id=\"logoutSessionConfirmModal\" role=\"dialog\" tabindex=\"-1\"><div class=\"modal-dialog modal-dialog-centered\" role=\"dialog\"><div class=\"modal-content\"><div class=\"pano-logout-session-confirm-modal__body modal-body text-center\"><div class=\"pb-3\"><i class=\"fas fa-question-circle fa-3x d-block m-auto text-gray\"></i></div> components.modals.logout-session-confirm.title</div> <div class=\"pano-logout-session-confirm-modal__footer modal-footer flex-nowrap\"><button class=\"pano-logout-session-confirm-modal__action btn btn-link col-6 m-0\" type=\"button\">buttons.cancel</button> <button class=\"pano-logout-session-confirm-modal__yes btn btn-danger col-6 m-0\" type=\"button\">buttons.yes</button></div></div></div></div>",
|
|
266
|
+
"NotificationContainer/four": "<div class=\"pano-notification-container toast-container position-fixed bottom-0 end-0 p-3 d-xl-block d-none\"><article id=\"notificationToast1\" class=\"toast position-relative\" aria-live=\"assertive\" aria-atomic=\"true\"><div class=\"toast-header text-bg-primary\"><strong class=\"me-auto\">components.notification-container.notification</strong> <small>T7-1700000000000-object</small> <button type=\"button\" class=\"btn-close btn-close-white position-relative z-3\" aria-label=\"buttons.close\" data-bs-dismiss=\"toast\"></button></div> <div class=\"toast-body\"><div class=\"pano-notification-container__item fw-normal list-group-item list-group-item-action d-flex align-items-center gap-3 text-wrap\"><button type=\"button\" title=\"buttons.view\" class=\"text-start border-0 bg-transparent p-0 d-flex align-items-center gap-3\"><span class=\"d-flex align-items-center\"><i class=\"fa-solid fa-star fa-fw\"></i></span> <span class=\"text-start\"><span class=\"text-wrap markdown-renderer text-break\">notif.1{\"faIcon\":\"fa-solid fa-star\"}</span></span></button></div></div> <button type=\"button\" class=\"stretched-link p-0 border-0 bg-transparent position-absolute top-0 start-0 w-100 h-100\" aria-label=\"buttons.view\"></button></article><article id=\"notificationToast2\" class=\"toast position-relative\" aria-live=\"assertive\" aria-atomic=\"true\"><div class=\"toast-header text-bg-primary\"><strong class=\"me-auto\">components.notification-container.notification</strong> <small>T7-1700000000001-object</small> <button type=\"button\" class=\"btn-close btn-close-white position-relative z-3\" aria-label=\"buttons.close\" data-bs-dismiss=\"toast\"></button></div> <div class=\"toast-body\"><div class=\"pano-notification-container__item fw-normal list-group-item list-group-item-action d-flex align-items-center gap-3 text-wrap\"><button type=\"button\" title=\"buttons.view\" class=\"text-start border-0 bg-transparent p-0 d-flex align-items-center gap-3\"><span class=\"d-flex align-items-center\"><img src=\"/api/v1/profile/picture/bob?v9\" alt=\"buttons.view\" width=\"48\" height=\"48\" class=\"pano-notification-container__image rounded\"/></span> <span class=\"text-start\"><span class=\"text-wrap markdown-renderer text-break\">notif.2{\"username\":\"bob\"}</span></span></button></div></div> <button type=\"button\" class=\"stretched-link p-0 border-0 bg-transparent position-absolute top-0 start-0 w-100 h-100\" aria-label=\"buttons.view\"></button></article><article id=\"notificationToast3\" class=\"toast position-relative\" aria-live=\"assertive\" aria-atomic=\"true\"><div class=\"toast-header text-bg-primary\"><strong class=\"me-auto\">components.notification-container.notification</strong> <small>T7-1700000000002-object</small> <button type=\"button\" class=\"btn-close btn-close-white position-relative z-3\" aria-label=\"buttons.close\" data-bs-dismiss=\"toast\"></button></div> <div class=\"toast-body\"><div class=\"pano-notification-container__item fw-normal list-group-item list-group-item-action d-flex align-items-center gap-3 text-wrap\"><button type=\"button\" title=\"buttons.view\" class=\"text-start border-0 bg-transparent p-0 d-flex align-items-center gap-3\"><span class=\"d-flex align-items-center\"><img src=\"/i.png\" alt=\"buttons.view\" width=\"48\" height=\"48\" class=\"pano-notification-container__image rounded\"/></span> <span class=\"text-start\"><span class=\"text-wrap markdown-renderer text-break\">notif.3{\"image\":\"/i.png\",\"x\":\"<b>\"}</span></span></button></div></div> <button type=\"button\" class=\"stretched-link p-0 border-0 bg-transparent position-absolute top-0 start-0 w-100 h-100\" aria-label=\"buttons.view\"></button></article><article id=\"notificationToast4\" class=\"toast position-relative\" aria-live=\"assertive\" aria-atomic=\"true\"><div class=\"toast-header text-bg-primary\"><strong class=\"me-auto\">components.notification-container.notification</strong> <small>T7-1700000000003-object</small> <button type=\"button\" class=\"btn-close btn-close-white position-relative z-3\" aria-label=\"buttons.close\" data-bs-dismiss=\"toast\"></button></div> <div class=\"toast-body\"><div class=\"pano-notification-container__item fw-normal list-group-item list-group-item-action d-flex align-items-center gap-3 text-wrap\"><button type=\"button\" title=\"buttons.view\" class=\"text-start border-0 bg-transparent p-0 d-flex align-items-center gap-3\"><span class=\"d-flex align-items-center\"><i class=\"fa fa-fw fa-bolt\"></i></span> <span class=\"text-start\"><span class=\"text-wrap markdown-renderer text-break\">notif.4</span></span></button></div></div> <button type=\"button\" class=\"stretched-link p-0 border-0 bg-transparent position-absolute top-0 start-0 w-100 h-100\" aria-label=\"buttons.view\"></button></article></div>"
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const WRAP_TOASTS = `<ToastContainer />
|
|
270
|
+
<script>
|
|
271
|
+
import ToastContainer, { show, showSuccess } from "$pano/lib/components/ToastContainer.svelte";
|
|
272
|
+
show("t.one", { who: "<b>w</b>" }).catch(() => {});
|
|
273
|
+
showSuccess("t.two").catch(() => {});
|
|
274
|
+
</script>`;
|
|
275
|
+
|
|
276
|
+
const WRAP_WARNING = `<ToastContainer />
|
|
277
|
+
<script>
|
|
278
|
+
import ToastContainer, { show } from "$pano/lib/components/ToastContainer.svelte";
|
|
279
|
+
show("t.warn", {}, undefined, { variant: "warning" }).catch(() => {});
|
|
280
|
+
show("t.none", {}, undefined, null).catch(() => {});
|
|
281
|
+
show("t.custom", {}, CustomToast, { variant: "danger" }).catch(() => {});
|
|
282
|
+
import CustomToast from "extra:custom-toast";
|
|
283
|
+
</script>`;
|
|
284
|
+
|
|
285
|
+
const NOTIFICATIONS = {
|
|
286
|
+
notifications: writable([
|
|
287
|
+
{ id: 1, createdAt: "1700000000000", details: { faIcon: "fa-solid fa-star" } },
|
|
288
|
+
{ id: 2, createdAt: "1700000000001", details: { username: "bob" } },
|
|
289
|
+
{ id: 3, createdAt: "1700000000002", details: { image: "/i.png", x: "<b>" } },
|
|
290
|
+
{ id: 4, createdAt: "1700000000003", details: {} },
|
|
291
|
+
]),
|
|
292
|
+
checkTime: 7,
|
|
293
|
+
currentLanguage: readable({ dateFnsCode: "enUS" }),
|
|
294
|
+
locales: { enUS: {} },
|
|
295
|
+
avatarVersion: readable("v9"),
|
|
296
|
+
getTime: (check, time, locale) => `T${check}-${time}-${typeof locale}`,
|
|
297
|
+
onNotificationClick: () => {},
|
|
298
|
+
navigate: () => {},
|
|
299
|
+
notificationTextKey: (n) => `notif.${n.id}`,
|
|
300
|
+
sanitizeObject: (o) => o,
|
|
301
|
+
onClick: () => {},
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
const C = "$pano/lib/components/";
|
|
305
|
+
const CASES = {
|
|
306
|
+
"Toast/neutral": { entry: `${C}Toast.svelte`, props: { id: 3 }, slot: "msg" },
|
|
307
|
+
"Toast/success": { entry: `${C}Toast.svelte`, props: { id: 4, variant: "success" }, slot: "msg" },
|
|
308
|
+
"Toast/danger": { entry: `${C}Toast.svelte`, props: { id: 5, variant: "danger" }, slot: "<b>m</b>" },
|
|
309
|
+
"Toast/unknown": { entry: `${C}Toast.svelte`, props: { id: 6, variant: "x" }, slot: "msg" },
|
|
310
|
+
"DefaultToast/plain": { entry: `${C}DefaultToast.svelte`, props: { id: 1, text: "a.b", values: {}, variant: null } },
|
|
311
|
+
"DefaultToast/values": {
|
|
312
|
+
entry: `${C}DefaultToast.svelte`,
|
|
313
|
+
props: { id: 2, text: "a.b", values: { name: "<i>x</i>", n: 3 }, variant: "danger" },
|
|
314
|
+
},
|
|
315
|
+
"ToastContainer/with-toasts": { entry: "extra:wrap-toast", extraSvelte: { "extra:wrap-toast": WRAP_TOASTS } },
|
|
316
|
+
"ToastContainer/empty": { entry: `${C}ToastContainer.svelte` },
|
|
317
|
+
"CloseTicketConfirmModal/default": { entry: `${C}modals/CloseTicketConfirmModal.svelte` },
|
|
318
|
+
"ConfirmRemoveAllNotificationsModal/default": { entry: `${C}modals/ConfirmRemoveAllNotificationsModal.svelte` },
|
|
319
|
+
"LogoutSessionConfirmModal/default": { entry: `${C}modals/LogoutSessionConfirmModal.svelte` },
|
|
320
|
+
// the controller needs the whole app (realtime, stores): the markup is rendered through the part
|
|
321
|
+
"NotificationContainer/four": { entry: "$pano/lib/views/parts/NotificationContainer.svelte", props: NOTIFICATIONS },
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
describe.skipIf(!svelteDir)("engine parts (B): default render is unchanged", () => {
|
|
325
|
+
beforeAll(() => {
|
|
326
|
+
registry.resetRegistryForTests();
|
|
327
|
+
registry.setThemeConfig({});
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
test("every expected render is covered", () => {
|
|
331
|
+
expect(Object.keys(CASES).sort()).toEqual(Object.keys(EXPECTED).sort());
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
for (const [name, c] of Object.entries(CASES)) {
|
|
335
|
+
test(`${name} renders the same HTML as before the split`, async () => {
|
|
336
|
+
const html = await renderPart({ svelteDir, entry: c.entry, props: c.props ?? {}, slot: c.slot, extraSvelte: c.extraSvelte });
|
|
337
|
+
expect(normalize(html)).toBe(EXPECTED[name]);
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
describe.skipIf(!svelteDir)("toasts: the 4th argument { variant }", () => {
|
|
343
|
+
beforeAll(() => {
|
|
344
|
+
registry.resetRegistryForTests();
|
|
345
|
+
registry.setThemeConfig({});
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
test("a variant colours the toast, null and a custom component stay neutral", async () => {
|
|
349
|
+
const html = await renderPart({
|
|
350
|
+
svelteDir,
|
|
351
|
+
entry: "extra:wrap-warning",
|
|
352
|
+
extraSvelte: {
|
|
353
|
+
"extra:wrap-warning": WRAP_WARNING,
|
|
354
|
+
"extra:custom-toast": `<div class="custom" id="appToast{id}">{text}</div>\n<script>export let id; export let text;</script>`,
|
|
355
|
+
},
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
const toast = (id) => html.match(new RegExp(`<div id="appToast${id}"[^>]*class="([^"]*)"`))?.[1] ?? "";
|
|
359
|
+
expect(toast(1)).toContain("text-warning");
|
|
360
|
+
expect(toast(2)).not.toMatch(/text-(success|danger|warning)/);
|
|
361
|
+
// DefaultToast is replaced, so `variant` is not threaded into the custom component
|
|
362
|
+
expect(html).toContain('<div class="custom" id="appToast3">t.custom</div>');
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
// ---------------------------------------------------------------------------
|
|
367
|
+
// Overrides
|
|
368
|
+
// ---------------------------------------------------------------------------
|
|
369
|
+
|
|
370
|
+
describe.skipIf(!svelteDir)("engine parts (B): an override renders", () => {
|
|
371
|
+
/** @type {string} */
|
|
372
|
+
let dir;
|
|
373
|
+
|
|
374
|
+
beforeAll(() => {
|
|
375
|
+
dir = mkdtempSync(join(tmpdir(), "tc32-override-"));
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
afterAll(() => {
|
|
379
|
+
rmSync(dir, { recursive: true, force: true });
|
|
380
|
+
registry.resetRegistryForTests();
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
/** A server component written by hand (Svelte 5 server signature) so no compile step is needed. */
|
|
384
|
+
const writeComponent = (file, body) => {
|
|
385
|
+
writeFileSync(join(dir, file), `export default function Component($$renderer, $$props) {\n${body}\n}\n`);
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
/** Registers `name` with a default module and a theme override, then loads the override. */
|
|
389
|
+
async function setup(name, overrideBody, { overrideContract } = {}) {
|
|
390
|
+
registry.resetRegistryForTests();
|
|
391
|
+
writeComponent(`${name}.default.mjs`, `$$renderer.push("<default/>");`);
|
|
392
|
+
writeComponent(`${name}.override.mjs`, overrideBody);
|
|
393
|
+
registry.registerEngineViews({ [name]: { contract: 1, component: () => import(join(dir, `${name}.default.mjs`)) } });
|
|
394
|
+
registry.setThemeConfig({
|
|
395
|
+
views: { [name]: { contract: overrideContract ?? 1, component: () => import(join(dir, `${name}.override.mjs`)) } },
|
|
396
|
+
});
|
|
397
|
+
await registry.preloadViews([name]);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
test("an override of ToastContainer replaces the stack and receives the toasts store", async () => {
|
|
401
|
+
await setup(
|
|
402
|
+
"ToastContainer",
|
|
403
|
+
[
|
|
404
|
+
"let list = [];",
|
|
405
|
+
"$$props.toasts.subscribe((v) => (list = v))();",
|
|
406
|
+
"$$renderer.push(`<ol class=\"custom-toasts\" data-count=\"${list.length}\">${list.map((t) => `<li data-id=\"${t.id}\" data-text=\"${t.params.text}\" data-variant=\"${t.params.variant}\"></li>`).join(\"\")}</ol>`);",
|
|
407
|
+
].join("\n"),
|
|
408
|
+
);
|
|
409
|
+
expect(registry.getOverride("ToastContainer")).not.toBeNull();
|
|
410
|
+
|
|
411
|
+
const html = await renderPart({
|
|
412
|
+
svelteDir,
|
|
413
|
+
entry: "extra:wrap",
|
|
414
|
+
extraSvelte: {
|
|
415
|
+
"extra:wrap": `<ToastContainer />
|
|
416
|
+
<script>
|
|
417
|
+
import ToastContainer, { showError } from "$pano/lib/components/ToastContainer.svelte";
|
|
418
|
+
showError("t.bad").catch(() => {});
|
|
419
|
+
</script>`,
|
|
420
|
+
},
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
expect(html).toContain('<ol class="custom-toasts" data-count="1"><li data-id="1" data-text="t.bad" data-variant="danger"></li></ol>');
|
|
424
|
+
expect(html).not.toContain("toast-container");
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
test("without a loaded override ToastContainer renders the default part", async () => {
|
|
428
|
+
registry.resetRegistryForTests();
|
|
429
|
+
registry.setThemeConfig({});
|
|
430
|
+
const html = await renderPart({ svelteDir, entry: `${C}ToastContainer.svelte` });
|
|
431
|
+
expect(html).toContain("toast-container position-fixed");
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
test("an override written for another contract is ignored and the default renders", async () => {
|
|
435
|
+
await setup("ToastContainer", `$$renderer.push("<custom/>");`, { overrideContract: 2 });
|
|
436
|
+
expect(registry.getOverride("ToastContainer")).toBeNull();
|
|
437
|
+
expect(registry.getIssues().map((i) => i.type)).toContain("CONTRACT_MISMATCH");
|
|
438
|
+
|
|
439
|
+
const html = await renderPart({ svelteDir, entry: `${C}ToastContainer.svelte` });
|
|
440
|
+
expect(html).not.toContain("<custom/>");
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
test("an override of Toast gets the id, the variant, its class and the message slot", async () => {
|
|
444
|
+
await setup(
|
|
445
|
+
"Toast",
|
|
446
|
+
[
|
|
447
|
+
"$$renderer.push(`<aside class=\"custom-toast ${$$props.variantClass}\" data-id=\"${$$props.id}\" data-variant=\"${$$props.variant}\">`);",
|
|
448
|
+
"$$props.children?.($$renderer);",
|
|
449
|
+
"$$renderer.push(`</aside>`);",
|
|
450
|
+
].join("\n"),
|
|
451
|
+
);
|
|
452
|
+
|
|
453
|
+
const html = await renderPart({ svelteDir, entry: `${C}Toast.svelte`, props: { id: 9, variant: "warning" }, slot: "hello" });
|
|
454
|
+
expect(html).toContain('<aside class="custom-toast text-warning" data-id="9" data-variant="warning">');
|
|
455
|
+
expect(html).toContain("hello");
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
test("an override of DefaultToast gets the escaped message", async () => {
|
|
459
|
+
await setup(
|
|
460
|
+
"DefaultToast",
|
|
461
|
+
"$$renderer.push(`<p class=\"custom-default\" data-text=\"${$$props.text}\">${$$props.message}</p>`);",
|
|
462
|
+
);
|
|
463
|
+
|
|
464
|
+
const html = await renderPart({
|
|
465
|
+
svelteDir,
|
|
466
|
+
entry: `${C}DefaultToast.svelte`,
|
|
467
|
+
props: { id: 1, text: "a.b", values: { name: "<script>x</script>" }, variant: null },
|
|
468
|
+
});
|
|
469
|
+
expect(html).toContain('<p class="custom-default" data-text="a.b">a.b{"name":"<script>x</script>"}</p>');
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
test("an override of NotificationContainer receives the stores, the formatters and the handlers", async () => {
|
|
473
|
+
await setup(
|
|
474
|
+
"NotificationContainer",
|
|
475
|
+
[
|
|
476
|
+
"const kinds = ['notifications', 'checkTime', 'currentLanguage', 'locales', 'avatarVersion', 'getTime', 'onNotificationClick', 'navigate', 'notificationTextKey', 'sanitizeObject', 'onClick'];",
|
|
477
|
+
"$$renderer.push(`<div class=\"custom-notifications\">${kinds.map((k) => `${k}:${typeof $$props[k]}`).join(',')}</div>`);",
|
|
478
|
+
].join("\n"),
|
|
479
|
+
);
|
|
480
|
+
|
|
481
|
+
// The controller's own script needs the whole app (stores, realtime); a harness that renders
|
|
482
|
+
// the registry choice exactly as the controller does is enough to show the props reach the override.
|
|
483
|
+
const html = await renderPart({
|
|
484
|
+
svelteDir,
|
|
485
|
+
entry: "extra:notification-controller",
|
|
486
|
+
props: NOTIFICATIONS,
|
|
487
|
+
extraSvelte: {
|
|
488
|
+
"extra:notification-controller": `<svelte:component this={getOverride("NotificationContainer")} {notifications} {checkTime} {currentLanguage} {locales} {avatarVersion} {getTime} {onNotificationClick} {navigate} {notificationTextKey} {sanitizeObject} {onClick} />
|
|
489
|
+
<script>
|
|
490
|
+
import { getOverride } from "$pano/registry/index.js";
|
|
491
|
+
export let notifications, checkTime, currentLanguage, locales, avatarVersion, getTime, onNotificationClick, navigate, notificationTextKey, sanitizeObject, onClick;
|
|
492
|
+
</script>`,
|
|
493
|
+
},
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
expect(html).toContain(
|
|
497
|
+
"notifications:object,checkTime:number,currentLanguage:object,locales:object,avatarVersion:object,getTime:function,onNotificationClick:function,navigate:function,notificationTextKey:function,sanitizeObject:function,onClick:function",
|
|
498
|
+
);
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
test("an override of LogoutSessionConfirmModal keeps the dialog id and gets the handlers", async () => {
|
|
502
|
+
await setup(
|
|
503
|
+
"LogoutSessionConfirmModal",
|
|
504
|
+
"$$renderer.push(`<dialog id=\"${$$props.dialogID}\" data-hide=\"${typeof $$props.hide}\" data-yes=\"${typeof $$props.onYesClick}\"></dialog>`);",
|
|
505
|
+
);
|
|
506
|
+
|
|
507
|
+
const html = await renderPart({ svelteDir, entry: `${C}modals/LogoutSessionConfirmModal.svelte` });
|
|
508
|
+
expect(html).toContain('<dialog id="logoutSessionConfirmModal" data-hide="function" data-yes="function"></dialog>');
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
test("an override of CloseTicketConfirmModal gets the error store and the loading flag", async () => {
|
|
512
|
+
await setup(
|
|
513
|
+
"CloseTicketConfirmModal",
|
|
514
|
+
"$$renderer.push(`<dialog id=\"${$$props.dialogID}\" data-error=\"${typeof $$props.error?.subscribe}\" data-loading=\"${$$props.loading}\"></dialog>`);",
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
const html = await renderPart({ svelteDir, entry: `${C}modals/CloseTicketConfirmModal.svelte` });
|
|
518
|
+
expect(html).toContain('<dialog id="closeTicketConfirmModal" data-error="function" data-loading="false"></dialog>');
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
test("an override of ConfirmRemoveAllNotificationsModal keeps the dialog id", async () => {
|
|
522
|
+
await setup(
|
|
523
|
+
"ConfirmRemoveAllNotificationsModal",
|
|
524
|
+
"$$renderer.push(`<dialog id=\"${$$props.dialogID}\" data-yes=\"${typeof $$props.onYesClick}\"></dialog>`);",
|
|
525
|
+
);
|
|
526
|
+
|
|
527
|
+
const html = await renderPart({ svelteDir, entry: `${C}modals/ConfirmRemoveAllNotificationsModal.svelte` });
|
|
528
|
+
expect(html).toContain('<dialog id="confirmDeleteAllNotifications" data-yes="function"></dialog>');
|
|
529
|
+
});
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
describe.skipIf(!svelteDir)("engine parts (B): the default parts render their props", () => {
|
|
533
|
+
const render = (entry, props) => renderPart({ svelteDir, entry, props });
|
|
534
|
+
|
|
535
|
+
test("CloseTicketConfirmModal shows the error and disables the buttons while loading", async () => {
|
|
536
|
+
const html = await render("$pano/lib/views/parts/CloseTicketConfirmModal.svelte", {
|
|
537
|
+
dialogID: "d1",
|
|
538
|
+
error: writable("NETWORK_ERROR"),
|
|
539
|
+
loading: true,
|
|
540
|
+
hide: () => {},
|
|
541
|
+
onYesClick: () => {},
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
expect(html).toContain('id="d1"');
|
|
545
|
+
expect(html).toContain("alert alert-danger");
|
|
546
|
+
expect(html).toContain("errors.NETWORK_ERROR");
|
|
547
|
+
expect(html.match(/disabled/g)?.length).toBeGreaterThanOrEqual(4);
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
test("DefaultToast puts the message through {@html} and passes the variant on", async () => {
|
|
551
|
+
registry.resetRegistryForTests();
|
|
552
|
+
registry.setThemeConfig({});
|
|
553
|
+
const html = await render("$pano/lib/views/parts/DefaultToast.svelte", { id: 5, text: "k", message: "<b>safe</b>", variant: "success" });
|
|
554
|
+
expect(html).toContain('id="appToast5"');
|
|
555
|
+
expect(html).toContain("text-success");
|
|
556
|
+
expect(html).toContain("<b>safe</b>");
|
|
557
|
+
});
|
|
558
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
|
|
6
|
+
// svelte is a peer of the theme (not installed in this repo): use it from the repo, or from the
|
|
7
|
+
// vanilla-theme checkout next to it when present. Without any, SSR tests are skipped.
|
|
8
|
+
export function findSvelte() {
|
|
9
|
+
for (const from of [import.meta.dir, join(import.meta.dir, "../../../../../../themes/vanilla-theme/package.json")]) {
|
|
10
|
+
try {
|
|
11
|
+
const req = createRequire(from);
|
|
12
|
+
return join(req.resolve("svelte/package.json"), "..");
|
|
13
|
+
} catch {
|
|
14
|
+
// try the next location
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Server-renders Svelte components.
|
|
22
|
+
*
|
|
23
|
+
* @param {object} args
|
|
24
|
+
* @param {string} args.svelteDir the svelte package directory (from findSvelte)
|
|
25
|
+
* @param {Record<string, string>} args.components specifier-or-name -> absolute .svelte path; the first entry is rendered
|
|
26
|
+
* @param {Record<string, string>} [args.modules] specifier -> JS source of a stub module the components import
|
|
27
|
+
* @param {object} [args.props]
|
|
28
|
+
* @returns {Promise<{ body: string, head: string }>}
|
|
29
|
+
*/
|
|
30
|
+
export async function renderSvelte({ svelteDir, components, modules = {}, props = {} }) {
|
|
31
|
+
const compiler = await import(join(svelteDir, "src", "compiler", "index.js"));
|
|
32
|
+
const dir = mkdtempSync(join(tmpdir(), "tc03-ssr-"));
|
|
33
|
+
mkdirSync(join(dir, "node_modules"));
|
|
34
|
+
symlinkSync(svelteDir, join(dir, "node_modules", "svelte"), "dir");
|
|
35
|
+
|
|
36
|
+
// specifier -> temp file
|
|
37
|
+
const files = new Map();
|
|
38
|
+
let n = 0;
|
|
39
|
+
for (const specifier of Object.keys(modules)) files.set(specifier, join(dir, `stub${n++}.mjs`));
|
|
40
|
+
const names = Object.keys(components);
|
|
41
|
+
for (const name of names) files.set(name, join(dir, `component${names.indexOf(name)}.mjs`));
|
|
42
|
+
|
|
43
|
+
const rewrite = (code) => {
|
|
44
|
+
let out = code;
|
|
45
|
+
for (const [specifier, file] of files) {
|
|
46
|
+
out = out.split(JSON.stringify(specifier)).join(JSON.stringify(file));
|
|
47
|
+
out = out.split(`'${specifier}'`).join(JSON.stringify(file));
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
for (const [specifier, source] of Object.entries(modules)) writeFileSync(files.get(specifier), rewrite(source));
|
|
54
|
+
for (const name of names) {
|
|
55
|
+
const source = readFileSync(components[name], "utf-8");
|
|
56
|
+
const { js } = compiler.compile(source, { generate: "server", filename: components[name].split("/").pop() });
|
|
57
|
+
writeFileSync(files.get(name), rewrite(js.code));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const { default: Component } = await import(files.get(names[0]));
|
|
61
|
+
const { render } = await import(join(dir, "node_modules", "svelte", "src", "server", "index.js"));
|
|
62
|
+
const out = render(Component, { props });
|
|
63
|
+
|
|
64
|
+
return { body: out.body, head: out.head };
|
|
65
|
+
} finally {
|
|
66
|
+
rmSync(dir, { recursive: true, force: true });
|
|
67
|
+
}
|
|
68
|
+
}
|