@panomc/theme-core 1.0.0-dev.59 → 1.0.0-dev.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/assets/css/pano-fallback-legacy.css +12381 -0
  2. package/assets/css/pano-fallback.css +3222 -0
  3. package/bin/__tests__/check/fixtures/plugin-contracts/market/controllers.json +4 -0
  4. package/bin/__tests__/check/fixtures/plugin-contracts/market/views.json +67 -0
  5. package/bin/__tests__/check/fixtures/routes.json +5 -0
  6. package/bin/__tests__/check/helpers.js +55 -0
  7. package/bin/__tests__/check/overrides.test.js +287 -0
  8. package/bin/__tests__/check/theme.test.js +332 -0
  9. package/bin/__tests__/cli/accept-and-list.test.js +159 -0
  10. package/bin/__tests__/cli/config-edit.test.js +213 -0
  11. package/bin/__tests__/cli/contracts-pull.test.js +187 -0
  12. package/bin/__tests__/cli/core-meta.test.js +305 -0
  13. package/bin/__tests__/cli/eject-view.test.js +356 -0
  14. package/bin/__tests__/cli/helpers.js +258 -0
  15. package/bin/__tests__/scaffold/scaffold.test.js +84 -0
  16. package/bin/bundle-internal-libs.js +14 -2
  17. package/bin/check.js +1150 -213
  18. package/bin/contracts.js +1643 -0
  19. package/bin/generate-contract.js +378 -0
  20. package/bin/generate-licenses.js +14 -2
  21. package/bin/generate-runtime-shims.js +27 -9
  22. package/bin/new.js +101 -2
  23. package/bin/package-zip.js +16 -2
  24. package/bin/sync.js +360 -7
  25. package/bin/theme-core.js +65 -107
  26. package/lang/en-US.json +1 -0
  27. package/lang/ru.json +1 -0
  28. package/lang/tr.json +1 -0
  29. package/package.json +7 -3
  30. package/skin-contract.json +864 -19
  31. package/src/kit/__tests__/hooks-server-fetch.test.js +56 -0
  32. package/src/kit/__tests__/route-map.test.js +154 -0
  33. package/src/kit/__tests__/theme-meta.test.js +249 -0
  34. package/src/kit/hooks-client.js +3 -0
  35. package/src/kit/hooks-server.js +91 -7
  36. package/src/kit/route-map.js +300 -0
  37. package/src/kit/specifiers.js +3 -0
  38. package/src/kit/svelte-config.js +3 -0
  39. package/src/kit/theme-meta.js +405 -0
  40. package/src/kit/vite-config.js +156 -12
  41. package/src/lib/NotificationManager.js +18 -0
  42. package/src/lib/PluginAPI.js +313 -9
  43. package/src/lib/Store.js +18 -5
  44. package/src/lib/__tests__/avatarVersion.test.js +25 -0
  45. package/src/lib/__tests__/check.test.js +201 -0
  46. package/src/lib/__tests__/controllerHost.test.js +363 -0
  47. package/src/lib/__tests__/cx03.test.js +245 -0
  48. package/src/lib/__tests__/engineBoot.test.js +151 -0
  49. package/src/lib/__tests__/engineParts.helper.js +284 -0
  50. package/src/lib/__tests__/engineParts.test.js +179 -0
  51. package/src/lib/__tests__/engineSidebars.helper.js +353 -0
  52. package/src/lib/__tests__/engineSidebars.test.js +273 -0
  53. package/src/lib/__tests__/engineStyles.test.js +227 -0
  54. package/src/lib/__tests__/engineWiring.test.js +1000 -0
  55. package/src/lib/__tests__/fallbackStyles.test.js +1254 -0
  56. package/src/lib/__tests__/fixtures/Probe.svelte +5 -0
  57. package/src/lib/__tests__/fixtures/engine-parts.ssr.json +29 -0
  58. package/src/lib/__tests__/fixtures/engine-sidebars.ssr.json +16 -0
  59. package/src/lib/__tests__/home.test.js +563 -0
  60. package/src/lib/__tests__/injectedScope.test.js +490 -0
  61. package/src/lib/__tests__/languageConcurrency.test.js +55 -0
  62. package/src/lib/__tests__/languageLayers.test.js +286 -0
  63. package/src/lib/__tests__/pageHead.test.js +167 -0
  64. package/src/lib/__tests__/pageMeta.util.test.js +216 -0
  65. package/src/lib/__tests__/pageTitle.util.test.js +96 -0
  66. package/src/lib/__tests__/pluginApiViews.test.js +529 -0
  67. package/src/lib/__tests__/plugins.test.js +53 -0
  68. package/src/lib/__tests__/profileNav.util.test.js +145 -0
  69. package/src/lib/__tests__/registryReady.test.js +26 -0
  70. package/src/lib/__tests__/returnTo.util.test.js +294 -0
  71. package/src/lib/__tests__/routeConfig.test.js +361 -0
  72. package/src/lib/__tests__/sidebarSpec.util.test.js +152 -0
  73. package/src/lib/__tests__/skinContract.test.js +558 -0
  74. package/src/lib/__tests__/svelteSsr.helper.js +68 -0
  75. package/src/lib/__tests__/tc03.test.js +427 -0
  76. package/src/lib/__tests__/tc11.test.js +184 -0
  77. package/src/lib/__tests__/translationLayers.test.js +161 -0
  78. package/src/lib/avatarVersion.js +39 -0
  79. package/src/lib/components/Breadcrumb.svelte +9 -40
  80. package/src/lib/components/Date.svelte +1 -1
  81. package/src/lib/components/DefaultToast.svelte +13 -3
  82. package/src/lib/components/FallbackLinks.svelte +28 -0
  83. package/src/lib/components/FallbackScope.svelte +24 -0
  84. package/src/lib/components/Footer.svelte +8 -8
  85. package/src/lib/components/Header.svelte +3 -3
  86. package/src/lib/components/Hook.svelte +12 -1
  87. package/src/lib/components/LoginFormBody.svelte +5 -5
  88. package/src/lib/components/Main.svelte +22 -47
  89. package/src/lib/components/Navbar.svelte +30 -29
  90. package/src/lib/components/NoContent.svelte +2 -2
  91. package/src/lib/components/NotificationContainer.svelte +31 -82
  92. package/src/lib/components/OnlineAdmins.svelte +3 -2
  93. package/src/lib/components/PageActions.svelte +1 -1
  94. package/src/lib/components/PageHead.svelte +50 -0
  95. package/src/lib/components/PageTitle.svelte +2 -2
  96. package/src/lib/components/Pagination.svelte +6 -6
  97. package/src/lib/components/PlayerHead.svelte +4 -4
  98. package/src/lib/components/PluginBlock.svelte +132 -0
  99. package/src/lib/components/PluginSlot.svelte +40 -0
  100. package/src/lib/components/Post.svelte +13 -230
  101. package/src/lib/components/Posts.svelte +7 -14
  102. package/src/lib/components/RegisterForm.svelte +12 -11
  103. package/src/lib/components/Sidebar.svelte +9 -7
  104. package/src/lib/components/TicketRow.svelte +8 -48
  105. package/src/lib/components/TicketStatus.svelte +10 -16
  106. package/src/lib/components/Tickets.svelte +8 -30
  107. package/src/lib/components/Toast.svelte +16 -14
  108. package/src/lib/components/ToastContainer.svelte +16 -9
  109. package/src/lib/components/ViewComponent.svelte +13 -1
  110. package/src/lib/components/modals/CloseTicketConfirmModal.svelte +15 -46
  111. package/src/lib/components/modals/ConfirmRemoveAllNotificationsModal.svelte +17 -39
  112. package/src/lib/components/modals/LogoutSessionConfirmModal.svelte +12 -30
  113. package/src/lib/components/sidebars/HomeSidebar.svelte +33 -284
  114. package/src/lib/components/sidebars/PlayerDetailSidebar.svelte +14 -63
  115. package/src/lib/components/sidebars/PluginSidebar.svelte +21 -0
  116. package/src/lib/components/sidebars/ProfileNavCard.svelte +24 -0
  117. package/src/lib/components/sidebars/ProfileSidebar.svelte +44 -84
  118. package/src/lib/components/sidebars/SupportSidebar.svelte +19 -22
  119. package/src/lib/components/sidebars/TicketCreateAndDetailSidebar.svelte +23 -35
  120. package/src/lib/components/sidebars/profileNav.util.js +105 -0
  121. package/src/lib/components/sidebars/sidebarSpec.util.js +92 -0
  122. package/src/lib/controllerHost.js +261 -0
  123. package/src/lib/fallbackStyles.js +317 -0
  124. package/src/lib/home.js +202 -0
  125. package/src/lib/language.util.js +70 -37
  126. package/src/lib/layouts/AppLayout.svelte +16 -8
  127. package/src/lib/layouts/AuthLayout.svelte +6 -4
  128. package/src/lib/layouts/MainLayout.svelte +17 -12
  129. package/src/lib/layouts/ProfileLayout.svelte +6 -4
  130. package/src/lib/layouts/ThemeSettingsLayout.svelte +6 -4
  131. package/src/lib/layouts/TicketsLayout.svelte +6 -5
  132. package/src/lib/pageMeta.util.js +212 -0
  133. package/src/lib/pageShape.js +33 -0
  134. package/src/lib/pageTitle.util.js +32 -0
  135. package/src/lib/pages/ActivateEmailPage.svelte +2 -7
  136. package/src/lib/pages/ConfirmNewEmailPage.svelte +2 -7
  137. package/src/lib/pages/ErrorPage.svelte +5 -2
  138. package/src/lib/pages/HomePage.svelte +31 -8
  139. package/src/lib/pages/LoginPage.svelte +38 -41
  140. package/src/lib/pages/NotificationsPage.svelte +2 -7
  141. package/src/lib/pages/PlayerDetailPage.svelte +2 -7
  142. package/src/lib/pages/PostDetailPage.svelte +2 -7
  143. package/src/lib/pages/PreviewPostPage.svelte +2 -7
  144. package/src/lib/pages/RegisterPage.svelte +10 -13
  145. package/src/lib/pages/RenewPasswordPage.svelte +2 -7
  146. package/src/lib/pages/ResetPasswordPage.svelte +2 -7
  147. package/src/lib/pages/RulesPage.svelte +3 -8
  148. package/src/lib/pages/SupportPage.svelte +2 -7
  149. package/src/lib/pages/ThemeSettingsPage.svelte +2 -7
  150. package/src/lib/pages/profile/ProfilePage.svelte +2 -7
  151. package/src/lib/pages/profile/SettingsPage.svelte +2 -7
  152. package/src/lib/pages/profile/TicketsPage.svelte +2 -7
  153. package/src/lib/pages/ticket/CreateTicketPage.svelte +2 -7
  154. package/src/lib/pages/ticket/TicketDetailPage.svelte +2 -7
  155. package/src/lib/plugins.js +61 -0
  156. package/src/lib/returnTo.util.js +116 -0
  157. package/src/lib/services/auth.js +11 -11
  158. package/src/lib/services/posts.js +21 -10
  159. package/src/lib/services/profile.js +5 -5
  160. package/src/lib/services/theme-setting.js +1 -1
  161. package/src/lib/services/tickets.js +36 -15
  162. package/src/lib/siteRealtime.js +55 -8
  163. package/src/lib/themePageLoad.js +38 -0
  164. package/src/lib/translationLayers.js +144 -0
  165. package/src/lib/ui-logics/layout-logics/AppLayoutLogics.js +160 -6
  166. package/src/lib/ui-logics/layout-logics/AuthLayoutLogics.js +3 -2
  167. package/src/lib/ui-logics/layout-logics/ProfileLayoutLogics.js +3 -2
  168. package/src/lib/ui-logics/layout-logics/TicketsLayoutLogics.js +3 -2
  169. package/src/lib/ui-logics/page-logics/ActiveEmailPageLogics.js +4 -4
  170. package/src/lib/ui-logics/page-logics/ConfirmNewEmailPageLogics.js +4 -4
  171. package/src/lib/ui-logics/page-logics/CreateTicketPageLogics.js +5 -5
  172. package/src/lib/ui-logics/page-logics/HomePageLogics.js +5 -3
  173. package/src/lib/ui-logics/page-logics/NotificationsPageLogics.js +40 -16
  174. package/src/lib/ui-logics/page-logics/PlayerDetailPageLogics.js +3 -3
  175. package/src/lib/ui-logics/page-logics/PostDetailPageLogics.js +3 -3
  176. package/src/lib/ui-logics/page-logics/PreviewPostPageLogics.js +1 -1
  177. package/src/lib/ui-logics/page-logics/RenewPasswordPageLogics.js +4 -4
  178. package/src/lib/ui-logics/page-logics/ResetPasswordPageLogics.js +6 -6
  179. package/src/lib/ui-logics/page-logics/SettingsPageLogics.js +8 -8
  180. package/src/lib/ui-logics/page-logics/TicketDetailPageLogics.js +3 -3
  181. package/src/lib/ui-logics/page-logics/TicketsPageLogics.js +5 -3
  182. package/src/lib/views/ActivateEmailView.samples.js +22 -0
  183. package/src/lib/views/ActivateEmailView.svelte +4 -4
  184. package/src/lib/views/AppLayoutView.samples.js +17 -0
  185. package/src/lib/views/AppLayoutView.svelte +1 -1
  186. package/src/lib/views/AuthLayoutView.samples.js +4 -0
  187. package/src/lib/views/AuthLayoutView.svelte +1 -1
  188. package/src/lib/views/Breadcrumb.samples.js +15 -0
  189. package/src/lib/views/CloseTicketConfirmModal.samples.js +12 -0
  190. package/src/lib/views/ConfirmNewEmailView.samples.js +22 -0
  191. package/src/lib/views/ConfirmNewEmailView.svelte +4 -4
  192. package/src/lib/views/ConfirmRemoveAllNotificationsModal.samples.js +9 -0
  193. package/src/lib/views/CreateTicketView.samples.js +21 -0
  194. package/src/lib/views/CreateTicketView.svelte +5 -5
  195. package/src/lib/views/Date.samples.js +9 -0
  196. package/src/lib/views/DefaultToast.samples.js +7 -0
  197. package/src/lib/views/ErrorView.samples.js +8 -0
  198. package/src/lib/views/ErrorView.svelte +4 -2
  199. package/src/lib/views/Footer.samples.js +8 -0
  200. package/src/lib/views/Header.samples.js +8 -0
  201. package/src/lib/views/HomeSidebar.samples.js +59 -0
  202. package/src/lib/views/HomeView.samples.js +34 -0
  203. package/src/lib/views/HomeView.svelte +14 -6
  204. package/src/lib/views/LoginFormBody.samples.js +8 -0
  205. package/src/lib/views/LoginView.samples.js +50 -0
  206. package/src/lib/views/LoginView.svelte +24 -22
  207. package/src/lib/views/LogoutSessionConfirmModal.samples.js +8 -0
  208. package/src/lib/views/Main.samples.js +23 -0
  209. package/src/lib/views/MainLayoutView.svelte +3 -4
  210. package/src/lib/views/Navbar.samples.js +8 -0
  211. package/src/lib/views/NoContent.samples.js +7 -0
  212. package/src/lib/views/NotificationContainer.samples.js +25 -0
  213. package/src/lib/views/NotificationsView.samples.js +36 -0
  214. package/src/lib/views/NotificationsView.svelte +21 -12
  215. package/src/lib/views/PageActions.samples.js +7 -0
  216. package/src/lib/views/PageTitle.samples.js +8 -0
  217. package/src/lib/views/Pagination.samples.js +7 -0
  218. package/src/lib/views/PlayerDetailSidebar.samples.js +35 -0
  219. package/src/lib/views/PlayerDetailView.samples.js +8 -0
  220. package/src/lib/views/PlayerDetailView.svelte +3 -3
  221. package/src/lib/views/PlayerHead.samples.js +8 -0
  222. package/src/lib/views/Post.samples.js +10 -0
  223. package/src/lib/views/PostDetailView.samples.js +28 -0
  224. package/src/lib/views/PostDetailView.svelte +24 -16
  225. package/src/lib/views/Posts.samples.js +9 -0
  226. package/src/lib/views/PreviewPostView.samples.js +20 -0
  227. package/src/lib/views/PreviewPostView.svelte +10 -10
  228. package/src/lib/views/ProfileLayoutView.samples.js +4 -0
  229. package/src/lib/views/ProfileSidebar.samples.js +33 -0
  230. package/src/lib/views/ProfileView.samples.js +29 -0
  231. package/src/lib/views/ProfileView.svelte +2 -2
  232. package/src/lib/views/RegisterForm.samples.js +7 -0
  233. package/src/lib/views/RegisterView.samples.js +28 -0
  234. package/src/lib/views/RegisterView.svelte +5 -3
  235. package/src/lib/views/RenewPasswordView.samples.js +24 -0
  236. package/src/lib/views/RenewPasswordView.svelte +6 -6
  237. package/src/lib/views/ResetPasswordView.samples.js +24 -0
  238. package/src/lib/views/ResetPasswordView.svelte +3 -3
  239. package/src/lib/views/RulesView.samples.js +14 -0
  240. package/src/lib/views/RulesView.svelte +3 -3
  241. package/src/lib/views/SettingsView.svelte +48 -17
  242. package/src/lib/views/Sidebar.samples.js +7 -0
  243. package/src/lib/views/SupportSidebar.samples.js +24 -0
  244. package/src/lib/views/SupportView.samples.js +16 -0
  245. package/src/lib/views/SupportView.svelte +8 -6
  246. package/src/lib/views/ThemeSettingsLayoutView.samples.js +9 -0
  247. package/src/lib/views/ThemeSettingsLayoutView.svelte +1 -1
  248. package/src/lib/views/ThemeSettingsView.svelte +89 -89
  249. package/src/lib/views/TicketCreateAndDetailSidebar.samples.js +33 -0
  250. package/src/lib/views/TicketDetailView.samples.js +34 -0
  251. package/src/lib/views/TicketDetailView.svelte +17 -15
  252. package/src/lib/views/TicketRow.samples.js +10 -0
  253. package/src/lib/views/TicketStatus.samples.js +8 -0
  254. package/src/lib/views/Tickets.samples.js +9 -0
  255. package/src/lib/views/TicketsLayoutView.samples.js +4 -0
  256. package/src/lib/views/TicketsView.samples.js +23 -0
  257. package/src/lib/views/TicketsView.svelte +11 -9
  258. package/src/lib/views/Toast.samples.js +9 -0
  259. package/src/lib/views/ToastContainer.samples.js +8 -0
  260. package/src/lib/views/parts/Breadcrumb.svelte +53 -0
  261. package/src/lib/views/parts/CloseTicketConfirmModal.svelte +63 -0
  262. package/src/lib/views/parts/ConfirmRemoveAllNotificationsModal.svelte +55 -0
  263. package/src/lib/views/parts/DefaultToast.svelte +22 -0
  264. package/src/lib/views/parts/HomeSidebar.svelte +334 -0
  265. package/src/lib/views/parts/LogoutSessionConfirmModal.svelte +46 -0
  266. package/src/lib/views/parts/Main.svelte +71 -0
  267. package/src/lib/views/parts/NotificationContainer.svelte +109 -0
  268. package/src/lib/views/parts/PlayerDetailSidebar.svelte +81 -0
  269. package/src/lib/views/parts/Post.svelte +255 -0
  270. package/src/lib/views/parts/Posts.svelte +25 -0
  271. package/src/lib/views/parts/ProfileSidebar.svelte +115 -0
  272. package/src/lib/views/parts/Sidebar.svelte +19 -0
  273. package/src/lib/views/parts/SupportSidebar.svelte +34 -0
  274. package/src/lib/views/parts/TicketCreateAndDetailSidebar.svelte +51 -0
  275. package/src/lib/views/parts/TicketRow.svelte +63 -0
  276. package/src/lib/views/parts/TicketStatus.svelte +24 -0
  277. package/src/lib/views/parts/Tickets.svelte +45 -0
  278. package/src/lib/views/parts/Toast.svelte +27 -0
  279. package/src/lib/views/parts/ToastContainer.svelte +17 -0
  280. package/src/lib/views/parts/engine-views.generated.js +63 -0
  281. package/src/lib/views/parts/publicHref.js +18 -0
  282. package/src/lib/views/parts/ticketStatuses.js +7 -0
  283. package/src/plugin-engine/__tests__/engine.test.js +161 -0
  284. package/src/plugin-engine/engine.js +80 -12
  285. package/src/registry/__tests__/registry.test.js +510 -0
  286. package/src/registry/__tests__/view.test.js +52 -0
  287. package/src/registry/index.js +700 -51
  288. package/src/registry/routes.js +62 -0
  289. package/src/registry/view.js +69 -0
  290. package/src/routes/RootLayout.svelte +24 -1
  291. package/src/routes/catalogue/List.svelte +163 -0
  292. package/src/routes/catalogue/Stage.svelte +355 -0
  293. package/src/routes/catalogue/__tests__/browserSafe.test.js +13 -0
  294. package/src/routes/catalogue/__tests__/catalogue.test.js +539 -0
  295. package/src/routes/catalogue/catalogue.js +129 -0
  296. package/src/routes/catalogue/deps.js +147 -0
  297. package/src/routes/catalogue/engineSamples.js +63 -0
  298. package/src/routes/catalogue/fixtures.js +77 -0
  299. package/src/routes/catalogue/list.js +37 -0
  300. package/src/routes/catalogue/model.js +286 -0
  301. package/src/routes/catalogue/stage.js +69 -0
  302. package/src/routes/catalogue/views-json.js +24 -0
  303. package/src/routes/plugin-ui/Layout.svelte +29 -4
  304. package/src/routes/plugin-ui/Page.svelte +86 -31
  305. package/src/routes/plugin-ui/load.js +173 -0
  306. package/src/routes/plugins-client-file.js +8 -3
  307. package/src/routes/plugins-ui-file.js +60 -0
  308. package/src/routes/root-layout-load.js +59 -2
@@ -0,0 +1,427 @@
1
+ import { describe, expect, mock, test } from "bun:test";
2
+ import { readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { writable } from "svelte/store";
5
+
6
+ import { findSvelte, renderSvelte } from "./svelteSsr.helper.js";
7
+
8
+
9
+ // The SvelteKit aliases and peer packages are not installed in this repo: stub exactly what
10
+ // Store.js and PluginAPI.js import, with SvelteKit's real `redirect` shape.
11
+ class Redirect {
12
+ constructor(status, location) {
13
+ this.status = status;
14
+ this.location = location;
15
+ }
16
+ }
17
+ mock.module("@sveltejs/kit", () => ({
18
+ redirect: (status, location) => new Redirect(status, location),
19
+ }));
20
+ mock.module("$app/paths", () => ({ base: "" }));
21
+ mock.module("$app/environment", () => ({ browser: false, dev: false }));
22
+ mock.module("$app/navigation", () => ({ goto: async () => {} }));
23
+ mock.module("$pano/lib/services/auth.js", () => ({ sendLogout: async () => {} }));
24
+ mock.module("$pano/lib/components/ToastContainer.svelte", () => ({ showSuccess: async () => {} }));
25
+ mock.module("$pano/lib/returnTo.util.js", () => import("../returnTo.util.js"));
26
+ mock.module("@panomc/sdk/core/js/PluginAPI", () =>
27
+ import("../../../../sdk/core/js/PluginAPI.js"),
28
+ );
29
+ // Superset of what the sdk tests mock for the same file (bun mocks are process-wide).
30
+ const pluginManagerStub = () => ({
31
+ plugins: writable([]),
32
+ registeredPages: {},
33
+ findMatch: () => null,
34
+ });
35
+ mock.module("@panomc/sdk/core/js/PluginManager.js", pluginManagerStub);
36
+ mock.module(new URL("../../../../sdk/core/js/PluginManager.js", import.meta.url).pathname, pluginManagerStub);
37
+ mock.module("$pano/plugin-engine/engine.js", () => ({
38
+ createHookEngine: () => ({ reset() {}, executeHookLoad() {}, register() {}, get() {}, setVisible() {} }),
39
+ createLifecycleRegistry: () => ({ reset() {}, executeLifecycle() {}, on() {} }),
40
+ createSlotRegistry: () => ({
41
+ reset() {},
42
+ executeSidebarLoad() {},
43
+ executeViewLoad() {},
44
+ edit() {},
45
+ upsert() {},
46
+ get() {},
47
+ }),
48
+ }));
49
+
50
+ const lib = join(import.meta.dir, "..");
51
+ const pkg = join(lib, "..", "..");
52
+ const sdkCore = join(pkg, "..", "sdk", "core", "js");
53
+ const read = (...parts) => readFileSync(join(...parts), "utf-8");
54
+ const svelteDir = findSvelte();
55
+
56
+ describe("pano.features (spec 15 section 4.1, theme ids)", () => {
57
+ test("lists exactly the theme ids", async () => {
58
+ const { panoApi, THEME_FEATURE_IDS } = await import("../PluginAPI.js");
59
+
60
+ const expected = [
61
+ "blocks",
62
+ "context-components",
63
+ "decoded-route-params",
64
+ "layout-route-params",
65
+ "login-return-url",
66
+ "named-views",
67
+ "page-meta",
68
+ "page-sidebar-id",
69
+ "page-title-options",
70
+ "plugin-notifications",
71
+ "plugin-slots",
72
+ "profile-nav",
73
+ "route-map",
74
+ "toast-escaped-values",
75
+ ];
76
+
77
+ expect(panoApi.features.list()).toEqual(expected);
78
+ expect(THEME_FEATURE_IDS.length).toBe(expected.length);
79
+ expect(Object.isFrozen(panoApi.features)).toBe(true);
80
+ });
81
+
82
+ test("ids that belong to the panel only are not announced by the theme", async () => {
83
+ const { panoApi } = await import("../PluginAPI.js");
84
+
85
+ for (const id of ["player-detail-menu", "panel-auth-util", "permission-any-of"]) {
86
+ expect(panoApi.features.has(id)).toBe(false);
87
+ }
88
+ });
89
+ });
90
+
91
+ describe("pano.ui additions", () => {
92
+ test("pano.ui.profile.nav has edit and get; pano.ui.notification.onClick exists", async () => {
93
+ const { panoApi } = await import("../PluginAPI.js");
94
+
95
+ expect(typeof panoApi.ui.profile.nav.edit).toBe("function");
96
+ expect(typeof panoApi.ui.profile.nav.get).toBe("function");
97
+ expect(typeof panoApi.ui.notification.onClick).toBe("function");
98
+ // existing profile slots are still there
99
+ expect(typeof panoApi.ui.profile.content.edit).toBe("function");
100
+ expect(typeof panoApi.ui.profile.cardRows.edit).toBe("function");
101
+ });
102
+
103
+ test("profile.nav.edit writes the profile-nav slot (source)", () => {
104
+ const source = read(lib, "PluginAPI.js");
105
+
106
+ expect(source).toMatch(/nav:\s*\{\s*edit\(callback\)\s*\{\s*slots\.edit\("profile-nav", callback\);/);
107
+ expect(source).toContain('panoApi.ui.view.get("profile-nav")');
108
+ });
109
+
110
+ test("notification.onClick registers a plugin listener that onNotificationClick runs after core ones", async () => {
111
+ const { panoApi, init } = await import("../PluginAPI.js");
112
+ const manager = await import(join(sdkCore, "NotificationManager.js"));
113
+ const seen = [];
114
+
115
+ panoApi.ui.notification.onClick("TC03_TYPE", (n) => seen.push(n.id));
116
+ manager.onNotificationClick({ id: 7, type: "TC03_TYPE" });
117
+ expect(seen).toEqual([7]);
118
+
119
+ // a listener suppresses the href fallback
120
+ const navigated = [];
121
+ manager.onNotificationClick({ id: 8, type: "TC03_TYPE", details: { href: "/x" } }, (p) => navigated.push(p));
122
+ expect(navigated).toEqual([]);
123
+ // without a listener the safe href navigates
124
+ manager.onNotificationClick({ id: 9, type: "TC03_OTHER", details: { href: "/orders/1" } }, (p) => navigated.push(p));
125
+ expect(navigated).toEqual(["/orders/1"]);
126
+
127
+ // the host init() resets the plugin listeners
128
+ await init();
129
+ manager.onNotificationClick({ id: 10, type: "TC03_TYPE" });
130
+ expect(seen).toEqual([7, 8]);
131
+ });
132
+ });
133
+
134
+ describe("source wiring", () => {
135
+ test("PluginAPI init resets plugin notification listeners", () => {
136
+ expect(read(lib, "PluginAPI.js")).toMatch(/lifecycle\.reset\(\);\s*resetPluginListeners\(\);/);
137
+ });
138
+
139
+ test("the plugin page load (load.js) resolves the string sidebar after the lifted keys, before returning; Page.svelte injects the sidebars", () => {
140
+ const source = read(pkg, "src", "routes", "plugin-ui", "load.js");
141
+
142
+ expect(source).toContain("resolveSidebarSpec");
143
+ expect(source.indexOf("for (const key of")).toBeLessThan(source.indexOf("await resolveSidebarSpec"));
144
+ expect(source.indexOf("await resolveSidebarSpec")).toBeLessThan(source.lastIndexOf("return output;"));
145
+
146
+ const page = read(pkg, "src", "routes", "plugin-ui", "Page.svelte");
147
+
148
+ expect(page).toContain("loadPluginPage(event, registeredPage, sidebarDeps)");
149
+ expect(page).toContain("HomeSidebar.svelte");
150
+ expect(page).toContain("ProfileSidebar.svelte");
151
+ expect(page).toContain("PluginSidebar.svelte");
152
+ expect(page).toContain("get(panoApi.ui.sidebar.get(sidebarId)).length");
153
+ });
154
+
155
+ test("ProfileSidebar registers the profile-nav item (priority 95), merges the built-ins and renders the card", () => {
156
+ const source = read(lib, "components", "sidebars", "ProfileSidebar.svelte");
157
+
158
+ expect(source).toMatch(/id: "profile-nav",\s*component: "local:profile-nav",\s*priority: 95/);
159
+ expect(source).toContain("panoApi.ui.profile.nav.edit");
160
+ expect(source).toContain("mergeProfileNav(navItems)");
161
+ expect(source).toContain("panoApi.ui.profile.nav.get()");
162
+ // the card itself is in the part (FX-05)
163
+ const part = read(lib, "views", "parts", "ProfileSidebar.svelte");
164
+ expect(part).toContain('item.id === "profile-nav"');
165
+ expect(part).toContain("<ProfileNavCard entries={navEntries} />");
166
+ });
167
+
168
+ test("AppLayoutLogics completes the context (T9)", () => {
169
+ const source = read(lib, "ui-logics", "layout-logics", "AppLayoutLogics.js");
170
+
171
+ expect(source).toMatch(/import \{ goto, invalidate, invalidateAll \} from "\$app\/navigation"/);
172
+ expect(source).toMatch(/goto,\s*invalidate,\s*invalidateAll,\s*error,\s*redirect,/);
173
+ for (const name of ["Toast", "Sidebar", "ViewComponent", "Hook"]) {
174
+ expect(source).toMatch(new RegExp(`import ${name} from "\\$pano/lib/components/${name}\\.svelte"`));
175
+ expect(source).toMatch(new RegExp(`PlayerHead: ResolvedPlayerHead,[\\s\\S]*\\b${name},[\\s\\S]*\\},\\s*utils:`));
176
+ }
177
+ });
178
+
179
+ test("NotificationsView renders through notificationTextKey with the UNKNOWN default and the href navigator", () => {
180
+ const source = read(lib, "views", "NotificationsView.svelte");
181
+
182
+ expect(source).toContain("notificationTextKey(notification)");
183
+ expect(source).toContain('default: $_("notifications.UNKNOWN")');
184
+ expect(source).toContain("onNotificationClick(notification, navigate)");
185
+ expect(source).toContain("goto(base + path)");
186
+ expect(source).not.toContain('"notifications." + notification.type');
187
+ });
188
+
189
+ test("NotificationContainer pop-up uses notificationTextKey, the UNKNOWN default and the href navigator", () => {
190
+ // the markup lives in the part, the navigator and the click handlers in the controller (TC-32)
191
+ const source = read(lib, "components", "NotificationContainer.svelte") + read(lib, "views", "parts", "NotificationContainer.svelte");
192
+
193
+ expect(source).toContain("notificationTextKey(notification)");
194
+ expect(source).toContain("notifications.UNKNOWN");
195
+ expect(source).toContain("goto(base + path)");
196
+ expect(source).not.toContain("'notifications.' + notification.type");
197
+ expect(source).not.toMatch(/onNotificationClick\(notification\)/);
198
+ expect(source.match(/onNotificationClick\(notification, navigate\)/g)?.length).toBe(2);
199
+ });
200
+
201
+ test("skin-contract lists the profile-nav slot", () => {
202
+ const contract = JSON.parse(read(pkg, "skin-contract.json"));
203
+
204
+ expect(contract.view_slots).toContain("profile-nav");
205
+ expect(contract.views.NotificationsView.props.onNotificationClick).toContain("navigate");
206
+ });
207
+
208
+ test("notifications.UNKNOWN exists in all three locales", () => {
209
+ for (const locale of ["en-US", "tr", "ru"]) {
210
+ const messages = JSON.parse(read(pkg, "lang", `${locale}.json`));
211
+ expect(typeof messages.notifications.UNKNOWN).toBe("string");
212
+ expect(messages.notifications.UNKNOWN.length).toBeGreaterThan(5);
213
+ }
214
+ });
215
+ });
216
+
217
+ describe.skipIf(!svelteDir)("server render", () => {
218
+ const sidebars = join(lib, "components", "sidebars");
219
+ const html = join(sdkCore, "html.util.js");
220
+
221
+ const i18nStub = `
222
+ import { readable } from "svelte/store";
223
+ export const _ = readable((text, options = {}) =>
224
+ String(text).replace(/\\{(\\w+)\\}/g, (m, k) => (options.values && k in options.values ? options.values[k] : m)));
225
+ `;
226
+
227
+ test("ProfileNavCard renders list-group links, the active one, icon and badge", async () => {
228
+ const { body } = await renderSvelte({
229
+ svelteDir,
230
+ components: { "#card": join(sidebars, "ProfileNavCard.svelte") },
231
+ props: {
232
+ entries: [
233
+ { id: "profile", href: "/profile", text: "Profile", icon: "fas fa-user", badge: null, active: false },
234
+ { id: "orders", href: "/profile/orders", text: "Orders", icon: null, badge: "3", active: true },
235
+ ],
236
+ },
237
+ });
238
+
239
+ expect(body).toContain('<div class="card"><div class="list-group list-group-flush">');
240
+ expect(body.match(/list-group-item list-group-item-action d-flex align-items-center/g).length).toBe(2);
241
+ expect(body).toMatch(/class="list-group-item list-group-item-action d-flex align-items-center active"[^>]*href="\/profile\/orders"/);
242
+ expect(body).toContain('aria-current="page"');
243
+ expect(body.match(/aria-current/g).length).toBe(1);
244
+ expect(body).toContain('<span class="badge text-bg-primary ms-auto">3</span>');
245
+ expect(body).toContain("fas fa-user");
246
+ });
247
+
248
+ test("ProfileNavCard escapes text coming from a plugin", async () => {
249
+ const { body } = await renderSvelte({
250
+ svelteDir,
251
+ components: { "#card": join(sidebars, "ProfileNavCard.svelte") },
252
+ props: {
253
+ entries: [{ id: "x", href: "/x", text: "<img src=x onerror=alert(1)>", icon: null, badge: null, active: false }],
254
+ },
255
+ });
256
+
257
+ expect(body).not.toContain("<img");
258
+ expect(body).toContain("&lt;img");
259
+ });
260
+
261
+ async function renderPluginSidebar(items, props = {}) {
262
+ return renderSvelte({
263
+ svelteDir,
264
+ components: {
265
+ "$pano/lib/components/sidebars/PluginSidebar.svelte": join(sidebars, "PluginSidebar.svelte"),
266
+ "$pano/lib/components/Sidebar.svelte": join(lib, "components", "Sidebar.svelte"),
267
+ "$pano/lib/views/parts/Sidebar.svelte": join(lib, "views", "parts", "Sidebar.svelte"),
268
+ "$pano/lib/components/ViewComponent.svelte": join(lib, "components", "ViewComponent.svelte"),
269
+ "$pano/lib/components/Probe.svelte": join(import.meta.dir, "fixtures", "Probe.svelte"),
270
+ },
271
+ modules: {
272
+ "$pano/registry/index.js": `export const getOverride = () => null;`,
273
+ "@panomc/sdk/internal": `export const getPanoContext = () => ({});`,
274
+ "$pano/lib/PluginAPI": `
275
+ import { readable } from "svelte/store";
276
+ import Probe from "$pano/lib/components/Probe.svelte";
277
+ const all = ${JSON.stringify(items)};
278
+ export const panoApi = { ui: { sidebar: { get: (id) => readable(all.filter((i) => i.sidebarId === id).map((i) => ({ ...i, component: { default: Probe } }))) } } };
279
+ `,
280
+ },
281
+ props,
282
+ });
283
+ }
284
+
285
+ test("PluginSidebar renders the slot items inside an aside in a vstack", async () => {
286
+ const { body } = await renderPluginSidebar(
287
+ [
288
+ { sidebarId: "fixture", id: "one", props: { label: "First" } },
289
+ { sidebarId: "fixture", id: "two", props: { label: "Second" } },
290
+ { sidebarId: "other", id: "three", props: { label: "Other slot" } },
291
+ ],
292
+ { sidebarId: "fixture", side: "left" },
293
+ );
294
+
295
+ expect(body).toContain('<aside class="pano-sidebar col-lg-4 order-first order-lg-first">');
296
+ expect(body).toContain('<div class="vstack gap-3">');
297
+ expect(body).toContain("First");
298
+ expect(body).toContain("Second");
299
+ expect(body).not.toContain("Other slot");
300
+ expect(body.indexOf("First")).toBeLessThan(body.indexOf("Second"));
301
+ });
302
+
303
+ test("PluginSidebar defaults to the right side", async () => {
304
+ const { body } = await renderPluginSidebar([{ sidebarId: "fixture", id: "one", props: { label: "First" } }], {
305
+ sidebarId: "fixture",
306
+ });
307
+
308
+ expect(body).toContain('class="pano-sidebar col-lg-4 order-first order-lg-last"');
309
+ });
310
+
311
+ test("DefaultToast escapes markup in values but keeps markup of the locale string", async () => {
312
+ const { body } = await renderSvelte({
313
+ svelteDir,
314
+ components: {
315
+ "#toast": join(lib, "components", "DefaultToast.svelte"),
316
+ "$pano/lib/components/Toast.svelte": join(lib, "components", "Toast.svelte"),
317
+ "$pano/lib/views/parts/DefaultToast.svelte": join(lib, "views", "parts", "DefaultToast.svelte"),
318
+ "$pano/lib/views/parts/Toast.svelte": join(lib, "views", "parts", "Toast.svelte"),
319
+ },
320
+ modules: {
321
+ "svelte-i18n": i18nStub,
322
+ "$pano/registry/index.js": "export const getOverride = () => null;",
323
+ "@panomc/sdk/core/js/html.util.js": `export * from ${JSON.stringify(html)};`,
324
+ },
325
+ props: { id: 1, text: "<b>Hello</b> {name}", values: { name: "<img src=x onerror=alert(1)>", n: 4 } },
326
+ });
327
+
328
+ expect(body).toContain("<b>Hello</b>");
329
+ expect(body).not.toContain("<img");
330
+ expect(body).toContain("&amp;lt;img src=x onerror=alert(1)&amp;gt;".replace(/&amp;/g, "&"));
331
+ expect(body).toContain("&lt;img src=x onerror=alert(1)&gt;");
332
+ });
333
+
334
+ test("DefaultToast without values renders", async () => {
335
+ const { body } = await renderSvelte({
336
+ svelteDir,
337
+ components: {
338
+ "#toast": join(lib, "components", "DefaultToast.svelte"),
339
+ "$pano/lib/components/Toast.svelte": join(lib, "components", "Toast.svelte"),
340
+ "$pano/lib/views/parts/DefaultToast.svelte": join(lib, "views", "parts", "DefaultToast.svelte"),
341
+ "$pano/lib/views/parts/Toast.svelte": join(lib, "views", "parts", "Toast.svelte"),
342
+ },
343
+ modules: {
344
+ "svelte-i18n": i18nStub,
345
+ "$pano/registry/index.js": "export const getOverride = () => null;",
346
+ "@panomc/sdk/core/js/html.util.js": `export * from ${JSON.stringify(html)};`,
347
+ },
348
+ props: { id: 2, text: "Plain", values: undefined, variant: "success" },
349
+ });
350
+
351
+ expect(body).toContain("Plain");
352
+ expect(body).toContain("text-success");
353
+ });
354
+ });
355
+
356
+ describe("TC-9 fixture plugin (test-fixtures, run in E2E-19)", () => {
357
+ const fixture = join(pkg, "..", "..", "test-fixtures", "tc9-fixture-plugin");
358
+ const readFixture = (...parts) => readFileSync(join(fixture, ...parts), "utf-8");
359
+
360
+ test("main.js is a short plugin that registers the seven check pages and both sidebars", () => {
361
+ const source = readFixture("src", "main.js");
362
+
363
+ expect(source.split("\n").length).toBeLessThanOrEqual(60);
364
+ for (const path of [
365
+ "/fixture/login-required",
366
+ "/fixture/hook",
367
+ "/fixture/meta",
368
+ "/profile/fixture",
369
+ "/fixture/sidebar-empty",
370
+ "/fixture/sidebar-one",
371
+ "/fixture/toast",
372
+ "/fixture/title",
373
+ ]) {
374
+ expect(source).toContain(`path: '${path}'`);
375
+ }
376
+ expect(source).toContain("loginRequired: true");
377
+ expect(source).toContain("systemLayout: 'ProfileLayout'");
378
+ expect(source).toContain("sidebarId: 'fixture', id: 'fixture-card'");
379
+ expect(source).toContain("startsWith: true");
380
+ });
381
+
382
+ test("Page.svelte returns the keys the host lifts for every check", () => {
383
+ const source = readFixture("src", "Page.svelte");
384
+
385
+ expect(source).toContain("sidebar: 'profile'");
386
+ expect(source).toContain("sidebar: 'plugin:fixture-empty'");
387
+ expect(source).toContain("sidebar: 'plugin:fixture'");
388
+ expect(source).toContain("pageTitle: { title: 'buttons.save', raw: true, hidden: true }");
389
+ expect(source).toContain("meta: {");
390
+ expect(source).toContain("<img src=x onerror=alert(1)>");
391
+ expect(source).toContain("context.components?.Hook");
392
+ });
393
+
394
+ test("README lists all seven checks and the ten theme feature ids", () => {
395
+ const readme = readFixture("README.md");
396
+
397
+ for (let i = 1; i <= 7; i++) expect(readme).toContain(`| ${i} |`);
398
+ for (const id of [
399
+ "context-components",
400
+ "decoded-route-params",
401
+ "layout-route-params",
402
+ "login-return-url",
403
+ "page-meta",
404
+ "page-sidebar-id",
405
+ "page-title-options",
406
+ "plugin-notifications",
407
+ "profile-nav",
408
+ "toast-escaped-values",
409
+ ]) {
410
+ expect(readme).toContain("`" + id + "`");
411
+ }
412
+ });
413
+
414
+ test("the locale file carries the toast key with a {value} placeholder", () => {
415
+ expect(JSON.parse(readFixture("src", "locales", "en-US.json")).toast).toContain("{value}");
416
+ });
417
+
418
+ test.skipIf(!svelteDir)("both fixture components compile with the svelte compiler", async () => {
419
+ const compiler = await import(join(svelteDir, "src", "compiler", "index.js"));
420
+
421
+ for (const file of ["Page.svelte", "SidebarItem.svelte"]) {
422
+ for (const generate of ["client", "server"]) {
423
+ expect(() => compiler.compile(readFixture("src", file), { generate, filename: file })).not.toThrow();
424
+ }
425
+ }
426
+ });
427
+ });
@@ -0,0 +1,184 @@
1
+ import { beforeEach, describe, expect, mock, test } from "bun:test";
2
+ import { mkdirSync, mkdtempSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+
6
+ // TC-11: every engine call site resolves its view through loadView. The page and
7
+ // layout controllers are .svelte files, which bun cannot import here, so their
8
+ // `<script context="module">` is extracted, its imports are replaced by stubs and
9
+ // its view thunks by markers, and `load` is run against the real registry.
10
+
11
+ mock.module("$app/environment", () => ({ dev: false, browser: false }));
12
+ const registry = await import("../../registry/index.js");
13
+ mock.module("$pano/registry/index.js", () => registry);
14
+ // root-layout-load.js registers the generated engine table at import; the tests register their own.
15
+ mock.module("$pano/lib/views/parts/engine-views.generated.js", () => ({ engineViews: {} }));
16
+
17
+ const libDir = join(import.meta.dir, "..");
18
+
19
+ function walk(dir) {
20
+ return readdirSync(dir).flatMap((entry) => {
21
+ const full = join(dir, entry);
22
+ return statSync(full).isDirectory() ? walk(full) : [full];
23
+ });
24
+ }
25
+
26
+ function moduleScript(file) {
27
+ const m = readFileSync(file, "utf8").match(/<script context="module">([\s\S]*?)<\/script>/);
28
+ return m ? m[1] : "";
29
+ }
30
+
31
+ const pageFiles = walk(join(libDir, "pages")).filter((f) => f.endsWith(".svelte"));
32
+ const layoutFiles = ["AppLayout", "AuthLayout", "ProfileLayout", "ThemeSettingsLayout", "TicketsLayout", "MainLayout"].map(
33
+ (n) => join(libDir, "layouts", `${n}.svelte`),
34
+ );
35
+
36
+ describe("call sites", () => {
37
+ test("no controller awaits a bare viewPromise", () => {
38
+ for (const file of [...pageFiles, ...layoutFiles]) {
39
+ expect(moduleScript(file)).not.toContain("await viewPromise");
40
+ }
41
+ });
42
+
43
+ test("every controller except the error page calls loadView", () => {
44
+ for (const file of [...pageFiles, ...layoutFiles].filter((f) => !f.endsWith("ErrorPage.svelte"))) {
45
+ expect(moduleScript(file)).toContain("loadView(");
46
+ expect(moduleScript(file)).not.toContain("resolveView(");
47
+ }
48
+ });
49
+ });
50
+
51
+ /** Stubs for everything a controller imports except the registry. */
52
+ function build(file) {
53
+ let src = moduleScript(file);
54
+ const names = [];
55
+ src = src.replace(/import\s+([\s\S]*?)\s+from\s+["']([^"']+)["'];?/g, (all, what, from) => {
56
+ if (from === "$pano/registry/index.js") return 'import { loadView, resolveView } from "$pano/registry/index.js";';
57
+ for (const part of what.replace(/[{}]/g, ",").split(",")) {
58
+ const name = part.trim().split(/\s+as\s+/).pop();
59
+ if (name) names.push(name);
60
+ }
61
+ return "";
62
+ });
63
+ // the default view thunks become markers
64
+ src = src.replace(/import\(\s*["']([^"']*\/([A-Za-z]+)\.svelte)["']\s*\)/g, (_, _p, base) =>
65
+ `Promise.resolve({ default: "<${base}>" })`,
66
+ );
67
+ const stubs = [...new Set(names)]
68
+ .filter((n) => n !== "loadView" && n !== "resolveView")
69
+ .map((n) => `const ${n} = globalThis.__tc11Stub("${n}");`)
70
+ .join("\n");
71
+ return `${stubs}\n${src}`;
72
+ }
73
+
74
+ const stubFor = (name) => {
75
+ const fn = async () => ({});
76
+ if (name === "processLoad" || name.startsWith("process")) return fn;
77
+ if (name === "error") return (status) => new Error(`error ${status}`);
78
+ if (name === "writable") return (v) => ({ set() {}, subscribe() {}, v });
79
+ if (name === "ApiUtil") return { get: async () => ({ registerAgreement: "x" }) };
80
+ if (name === "panoApiServer") {
81
+ const handler = { get: () => new Proxy(function () {}, handler), apply: () => undefined };
82
+ return new Proxy(function () {}, handler);
83
+ }
84
+ return fn;
85
+ };
86
+ globalThis.__tc11Stub = stubFor;
87
+
88
+ const event = () => ({
89
+ parent: async () => ({
90
+ session: { siteInfo: { hasRegisterAgreement: true }, csrfToken: "t" },
91
+ themeSettings: {},
92
+ }),
93
+ url: new URL("http://localhost/"),
94
+ params: {},
95
+ });
96
+
97
+ const tmpRoot = mkdtempSync(join(tmpdir(), "tc11-"));
98
+
99
+ async function loadFor(file) {
100
+ const out = join(tmpRoot, file.split("/").slice(-2).join("_").replace(".svelte", ".mjs"));
101
+ writeFileSync(out, build(file));
102
+ const mod = await import(out + "?v=" + Math.random());
103
+ return mod.load(event());
104
+ }
105
+
106
+ beforeEach(() => {
107
+ registry.resetRegistryForTests();
108
+ registry.setThemeConfig({});
109
+ });
110
+
111
+ const expectedKey = (file) => {
112
+ const alias = readFileSync(file, "utf8").match(/(\w*[Ll]ayoutView): View/);
113
+ return alias ? alias[1] : "View";
114
+ };
115
+
116
+ describe("controllers return their view through loadView", () => {
117
+ for (const file of [...pageFiles, ...layoutFiles].filter((f) => !f.endsWith("ErrorPage.svelte"))) {
118
+ const label = file.slice(libDir.length + 1);
119
+ test(label, async () => {
120
+ const data = await loadFor(file);
121
+ const key = expectedKey(file);
122
+ expect(typeof data[key]).toBe("string");
123
+ expect(data[key]).toMatch(/^<[A-Za-z]+View>$/);
124
+ });
125
+ }
126
+
127
+ test("a theme override replaces the markup and a block's data is merged", async () => {
128
+ registry.registerEngineViews({
129
+ HomeView: { contract: 1, component: async () => ({ default: "<HomeView>" }), uses: ["market:NavCart"] },
130
+ });
131
+ registry.registerViews([
132
+ {
133
+ name: "market:NavCart",
134
+ pluginId: "pano-plugin-market",
135
+ contract: 1,
136
+ kind: "component",
137
+ block: true,
138
+ component: async () => ({ default: "<NavCart>", load: async () => ({ items: 3 }) }),
139
+ },
140
+ ]);
141
+ registry.setThemeConfig({ views: { HomeView: async () => "<ThemeHome>" } });
142
+ registry.setThemeMeta({ refs: { HomeView: [{ id: "market:NavCart", props: {} }] }, claims: [], homePages: {} });
143
+ const data = await loadFor(join(libDir, "pages/HomePage.svelte"));
144
+ expect(data.View).toBe("<ThemeHome>");
145
+ expect(data["block:market:NavCart#{}"]).toEqual({ items: 3 });
146
+ });
147
+ });
148
+
149
+ describe("loadChrome", () => {
150
+ test("no override: nothing is loaded and nothing is returned", async () => {
151
+ mock.module("$pano/lib/layouts/AppLayout.svelte", () => ({ load: async () => ({ app: 1 }) }));
152
+ mock.module("$pano/lib/layouts/MainLayout.svelte", () => ({ load: async () => ({ main: 1 }) }));
153
+ const { loadChrome, load } = await import("../../routes/root-layout-load.js");
154
+ expect(await loadChrome(event())).toEqual({});
155
+ expect(await load(event())).toEqual({ app: 1, main: 1 });
156
+ });
157
+
158
+ test("an overridden chrome part is preloaded and its block data is returned without a View key", async () => {
159
+ registry.registerEngineViews({
160
+ Sidebar: { contract: 1, component: async () => ({ default: "<Sidebar>" }) },
161
+ });
162
+ registry.registerViews([
163
+ {
164
+ name: "market:SideCart",
165
+ pluginId: "pano-plugin-market",
166
+ contract: 1,
167
+ kind: "component",
168
+ block: true,
169
+ component: async () => ({ default: "<SideCart>", load: async () => ({ items: 2 }) }),
170
+ },
171
+ ]);
172
+ registry.setThemeConfig({ views: { Sidebar: async () => ({ default: "<ThemeSidebar>" }) } });
173
+ registry.setThemeMeta({
174
+ refs: { Sidebar: [{ id: "market:SideCart", props: {} }] },
175
+ claims: [],
176
+ homePages: {},
177
+ });
178
+ const { loadChrome } = await import("../../routes/root-layout-load.js");
179
+ const out = await loadChrome(event());
180
+ expect(out.View).toBeUndefined();
181
+ expect(out["block:market:SideCart#{}"]).toEqual({ items: 2 });
182
+ expect(registry.getOverride("Sidebar")).toBe("<ThemeSidebar>");
183
+ });
184
+ });