@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,332 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { writePins } from "../../check.js";
|
|
3
|
+
import { at, check, makeTheme, read } from "./helpers.js";
|
|
4
|
+
|
|
5
|
+
const NAVBAR = `Navbar: () => import("./src/views/Navbar.svelte")`;
|
|
6
|
+
const config = (entries = NAVBAR, rest = "") => `export default { ${rest} views: { ${entries} } };\n`;
|
|
7
|
+
const withNavbar = (markup, extra = {}, cfg = config()) =>
|
|
8
|
+
makeTheme({ snapshot: true, config: cfg, files: { "src/views/Navbar.svelte": markup, ...extra } });
|
|
9
|
+
|
|
10
|
+
describe("C7 block and pluginView placements", () => {
|
|
11
|
+
test("a literal id missing from the snapshot is an error ending with the pull command", async () => {
|
|
12
|
+
const msg = at(await check(withNavbar('<PluginBlock id="market:Nope" />')), "error", "C7");
|
|
13
|
+
expect(msg).toHaveLength(1);
|
|
14
|
+
expect(msg[0]).toEndWith("run: theme-core contracts pull");
|
|
15
|
+
expect(msg[0]).toContain("src/views/Navbar.svelte:1");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("pluginView() with an unknown id is an error; an engine name is checked against the contract", async () => {
|
|
19
|
+
const dir = withNavbar(
|
|
20
|
+
'<script>\n import { pluginView } from "$pano/registry/view.js";\n const A = pluginView("market:Gone");\n const B = pluginView("Pagination");\n const C = pluginView("Nothing");\n</script>',
|
|
21
|
+
);
|
|
22
|
+
expect(at(await check(dir), "error", "C7")).toHaveLength(2);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("a dynamic id is a warning: its data loads in the browser", async () => {
|
|
26
|
+
const report = await check(withNavbar("<script>let id = 'market:NavCart';</script><PluginBlock {id} /><PluginBlock id={id} />"));
|
|
27
|
+
expect(at(report, "error", "C7")).toEqual([]);
|
|
28
|
+
const msg = at(report, "warning", "C7");
|
|
29
|
+
expect(msg).toHaveLength(2);
|
|
30
|
+
expect(msg[0]).toContain("its data loads in the browser, not on the server");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("a non-literal prop is a warning", async () => {
|
|
34
|
+
const report = await check(withNavbar('<script>let n = 3;</script><PluginBlock id="market:ProductGrid" limit={n} category="vip" {...rest} />'));
|
|
35
|
+
const msg = at(report, "warning", "C7");
|
|
36
|
+
expect(msg).toHaveLength(1);
|
|
37
|
+
expect(msg[0]).toContain("limit");
|
|
38
|
+
expect(msg[0]).toContain("{...spread}");
|
|
39
|
+
expect(at(report, "error", "C7")).toEqual([]);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("no snapshot for the namespace is a warning", async () => {
|
|
43
|
+
const dir = makeTheme({ config: config(), files: { "src/views/Navbar.svelte": '<PluginBlock id="market:ProductGrid" />' } });
|
|
44
|
+
const report = await check(dir);
|
|
45
|
+
expect(at(report, "error", "C7")).toEqual([]);
|
|
46
|
+
expect(at(report, "warning", "C7")).toHaveLength(1);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("control: literal ids and literal props, also in a nested theme file", async () => {
|
|
50
|
+
const dir = withNavbar(
|
|
51
|
+
'<script>import Cart from "./Cart.svelte";</script><PluginBlock id="market:ProductGrid" limit={8} category="vip" /><Cart />',
|
|
52
|
+
{ "src/views/Cart.svelte": '<PluginBlock id="pano-plugin-market:NavCart" />' },
|
|
53
|
+
);
|
|
54
|
+
const report = await check(dir);
|
|
55
|
+
expect(at(report, "error", "C7")).toEqual([]);
|
|
56
|
+
expect(at(report, "warning", "C7")).toEqual([]);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe("C8 claims", () => {
|
|
61
|
+
test("a claimed injection is reported as info and never fails", async () => {
|
|
62
|
+
const report = await check(withNavbar('<PluginBlock id="market:NavCart" />'));
|
|
63
|
+
expect(at(report, "info", "C8")).toEqual(["theme claims 'market:NavCart': its automatic copy in 'navbar-right' is suppressed"]);
|
|
64
|
+
expect(at(report, "error")).toEqual([]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("an explicit claims entry counts, claims: false removes it", async () => {
|
|
68
|
+
const claimed = await check(withNavbar("<div></div>", {}, config(NAVBAR, `claims: { "market:NavCart": true },`)));
|
|
69
|
+
expect(at(claimed, "info", "C8")).toHaveLength(1);
|
|
70
|
+
const kept = await check(withNavbar('<PluginBlock id="market:NavCart" />', {}, config(NAVBAR, `claims: { "market:NavCart": false },`)));
|
|
71
|
+
expect(at(kept, "info", "C8")).toEqual([]);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe("C9 routes", () => {
|
|
76
|
+
const routes = (r) => makeTheme({ snapshot: true, config: `export default { routes: ${r} };\n`, files: { "src/pages/A.svelte": "<div></div>" } });
|
|
77
|
+
|
|
78
|
+
test("an invalid pattern is an error", async () => {
|
|
79
|
+
expect(at(await check(routes(`{ disable: ["no-slash"] }`)), "error", "C9")).toHaveLength(1);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("a rename with different params is an error naming the entry", async () => {
|
|
83
|
+
const msg = at(await check(routes(`{ rename: { "/store/[slug]": "/shop/[id]" } }`)), "error", "C9");
|
|
84
|
+
expect(msg).toHaveLength(1);
|
|
85
|
+
expect(msg[0]).toContain("/store/[slug]");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("two renames to the same public path are an error", async () => {
|
|
89
|
+
expect(at(await check(routes(`{ rename: { "/a": "/x", "/b": "/x" } }`)), "error", "C9")).toHaveLength(1);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("nothing may target /posts or /__pano*", async () => {
|
|
93
|
+
const msg = at(await check(routes(`{ rename: { "/store": "/posts", "/rules": "/__pano-x" } }`)), "error", "C9");
|
|
94
|
+
expect(msg).toHaveLength(2);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("add: path must be free, valid and have an existing file", async () => {
|
|
98
|
+
const dir = routes(
|
|
99
|
+
`{ add: { "/login": "./src/pages/A.svelte", "/posts": "./src/pages/A.svelte", "/__pano/x": "./src/pages/A.svelte", "/store": "./src/pages/A.svelte", "/staff": "./src/pages/Missing.svelte", "/ok": "./src/pages/A.svelte" } }`,
|
|
100
|
+
);
|
|
101
|
+
const msg = at(await check(dir), "error", "C9");
|
|
102
|
+
expect(msg).toHaveLength(5);
|
|
103
|
+
expect(msg.some((m) => m.includes('"/login"'))).toBe(true);
|
|
104
|
+
expect(msg.some((m) => m.includes('"/store"'))).toBe(true);
|
|
105
|
+
expect(msg.some((m) => m.includes("Missing.svelte"))).toBe(true);
|
|
106
|
+
expect(msg.some((m) => m.includes('"/ok"'))).toBe(false);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("add: a path renamed away is free again", async () => {
|
|
110
|
+
const dir = routes(`{ rename: { "/store": "/shop" }, add: { "/store": "./src/pages/A.svelte" } }`);
|
|
111
|
+
expect(at(await check(dir), "error", "C9")).toEqual([]);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("control: a clean route config passes", async () => {
|
|
115
|
+
const dir = routes(`{ rename: { "/store": "/shop" }, disable: ["/rules"], add: { "/staff-team": "./src/pages/A.svelte" } }`);
|
|
116
|
+
expect(at(await check(dir), "error", "C9")).toEqual([]);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe("C10 home", () => {
|
|
121
|
+
const home = (h) => makeTheme({ config: `export default { home: ${h} };\n`, files: { "src/pages/Landing.svelte": "<div></div>" } });
|
|
122
|
+
|
|
123
|
+
test("default must be an option", async () => {
|
|
124
|
+
const msg = at(await check(home(`{ default: "gone", options: { posts: { label: "Posts" } } }`)), "error", "C10");
|
|
125
|
+
expect(msg).toHaveLength(1);
|
|
126
|
+
expect(msg[0]).toContain("gone");
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("option ids are [a-z0-9-]+, page files exist, paths start with / or are *", async () => {
|
|
130
|
+
const dir = home(
|
|
131
|
+
`{ default: "posts", options: { posts: { label: "P" }, "Bad_Id": { label: "x" }, landing: { label: "L", page: "./src/pages/Nope.svelte" }, store: { label: "S", path: "store" }, custom: { label: "C", path: "*" } } }`,
|
|
132
|
+
);
|
|
133
|
+
const msg = at(await check(dir), "error", "C10");
|
|
134
|
+
expect(msg).toHaveLength(3);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test("control: thunk page, string page, canonical path, custom", async () => {
|
|
138
|
+
const dir = home(
|
|
139
|
+
`{ default: "landing", options: { posts: { label: "P" }, landing: { label: { "en-US": "L" }, page: () => import("./src/pages/Landing.svelte") }, alt: { label: "A", page: "./src/pages/Landing.svelte" }, store: { label: "S", path: "/store" }, custom: { label: "C", path: "*" } } }`,
|
|
140
|
+
);
|
|
141
|
+
expect(at(await check(dir), "error", "C10")).toEqual([]);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe("C12 controller pins", () => {
|
|
146
|
+
const useCart = '<script>\n import { plugin } from "@panomc/sdk/controllers";\n const cart = plugin("market").use("cart");\n</script>{#if cart}x{/if}';
|
|
147
|
+
const cartEntry = `"market:ProductCard": { contract: 2, controllers: ["market/cart", "market/format"], component: () => import("./src/views/ProductCard.svelte") }`;
|
|
148
|
+
const card = '<script>let { product } = $props();</script><div class="market-product-card"></div>';
|
|
149
|
+
|
|
150
|
+
test("a missing pin is a warning ending with --fix; --fix writes it and the warning is gone", async () => {
|
|
151
|
+
const dir = makeTheme({ snapshot: true, config: config(cartEntry), files: { "src/views/ProductCard.svelte": card } });
|
|
152
|
+
const before = await check(dir);
|
|
153
|
+
const msg = at(before, "warning", "C12");
|
|
154
|
+
expect(msg).toHaveLength(2);
|
|
155
|
+
for (const m of msg) expect(m).toEndWith("run: theme-core check --fix");
|
|
156
|
+
|
|
157
|
+
const fixed = await check(dir, { fix: true });
|
|
158
|
+
expect(at(fixed, "warning", "C12")).toEqual([]);
|
|
159
|
+
expect(fixed.fixed).toHaveLength(2);
|
|
160
|
+
const text = read(dir, "theme.config.js");
|
|
161
|
+
expect(text).toContain('"market/cart": 2');
|
|
162
|
+
expect(text).toContain('"market/format": 1');
|
|
163
|
+
|
|
164
|
+
const after = await check(dir);
|
|
165
|
+
expect(at(after, "warning", "C12")).toEqual([]);
|
|
166
|
+
expect(at(after, "error")).toEqual([]);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("a literal plugin('ns').use('name') in a theme page needs a pin too", async () => {
|
|
170
|
+
const dir = makeTheme({ snapshot: true, config: config(""), files: { "src/pages/Header.svelte": useCart } });
|
|
171
|
+
const msg = at(await check(dir), "warning", "C12");
|
|
172
|
+
expect(msg).toHaveLength(1);
|
|
173
|
+
expect(msg[0]).toContain("market/cart");
|
|
174
|
+
expect(msg[0]).toContain("src/pages/Header.svelte:3");
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("a pin that differs from the snapshot is a warning; --fix re-pins and keeps other pins", async () => {
|
|
178
|
+
const dir = makeTheme({
|
|
179
|
+
snapshot: true,
|
|
180
|
+
config: `export default {\n controllers: { "market/cart": 1, "other/thing": 7 },\n views: {},\n};\n`,
|
|
181
|
+
files: { "src/pages/Header.svelte": useCart },
|
|
182
|
+
});
|
|
183
|
+
const msg = at(await check(dir), "warning", "C12");
|
|
184
|
+
expect(msg).toHaveLength(1);
|
|
185
|
+
expect(msg[0]).toContain("pinned to 1");
|
|
186
|
+
await check(dir, { fix: true });
|
|
187
|
+
const text = read(dir, "theme.config.js");
|
|
188
|
+
expect(text).toContain('"market/cart": 2');
|
|
189
|
+
expect(text).toContain('"other/thing": 7');
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test("an unknown controller name is a warning (and --fix does not invent a pin)", async () => {
|
|
193
|
+
const dir = makeTheme({ snapshot: true, config: config(""), files: { "src/pages/H.svelte": useCart.replace('"cart"', '"carts"') } });
|
|
194
|
+
const msg = at(await check(dir, { fix: true }), "warning", "C12");
|
|
195
|
+
expect(msg).toHaveLength(1);
|
|
196
|
+
expect(read(dir, "theme.config.js")).not.toContain("controllers");
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test("control: matching pins pass", async () => {
|
|
200
|
+
const dir = makeTheme({
|
|
201
|
+
snapshot: true,
|
|
202
|
+
config: `export default { controllers: { "market/cart": 2 }, views: {} };\n`,
|
|
203
|
+
files: { "src/pages/Header.svelte": useCart },
|
|
204
|
+
});
|
|
205
|
+
expect(at(await check(dir), "warning", "C12")).toEqual([]);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test("writePins: appends with a comma, replaces in place, inserts when absent, null when unlocatable", () => {
|
|
209
|
+
const pins = new Map([["market/cart", 2]]);
|
|
210
|
+
expect(writePins(`export default { controllers: { "a/b": 1 } };`, pins)).toContain(`"a/b": 1,\n`);
|
|
211
|
+
expect(writePins(`export default { controllers: { 'market/cart': 1 } };`, pins)).toContain(`'market/cart': 2`);
|
|
212
|
+
expect(writePins(`export default {};`, pins)).toContain('controllers: {\n "market/cart": 2,');
|
|
213
|
+
expect(writePins(`const c = {}; export default c;`, pins)).toBeNull();
|
|
214
|
+
// a commented-out block is not the block
|
|
215
|
+
expect(writePins(`// controllers: { "x/y": 1 }\nexport default {};`, pins)).toContain('"market/cart": 2');
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
describe("C13 styles and provides.bootstrap", () => {
|
|
220
|
+
const styled = (scss, cfg = "export default { views: {} };\n") => makeTheme({ config: cfg, files: { "src/styles/style.scss": scss } });
|
|
221
|
+
const BOOTSTRAP = '@import "node_modules/bootstrap/scss/bootstrap";\n';
|
|
222
|
+
const SDK_MAIN = '@import "node_modules/@panomc/sdk/core/scss/main";\n';
|
|
223
|
+
|
|
224
|
+
test("Bootstrap imported directly without pano-tokens is an error naming the line to add", async () => {
|
|
225
|
+
const msg = at(await check(styled(BOOTSTRAP)), "error", "C13");
|
|
226
|
+
expect(msg).toHaveLength(1);
|
|
227
|
+
expect(msg[0]).toContain("src/styles/style.scss:1");
|
|
228
|
+
expect(msg[0]).toEndWith('@import "node_modules/@panomc/sdk/core/scss/pano-tokens";');
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test("a direct import plus pano-tokens, or the SDK main file, passes", async () => {
|
|
232
|
+
const tokens = '@import "node_modules/@panomc/sdk/core/scss/pano-tokens";\n';
|
|
233
|
+
expect(at(await check(styled(BOOTSTRAP + tokens)), "error", "C13")).toEqual([]);
|
|
234
|
+
const report = await check(styled(SDK_MAIN));
|
|
235
|
+
expect(at(report, "error", "C13")).toEqual([]);
|
|
236
|
+
expect(at(report, "warning", "C13")).toEqual([]);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test("provides.bootstrap false with a Bootstrap import is an error", async () => {
|
|
240
|
+
const cfg = "export default { provides: { bootstrap: false }, views: {} };\n";
|
|
241
|
+
expect(at(await check(styled(BOOTSTRAP, cfg)), "error", "C13")).toHaveLength(1);
|
|
242
|
+
expect(at(await check(styled(SDK_MAIN, cfg)), "error", "C13")).toHaveLength(1);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
test("provides.bootstrap false without an import passes and prints the browser floor once", async () => {
|
|
246
|
+
const report = await check(styled(".a { color: red; }\n", "export default { provides: { bootstrap: false }, views: {} };\n"));
|
|
247
|
+
expect(at(report, "error", "C13")).toEqual([]);
|
|
248
|
+
expect(at(report, "info", "C13")).toHaveLength(1);
|
|
249
|
+
expect(at(report, "info", "C13")[0]).toContain("Chrome 118");
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
test("no Bootstrap import while provides.bootstrap is not false is a warning naming the line to add", async () => {
|
|
253
|
+
const msg = at(await check(styled(".a { color: red; }\n")), "warning", "C13");
|
|
254
|
+
expect(msg).toHaveLength(1);
|
|
255
|
+
expect(msg[0]).toContain('@import "node_modules/@panomc/sdk/core/scss/main"');
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test("never reads static/style.css", async () => {
|
|
259
|
+
const dir = makeTheme({
|
|
260
|
+
config: "export default { provides: { bootstrap: false }, views: {} };\n",
|
|
261
|
+
files: { "static/style.css": '/* @import "bootstrap/scss/bootstrap" */ .a{}', "src/styles/style.scss": ".a { color: red; }\n" },
|
|
262
|
+
});
|
|
263
|
+
expect(at(await check(dir), "error", "C13")).toEqual([]);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
test("a theme without src/styles is not warned", async () => {
|
|
267
|
+
expect(at(await check(makeTheme()), "warning", "C13")).toEqual([]);
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
describe("C15 plugin lang overrides", () => {
|
|
272
|
+
const lang = (files) => makeTheme({ files });
|
|
273
|
+
|
|
274
|
+
test("invalid JSON, a non-object top and a bad folder name are errors", async () => {
|
|
275
|
+
const dir = lang({
|
|
276
|
+
"lang-overrides/plugins/market/tr.json": "{ nope",
|
|
277
|
+
"lang-overrides/plugins/market/en-US.json": "[]",
|
|
278
|
+
"lang-overrides/plugins/Market_X/tr.json": "{}",
|
|
279
|
+
"lang-overrides/plugins/stray.json": "{}",
|
|
280
|
+
});
|
|
281
|
+
expect(at(await check(dir), "error", "C15")).toHaveLength(4);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
test("control: valid files, the plugin id as folder alias", async () => {
|
|
285
|
+
const dir = lang({
|
|
286
|
+
"lang-overrides/plugins/market/tr.json": '{ "theme": { "store": { "title": "Dukkan" } } }',
|
|
287
|
+
"lang-overrides/plugins/pano-plugin-pages/tr.json": "{}",
|
|
288
|
+
});
|
|
289
|
+
expect(at(await check(dir), "error", "C15")).toEqual([]);
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
describe("C16 API paths are Pano routes", () => {
|
|
294
|
+
const api = (text) => makeTheme({ files: { "src/pages/api.js": `import ApiUtil from "@panomc/sdk/utils/api";\n${text}\n` } });
|
|
295
|
+
|
|
296
|
+
test("an unknown path is an error with the nearest route", async () => {
|
|
297
|
+
const msg = at(await check(api('ApiUtil.get({ path: "/postz" });')), "error", "C16");
|
|
298
|
+
expect(msg).toHaveLength(1);
|
|
299
|
+
expect(msg[0]).toContain("src/pages/api.js:2");
|
|
300
|
+
expect(msg[0]).toContain("did you mean '/posts'?");
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test("a path starting with /api is an error", async () => {
|
|
304
|
+
expect(at(await check(api('ApiUtil.get({ path: "/api/posts" });')), "error", "C16")).toHaveLength(1);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
test("control: known paths and template holes pass", async () => {
|
|
308
|
+
const report = await check(api('ApiUtil.get({ path: "/posts" });\nApiUtil.get({ path: `/posts/${url}` });'));
|
|
309
|
+
expect(at(report, "error", "C16")).toEqual([]);
|
|
310
|
+
expect(at(report, "warning", "C16")).toEqual([]);
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
describe("--strict", () => {
|
|
315
|
+
test("warnings become errors", async () => {
|
|
316
|
+
const dir = makeTheme({ snapshot: true, config: config(`"market:Nope": () => import("./src/views/N.svelte")`), files: { "src/views/N.svelte": "<div></div>" } });
|
|
317
|
+
const lax = await check(makeTheme({ config: config(`"other:X": () => import("./src/views/N.svelte")`), files: { "src/views/N.svelte": "<div></div>" } }));
|
|
318
|
+
expect(lax.warnings).toHaveLength(1);
|
|
319
|
+
expect(lax.problems).toEqual([]);
|
|
320
|
+
const strict = await check(makeTheme({ config: config(`"other:X": () => import("./src/views/N.svelte")`), files: { "src/views/N.svelte": "<div></div>" } }), { strict: true });
|
|
321
|
+
expect(strict.warnings).toEqual([]);
|
|
322
|
+
expect(strict.problems).toHaveLength(1);
|
|
323
|
+
expect(dir).toBeTruthy();
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
test("info stays info", async () => {
|
|
327
|
+
const dir = withNavbar('<PluginBlock id="market:NavCart" />');
|
|
328
|
+
const strict = await check(dir, { strict: true });
|
|
329
|
+
expect(strict.infos).toHaveLength(1);
|
|
330
|
+
expect(strict.problems).toEqual([]);
|
|
331
|
+
});
|
|
332
|
+
});
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { cleanupAfterAll, cli, exists, importConfig, makeTheme, read, themeWithMarket, write } from "./helpers.js";
|
|
3
|
+
|
|
4
|
+
cleanupAfterAll();
|
|
5
|
+
|
|
6
|
+
const OUTDATED_CONFIG = `export default {
|
|
7
|
+
views: {
|
|
8
|
+
"market:ProductCard": {
|
|
9
|
+
contract: 1,
|
|
10
|
+
controllers: ["market/cart"],
|
|
11
|
+
component: () => import("./src/views/market/ProductCard.svelte"),
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
controllers: { "market/cart": 1, "market/format": 1 },
|
|
15
|
+
};
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
/** A theme whose ProductCard override was made for contract 1 while the plugin is on contract 2, cart 3. */
|
|
19
|
+
function outdatedTheme() {
|
|
20
|
+
const { theme } = themeWithMarket({ config: OUTDATED_CONFIG, packageOptions: { productCardContract: 2, cartVersion: 3 } });
|
|
21
|
+
write(theme, "src/views/market/ProductCard.svelte", "<div>mine</div>\n");
|
|
22
|
+
write(theme, "src/views/market/ProductCard.svelte.new", "<div>plugin</div>\n");
|
|
23
|
+
return theme;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe("accept", () => {
|
|
27
|
+
test("sets contract to the snapshot's, re-pins the override's controllers and deletes .new", async () => {
|
|
28
|
+
const theme = outdatedTheme();
|
|
29
|
+
const run = cli(theme, ["accept", "market:ProductCard"]);
|
|
30
|
+
expect(run.code).toBe(0);
|
|
31
|
+
expect(run.out).toContain("market:ProductCard now targets contract 2");
|
|
32
|
+
expect(run.out).toContain("market/cart");
|
|
33
|
+
|
|
34
|
+
const config = await importConfig(theme);
|
|
35
|
+
expect(config.views["market:ProductCard"].contract).toBe(2);
|
|
36
|
+
// only the controllers the override names are re-pinned
|
|
37
|
+
expect(config.controllers).toEqual({ "market/cart": 3, "market/format": 1 });
|
|
38
|
+
expect(config.views["market:ProductCard"].controllers).toEqual(["market/cart"]);
|
|
39
|
+
expect(exists(theme, "src/views/market/ProductCard.svelte.new")).toBe(false);
|
|
40
|
+
expect(read(theme, "src/views/market/ProductCard.svelte")).toBe("<div>mine</div>\n");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("works from a snapshot alone (the plugin is not installed)", async () => {
|
|
44
|
+
const theme = outdatedTheme();
|
|
45
|
+
cli(theme, ["contracts", "pull"]);
|
|
46
|
+
cli(theme, ["accept", "market:ProductCard"]);
|
|
47
|
+
// reset and remove plugins/
|
|
48
|
+
write(theme, "theme.config.js", OUTDATED_CONFIG);
|
|
49
|
+
const { rmSync } = await import("node:fs");
|
|
50
|
+
rmSync(`${theme}/plugins`, { recursive: true });
|
|
51
|
+
|
|
52
|
+
const run = cli(theme, ["accept", "market:ProductCard"]);
|
|
53
|
+
expect(run.code).toBe(0);
|
|
54
|
+
expect((await importConfig(theme)).views["market:ProductCard"].contract).toBe(2);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("a bare thunk entry becomes the object form", async () => {
|
|
58
|
+
const config = `export default {
|
|
59
|
+
views: {
|
|
60
|
+
"market:PriceTag": () => import("./src/views/market/PriceTag.svelte"),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
`;
|
|
64
|
+
const { theme } = themeWithMarket({ config });
|
|
65
|
+
write(theme, "src/views/market/PriceTag.svelte", "<span></span>\n");
|
|
66
|
+
expect(cli(theme, ["accept", "market:PriceTag"]).code).toBe(0);
|
|
67
|
+
const loaded = await importConfig(theme);
|
|
68
|
+
expect(loaded.views["market:PriceTag"].contract).toBe(1);
|
|
69
|
+
expect(typeof loaded.views["market:PriceTag"].component).toBe("function");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("an entry without contract gets one", async () => {
|
|
73
|
+
const config = `export default {
|
|
74
|
+
views: {
|
|
75
|
+
"market:ProductCard": { component: () => import("./src/views/market/ProductCard.svelte") },
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
`;
|
|
79
|
+
const { theme } = themeWithMarket({ config, packageOptions: { productCardContract: 4 } });
|
|
80
|
+
expect(cli(theme, ["accept", "market:ProductCard"]).code).toBe(0);
|
|
81
|
+
expect((await importConfig(theme)).views["market:ProductCard"].contract).toBe(4);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("an engine view takes the engine contract", async () => {
|
|
85
|
+
const config = `export default {\n views: {\n LoginView: { contract: 0, component: () => import("./src/views/LoginView.svelte") },\n },\n};\n`;
|
|
86
|
+
const theme = makeTheme({ config });
|
|
87
|
+
write(theme, "src/views/LoginView.svelte.new", "x");
|
|
88
|
+
expect(cli(theme, ["accept", "LoginView"]).code).toBe(0);
|
|
89
|
+
expect((await importConfig(theme)).views.LoginView.contract).toBe(1);
|
|
90
|
+
expect(exists(theme, "src/views/LoginView.svelte.new")).toBe(false);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("a view that is not overridden is an error", () => {
|
|
94
|
+
const { theme } = themeWithMarket();
|
|
95
|
+
const run = cli(theme, ["accept", "market:ProductCard"]);
|
|
96
|
+
expect(run.code).toBe(1);
|
|
97
|
+
expect(run.out).toContain("not overridden");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("a view the plugin removed, an unknown plugin and a missing argument are errors", () => {
|
|
101
|
+
const theme = outdatedTheme();
|
|
102
|
+
expect(cli(theme, ["accept", "market:Gone"]).out).toContain("not in the snapshot");
|
|
103
|
+
expect(cli(theme, ["accept", "shop:Thing"]).out).toContain("no snapshot for 'shop'");
|
|
104
|
+
expect(cli(theme, ["accept"]).out).toContain("usage");
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe("list-views", () => {
|
|
109
|
+
test("marks overridden and outdated views, engine and plugin", async () => {
|
|
110
|
+
const config = `export default {
|
|
111
|
+
views: {
|
|
112
|
+
LoginView: () => import("./src/views/LoginView.svelte"),
|
|
113
|
+
"market:ProductCard": { contract: 1, component: () => import("./src/views/market/ProductCard.svelte") },
|
|
114
|
+
"market:PriceTag": { contract: 1, component: () => import("./src/views/market/PriceTag.svelte") },
|
|
115
|
+
"market:Ghost": { contract: 1, component: () => import("./src/views/market/Ghost.svelte") },
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
`;
|
|
119
|
+
const { theme } = themeWithMarket({ config, packageOptions: { productCardContract: 2 } });
|
|
120
|
+
const run = cli(theme, ["list-views", "--json"]);
|
|
121
|
+
expect(run.code).toBe(0);
|
|
122
|
+
const result = JSON.parse(run.stdout);
|
|
123
|
+
|
|
124
|
+
const login = result.engine.find((v) => v.id === "LoginView");
|
|
125
|
+
expect(login).toMatchObject({ contract: 1, overridden: true, outdated: false });
|
|
126
|
+
expect(result.engine.find((v) => v.id === "RulesView").overridden).toBe(false);
|
|
127
|
+
|
|
128
|
+
const byId = Object.fromEntries(result.plugins.map((v) => [v.id, v]));
|
|
129
|
+
expect(byId["market:ProductCard"]).toMatchObject({ contract: 2, overridden: true, outdated: true, overrideContract: 1, kind: "component" });
|
|
130
|
+
expect(byId["market:PriceTag"]).toMatchObject({ contract: 1, overridden: true, outdated: false });
|
|
131
|
+
expect(byId["market:StorePage"]).toMatchObject({ overridden: false, kind: "page", page: "/store", pluginId: "pano-plugin-market" });
|
|
132
|
+
expect(result.unknown).toEqual(["market:Ghost"]);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("pulls a missing snapshot first and prints the plain list", () => {
|
|
136
|
+
const { theme } = themeWithMarket();
|
|
137
|
+
expect(exists(theme, "plugin-contracts/market/views.json")).toBe(false);
|
|
138
|
+
const run = cli(theme, ["list-views"]);
|
|
139
|
+
expect(run.code).toBe(0);
|
|
140
|
+
expect(exists(theme, "plugin-contracts/market/views.json")).toBe(true);
|
|
141
|
+
expect(run.stdout).toContain("Engine views");
|
|
142
|
+
expect(run.stdout).toContain("Plugin views");
|
|
143
|
+
expect(run.stdout).toContain("market:ProductCard contract 1");
|
|
144
|
+
expect(run.stdout).toContain("market:StorePage contract 1 page /store");
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("text output carries the overridden marks", () => {
|
|
148
|
+
const { theme } = themeWithMarket({ config: OUTDATED_CONFIG, packageOptions: { productCardContract: 2 } });
|
|
149
|
+
const run = cli(theme, ["list-views"]);
|
|
150
|
+
expect(run.stdout).toContain("market:ProductCard contract 2 component overridden (contract 1, outdated)");
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("a theme without plugins still lists the engine views", () => {
|
|
154
|
+
const run = cli(makeTheme(), ["list-views"]);
|
|
155
|
+
expect(run.code).toBe(0);
|
|
156
|
+
expect(run.stdout).toContain("LoginView contract 1");
|
|
157
|
+
expect(run.stdout).toContain("install a plugin");
|
|
158
|
+
});
|
|
159
|
+
});
|