@eldrajs/theme-cli 0.0.0-stage → 0.1.0
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/CHANGELOG.md +69 -0
- package/LICENSE +21 -0
- package/README.md +27 -2
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +203 -0
- package/dist/index.d.ts +174 -0
- package/dist/index.js +3 -0
- package/dist/validate-C6jB8_Oc.js +510 -0
- package/package.json +56 -3
- package/template/.eldra/block-types.d.ts +429 -0
- package/template/.eldra/manifest.json +9377 -0
- package/template/.eldra/previews.json +36 -0
- package/template/.github/workflows/eldra-deploy.yml +24 -0
- package/template/.gitlab-ci.yml +16 -0
- package/template/.storybook/eldra.ts +123 -0
- package/template/.storybook/i18n.ts +23 -0
- package/template/.storybook/main.ts +59 -0
- package/template/.storybook/nuxt-link-stub.ts +23 -0
- package/template/.storybook/preview.ts +52 -0
- package/template/.storybook/shims-vue.d.ts +10 -0
- package/template/.storybook/virtual-eldra.d.ts +27 -0
- package/template/README.md +288 -0
- package/template/app/app.vue +126 -0
- package/template/app/assets/main.css +404 -0
- package/template/app/components/EldraIcon.vue +66 -0
- package/template/app/components/EldraRouterLink.vue +62 -0
- package/template/app/components/ui/UiImage.stories.ts +30 -0
- package/template/app/components/ui/UiImage.vue +224 -0
- package/template/app/components/ui/__tests__/UiImage.spec.ts +292 -0
- package/template/app/composables/iconComponent.ts +84 -0
- package/template/app/composables/iconFetcher.ts +14 -0
- package/template/app/composables/useBlockData.ts +30 -0
- package/template/app/composables/useEditing.ts +31 -0
- package/template/app/composables/useEldraIcon.ts +46 -0
- package/template/app/composables/useRevalidating.ts +69 -0
- package/template/app/composables/useRichTextScrollRegions.ts +80 -0
- package/template/app/composables/useStorefront.ts +18 -0
- package/template/app/composables/useStorefrontFeedback.ts +49 -0
- package/template/app/composables/useUiId.ts +18 -0
- package/template/app/composables/useWishlist.ts +42 -0
- package/template/app/i18n.d.ts +28 -0
- package/template/app/icons.ts +185 -0
- package/template/app/pages/[...slug].vue +134 -0
- package/template/app/plugins/eldra-i18n.ts +98 -0
- package/template/app/plugins/eldra-storefront.ts +288 -0
- package/template/app/plugins/eldra-ui-messages.ts +112 -0
- package/template/app/storefront/cart.ts +245 -0
- package/template/app/storefront/categories.ts +283 -0
- package/template/app/storefront/collectionSelector.ts +60 -0
- package/template/app/storefront/commerce.ts +58 -0
- package/template/app/storefront/demo.ts +1313 -0
- package/template/app/storefront/facets.ts +476 -0
- package/template/app/storefront/feedback.ts +122 -0
- package/template/app/storefront/gateway.ts +2256 -0
- package/template/app/storefront/history.ts +233 -0
- package/template/app/storefront/money.ts +247 -0
- package/template/app/storefront/options.ts +71 -0
- package/template/app/storefront/prerender.ts +77 -0
- package/template/app/storefront/refresh.ts +222 -0
- package/template/app/storefront/toProductCard.ts +154 -0
- package/template/app/storefront/types.ts +815 -0
- package/template/app/storefront/volatile.ts +211 -0
- package/template/app/templates.ts +544 -0
- package/template/app/utils/classes.ts +40 -0
- package/template/app/utils/links.ts +70 -0
- package/template/app/utils/pageStructure.ts +77 -0
- package/template/app/utils/pageTitle.ts +37 -0
- package/template/app/virtual-eldra.d.ts +12 -0
- package/template/bitbucket-pipelines.yml +19 -0
- package/template/blocks/announcement-bar/Block.vue +203 -0
- package/template/blocks/announcement-bar/__tests__/Block.spec.ts +227 -0
- package/template/blocks/announcement-bar/block.json +45 -0
- package/template/blocks/announcement-bar/mock.json +7 -0
- package/template/blocks/announcement-bar/preview.png +0 -0
- package/template/blocks/article/Block.vue +317 -0
- package/template/blocks/article/__tests__/Block.spec.ts +229 -0
- package/template/blocks/article/block.json +148 -0
- package/template/blocks/article/mock.json +512 -0
- package/template/blocks/article/preview.json +16 -0
- package/template/blocks/article/preview.png +0 -0
- package/template/blocks/article-list/Block.vue +343 -0
- package/template/blocks/article-list/__tests__/Block.spec.ts +279 -0
- package/template/blocks/article-list/block.json +181 -0
- package/template/blocks/article-list/mock.json +68 -0
- package/template/blocks/article-list/preview.json +84 -0
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/Block.vue +278 -0
- package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +461 -0
- package/template/blocks/breadcrumbs/block.json +89 -0
- package/template/blocks/breadcrumbs/mock.json +11 -0
- package/template/blocks/breadcrumbs/preview.json +3 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/Block.vue +372 -0
- package/template/blocks/cart/__tests__/Block.spec.ts +561 -0
- package/template/blocks/cart/__tests__/ShippingBar.spec.ts +78 -0
- package/template/blocks/cart/__tests__/Summary.spec.ts +245 -0
- package/template/blocks/cart/block.json +74 -0
- package/template/blocks/cart/mock.json +11 -0
- package/template/blocks/cart/parts/CartLines.vue +257 -0
- package/template/blocks/cart/parts/ShippingBar.vue +105 -0
- package/template/blocks/cart/parts/Summary.vue +291 -0
- package/template/blocks/cart/preview.png +0 -0
- package/template/blocks/collection-grid/Block.vue +1832 -0
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +3037 -0
- package/template/blocks/collection-grid/__tests__/groups.spec.ts +731 -0
- package/template/blocks/collection-grid/block.json +187 -0
- package/template/blocks/collection-grid/mock.json +23 -0
- package/template/blocks/collection-grid/parts/groups.ts +861 -0
- package/template/blocks/collection-grid/preview.json +7 -0
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/Block.vue +533 -0
- package/template/blocks/collection-header/__tests__/Block.spec.ts +381 -0
- package/template/blocks/collection-header/block.json +140 -0
- package/template/blocks/collection-header/mock.json +28 -0
- package/template/blocks/collection-header/preview.json +14 -0
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/contact/Block.vue +621 -0
- package/template/blocks/contact/__tests__/Block.spec.ts +347 -0
- package/template/blocks/contact/block.json +174 -0
- package/template/blocks/contact/mock.json +28 -0
- package/template/blocks/contact/preview.json +9 -0
- package/template/blocks/contact/preview.png +0 -0
- package/template/blocks/cta/Block.vue +383 -0
- package/template/blocks/cta/__tests__/Block.spec.ts +309 -0
- package/template/blocks/cta/block.json +86 -0
- package/template/blocks/cta/mock.json +10 -0
- package/template/blocks/cta/preview.json +9 -0
- package/template/blocks/cta/preview.png +0 -0
- package/template/blocks/faq/Block.vue +254 -0
- package/template/blocks/faq/__tests__/Block.spec.ts +312 -0
- package/template/blocks/faq/block.json +113 -0
- package/template/blocks/faq/mock.json +115 -0
- package/template/blocks/faq/preview.png +0 -0
- package/template/blocks/feature-grid/Block.vue +241 -0
- package/template/blocks/feature-grid/__tests__/Block.spec.ts +311 -0
- package/template/blocks/feature-grid/block.json +106 -0
- package/template/blocks/feature-grid/mock.json +29 -0
- package/template/blocks/feature-grid/preview.json +45 -0
- package/template/blocks/feature-grid/preview.png +0 -0
- package/template/blocks/footer/Block.vue +652 -0
- package/template/blocks/footer/__tests__/Block.spec.ts +700 -0
- package/template/blocks/footer/block.json +240 -0
- package/template/blocks/footer/mock.json +161 -0
- package/template/blocks/footer/preview.png +0 -0
- package/template/blocks/gallery/Block.vue +416 -0
- package/template/blocks/gallery/__tests__/Block.spec.ts +289 -0
- package/template/blocks/gallery/block.json +87 -0
- package/template/blocks/gallery/mock.json +16 -0
- package/template/blocks/gallery/preview.json +64 -0
- package/template/blocks/gallery/preview.png +0 -0
- package/template/blocks/hero/Block.vue +378 -0
- package/template/blocks/hero/__tests__/Block.spec.ts +324 -0
- package/template/blocks/hero/block.json +146 -0
- package/template/blocks/hero/mock.json +11 -0
- package/template/blocks/hero/preview.json +55 -0
- package/template/blocks/hero/preview.png +0 -0
- package/template/blocks/image/Block.vue +232 -0
- package/template/blocks/image/__tests__/Block.spec.ts +224 -0
- package/template/blocks/image/block.json +67 -0
- package/template/blocks/image/mock.json +7 -0
- package/template/blocks/image/preview.json +9 -0
- package/template/blocks/image/preview.png +0 -0
- package/template/blocks/logo-cloud/Block.vue +206 -0
- package/template/blocks/logo-cloud/__tests__/Block.spec.ts +210 -0
- package/template/blocks/logo-cloud/block.json +79 -0
- package/template/blocks/logo-cloud/mock.json +15 -0
- package/template/blocks/logo-cloud/preview.json +92 -0
- package/template/blocks/logo-cloud/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +1348 -0
- package/template/blocks/navigation/__tests__/Block.spec.ts +2030 -0
- package/template/blocks/navigation/block.json +167 -0
- package/template/blocks/navigation/mock.json +191 -0
- package/template/blocks/navigation/preview.png +0 -0
- package/template/blocks/navigation/useMegaMenuKeys.ts +276 -0
- package/template/blocks/newsletter/Block.vue +399 -0
- package/template/blocks/newsletter/__tests__/Block.spec.ts +365 -0
- package/template/blocks/newsletter/block.json +105 -0
- package/template/blocks/newsletter/mock.json +31 -0
- package/template/blocks/newsletter/preview.png +0 -0
- package/template/blocks/order-status/Block.vue +754 -0
- package/template/blocks/order-status/__tests__/Block.spec.ts +515 -0
- package/template/blocks/order-status/block.json +138 -0
- package/template/blocks/order-status/mock.json +19 -0
- package/template/blocks/order-status/preview.png +0 -0
- package/template/blocks/pricing-table/Block.vue +297 -0
- package/template/blocks/pricing-table/__tests__/Block.spec.ts +357 -0
- package/template/blocks/pricing-table/block.json +155 -0
- package/template/blocks/pricing-table/mock.json +47 -0
- package/template/blocks/pricing-table/preview.png +0 -0
- package/template/blocks/product-carousel/Block.vue +459 -0
- package/template/blocks/product-carousel/__tests__/Block.spec.ts +957 -0
- package/template/blocks/product-carousel/block.json +71 -0
- package/template/blocks/product-carousel/mock.json +9 -0
- package/template/blocks/product-carousel/preview.json +7 -0
- package/template/blocks/product-carousel/preview.png +0 -0
- package/template/blocks/product-detail/Block.vue +886 -0
- package/template/blocks/product-detail/__tests__/Block.spec.ts +1495 -0
- package/template/blocks/product-detail/__tests__/stock.spec.ts +119 -0
- package/template/blocks/product-detail/block.json +155 -0
- package/template/blocks/product-detail/mock.json +113 -0
- package/template/blocks/product-detail/parts/Gallery.vue +181 -0
- package/template/blocks/product-detail/parts/StickyBuyBar.vue +99 -0
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/product-detail/stock.ts +150 -0
- package/template/blocks/quote/Block.vue +206 -0
- package/template/blocks/quote/__tests__/Block.spec.ts +265 -0
- package/template/blocks/quote/block.json +76 -0
- package/template/blocks/quote/mock.json +9 -0
- package/template/blocks/quote/preview.json +16 -0
- package/template/blocks/quote/preview.png +0 -0
- package/template/blocks/rich-text/Block.vue +143 -0
- package/template/blocks/rich-text/__tests__/Block.spec.ts +191 -0
- package/template/blocks/rich-text/block.json +57 -0
- package/template/blocks/rich-text/mock.json +87 -0
- package/template/blocks/rich-text/preview.png +0 -0
- package/template/blocks/search/Block.vue +589 -0
- package/template/blocks/search/PopularChips.vue +40 -0
- package/template/blocks/search/TypeSection.vue +148 -0
- package/template/blocks/search/__tests__/Block.spec.ts +718 -0
- package/template/blocks/search/__tests__/results.spec.ts +166 -0
- package/template/blocks/search/block.json +102 -0
- package/template/blocks/search/mock.json +18 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/search/results.ts +85 -0
- package/template/blocks/split-content/Block.vue +195 -0
- package/template/blocks/split-content/__tests__/Block.spec.ts +225 -0
- package/template/blocks/split-content/block.json +70 -0
- package/template/blocks/split-content/mock.json +45 -0
- package/template/blocks/split-content/preview.json +58 -0
- package/template/blocks/split-content/preview.png +0 -0
- package/template/blocks/stats/Block.vue +159 -0
- package/template/blocks/stats/__tests__/Block.spec.ts +194 -0
- package/template/blocks/stats/block.json +73 -0
- package/template/blocks/stats/mock.json +12 -0
- package/template/blocks/stats/preview.png +0 -0
- package/template/blocks/tabs/Block.vue +278 -0
- package/template/blocks/tabs/__tests__/Block.spec.ts +303 -0
- package/template/blocks/tabs/block.json +97 -0
- package/template/blocks/tabs/mock.json +129 -0
- package/template/blocks/tabs/preview.json +153 -0
- package/template/blocks/tabs/preview.png +0 -0
- package/template/blocks/team/Block.vue +288 -0
- package/template/blocks/team/__tests__/Block.spec.ts +221 -0
- package/template/blocks/team/block.json +125 -0
- package/template/blocks/team/mock.json +39 -0
- package/template/blocks/team/preview.json +62 -0
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/testimonials/Block.vue +408 -0
- package/template/blocks/testimonials/__tests__/Block.spec.ts +319 -0
- package/template/blocks/testimonials/block.json +121 -0
- package/template/blocks/testimonials/mock.json +46 -0
- package/template/blocks/testimonials/preview.json +68 -0
- package/template/blocks/testimonials/preview.png +0 -0
- package/template/blocks/timeline/Block.vue +274 -0
- package/template/blocks/timeline/__tests__/Block.spec.ts +310 -0
- package/template/blocks/timeline/block.json +98 -0
- package/template/blocks/timeline/mock.json +27 -0
- package/template/blocks/timeline/preview.png +0 -0
- package/template/blocks/trust-strip/Block.vue +330 -0
- package/template/blocks/trust-strip/__tests__/Block.spec.ts +290 -0
- package/template/blocks/trust-strip/block.json +117 -0
- package/template/blocks/trust-strip/mock.json +37 -0
- package/template/blocks/trust-strip/preview.png +0 -0
- package/template/blocks/video-embed/Block.vue +354 -0
- package/template/blocks/video-embed/__tests__/Block.spec.ts +219 -0
- package/template/blocks/video-embed/__tests__/embed.spec.ts +76 -0
- package/template/blocks/video-embed/block.json +94 -0
- package/template/blocks/video-embed/embed.ts +84 -0
- package/template/blocks/video-embed/mock.json +13 -0
- package/template/blocks/video-embed/preview.json +9 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/blocks/wishlist/Block.vue +367 -0
- package/template/blocks/wishlist/__tests__/Block.spec.ts +508 -0
- package/template/blocks/wishlist/block.json +42 -0
- package/template/blocks/wishlist/mock.json +9 -0
- package/template/blocks/wishlist/preview.png +0 -0
- package/template/i18n/en-US.json +602 -0
- package/template/i18n/is-IS.json +602 -0
- package/template/nuxt.config.ts +148 -0
- package/template/package.json +55 -0
- package/template/pages/article.page.json +731 -0
- package/template/pages/cart.page.json +85 -0
- package/template/pages/category.page.json +133 -0
- package/template/pages/collection.page.json +194 -0
- package/template/pages/home.page.json +353 -0
- package/template/pages/product.page.json +323 -0
- package/template/pages/products.page.json +144 -0
- package/template/pages/search.page.json +83 -0
- package/template/pages/wishlist.page.json +88 -0
- package/template/public/demo/article-cover.svg +1 -0
- package/template/public/demo/article-figure.svg +1 -0
- package/template/public/demo/avatar-1.svg +3 -0
- package/template/public/demo/avatar-2.svg +3 -0
- package/template/public/demo/avatar-3.svg +3 -0
- package/template/public/demo/avatar-4.svg +3 -0
- package/template/public/demo/avatar-5.svg +3 -0
- package/template/public/demo/avatar-6.svg +3 -0
- package/template/public/demo/avatar-7.svg +3 -0
- package/template/public/demo/avatar-8.svg +3 -0
- package/template/public/demo/collection-1.svg +1 -0
- package/template/public/demo/collection-2.svg +1 -0
- package/template/public/demo/cta-split.svg +1 -0
- package/template/public/demo/feature-1.svg +1 -0
- package/template/public/demo/feature-2.svg +1 -0
- package/template/public/demo/feature-3.svg +1 -0
- package/template/public/demo/feature-4.svg +1 -0
- package/template/public/demo/gallery-1.svg +1 -0
- package/template/public/demo/gallery-2.svg +1 -0
- package/template/public/demo/gallery-3.svg +1 -0
- package/template/public/demo/gallery-4.svg +1 -0
- package/template/public/demo/gallery-5.svg +1 -0
- package/template/public/demo/gallery-6.svg +1 -0
- package/template/public/demo/gallery-7.svg +1 -0
- package/template/public/demo/gallery-8.svg +1 -0
- package/template/public/demo/hero-slide-1.svg +1 -0
- package/template/public/demo/hero-slide-2.svg +1 -0
- package/template/public/demo/hero-slide-3.svg +1 -0
- package/template/public/demo/hero-slide-4.svg +1 -0
- package/template/public/demo/hero-wide.svg +1 -0
- package/template/public/demo/hero.svg +1 -0
- package/template/public/demo/logo-1.svg +4 -0
- package/template/public/demo/logo-2.svg +4 -0
- package/template/public/demo/logo-3.svg +4 -0
- package/template/public/demo/logo-4.svg +4 -0
- package/template/public/demo/logo-5.svg +4 -0
- package/template/public/demo/logo-6.svg +4 -0
- package/template/public/demo/logo-7.svg +4 -0
- package/template/public/demo/logo-8.svg +4 -0
- package/template/public/demo/logo.svg +3 -0
- package/template/public/demo/map.svg +1 -0
- package/template/public/demo/poster.svg +1 -0
- package/template/public/demo/product-1.svg +4 -0
- package/template/public/demo/product-10.svg +4 -0
- package/template/public/demo/product-11.svg +4 -0
- package/template/public/demo/product-12.svg +4 -0
- package/template/public/demo/product-2.svg +4 -0
- package/template/public/demo/product-3.svg +4 -0
- package/template/public/demo/product-4.svg +4 -0
- package/template/public/demo/product-5.svg +4 -0
- package/template/public/demo/product-6.svg +4 -0
- package/template/public/demo/product-7.svg +4 -0
- package/template/public/demo/product-8.svg +4 -0
- package/template/public/demo/product-9.svg +4 -0
- package/template/public/demo/product-square-1.svg +4 -0
- package/template/public/demo/product-square-2.svg +4 -0
- package/template/public/demo/product-square-3.svg +4 -0
- package/template/public/demo/product-square-4.svg +4 -0
- package/template/public/demo/product-square-5.svg +4 -0
- package/template/public/demo/product-square-6.svg +4 -0
- package/template/public/demo/quote-portrait.svg +4 -0
- package/template/public/demo/split-1.svg +1 -0
- package/template/public/demo/split-2.svg +1 -0
- package/template/public/demo/split-3.svg +1 -0
- package/template/public/demo/split-4.svg +1 -0
- package/template/public/demo/team-1.svg +4 -0
- package/template/public/demo/team-2.svg +4 -0
- package/template/public/demo/team-3.svg +4 -0
- package/template/public/demo/team-4.svg +4 -0
- package/template/scripts/demo-images.mjs +393 -0
- package/template/scripts/generate-stories.mjs +156 -0
- package/template/scripts/previewHash.mjs +125 -0
- package/template/scripts/previews.mjs +149 -0
- package/template/stories/generated/announcement-bar.stories.ts +44 -0
- package/template/stories/generated/article-list.stories.ts +87 -0
- package/template/stories/generated/article.stories.ts +27 -0
- package/template/stories/generated/breadcrumbs.stories.ts +39 -0
- package/template/stories/generated/cart.stories.ts +38 -0
- package/template/stories/generated/collection-grid.stories.ts +117 -0
- package/template/stories/generated/collection-header.stories.ts +51 -0
- package/template/stories/generated/contact.stories.ts +45 -0
- package/template/stories/generated/cta.stories.ts +51 -0
- package/template/stories/generated/faq.stories.ts +56 -0
- package/template/stories/generated/feature-grid.stories.ts +69 -0
- package/template/stories/generated/footer.stories.ts +50 -0
- package/template/stories/generated/gallery.stories.ts +81 -0
- package/template/stories/generated/hero.stories.ts +75 -0
- package/template/stories/generated/image.stories.ts +99 -0
- package/template/stories/generated/logo-cloud.stories.ts +57 -0
- package/template/stories/generated/navigation.stories.ts +62 -0
- package/template/stories/generated/newsletter.stories.ts +68 -0
- package/template/stories/generated/order-status.stories.ts +32 -0
- package/template/stories/generated/pricing-table.stories.ts +44 -0
- package/template/stories/generated/product-carousel.stories.ts +75 -0
- package/template/stories/generated/product-detail.stories.ts +62 -0
- package/template/stories/generated/quote.stories.ts +69 -0
- package/template/stories/generated/rich-text.stories.ts +50 -0
- package/template/stories/generated/search.stories.ts +56 -0
- package/template/stories/generated/split-content.stories.ts +39 -0
- package/template/stories/generated/stats.stories.ts +68 -0
- package/template/stories/generated/tabs.stories.ts +45 -0
- package/template/stories/generated/team.stories.ts +45 -0
- package/template/stories/generated/testimonials.stories.ts +69 -0
- package/template/stories/generated/timeline.stories.ts +80 -0
- package/template/stories/generated/trust-strip.stories.ts +62 -0
- package/template/stories/generated/video-embed.stories.ts +63 -0
- package/template/stories/generated/wishlist.stories.ts +26 -0
- package/template/stories/pages/article.stories.ts +51 -0
- package/template/stories/pages/cart.stories.ts +56 -0
- package/template/stories/pages/category.stories.ts +56 -0
- package/template/stories/pages/collection.stories.ts +51 -0
- package/template/stories/pages/home.stories.ts +51 -0
- package/template/stories/pages/product.stories.ts +47 -0
- package/template/stories/pages/products.stories.ts +58 -0
- package/template/stories/pages/search.stories.ts +54 -0
- package/template/stories/pages/wishlist.stories.ts +53 -0
- package/template/stories/support/pageBlocks.ts +115 -0
- package/template/test/blocksEmptyData.spec.ts +52 -0
- package/template/test/carouselKeyboard.spec.ts +272 -0
- package/template/test/carouselRing.browser.spec.ts +193 -0
- package/template/test/carouselSlideWidth.browser.spec.ts +102 -0
- package/template/test/cartDrawer.spec.ts +295 -0
- package/template/test/cartToast.spec.ts +86 -0
- package/template/test/countPill.browser.spec.ts +196 -0
- package/template/test/demoImages.spec.ts +140 -0
- package/template/test/deps.spec.ts +102 -0
- package/template/test/eldraIcon.spec.ts +58 -0
- package/template/test/framing.spec.ts +76 -0
- package/template/test/i18n.spec.ts +200 -0
- package/template/test/iconComponent.spec.ts +91 -0
- package/template/test/inlineEditable.spec.ts +334 -0
- package/template/test/localePrefix.spec.ts +342 -0
- package/template/test/mainCss.spec.ts +107 -0
- package/template/test/mockGatewayContract.spec.ts +122 -0
- package/template/test/mocks/blocks.ts +20 -0
- package/template/test/mocks/breakpoints.ts +7 -0
- package/template/test/mocks/manifest.ts +11 -0
- package/template/test/moneyFormatting.spec.ts +89 -0
- package/template/test/pageTitle.spec.ts +49 -0
- package/template/test/pages/article.spec.ts +231 -0
- package/template/test/pages/category.spec.ts +185 -0
- package/template/test/pages/collection.spec.ts +396 -0
- package/template/test/pages/home.spec.ts +295 -0
- package/template/test/pages/hydration.spec.ts +557 -0
- package/template/test/pages/product.spec.ts +396 -0
- package/template/test/pages/seededPages.spec.ts +190 -0
- package/template/test/pages/ssr.spec.ts +393 -0
- package/template/test/prerenderCommerce.spec.ts +134 -0
- package/template/test/prerenderFailure.spec.ts +130 -0
- package/template/test/prerenderRefresh.browser.spec.ts +1431 -0
- package/template/test/previewsFresh.spec.ts +56 -0
- package/template/test/richText.spec.ts +161 -0
- package/template/test/richTextTypography.spec.ts +182 -0
- package/template/test/setup.ts +21 -0
- package/template/test/slugPage.spec.ts +244 -0
- package/template/test/slugPageTemplate.spec.ts +194 -0
- package/template/test/starter.spec.ts +1416 -0
- package/template/test/storefront/cart.spec.ts +404 -0
- package/template/test/storefront/categories.spec.ts +235 -0
- package/template/test/storefront/collectionSelector.spec.ts +74 -0
- package/template/test/storefront/demo.spec.ts +555 -0
- package/template/test/storefront/facets.spec.ts +425 -0
- package/template/test/storefront/feedback.spec.ts +97 -0
- package/template/test/storefront/gateway.spec.ts +2673 -0
- package/template/test/storefront/gatewayCart.spec.ts +289 -0
- package/template/test/storefront/gatewayPrerender.spec.ts +1037 -0
- package/template/test/storefront/history.spec.ts +341 -0
- package/template/test/storefront/money.spec.ts +171 -0
- package/template/test/storefront/toProductCard.spec.ts +138 -0
- package/template/test/storefront/volatile.spec.ts +284 -0
- package/template/test/support/axe.ts +14 -0
- package/template/test/support/dialog.ts +51 -0
- package/template/test/support/hydrate.ts +118 -0
- package/template/test/support/i18nText.ts +11 -0
- package/template/test/support/mockGateway.ts +1017 -0
- package/template/test/support/mountBlock.ts +194 -0
- package/template/test/support/mountPage.spec.ts +72 -0
- package/template/test/support/mountPage.ts +254 -0
- package/template/test/support/mountProbe.client.ts +69 -0
- package/template/test/support/renderSsr.ts +97 -0
- package/template/test/support/staticServer.ts +96 -0
- package/template/test/themeIcons.spec.ts +140 -0
- package/template/test/toastAnnouncement.spec.ts +133 -0
- package/template/test/tokens.spec.ts +102 -0
- package/template/test/uiMessagesPlugin.spec.ts +104 -0
- package/template/test/useBlockData.spec.ts +46 -0
- package/template/test/useEditing.spec.ts +54 -0
- package/template/test/useEldraIcon.spec.ts +126 -0
- package/template/test/useUiId.spec.ts +40 -0
- package/template/tokens.json +149 -0
- package/template/tsconfig.json +3 -0
- package/template/tsconfig.storybook.json +17 -0
- package/template/vitest-axe.d.ts +13 -0
- package/template/vitest.config.ts +44 -0
|
@@ -0,0 +1,1416 @@
|
|
|
1
|
+
import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, symlinkSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { describe, expect, it } from 'vitest';
|
|
7
|
+
import { execa } from 'execa';
|
|
8
|
+
import { scanTheme } from '@eldrajs/vite-plugin-theme/scan';
|
|
9
|
+
import { encodeStega } from '@eldrajs/theme-core/stega';
|
|
10
|
+
import { safeHref } from '../app/utils/links';
|
|
11
|
+
import { starterSeeds, starterTemplateRoles, stripSeedMedia } from '../app/templates';
|
|
12
|
+
|
|
13
|
+
const templateDir = fileURLToPath(new URL('..', import.meta.url));
|
|
14
|
+
// Resolved by package name (a real devDependency of this starter, like a
|
|
15
|
+
// customer's `eldra-theme init` copy has too), not a relative reach into the
|
|
16
|
+
// monorepo's theme-cli source directory — that sibling does not exist
|
|
17
|
+
// outside this monorepo. Requires @eldrajs/theme-cli to already be built
|
|
18
|
+
// (`dist/cli.js`), same precondition the root gates already enforce.
|
|
19
|
+
const cli = join(
|
|
20
|
+
dirname(createRequire(import.meta.url).resolve('@eldrajs/theme-cli/package.json')),
|
|
21
|
+
'dist',
|
|
22
|
+
'cli.js'
|
|
23
|
+
);
|
|
24
|
+
const nuxi = join(templateDir, 'node_modules', '.bin', 'nuxi');
|
|
25
|
+
const expectedBlocks = [
|
|
26
|
+
'announcement-bar',
|
|
27
|
+
'article',
|
|
28
|
+
'article-list',
|
|
29
|
+
'breadcrumbs',
|
|
30
|
+
'cart',
|
|
31
|
+
'collection-grid',
|
|
32
|
+
'collection-header',
|
|
33
|
+
'contact',
|
|
34
|
+
'cta',
|
|
35
|
+
'faq',
|
|
36
|
+
'feature-grid',
|
|
37
|
+
'footer',
|
|
38
|
+
'gallery',
|
|
39
|
+
'hero',
|
|
40
|
+
'image',
|
|
41
|
+
'logo-cloud',
|
|
42
|
+
'navigation',
|
|
43
|
+
'newsletter',
|
|
44
|
+
'order-status',
|
|
45
|
+
'pricing-table',
|
|
46
|
+
'product-carousel',
|
|
47
|
+
'product-detail',
|
|
48
|
+
'quote',
|
|
49
|
+
'rich-text',
|
|
50
|
+
'search',
|
|
51
|
+
'split-content',
|
|
52
|
+
'stats',
|
|
53
|
+
'tabs',
|
|
54
|
+
'team',
|
|
55
|
+
'testimonials',
|
|
56
|
+
'timeline',
|
|
57
|
+
'trust-strip',
|
|
58
|
+
'video-embed',
|
|
59
|
+
'wishlist',
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
describe('starter theme', () => {
|
|
63
|
+
it('allows ordinary links and rejects executable or opaque protocols', () => {
|
|
64
|
+
expect(safeHref('/contact')).toBe('/contact');
|
|
65
|
+
expect(safeHref('https://example.com')).toBe('https://example.com');
|
|
66
|
+
expect(safeHref('mailto:hello@example.com')).toBe('mailto:hello@example.com');
|
|
67
|
+
expect(safeHref(' #details ')).toBe('#details');
|
|
68
|
+
expect(safeHref('javascript:alert(1)')).toBeNull();
|
|
69
|
+
expect(safeHref('data:text/html,<script>alert(1)</script>')).toBeNull();
|
|
70
|
+
expect(safeHref('vbscript:msgbox(1)')).toBeNull();
|
|
71
|
+
expect(safeHref('//evil.example/path')).toBeNull();
|
|
72
|
+
expect(safeHref('/\\evil.example/path')).toBeNull();
|
|
73
|
+
expect(safeHref('/safe\npath')).toBeNull();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('cleans preview metadata before validating ordinary and templated links', () => {
|
|
77
|
+
const meta = { entryId: 'guide-1', fieldPath: 'slug', locale: 'en-US' };
|
|
78
|
+
expect(safeHref('/guides/' + encodeStega('volcanic-coast', meta))).toBe(
|
|
79
|
+
'/guides/volcanic-coast'
|
|
80
|
+
);
|
|
81
|
+
expect(safeHref(encodeStega('/about', meta))).toBe('/about');
|
|
82
|
+
expect(safeHref(encodeStega('javascript:alert(1)', meta))).toBeNull();
|
|
83
|
+
expect(safeHref(encodeStega('//evil.example/path', meta))).toBeNull();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('validates every contract block and includes design tokens', () => {
|
|
87
|
+
const result = scanTheme({ themeDir: templateDir, framework: 'nuxt' });
|
|
88
|
+
expect(result.errors).toEqual([]);
|
|
89
|
+
expect(result.manifest?.blocks.map((block) => block.apiId).sort()).toEqual(expectedBlocks);
|
|
90
|
+
// The design spec's brand slot (eldra-starter-spec/tokens.json): a deep
|
|
91
|
+
// ink a customer replaces with their own colour, not a blue.
|
|
92
|
+
expect(result.manifest?.tokens.colors.primary.value).toBe('#24201c');
|
|
93
|
+
// The roles `@eldrajs/ui` needs beyond the original thirteen.
|
|
94
|
+
expect(result.manifest?.tokens.colors['border-strong']?.value).toBe('#7d7466');
|
|
95
|
+
expect(result.manifest?.tokens.colors.focus?.value).toBe('#1c1917');
|
|
96
|
+
expect(result.manifest?.tokens.colors['focus-inner']?.value).toBe('#ffffff');
|
|
97
|
+
expect(result.manifest?.tokens.colors.overlay?.value).toBe('#1c1917b3');
|
|
98
|
+
const fields = Object.fromEntries(
|
|
99
|
+
result.manifest!.blocks.map((block) => [
|
|
100
|
+
block.apiId,
|
|
101
|
+
block.fields.map((field) => field.fieldId),
|
|
102
|
+
])
|
|
103
|
+
);
|
|
104
|
+
const expectedFields: Record<string, string[]> = {
|
|
105
|
+
// Every one of the 34 blocks has its field list here — the map used to cover 31, leaving
|
|
106
|
+
// `announcement-bar` and `newsletter` with only the manifest version rule behind a field
|
|
107
|
+
// rename or reorder, not the explicit list every sibling block has.
|
|
108
|
+
'announcement-bar': ['variant', 'message', 'linkLabel', 'linkHref', 'dismissable'],
|
|
109
|
+
newsletter: [
|
|
110
|
+
'variant',
|
|
111
|
+
'heading',
|
|
112
|
+
'text',
|
|
113
|
+
'fieldLabel',
|
|
114
|
+
'placeholder',
|
|
115
|
+
'buttonLabel',
|
|
116
|
+
'consent',
|
|
117
|
+
'requireConsentCheckbox',
|
|
118
|
+
'consentCheckboxLabel',
|
|
119
|
+
'successTitle',
|
|
120
|
+
'successText',
|
|
121
|
+
'list',
|
|
122
|
+
'sectionBackground',
|
|
123
|
+
],
|
|
124
|
+
hero: [
|
|
125
|
+
'variant',
|
|
126
|
+
'eyebrow',
|
|
127
|
+
'heading',
|
|
128
|
+
'subheading',
|
|
129
|
+
'image',
|
|
130
|
+
'slides',
|
|
131
|
+
'spacing',
|
|
132
|
+
'primaryCtaLabel',
|
|
133
|
+
'primaryCtaHref',
|
|
134
|
+
'secondaryCtaLabel',
|
|
135
|
+
'secondaryCtaHref',
|
|
136
|
+
],
|
|
137
|
+
footer: [
|
|
138
|
+
'variant',
|
|
139
|
+
'background',
|
|
140
|
+
'brandText',
|
|
141
|
+
'brandLogo',
|
|
142
|
+
'description',
|
|
143
|
+
'groups',
|
|
144
|
+
'links',
|
|
145
|
+
'showNewsletter',
|
|
146
|
+
'newsletterTitle',
|
|
147
|
+
'newsletterText',
|
|
148
|
+
'social',
|
|
149
|
+
'legalText',
|
|
150
|
+
'legalLinks',
|
|
151
|
+
'showLocale',
|
|
152
|
+
'showCurrency',
|
|
153
|
+
],
|
|
154
|
+
navigation: [
|
|
155
|
+
'variant',
|
|
156
|
+
'brandText',
|
|
157
|
+
'brandLogo',
|
|
158
|
+
'links',
|
|
159
|
+
'showSearch',
|
|
160
|
+
'searchStyle',
|
|
161
|
+
'ctaLabel',
|
|
162
|
+
'cta',
|
|
163
|
+
'sticky',
|
|
164
|
+
'transparentOverHero',
|
|
165
|
+
],
|
|
166
|
+
article: [
|
|
167
|
+
'title',
|
|
168
|
+
'dek',
|
|
169
|
+
'categoryLabel',
|
|
170
|
+
'categoryHref',
|
|
171
|
+
'publishedAt',
|
|
172
|
+
'readingTime',
|
|
173
|
+
'coverImage',
|
|
174
|
+
'coverCaption',
|
|
175
|
+
'body',
|
|
176
|
+
'authorName',
|
|
177
|
+
'authorRole',
|
|
178
|
+
'authorAvatar',
|
|
179
|
+
'authorBio',
|
|
180
|
+
'authorLinkLabel',
|
|
181
|
+
'authorLinkHref',
|
|
182
|
+
'showByline',
|
|
183
|
+
],
|
|
184
|
+
image: [
|
|
185
|
+
'image',
|
|
186
|
+
'decorative',
|
|
187
|
+
'aspect',
|
|
188
|
+
'width',
|
|
189
|
+
'caption',
|
|
190
|
+
'captionAlign',
|
|
191
|
+
'linkLabel',
|
|
192
|
+
'linkHref',
|
|
193
|
+
],
|
|
194
|
+
gallery: ['variant', 'heading', 'intro', 'columns', 'aspect', 'showCaptions', 'items'],
|
|
195
|
+
cta: [
|
|
196
|
+
'variant',
|
|
197
|
+
'eyebrow',
|
|
198
|
+
'heading',
|
|
199
|
+
'text',
|
|
200
|
+
'primaryCtaLabel',
|
|
201
|
+
'primaryCtaHref',
|
|
202
|
+
'secondaryCtaLabel',
|
|
203
|
+
'secondaryCtaHref',
|
|
204
|
+
'image',
|
|
205
|
+
],
|
|
206
|
+
'feature-grid': [
|
|
207
|
+
'variant',
|
|
208
|
+
'heading',
|
|
209
|
+
'intro',
|
|
210
|
+
'headLinkLabel',
|
|
211
|
+
'headLinkHref',
|
|
212
|
+
'columns',
|
|
213
|
+
'mediaType',
|
|
214
|
+
'items',
|
|
215
|
+
],
|
|
216
|
+
testimonials: [
|
|
217
|
+
'variant',
|
|
218
|
+
'heading',
|
|
219
|
+
'summary',
|
|
220
|
+
'linkLabel',
|
|
221
|
+
'linkHref',
|
|
222
|
+
'items',
|
|
223
|
+
'sectionBackground',
|
|
224
|
+
],
|
|
225
|
+
faq: [
|
|
226
|
+
'variant',
|
|
227
|
+
'heading',
|
|
228
|
+
'intro',
|
|
229
|
+
'exclusive',
|
|
230
|
+
'items',
|
|
231
|
+
'contactText',
|
|
232
|
+
'contactLinkLabel',
|
|
233
|
+
'contactLinkHref',
|
|
234
|
+
'sectionBackground',
|
|
235
|
+
],
|
|
236
|
+
'logo-cloud': ['variant', 'heading', 'logos', 'sectionBackground'],
|
|
237
|
+
breadcrumbs: [
|
|
238
|
+
'showHome',
|
|
239
|
+
'homeLabel',
|
|
240
|
+
'trail',
|
|
241
|
+
'fromProduct',
|
|
242
|
+
'fromCategory',
|
|
243
|
+
'currentTitle',
|
|
244
|
+
'showCurrent',
|
|
245
|
+
'container',
|
|
246
|
+
],
|
|
247
|
+
'collection-header': [
|
|
248
|
+
'scope',
|
|
249
|
+
'collection',
|
|
250
|
+
'variant',
|
|
251
|
+
'title',
|
|
252
|
+
'description',
|
|
253
|
+
'image',
|
|
254
|
+
'showCount',
|
|
255
|
+
'showBreadcrumb',
|
|
256
|
+
'trail',
|
|
257
|
+
'subcollections',
|
|
258
|
+
],
|
|
259
|
+
'split-content': ['startWith', 'rows'],
|
|
260
|
+
quote: [
|
|
261
|
+
'variant',
|
|
262
|
+
'quote',
|
|
263
|
+
'name',
|
|
264
|
+
'role',
|
|
265
|
+
'avatar',
|
|
266
|
+
'image',
|
|
267
|
+
'sourceLinkLabel',
|
|
268
|
+
'sourceLinkHref',
|
|
269
|
+
'sectionBackground',
|
|
270
|
+
],
|
|
271
|
+
'rich-text': ['heading', 'body', 'alignment', 'container'],
|
|
272
|
+
stats: ['variant', 'heading', 'intro', 'items', 'sectionBackground'],
|
|
273
|
+
'pricing-table': [
|
|
274
|
+
'heading',
|
|
275
|
+
'intro',
|
|
276
|
+
'featureRows',
|
|
277
|
+
'plans',
|
|
278
|
+
'highlightedPlan',
|
|
279
|
+
'highlightLabel',
|
|
280
|
+
'footnote',
|
|
281
|
+
'sectionBackground',
|
|
282
|
+
],
|
|
283
|
+
contact: [
|
|
284
|
+
'variant',
|
|
285
|
+
'heading',
|
|
286
|
+
'hideHeading',
|
|
287
|
+
'intro',
|
|
288
|
+
'address',
|
|
289
|
+
'hours',
|
|
290
|
+
'phone',
|
|
291
|
+
'email',
|
|
292
|
+
'mapLinkLabel',
|
|
293
|
+
'mapLinkHref',
|
|
294
|
+
'mapEmbed',
|
|
295
|
+
'mapImage',
|
|
296
|
+
'mapNote',
|
|
297
|
+
'formTitle',
|
|
298
|
+
'topics',
|
|
299
|
+
'showOrderNumber',
|
|
300
|
+
'recipient',
|
|
301
|
+
'successText',
|
|
302
|
+
],
|
|
303
|
+
'video-embed': [
|
|
304
|
+
'variant',
|
|
305
|
+
'heading',
|
|
306
|
+
'intro',
|
|
307
|
+
'videoUrl',
|
|
308
|
+
'videoTitle',
|
|
309
|
+
'duration',
|
|
310
|
+
'poster',
|
|
311
|
+
'caption',
|
|
312
|
+
'transcriptLabel',
|
|
313
|
+
'transcriptHref',
|
|
314
|
+
'privacyNote',
|
|
315
|
+
'sectionBackground',
|
|
316
|
+
],
|
|
317
|
+
wishlist: ['heading', 'emptyTitle', 'emptyText', 'emptyLink'],
|
|
318
|
+
timeline: [
|
|
319
|
+
'variant',
|
|
320
|
+
'heading',
|
|
321
|
+
'intro',
|
|
322
|
+
'linkLabel',
|
|
323
|
+
'linkHref',
|
|
324
|
+
'items',
|
|
325
|
+
'columns',
|
|
326
|
+
'sectionBackground',
|
|
327
|
+
],
|
|
328
|
+
team: ['heading', 'intro', 'linkLabel', 'linkHref', 'people', 'sectionBackground'],
|
|
329
|
+
tabs: ['heading', 'intro', 'tabs', 'defaultTab', 'sectionBackground'],
|
|
330
|
+
'trust-strip': [
|
|
331
|
+
'variant',
|
|
332
|
+
'items',
|
|
333
|
+
'mobileLayout',
|
|
334
|
+
'showPayments',
|
|
335
|
+
'paymentsLabel',
|
|
336
|
+
'payments',
|
|
337
|
+
'background',
|
|
338
|
+
],
|
|
339
|
+
'article-list': [
|
|
340
|
+
'variant',
|
|
341
|
+
'heading',
|
|
342
|
+
'viewAllLabel',
|
|
343
|
+
'viewAllHref',
|
|
344
|
+
'source',
|
|
345
|
+
'categoryHref',
|
|
346
|
+
'items',
|
|
347
|
+
'perPage',
|
|
348
|
+
'showFilters',
|
|
349
|
+
'filters',
|
|
350
|
+
'showPagination',
|
|
351
|
+
'showExcerpt',
|
|
352
|
+
'emptyTitle',
|
|
353
|
+
'emptyText',
|
|
354
|
+
],
|
|
355
|
+
'product-carousel': [
|
|
356
|
+
'heading',
|
|
357
|
+
'variant',
|
|
358
|
+
'sourceCollection',
|
|
359
|
+
'limit',
|
|
360
|
+
'viewAllLabel',
|
|
361
|
+
'viewAllHref',
|
|
362
|
+
'showSwatches',
|
|
363
|
+
'background',
|
|
364
|
+
],
|
|
365
|
+
'collection-grid': [
|
|
366
|
+
'scope',
|
|
367
|
+
'collection',
|
|
368
|
+
'variant',
|
|
369
|
+
'columns',
|
|
370
|
+
'pageSize',
|
|
371
|
+
'paginationStyle',
|
|
372
|
+
'sortOptions',
|
|
373
|
+
'filters',
|
|
374
|
+
'priceSlider',
|
|
375
|
+
'colourLayout',
|
|
376
|
+
'sizeGuideHref',
|
|
377
|
+
'priceStep',
|
|
378
|
+
'showColumnSelect',
|
|
379
|
+
'emptyTitle',
|
|
380
|
+
'emptyText',
|
|
381
|
+
],
|
|
382
|
+
'product-detail': [
|
|
383
|
+
'productHandle',
|
|
384
|
+
'variant',
|
|
385
|
+
'showRating',
|
|
386
|
+
'showQuantity',
|
|
387
|
+
'showWishlist',
|
|
388
|
+
'lowStockThreshold',
|
|
389
|
+
'perks',
|
|
390
|
+
'tabs',
|
|
391
|
+
'sizeGuideLabel',
|
|
392
|
+
'sizeGuideHref',
|
|
393
|
+
'stickyBar',
|
|
394
|
+
'showCategory',
|
|
395
|
+
],
|
|
396
|
+
search: [
|
|
397
|
+
'variant',
|
|
398
|
+
'heading',
|
|
399
|
+
'placeholder',
|
|
400
|
+
'types',
|
|
401
|
+
'suggestionsPerGroup',
|
|
402
|
+
'popularSearches',
|
|
403
|
+
'noResultsCollection',
|
|
404
|
+
],
|
|
405
|
+
cart: [
|
|
406
|
+
'variant',
|
|
407
|
+
'freeShippingThreshold',
|
|
408
|
+
'showDiscountField',
|
|
409
|
+
'showPaymentIcons',
|
|
410
|
+
'note',
|
|
411
|
+
'emptyTitle',
|
|
412
|
+
'emptyText',
|
|
413
|
+
'emptyLinkLabel',
|
|
414
|
+
'emptyLinkHref',
|
|
415
|
+
],
|
|
416
|
+
'order-status': [
|
|
417
|
+
'variant',
|
|
418
|
+
'processingTitle',
|
|
419
|
+
'processingText',
|
|
420
|
+
'shippedTitle',
|
|
421
|
+
'deliveredTitle',
|
|
422
|
+
'deliveredText',
|
|
423
|
+
'delayedTitle',
|
|
424
|
+
'cancelledTitle',
|
|
425
|
+
'returnLinkLabel',
|
|
426
|
+
'returnLinkHref',
|
|
427
|
+
'shopAgainLinkLabel',
|
|
428
|
+
'shopAgainLinkHref',
|
|
429
|
+
'helpLinks',
|
|
430
|
+
],
|
|
431
|
+
};
|
|
432
|
+
expect(fields).toMatchObject(expectedFields);
|
|
433
|
+
// And the map covers every block, so a new one cannot land without its field list.
|
|
434
|
+
expect(Object.keys(expectedFields).sort()).toEqual([...expectedBlocks].sort());
|
|
435
|
+
|
|
436
|
+
// Starter mocks cannot carry organization-specific asset IDs. Keep media
|
|
437
|
+
// fields with asset-free mock values optional so a freshly inserted block
|
|
438
|
+
// is publishable before an editor selects an asset.
|
|
439
|
+
const imageBlock = result.manifest!.blocks.find((block) => block.apiId === 'image')!;
|
|
440
|
+
const imageField = imageBlock.fields.find((field) => field.fieldId === 'image');
|
|
441
|
+
expect(imageField?.validators?.required).not.toBe(true);
|
|
442
|
+
expect(imageField?.metadata?.multiple).toBe(false);
|
|
443
|
+
const galleryBlock = result.manifest!.blocks.find((block) => block.apiId === 'gallery')!;
|
|
444
|
+
const galleryItems = galleryBlock.fields.find((field) => field.fieldId === 'items');
|
|
445
|
+
// Core's `list` field type accepts no validators at all — a manifest that declares even
|
|
446
|
+
// `required` on one is rejected at deploy ("list fields do not support the required
|
|
447
|
+
// validator"), so the "at least one" intent lives in the field's `helpText` instead.
|
|
448
|
+
expect(galleryItems?.validators).toBeUndefined();
|
|
449
|
+
const galleryItemImage = galleryItems?.metadata?.item?.metadata?.fields?.find(
|
|
450
|
+
(field) => field.fieldId === 'image'
|
|
451
|
+
);
|
|
452
|
+
expect(galleryItemImage?.validators?.required).toBe(true);
|
|
453
|
+
expect(galleryItemImage?.metadata?.multiple).toBe(false);
|
|
454
|
+
expect(galleryItemImage?.metadata?.framing).toBe(true);
|
|
455
|
+
|
|
456
|
+
const heroBlock = result.manifest!.blocks.find((block) => block.apiId === 'hero')!;
|
|
457
|
+
expect(heroBlock.fields.find((field) => field.fieldId === 'image')?.metadata?.multiple).toBe(
|
|
458
|
+
false
|
|
459
|
+
);
|
|
460
|
+
expect(heroBlock.previewImage).toBe('.eldra/previews/hero.png');
|
|
461
|
+
expect(existsSync(join(templateDir, heroBlock.previewImage!))).toBe(true);
|
|
462
|
+
const testimonialsBlock = result.manifest!.blocks.find(
|
|
463
|
+
(block) => block.apiId === 'testimonials'
|
|
464
|
+
)!;
|
|
465
|
+
const testimonialsItems = testimonialsBlock.fields.find((field) => field.fieldId === 'items');
|
|
466
|
+
const avatar = testimonialsItems?.metadata?.item?.metadata?.fields?.find(
|
|
467
|
+
(field) => field.fieldId === 'avatar'
|
|
468
|
+
);
|
|
469
|
+
expect(avatar?.metadata?.multiple).toBe(false);
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
it('ships the Nuxt shell, documentation, and all provider deploy workflows', () => {
|
|
473
|
+
for (const path of [
|
|
474
|
+
'nuxt.config.ts',
|
|
475
|
+
'app/app.vue',
|
|
476
|
+
'app/pages/[...slug].vue',
|
|
477
|
+
'README.md',
|
|
478
|
+
'.github/workflows/eldra-deploy.yml',
|
|
479
|
+
'.gitlab-ci.yml',
|
|
480
|
+
'bitbucket-pipelines.yml',
|
|
481
|
+
])
|
|
482
|
+
expect(existsSync(join(templateDir, path)), path).toBe(true);
|
|
483
|
+
expect(readFileSync(join(templateDir, '.github/workflows/eldra-deploy.yml'), 'utf8')).toContain(
|
|
484
|
+
'github.event.client_payload.deploymentId'
|
|
485
|
+
);
|
|
486
|
+
expect(readFileSync(join(templateDir, '.gitlab-ci.yml'), 'utf8')).toContain(
|
|
487
|
+
'ELDRA_TRIGGER_DEPLOYMENT_ID'
|
|
488
|
+
);
|
|
489
|
+
expect(readFileSync(join(templateDir, 'bitbucket-pipelines.yml'), 'utf8')).toContain(
|
|
490
|
+
'eldra-rebuild'
|
|
491
|
+
);
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
it('generates the static shell, manifest, headers, and fallback without gateway credentials', async () => {
|
|
495
|
+
const result = await execa(nuxi, ['generate'], {
|
|
496
|
+
cwd: templateDir,
|
|
497
|
+
env: { ELDRA_GATEWAY_URL: '', ELDRA_ORG_ID: '' },
|
|
498
|
+
reject: false,
|
|
499
|
+
timeout: 300_000,
|
|
500
|
+
});
|
|
501
|
+
expect(result.exitCode, result.stderr).toBe(0);
|
|
502
|
+
const output = (path: string) => join(templateDir, '.output', 'public', path);
|
|
503
|
+
expect(existsSync(output('index.html'))).toBe(true);
|
|
504
|
+
expect(existsSync(output('200.html'))).toBe(true);
|
|
505
|
+
expect(existsSync(output('.eldra/manifest.json'))).toBe(true);
|
|
506
|
+
// The seeds and roles `nuxt.config.ts` declares reach the manifest the build writes — the
|
|
507
|
+
// artifact `eldra-theme deploy` uploads and Core seeds a site from. The scan-level
|
|
508
|
+
// assertions live in "seeded templates" below; this one proves the config wiring.
|
|
509
|
+
const built = JSON.parse(readFileSync(output('.eldra/manifest.json'), 'utf8')) as {
|
|
510
|
+
templates?: Array<{ routePattern: string }>;
|
|
511
|
+
pageSeeds?: Array<{ slug: string }>;
|
|
512
|
+
templateRoles?: { header?: { apiId: string }; footer?: { apiId: string } };
|
|
513
|
+
};
|
|
514
|
+
expect(built.templates?.map((template) => template.routePattern)).toEqual([
|
|
515
|
+
'/products/:slug',
|
|
516
|
+
'/collections/:slug',
|
|
517
|
+
'/categories/:path*',
|
|
518
|
+
'/',
|
|
519
|
+
]);
|
|
520
|
+
expect(built.pageSeeds?.map((seed) => seed.slug)).toEqual([
|
|
521
|
+
'cart',
|
|
522
|
+
'wishlist',
|
|
523
|
+
'search',
|
|
524
|
+
'products',
|
|
525
|
+
]);
|
|
526
|
+
expect([built.templateRoles?.header?.apiId, built.templateRoles?.footer?.apiId]).toEqual([
|
|
527
|
+
'navigation',
|
|
528
|
+
'footer',
|
|
529
|
+
]);
|
|
530
|
+
expect(readFileSync(output('_headers'), 'utf8')).toContain(
|
|
531
|
+
"frame-ancestors 'self' https://localhost:4311"
|
|
532
|
+
);
|
|
533
|
+
// A build with no credentials cannot know what the store sells in, and says so in the one place
|
|
534
|
+
// that matters: the runtime config baked into every page carries no currency, rather than one
|
|
535
|
+
// the theme picked. It reads `""` and not `null` because that is what Nuxt serialises a null
|
|
536
|
+
// public-runtime-config value as — `locale` beside it does the same — which is exactly why
|
|
537
|
+
// `toStorefrontCommerce` treats an empty string as "the store published nothing" rather than as
|
|
538
|
+
// a malformed record. `@eldrajs/theme-nuxt` warns once; the page then renders plain numbers.
|
|
539
|
+
expect(readFileSync(output('index.html'), 'utf8')).toContain('commerce:""');
|
|
540
|
+
expect(result.stderr + result.stdout).toContain('the store publishes no currency');
|
|
541
|
+
|
|
542
|
+
// **And what that page renders**, which is the half this used to leave unsaid. A scaffold build
|
|
543
|
+
// reaches every gateway read's failure as a certainty, not as news — `eldra-theme init` &&
|
|
544
|
+
// `pnpm generate` exists to render the theme before an organisation does — so the composable
|
|
545
|
+
// resolves such a route to the empty route with no error and the page draws the styled
|
|
546
|
+
// not-found shell. Once a failed resolution had somewhere to be reported
|
|
547
|
+
// (`@eldrajs/theme-nuxt`'s `ResolvedEldraRoute.error`) and the credential exemption suppressed
|
|
548
|
+
// only the response status, `/` came out as a raw `<p role="alert">Invalid URL</p>` — the first
|
|
549
|
+
// page a developer ever generates, and nothing here could see it.
|
|
550
|
+
const home = readFileSync(output('index.html'), 'utf8');
|
|
551
|
+
expect(home).toContain('data-eldra-not-found');
|
|
552
|
+
expect(home).not.toContain('role="alert"');
|
|
553
|
+
|
|
554
|
+
// Nitro's own `/404.html` is normally a generic SPA-fallback shell
|
|
555
|
+
// (identical to `200.html`) used by static hosts for unmatched routes —
|
|
556
|
+
// it never goes through the app's catch-all page on its own. Adding
|
|
557
|
+
// `/404` to nitro.prerender.routes makes Nitro *also* render that path
|
|
558
|
+
// through `app/pages/[...slug].vue`, writing it to `404/index.html`
|
|
559
|
+
// (Nitro's convention for extension-less routes); a `prerender:done`
|
|
560
|
+
// hook in nuxt.config.ts then copies that file over the literal
|
|
561
|
+
// `404.html` so static hosts serving the literal path get the styled
|
|
562
|
+
// not-found shell instead of the blank fallback.
|
|
563
|
+
const notFound = readFileSync(output('404.html'), 'utf8');
|
|
564
|
+
expect(notFound).toContain('data-eldra-not-found');
|
|
565
|
+
expect(notFound).toContain('href="/"');
|
|
566
|
+
|
|
567
|
+
// **No page path is prerendered by name any more.** `/cart`, `/search`, `/wishlist` and
|
|
568
|
+
// `/products` were
|
|
569
|
+
// listed in `nitro.prerender.routes` while they were code routes under `app/pages/`; they are
|
|
570
|
+
// CMS pages now, so the only thing that writes a file for them is `@eldrajs/theme-nuxt`'s
|
|
571
|
+
// `prerender:routes` hook listing every published page's own path — which needs a gateway, and
|
|
572
|
+
// is asserted against one in `test/prerenderRefresh.browser.spec.ts`.
|
|
573
|
+
//
|
|
574
|
+
// A credential-free build therefore writes `/` and `/404` and nothing else, and that is the
|
|
575
|
+
// honest answer: naming the three paths here as well would bake the not-found shell into the
|
|
576
|
+
// artifact under names a visitor can reach, on every build whose gateway has no such page.
|
|
577
|
+
const metaDir = output(join('_nuxt', 'builds', 'meta'));
|
|
578
|
+
const [metaFile] = readdirSync(metaDir);
|
|
579
|
+
const buildMeta = JSON.parse(readFileSync(join(metaDir, metaFile ?? ''), 'utf8')) as {
|
|
580
|
+
prerendered: string[];
|
|
581
|
+
};
|
|
582
|
+
expect(buildMeta.prerendered.sort()).toEqual(['/', '/404']);
|
|
583
|
+
for (const path of ['cart', 'search', 'wishlist', 'products']) {
|
|
584
|
+
expect(existsSync(output(join(path, 'index.html'))), `${path}/index.html`).toBe(false);
|
|
585
|
+
}
|
|
586
|
+
expect(result.stderr + result.stdout).toContain('prerendering "/" only');
|
|
587
|
+
}, 360_000);
|
|
588
|
+
|
|
589
|
+
it('supports an exact authenticated Studio origin override', async () => {
|
|
590
|
+
const result = await execa(nuxi, ['generate'], {
|
|
591
|
+
cwd: templateDir,
|
|
592
|
+
env: {
|
|
593
|
+
ELDRA_GATEWAY_URL: '',
|
|
594
|
+
ELDRA_ORG_ID: '',
|
|
595
|
+
ELDRA_STUDIO_ORIGIN: 'https://studio.example.test:3000',
|
|
596
|
+
},
|
|
597
|
+
reject: false,
|
|
598
|
+
timeout: 300_000,
|
|
599
|
+
});
|
|
600
|
+
expect(result.exitCode, result.stderr).toBe(0);
|
|
601
|
+
expect(readFileSync(join(templateDir, '.output', 'public', '_headers'), 'utf8')).toContain(
|
|
602
|
+
"frame-ancestors 'self' https://studio.example.test:3000"
|
|
603
|
+
);
|
|
604
|
+
}, 360_000);
|
|
605
|
+
|
|
606
|
+
it('initializes, validates, and generates a working theme in a scratch directory', async () => {
|
|
607
|
+
const scratchRoot = mkdtempSync(join(tmpdir(), 'eldra-starter-'));
|
|
608
|
+
const themeDir = join(scratchRoot, 'site');
|
|
609
|
+
try {
|
|
610
|
+
const initialized = await execa('node', [cli, 'init', themeDir], { reject: false });
|
|
611
|
+
expect(initialized.exitCode, initialized.stderr).toBe(0);
|
|
612
|
+
const packageJson = JSON.parse(readFileSync(join(themeDir, 'package.json'), 'utf8')) as {
|
|
613
|
+
dependencies: Record<string, string>;
|
|
614
|
+
};
|
|
615
|
+
expect(packageJson.dependencies['@eldrajs/theme-nuxt']).toBe('^0.1.0');
|
|
616
|
+
|
|
617
|
+
// Equivalent to the dependency-install boundary, but deterministic and offline in this monorepo test.
|
|
618
|
+
symlinkSync(join(templateDir, 'node_modules'), join(themeDir, 'node_modules'), 'dir');
|
|
619
|
+
const validated = await execa('node', [cli, 'validate'], { cwd: themeDir, reject: false });
|
|
620
|
+
expect(validated.exitCode, validated.stderr).toBe(0);
|
|
621
|
+
expect(validated.stdout).toContain(`${expectedBlocks.length} blocks valid`);
|
|
622
|
+
|
|
623
|
+
const generated = await execa(nuxi, ['generate'], {
|
|
624
|
+
cwd: themeDir,
|
|
625
|
+
env: { ELDRA_GATEWAY_URL: '', ELDRA_ORG_ID: '' },
|
|
626
|
+
reject: false,
|
|
627
|
+
timeout: 300_000,
|
|
628
|
+
});
|
|
629
|
+
expect(generated.exitCode, `${generated.stdout}\n${generated.stderr}`).toBe(0);
|
|
630
|
+
expect(existsSync(join(themeDir, '.output', 'public', 'index.html'))).toBe(true);
|
|
631
|
+
expect(existsSync(join(themeDir, '.output', 'public', '.eldra', 'manifest.json'))).toBe(true);
|
|
632
|
+
} finally {
|
|
633
|
+
rmSync(scratchRoot, { recursive: true, force: true });
|
|
634
|
+
}
|
|
635
|
+
}, 360_000);
|
|
636
|
+
/**
|
|
637
|
+
* The name→icon-component adapter lives in exactly one place
|
|
638
|
+
* (`app/composables/iconComponent.ts`). It used to be copy-pasted into eight blocks — nine copies
|
|
639
|
+
* of one fragile regex over Tabler's markup, in a codebase the customer is expected to edit — and
|
|
640
|
+
* the copies also dropped what routing through `@eldrajs/ui`'s `Icon` adds: the spec's stroke
|
|
641
|
+
* width, the four sizes and the decorative/labelled ARIA state. This keeps it at one.
|
|
642
|
+
*/
|
|
643
|
+
it('no block re-implements the Tabler markup transform or hand-rolls an icon <svg>', () => {
|
|
644
|
+
const blocksDir = join(templateDir, 'blocks');
|
|
645
|
+
const reimplemented: string[] = [];
|
|
646
|
+
const handRolled: string[] = [];
|
|
647
|
+
|
|
648
|
+
for (const apiId of expectedBlocks) {
|
|
649
|
+
for (const file of blockSourceFiles(join(blocksDir, apiId))) {
|
|
650
|
+
const source = readFileSync(file, 'utf8');
|
|
651
|
+
const where = file.slice(blocksDir.length + 1);
|
|
652
|
+
// The transform: the `<svg …>` head strip that `tablerSvgBody` owns.
|
|
653
|
+
if (source.includes('<svg\\b[^>]*>')) reimplemented.push(where);
|
|
654
|
+
// A hand-written icon element in a template: an `<svg` with a `viewBox`, which is what a
|
|
655
|
+
// copied Tabler path looks like. `EldraIcon`/`iconComponent` is the only way icons render.
|
|
656
|
+
if (/<svg[\s\n][^>]*viewBox/.test(source)) handRolled.push(where);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
expect(
|
|
661
|
+
reimplemented,
|
|
662
|
+
'use `tablerSvgBody`/`renderTablerSvg` from `app/composables/iconComponent.ts` instead of ' +
|
|
663
|
+
"re-implementing Tabler's markup transform"
|
|
664
|
+
).toEqual([]);
|
|
665
|
+
expect(
|
|
666
|
+
handRolled,
|
|
667
|
+
'render icons through `EldraIcon` (a template) or `iconComponent()` (a package prop that ' +
|
|
668
|
+
'takes a component) — never a hand-written `<svg>` with a copied path'
|
|
669
|
+
).toEqual([]);
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* The constraint every customer block is judged by — "no Nuxt globals, no `@eldrajs/sdk`, no
|
|
674
|
+
* auto-imports in `blocks/**`" (`docs/starter-kit.md`) — had nothing guarding it:
|
|
675
|
+
* `test/deps.spec.ts` only checks that bare specifiers resolve to this package's own
|
|
676
|
+
* `package.json`, which a Nuxt auto-import never appears in at all. A block that reaches for
|
|
677
|
+
* `useRoute()` still renders in the Nuxt app and only breaks in Storybook, so this is exactly the
|
|
678
|
+
* kind of drift review catches late or not at all.
|
|
679
|
+
*/
|
|
680
|
+
it('no block uses a Nuxt global, an auto-import or @eldrajs/sdk', () => {
|
|
681
|
+
const blocksDir = join(templateDir, 'blocks');
|
|
682
|
+
// `useStorefront()` is deliberately not here: it is a plain `inject()` off `STOREFRONT_KEY`
|
|
683
|
+
// (`app/composables/useStorefront.ts`), imported explicitly like every other `app/**` helper.
|
|
684
|
+
const FORBIDDEN = [
|
|
685
|
+
'useRoute(',
|
|
686
|
+
'useRouter(',
|
|
687
|
+
'useHead(',
|
|
688
|
+
'useSeoMeta(',
|
|
689
|
+
'useFetch(',
|
|
690
|
+
'useAsyncData(',
|
|
691
|
+
'useState(',
|
|
692
|
+
'useRuntimeConfig(',
|
|
693
|
+
'useNuxtApp(',
|
|
694
|
+
'$fetch(',
|
|
695
|
+
'<NuxtLink',
|
|
696
|
+
"from '@eldrajs/sdk'",
|
|
697
|
+
"from '#imports'",
|
|
698
|
+
"from '#app'",
|
|
699
|
+
];
|
|
700
|
+
const offenders: string[] = [];
|
|
701
|
+
|
|
702
|
+
for (const apiId of expectedBlocks) {
|
|
703
|
+
for (const file of blockSourceFiles(join(blocksDir, apiId))) {
|
|
704
|
+
const source = readFileSync(file, 'utf8');
|
|
705
|
+
for (const needle of FORBIDDEN) {
|
|
706
|
+
// Only real code, never prose: every one of these blocks documents the rule in its own
|
|
707
|
+
// comments, so a bare substring scan would flag the documentation.
|
|
708
|
+
const inCode = source
|
|
709
|
+
.split('\n')
|
|
710
|
+
.filter((line) => !/^\s*(\*|\/\/|<!--)/.test(line))
|
|
711
|
+
.join('\n');
|
|
712
|
+
if (inCode.includes(needle)) {
|
|
713
|
+
offenders.push(`${file.slice(blocksDir.length + 1)} uses ${needle}`);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
expect(
|
|
720
|
+
offenders,
|
|
721
|
+
'blocks/** may not use a Nuxt global, a Nuxt auto-import or `@eldrajs/sdk` — every `vue`/' +
|
|
722
|
+
'`@eldrajs/*` import is explicit, which is what lets a block render in Storybook with no ' +
|
|
723
|
+
'Nuxt build step. Route a same-site link through `app/components/EldraRouterLink.vue`, and ' +
|
|
724
|
+
'commerce data through `useStorefront()`.'
|
|
725
|
+
).toEqual([]);
|
|
726
|
+
});
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* `metadata.framing` is a promise to the editor: Studio shows framing controls for that field, and
|
|
730
|
+
* the render honours them only if it goes through this theme's `UiImage`, which is what emits the
|
|
731
|
+
* `data-eldra-framing*` markers and applies the focal point/zoom. `article-list` declared framing
|
|
732
|
+
* on `items[].image` and then mapped the media into `ContentCard`'s `image` *prop* — a component
|
|
733
|
+
* that exposes no media slot, so the theme can never render that image itself — leaving an editor
|
|
734
|
+
* with controls the page ignored. The metadata is gone from that field now (see
|
|
735
|
+
* `blocks/article-list/Block.vue`'s "Three documented package limits"), and this keeps the
|
|
736
|
+
* promise honest for every block: declare framing only where `UiImage` does the rendering.
|
|
737
|
+
*/
|
|
738
|
+
it('every block declaring metadata.framing renders through UiImage', () => {
|
|
739
|
+
const blocksDir = join(templateDir, 'blocks');
|
|
740
|
+
const offenders: string[] = [];
|
|
741
|
+
let framingFields = 0;
|
|
742
|
+
|
|
743
|
+
for (const apiId of expectedBlocks) {
|
|
744
|
+
const manifest = JSON.parse(
|
|
745
|
+
readFileSync(join(blocksDir, apiId, 'block.json'), 'utf8')
|
|
746
|
+
) as ThemeBlockManifest;
|
|
747
|
+
const declared = framingFieldIds(manifest.fields ?? []);
|
|
748
|
+
framingFields += declared.length;
|
|
749
|
+
if (declared.length === 0) continue;
|
|
750
|
+
const source = blockSourceFiles(join(blocksDir, apiId))
|
|
751
|
+
.map((file) => readFileSync(file, 'utf8'))
|
|
752
|
+
.join('\n');
|
|
753
|
+
if (!source.includes('UiImage')) {
|
|
754
|
+
offenders.push(`${apiId} (${declared.join(', ')})`);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// Guards the scan itself: fourteen media fields opt into framing across the block set.
|
|
759
|
+
expect(framingFields).toBeGreaterThanOrEqual(14);
|
|
760
|
+
expect(
|
|
761
|
+
offenders,
|
|
762
|
+
'a field with `metadata.framing` must be rendered through `app/components/ui/UiImage.vue` — ' +
|
|
763
|
+
'it is what emits the `data-eldra-framing*` markers Studio keys off; otherwise drop the ' +
|
|
764
|
+
'metadata rather than offering a control the render ignores'
|
|
765
|
+
).toEqual([]);
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* A rich-text field cannot declare its own heading outline: `metadata.toolbar`'s `heading` control
|
|
770
|
+
* is one level-agnostic id, so an editor can insert any level anywhere. The page owns the outline,
|
|
771
|
+
* so each block passes `EldraRichText`'s `minHeadingLevel` floor for the place its own document
|
|
772
|
+
* sits in (the clamping itself lives in `@eldrajs/theme-core`'s `clampHeadingLevel`). That prop
|
|
773
|
+
* landed with exactly one of the nine call sites using it, which left an `h1` typed into an
|
|
774
|
+
* article body producing a second `<h1>` on the article page — the very invariant
|
|
775
|
+
* `test/pages/article.spec.ts` asserts, passing only because the fixture happens to use levels
|
|
776
|
+
* 2/2/2/3. The floor is a per-call-site decision, so it cannot be enforced inside the component;
|
|
777
|
+
* this scans the source instead, the same shape as `packages/ui`'s own hygiene spec. Each floor's
|
|
778
|
+
* *value* is argued in a comment next to the call site it belongs to, and
|
|
779
|
+
* `test/richText.spec.ts` asserts the behaviour for `article`.
|
|
780
|
+
*/
|
|
781
|
+
it('every EldraRichText call site in blocks/** passes a min-heading-level', () => {
|
|
782
|
+
const blocksDir = join(templateDir, 'blocks');
|
|
783
|
+
const offenders: string[] = [];
|
|
784
|
+
let callSites = 0;
|
|
785
|
+
|
|
786
|
+
for (const apiId of expectedBlocks) {
|
|
787
|
+
for (const file of blockSourceFiles(join(blocksDir, apiId))) {
|
|
788
|
+
const source = readFileSync(file, 'utf8');
|
|
789
|
+
// Each `<EldraRichText …>` element up to its closing `/>` — the theme never writes it with
|
|
790
|
+
// a separate closing tag.
|
|
791
|
+
for (const match of source.matchAll(/<EldraRichText\b[\s\S]*?\/>/g)) {
|
|
792
|
+
callSites += 1;
|
|
793
|
+
if (!match[0].includes('min-heading-level')) {
|
|
794
|
+
offenders.push(file.slice(blocksDir.length + 1));
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// Guards the scan itself: the starter renders rich text in nine places today.
|
|
801
|
+
expect(callSites).toBeGreaterThanOrEqual(9);
|
|
802
|
+
expect(
|
|
803
|
+
offenders,
|
|
804
|
+
'a rich-text document has no heading outline of its own — pass `:min-heading-level` for the ' +
|
|
805
|
+
'level the document sits under in this block, and say why in a comment next to it'
|
|
806
|
+
).toEqual([]);
|
|
807
|
+
});
|
|
808
|
+
it('declares no validators on any list field, at any depth — Core rejects every one of them at deploy', () => {
|
|
809
|
+
const result = scanTheme({ themeDir: templateDir, framework: 'nuxt' });
|
|
810
|
+
const offenders: string[] = [];
|
|
811
|
+
const walk = (fields: ThemeBlockManifestField[], path: string) => {
|
|
812
|
+
for (const field of fields) {
|
|
813
|
+
const at = `${path}${field.fieldId}`;
|
|
814
|
+
if (field.type === 'list' && field.validators !== undefined) offenders.push(at);
|
|
815
|
+
const item = field.metadata?.item as ThemeBlockManifestField | undefined;
|
|
816
|
+
const nested = (field.metadata?.fields ?? item?.metadata?.fields) as
|
|
817
|
+
| ThemeBlockManifestField[]
|
|
818
|
+
| undefined;
|
|
819
|
+
if (nested !== undefined) walk(nested, `${at}.`);
|
|
820
|
+
}
|
|
821
|
+
};
|
|
822
|
+
for (const block of result.manifest!.blocks) walk(block.fields, `${block.apiId}.`);
|
|
823
|
+
expect(offenders).toEqual([]);
|
|
824
|
+
});
|
|
825
|
+
});
|
|
826
|
+
|
|
827
|
+
/** Every shipped `.vue` and `.ts` module under one block directory (never its `__tests__/`). */
|
|
828
|
+
function blockSourceFiles(dir: string): string[] {
|
|
829
|
+
const out: string[] = [];
|
|
830
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
831
|
+
if (entry.name === '__tests__') continue;
|
|
832
|
+
const full = join(dir, entry.name);
|
|
833
|
+
if (entry.isDirectory()) out.push(...blockSourceFiles(full));
|
|
834
|
+
else if (entry.name.endsWith('.vue') || entry.name.endsWith('.ts')) out.push(full);
|
|
835
|
+
}
|
|
836
|
+
return out;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
interface ThemeBlockManifestField {
|
|
840
|
+
fieldId: string;
|
|
841
|
+
type: string;
|
|
842
|
+
validators?: { required?: boolean };
|
|
843
|
+
metadata?: {
|
|
844
|
+
framing?: boolean;
|
|
845
|
+
item?: ThemeBlockManifestField;
|
|
846
|
+
fields?: ThemeBlockManifestField[];
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
interface ThemeBlockManifest {
|
|
850
|
+
fields?: ThemeBlockManifestField[];
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
/** Every `media` field id under one block that opts into framing, nested fields included. */
|
|
854
|
+
function framingFieldIds(fields: ThemeBlockManifestField[], prefix = ''): string[] {
|
|
855
|
+
const out: string[] = [];
|
|
856
|
+
for (const field of fields) {
|
|
857
|
+
const path = prefix === '' ? field.fieldId : `${prefix}.${field.fieldId}`;
|
|
858
|
+
if (field.type === 'media' && field.metadata?.framing === true) out.push(path);
|
|
859
|
+
const item = field.metadata?.item;
|
|
860
|
+
if (item !== undefined) out.push(...framingFieldIds([item], path));
|
|
861
|
+
const nested = field.metadata?.fields;
|
|
862
|
+
if (nested !== undefined) out.push(...framingFieldIds(nested, path));
|
|
863
|
+
}
|
|
864
|
+
return out;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
describe('seeded templates and pages (app/templates.ts)', () => {
|
|
868
|
+
// The seeds and roles as the theme declares them in `nuxt.config.ts`, put through the very
|
|
869
|
+
// scanner the build runs — so every assertion below is about what lands in
|
|
870
|
+
// `.eldra/manifest.json` and, from there, in the deploy Core seeds a site from.
|
|
871
|
+
const scanned = scanTheme({
|
|
872
|
+
themeDir: templateDir,
|
|
873
|
+
framework: 'nuxt',
|
|
874
|
+
// `starterSeeds()` is what `nuxt.config.ts` passes: the three route templates and the three
|
|
875
|
+
// page seeds in one list, exactly as `eldra.templates` takes them.
|
|
876
|
+
templates: starterSeeds(),
|
|
877
|
+
templateRoles: starterTemplateRoles(),
|
|
878
|
+
});
|
|
879
|
+
|
|
880
|
+
/** The blocks of one `pages/<name>.page.json` fixture in order, minus the two role blocks. */
|
|
881
|
+
const fixtureBlocks = (name: string): string[] =>
|
|
882
|
+
(
|
|
883
|
+
JSON.parse(readFileSync(join(templateDir, 'pages', `${name}.page.json`), 'utf8')) as {
|
|
884
|
+
blocks: Array<{ apiId: string; id: string }>;
|
|
885
|
+
}
|
|
886
|
+
).blocks
|
|
887
|
+
.filter((block) => block.apiId !== 'navigation' && block.apiId !== 'footer')
|
|
888
|
+
.map((block) => `${block.apiId}#${block.id}`);
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* The emitted page-seed wire shape, which Core decodes strictly — an unknown key fails the whole
|
|
892
|
+
* manifest ingest, so this asserts the *exact* object rather than a subset.
|
|
893
|
+
*
|
|
894
|
+
* Three things in it are easy to lose and impossible to notice afterwards: `type` rather than
|
|
895
|
+
* `apiId` (the key Core reads), the reserved `@header`/`@footer` placements standing where the
|
|
896
|
+
* fixture puts the two role blocks, and `required: true` on the one block the page exists for.
|
|
897
|
+
*/
|
|
898
|
+
it('emits each seeded page as slug, title and its entries in document order', () => {
|
|
899
|
+
const pageSeeds = scanned.manifest!.pageSeeds!;
|
|
900
|
+
expect(pageSeeds.map((seed) => [seed.slug, seed.title])).toEqual([
|
|
901
|
+
['cart', 'Your cart'],
|
|
902
|
+
['wishlist', 'Your wishlist'],
|
|
903
|
+
['search', 'Search'],
|
|
904
|
+
['products', 'All products'],
|
|
905
|
+
]);
|
|
906
|
+
for (const seed of pageSeeds) {
|
|
907
|
+
expect(Object.keys(seed)).toEqual(['slug', 'title', 'blocks']);
|
|
908
|
+
}
|
|
909
|
+
// The announcement bar precedes the header, which is only expressible because a region is a
|
|
910
|
+
// placement in the page's own order rather than a frame around the blocks.
|
|
911
|
+
expect(pageSeeds[0]!.blocks.map((entry) => entry.type)).toEqual([
|
|
912
|
+
'announcement-bar',
|
|
913
|
+
'@header',
|
|
914
|
+
'breadcrumbs',
|
|
915
|
+
'cart',
|
|
916
|
+
'product-carousel',
|
|
917
|
+
'@footer',
|
|
918
|
+
]);
|
|
919
|
+
const fixed = pageSeeds.map((seed) =>
|
|
920
|
+
seed.blocks.filter((entry) => 'required' in entry && entry.required === true)
|
|
921
|
+
);
|
|
922
|
+
expect(fixed.map((entries) => entries.map((entry) => entry.type))).toEqual([
|
|
923
|
+
['cart'],
|
|
924
|
+
['wishlist'],
|
|
925
|
+
['search'],
|
|
926
|
+
// `/products`' own fixed block is the grid: a catalogue page without the catalogue is not a
|
|
927
|
+
// page a merchant should be able to empty by accident.
|
|
928
|
+
['collection-grid'],
|
|
929
|
+
]);
|
|
930
|
+
// A region placement is the reserved type and nothing else; a block always carries data.
|
|
931
|
+
for (const seed of pageSeeds) {
|
|
932
|
+
for (const entry of seed.blocks) {
|
|
933
|
+
if (entry.type.startsWith('@')) expect(Object.keys(entry)).toEqual(['type']);
|
|
934
|
+
else expect(Object.keys(entry)).toContain('data');
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
// No node ids reach a page seed: there is no layout for one to be referenced from.
|
|
938
|
+
expect(JSON.stringify(pageSeeds)).not.toContain('"id"');
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
/**
|
|
942
|
+
* The home page is deliberately **not** a page seed: it stays the `templates` entry Core has
|
|
943
|
+
* always mapped to the site's root Page, so this manifest's home seed is the one every previous
|
|
944
|
+
* deploy sent. A second seed for the same slug would be one of the two being silently ignored.
|
|
945
|
+
*/
|
|
946
|
+
it('leaves the home page to its template seed and never seeds the slug "home"', () => {
|
|
947
|
+
expect(scanned.manifest!.templates!.map((template) => template.schemaApiId)).toContain('home');
|
|
948
|
+
expect(scanned.manifest!.pageSeeds!.map((seed) => seed.slug)).not.toContain('home');
|
|
949
|
+
});
|
|
950
|
+
|
|
951
|
+
it('seeds the three pages with the one block each of them exists for, and nothing pinned', () => {
|
|
952
|
+
const pageSeeds = scanned.manifest!.pageSeeds!;
|
|
953
|
+
const cart = pageSeeds[0]!.blocks.find((entry) => entry.type === 'cart')!;
|
|
954
|
+
const search = pageSeeds[2]!.blocks.find((entry) => entry.type === 'search')!;
|
|
955
|
+
|
|
956
|
+
// The entry each code route used to build in TypeScript, now the page's own editable copy.
|
|
957
|
+
expect('data' in cart ? cart.data : {}).toMatchObject({ variant: 'page', emptyLinkHref: '/' });
|
|
958
|
+
expect('data' in search ? search.data : {}).toMatchObject({ variant: 'results-page' });
|
|
959
|
+
// `popularSearches` and `noResultsCollection` are a merchant's answers, so the seed ships
|
|
960
|
+
// neither — the same decision the code route this page replaced documented.
|
|
961
|
+
expect('data' in search ? Object.keys(search.data) : []).not.toContain('popularSearches');
|
|
962
|
+
expect('data' in search ? Object.keys(search.data) : []).not.toContain('noResultsCollection');
|
|
963
|
+
});
|
|
964
|
+
|
|
965
|
+
it('seeds exactly the product, collection and home templates', () => {
|
|
966
|
+
const templates = scanned.manifest!.templates!;
|
|
967
|
+
expect(
|
|
968
|
+
templates.map((template) => [template.routePattern, template.schemaApiId, template.title])
|
|
969
|
+
).toEqual([
|
|
970
|
+
['/products/:slug', 'catalog:product', 'Product'],
|
|
971
|
+
['/collections/:slug', 'catalog:collection', 'Collection'],
|
|
972
|
+
// A category is addressed by its whole canonical path, so its parameter is the catch-all
|
|
973
|
+
// `:path*` — the one pattern in the kit that carries a star.
|
|
974
|
+
['/categories/:path*', 'catalog:category', 'Category'],
|
|
975
|
+
['/', 'home', 'Home'],
|
|
976
|
+
]);
|
|
977
|
+
});
|
|
978
|
+
|
|
979
|
+
it('seeds each sample page’s blocks, in order, minus the two role blocks', () => {
|
|
980
|
+
const templates = scanned.manifest!.templates!;
|
|
981
|
+
const seeded = (index: number) =>
|
|
982
|
+
templates[index]!.blocks.map((block) => `${block.apiId}#${block.id}`);
|
|
983
|
+
expect(seeded(0)).toEqual(fixtureBlocks('product'));
|
|
984
|
+
expect(seeded(1)).toEqual(fixtureBlocks('collection'));
|
|
985
|
+
expect(seeded(2)).toEqual(fixtureBlocks('category'));
|
|
986
|
+
expect(seeded(3)).toEqual(fixtureBlocks('home'));
|
|
987
|
+
// Guards the filter itself: the fixtures do carry a navigation and a footer block, so an
|
|
988
|
+
// empty filter would still make the three assertions above pass.
|
|
989
|
+
expect(seeded(0)).not.toContain('navigation#product-navigation');
|
|
990
|
+
expect(seeded(0)).not.toContain('footer#product-footer');
|
|
991
|
+
// And each seed's generated layout frames those blocks with the two roles, in one column.
|
|
992
|
+
for (const [index, template] of templates.entries()) {
|
|
993
|
+
const placed = template.layout.root.children.map((child) =>
|
|
994
|
+
child.type === 'reusable' ? child.role : child.entryId
|
|
995
|
+
);
|
|
996
|
+
expect(placed).toEqual([
|
|
997
|
+
'header',
|
|
998
|
+
...templates[index]!.blocks.map((block) => block.id),
|
|
999
|
+
'footer',
|
|
1000
|
+
]);
|
|
1001
|
+
}
|
|
1002
|
+
});
|
|
1003
|
+
|
|
1004
|
+
it('pins no product or collection into a catalog seed, and takes the title from the route', () => {
|
|
1005
|
+
// The live failure this guards: every seeded product page rendered the
|
|
1006
|
+
// fixture's own product, because `product-detail.productHandle` (and the
|
|
1007
|
+
// collection blocks' own collection field) won over the route the template
|
|
1008
|
+
// was resolved by.
|
|
1009
|
+
const templates = scanned.manifest!.templates!;
|
|
1010
|
+
const catalogSeeds = templates.filter((template) => template.schemaApiId !== 'home');
|
|
1011
|
+
expect(catalogSeeds).toHaveLength(3);
|
|
1012
|
+
|
|
1013
|
+
const pinned: Record<string, readonly string[]> = {
|
|
1014
|
+
'product-detail': ['productHandle'],
|
|
1015
|
+
'collection-header': ['collection', 'title', 'description'],
|
|
1016
|
+
'collection-grid': ['collection'],
|
|
1017
|
+
'product-carousel': ['viewAllHref'],
|
|
1018
|
+
};
|
|
1019
|
+
for (const template of catalogSeeds) {
|
|
1020
|
+
for (const block of template.blocks) {
|
|
1021
|
+
for (const fieldId of pinned[block.apiId] ?? []) {
|
|
1022
|
+
expect(`${block.apiId}.${fieldId}`).toBe(`${block.apiId}.${fieldId}`);
|
|
1023
|
+
expect(Object.hasOwn(block.data, fieldId)).toBe(false);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
// The home seed keeps its carousel's collection: there is no route context
|
|
1029
|
+
// on `/` for the block to fall back to, and the carousel has no route
|
|
1030
|
+
// fallback at all. A theme cannot know the organisation's collection ids, so
|
|
1031
|
+
// it names the collection by slug and Core resolves it on deploy.
|
|
1032
|
+
const home = templates.find((template) => template.schemaApiId === 'home')!;
|
|
1033
|
+
const carousel = home.blocks.find((block) => block.apiId === 'product-carousel')!;
|
|
1034
|
+
expect(carousel.data.sourceCollection).toEqual({
|
|
1035
|
+
_type: 'collection',
|
|
1036
|
+
slug: 'the-winter-edit',
|
|
1037
|
+
});
|
|
1038
|
+
expect(Object.hasOwn(carousel.data, 'sourceHandle')).toBe(false);
|
|
1039
|
+
|
|
1040
|
+
// Breadcrumbs: Home and nothing else in the data, with the current page's
|
|
1041
|
+
// own title bound on the layout node instead of the fixture's product name.
|
|
1042
|
+
for (const template of catalogSeeds) {
|
|
1043
|
+
const crumbs = template.blocks.find((block) => block.apiId === 'breadcrumbs')!;
|
|
1044
|
+
expect(crumbs.data.trail).toEqual([]);
|
|
1045
|
+
expect(crumbs.data.showHome).toBe(true);
|
|
1046
|
+
expect(Object.hasOwn(crumbs.data, 'currentTitle')).toBe(false);
|
|
1047
|
+
const node = template.layout.root.children.find(
|
|
1048
|
+
(child) => child.type === 'block' && child.entryId === crumbs.id
|
|
1049
|
+
);
|
|
1050
|
+
expect(node).toMatchObject({ templates: { currentTitle: '{{ title }}' } });
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
// The collection header carries the same treatment for the fields that are
|
|
1054
|
+
// the collection's own: emptied here, bound to the routed collection's
|
|
1055
|
+
// title on the node. Its `description` is rich text, which a text template
|
|
1056
|
+
// cannot render, so it is only emptied — the block falls back to the
|
|
1057
|
+
// collection's own description anyway.
|
|
1058
|
+
const collection = templates.find((template) => template.schemaApiId === 'catalog:collection')!;
|
|
1059
|
+
const header = collection.blocks.find((block) => block.apiId === 'collection-header')!;
|
|
1060
|
+
expect(Object.hasOwn(header.data, 'title')).toBe(false);
|
|
1061
|
+
expect(Object.hasOwn(header.data, 'description')).toBe(false);
|
|
1062
|
+
expect(header.data.trail).toEqual([]);
|
|
1063
|
+
expect(header.data.subcollections).toEqual([]);
|
|
1064
|
+
expect(
|
|
1065
|
+
collection.layout.root.children.find(
|
|
1066
|
+
(child) => child.type === 'block' && child.entryId === header.id
|
|
1067
|
+
)
|
|
1068
|
+
).toMatchObject({ templates: { title: '{{ title }}' } });
|
|
1069
|
+
});
|
|
1070
|
+
|
|
1071
|
+
it('names the sample pages’ own product and collection nowhere in a catalog seed', () => {
|
|
1072
|
+
// The blunt guard behind the per-field assertions above: a catalog template
|
|
1073
|
+
// renders whatever its `:slug` resolved to, so the fixture's product and
|
|
1074
|
+
// collection must not survive anywhere in its blocks — not in a handle, a
|
|
1075
|
+
// title, a trail, a link, or a paragraph of tab copy. The home seed is
|
|
1076
|
+
// exempt: it names them the way any hand-authored home page does.
|
|
1077
|
+
const templates = scanned.manifest!.templates!;
|
|
1078
|
+
const named = /merino|winter edit|the-winter-edit/i;
|
|
1079
|
+
for (const template of templates.filter((entry) => entry.schemaApiId !== 'home')) {
|
|
1080
|
+
for (const block of template.blocks) {
|
|
1081
|
+
expect({ block: block.apiId, named: named.test(JSON.stringify(block.data)) }).toEqual({
|
|
1082
|
+
block: block.apiId,
|
|
1083
|
+
named: false,
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
// And the guard guards something: the fixtures do name them, and the home
|
|
1088
|
+
// seed still does.
|
|
1089
|
+
const home = templates.find((template) => template.schemaApiId === 'home')!;
|
|
1090
|
+
expect(named.test(JSON.stringify(home.blocks))).toBe(true);
|
|
1091
|
+
});
|
|
1092
|
+
|
|
1093
|
+
it('carries the navigation and footer role data the seeds place', () => {
|
|
1094
|
+
const roles = scanned.manifest!.templateRoles!;
|
|
1095
|
+
expect(roles.header?.apiId).toBe('navigation');
|
|
1096
|
+
expect(roles.footer?.apiId).toBe('footer');
|
|
1097
|
+
// Real data, not an empty stub: the home fixture's own header and footer settings.
|
|
1098
|
+
expect(roles.header?.data.brandText).toBe('Northwind Goods');
|
|
1099
|
+
expect(roles.header?.data.showSearch).toBe(true);
|
|
1100
|
+
expect(roles.footer?.data.description).toEqual(expect.stringContaining('small workshops'));
|
|
1101
|
+
});
|
|
1102
|
+
|
|
1103
|
+
it('seeds a header and footer with no destinations at all', () => {
|
|
1104
|
+
// A theme cannot know an organisation's own pages, collections or policies, so it ships none:
|
|
1105
|
+
// every seeded link would resolve to nothing on a fresh org and render as a label or a bare
|
|
1106
|
+
// path to a page that does not exist. The *fields* stay — an author fills them in Studio — and
|
|
1107
|
+
// `blocks/*/mock.json` keeps its demo rows, because that is the state of a block an author has
|
|
1108
|
+
// just inserted, not the state a deploy seeds.
|
|
1109
|
+
const roles = scanned.manifest!.templateRoles!;
|
|
1110
|
+
expect(roles.header!.data.links).toEqual([]);
|
|
1111
|
+
expect(roles.header!.data.cta).toBeUndefined();
|
|
1112
|
+
expect(roles.header!.data.ctaLabel).toBeUndefined();
|
|
1113
|
+
expect(roles.footer!.data.groups).toEqual([]);
|
|
1114
|
+
expect(roles.footer!.data.links).toEqual([]);
|
|
1115
|
+
expect(roles.footer!.data.legalLinks).toEqual([]);
|
|
1116
|
+
expect(roles.footer!.data.social).toEqual([]);
|
|
1117
|
+
|
|
1118
|
+
// And the same is true of every page fixture the seeds are built from, not just the home one
|
|
1119
|
+
// the roles happen to come from.
|
|
1120
|
+
for (const name of ['home', 'product', 'collection', 'article']) {
|
|
1121
|
+
const fixture = JSON.parse(
|
|
1122
|
+
readFileSync(join(templateDir, 'pages', `${name}.page.json`), 'utf8')
|
|
1123
|
+
) as { blocks: Array<{ apiId: string; data: Record<string, unknown> }> };
|
|
1124
|
+
const header = fixture.blocks.find((block) => block.apiId === 'navigation')!;
|
|
1125
|
+
const footer = fixture.blocks.find((block) => block.apiId === 'footer')!;
|
|
1126
|
+
expect({ page: name, links: header.data.links }).toEqual({ page: name, links: [] });
|
|
1127
|
+
expect({ page: name, groups: footer.data.groups, legal: footer.data.legalLinks }).toEqual({
|
|
1128
|
+
page: name,
|
|
1129
|
+
groups: [],
|
|
1130
|
+
legal: [],
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
* The retirement half of the same decision: the platform has no customer login, so the header
|
|
1137
|
+
* offers no account control at all and `showAccount` is gone from the schema as of version 4.
|
|
1138
|
+
* A removed field is declared by the `version` bump and nothing else — `@eldrajs/vite-plugin-theme`
|
|
1139
|
+
* accepts no `migrations` step for one (a step must carry `renames` or `convertToLink`), and Core's
|
|
1140
|
+
* own retirement pass stashes whatever an entry held as `showAccount__v3`.
|
|
1141
|
+
*/
|
|
1142
|
+
it('ships no showAccount field, at a version that tells Core to retire it', () => {
|
|
1143
|
+
const navigation = scanned.manifest!.blocks.find((block) => block.apiId === 'navigation')!;
|
|
1144
|
+
expect(navigation.fields.map((field) => field.fieldId)).not.toContain('showAccount');
|
|
1145
|
+
expect(navigation.version).toBe(4);
|
|
1146
|
+
// No step names it: a retire has no rename to declare.
|
|
1147
|
+
const named = (navigation.migrations ?? []).flatMap((step) => [
|
|
1148
|
+
...(step.renames ?? []).map((rename) => rename.from),
|
|
1149
|
+
...(step.convertToLink ?? []).map((conversion) => conversion.from),
|
|
1150
|
+
]);
|
|
1151
|
+
expect(named).not.toContain('showAccount');
|
|
1152
|
+
});
|
|
1153
|
+
|
|
1154
|
+
it('seeds Core-valid data: every seed block and both roles pass the mock.json rules', () => {
|
|
1155
|
+
// `scanTheme` runs `templates[].blocks[].data` and `templateRoles.*.data` through exactly the
|
|
1156
|
+
// walk it applies to every block's `mock.json` — the rule `eldra-theme validate` enforces —
|
|
1157
|
+
// so an error here is a seed the CMS would 400 on deploy.
|
|
1158
|
+
expect(scanned.errors).toEqual([]);
|
|
1159
|
+
|
|
1160
|
+
// And proven directly, because an empty error list would also be what a scanner that never
|
|
1161
|
+
// looked at the seeds returns: the sample pages carry demo imagery
|
|
1162
|
+
// (`{assetId: "demo-hero", url, altText, width, height}`) in `hero.image`, `hero.slides[]`,
|
|
1163
|
+
// `split-content.rows[]`, `testimonials.items[]`, `collection-header.image` and `cta.image` —
|
|
1164
|
+
// none of it may survive into a seed.
|
|
1165
|
+
const seeded = JSON.stringify([scanned.manifest!.templates, scanned.manifest!.templateRoles]);
|
|
1166
|
+
// A media value's own `url` key, not the `url` a `link` value legitimately carries for
|
|
1167
|
+
// `kind: "url"` — so the match is the demo asset's shape, and a header's `/journal` link is
|
|
1168
|
+
// left alone.
|
|
1169
|
+
expect(seeded).not.toMatch(/"assetId"\s*:\s*"demo-/);
|
|
1170
|
+
expect(seeded).not.toContain('"altText"');
|
|
1171
|
+
expect(seeded).not.toContain('demo-');
|
|
1172
|
+
// The non-media copy of those same blocks is still there, so the strip took the media and
|
|
1173
|
+
// not the block.
|
|
1174
|
+
expect(scanned.manifest!.templateRoles!.header!.data.brandText).toBe('Northwind Goods');
|
|
1175
|
+
});
|
|
1176
|
+
|
|
1177
|
+
it('strips exactly the media values the CMS refuses, at every nesting depth', () => {
|
|
1178
|
+
const asset = '3f1c5a2e-9b4d-4c7a-8e21-0d6f4b9c1a55';
|
|
1179
|
+
const fields = [
|
|
1180
|
+
{ fieldId: 'heading', type: 'string' },
|
|
1181
|
+
{ fieldId: 'image', type: 'media' },
|
|
1182
|
+
{ fieldId: 'logo', type: 'media' },
|
|
1183
|
+
{ fieldId: 'shots', type: 'media', metadata: { multiple: true } },
|
|
1184
|
+
{
|
|
1185
|
+
fieldId: 'seo',
|
|
1186
|
+
type: 'composite',
|
|
1187
|
+
metadata: { fields: [{ fieldId: 'share', type: 'media' }] },
|
|
1188
|
+
},
|
|
1189
|
+
{ fieldId: 'photos', type: 'list', metadata: { item: { fieldId: 'item', type: 'media' } } },
|
|
1190
|
+
{
|
|
1191
|
+
fieldId: 'links',
|
|
1192
|
+
type: 'list',
|
|
1193
|
+
metadata: {
|
|
1194
|
+
item: {
|
|
1195
|
+
fieldId: 'item',
|
|
1196
|
+
type: 'composite',
|
|
1197
|
+
metadata: {
|
|
1198
|
+
fields: [
|
|
1199
|
+
{ fieldId: 'label', type: 'string' },
|
|
1200
|
+
{
|
|
1201
|
+
fieldId: 'features',
|
|
1202
|
+
type: 'list',
|
|
1203
|
+
metadata: {
|
|
1204
|
+
item: {
|
|
1205
|
+
fieldId: 'item',
|
|
1206
|
+
type: 'composite',
|
|
1207
|
+
metadata: { fields: [{ fieldId: 'image', type: 'media' }] },
|
|
1208
|
+
},
|
|
1209
|
+
},
|
|
1210
|
+
},
|
|
1211
|
+
],
|
|
1212
|
+
},
|
|
1213
|
+
},
|
|
1214
|
+
},
|
|
1215
|
+
},
|
|
1216
|
+
];
|
|
1217
|
+
const data = {
|
|
1218
|
+
heading: 'Kept',
|
|
1219
|
+
image: { assetId: 'demo-hero', url: '/demo/hero.svg', altText: 'Hero' },
|
|
1220
|
+
logo: { assetId: asset, framing: { x: 0.5 } },
|
|
1221
|
+
shots: [{ assetId: asset }, { assetId: 'demo-2', url: '/demo/2.svg' }],
|
|
1222
|
+
seo: { share: { assetId: 'demo-share', url: '/demo/share.svg' } },
|
|
1223
|
+
photos: [{ assetId: 'demo-a', url: '/demo/a.svg' }],
|
|
1224
|
+
links: [{ label: 'Shop', features: [{ image: { assetId: 'demo-f', url: '/demo/f.svg' } }] }],
|
|
1225
|
+
untyped: { assetId: 'demo-x', url: '/demo/x.svg' },
|
|
1226
|
+
};
|
|
1227
|
+
const stripped = stripSeedMedia(data, fields, 'demo-block');
|
|
1228
|
+
|
|
1229
|
+
expect(stripped.heading).toBe('Kept');
|
|
1230
|
+
// A write-valid value is a real asset the theme meant to seed — kept, `framing` included.
|
|
1231
|
+
expect(stripped.logo).toEqual({ assetId: asset, framing: { x: 0.5 } });
|
|
1232
|
+
expect(stripped.shots).toEqual([{ assetId: asset }]);
|
|
1233
|
+
// Everything else is dropped rather than blanked: absent is what the CMS accepts.
|
|
1234
|
+
expect(Object.hasOwn(stripped, 'image')).toBe(false);
|
|
1235
|
+
expect(stripped.seo).toEqual({});
|
|
1236
|
+
expect(Object.hasOwn(stripped, 'photos')).toBe(false);
|
|
1237
|
+
expect(stripped.links).toEqual([{ label: 'Shop', features: [{}] }]);
|
|
1238
|
+
// A key no field declares is data the walk never reaches, and is left alone — the block's
|
|
1239
|
+
// field list is the only thing that decides what a media value is.
|
|
1240
|
+
expect(stripped.untyped).toEqual({ assetId: 'demo-x', url: '/demo/x.svg' });
|
|
1241
|
+
// Pure: the caller's fixture is never mutated.
|
|
1242
|
+
expect(data.image).toEqual({ assetId: 'demo-hero', url: '/demo/hero.svg', altText: 'Hero' });
|
|
1243
|
+
});
|
|
1244
|
+
|
|
1245
|
+
/**
|
|
1246
|
+
* Core creates a seed's block entries **published**, so a seed has to satisfy publish
|
|
1247
|
+
* validation as well as the write-side media rule — and a published entry cannot omit a value
|
|
1248
|
+
* for a `required` field. There is nothing to invent for a media field, so the only honest
|
|
1249
|
+
* moves are: drop the list item that carried it, or refuse to seed the block at all.
|
|
1250
|
+
*/
|
|
1251
|
+
it('drops a list item whose required media cannot be seeded, and refuses a block whose own is', () => {
|
|
1252
|
+
const required = { required: true };
|
|
1253
|
+
const fields = [
|
|
1254
|
+
{
|
|
1255
|
+
fieldId: 'slides',
|
|
1256
|
+
type: 'list',
|
|
1257
|
+
metadata: {
|
|
1258
|
+
item: {
|
|
1259
|
+
fieldId: 'item',
|
|
1260
|
+
type: 'composite',
|
|
1261
|
+
metadata: {
|
|
1262
|
+
fields: [
|
|
1263
|
+
{ fieldId: 'caption', type: 'string' },
|
|
1264
|
+
{ fieldId: 'image', type: 'media', validators: required },
|
|
1265
|
+
],
|
|
1266
|
+
},
|
|
1267
|
+
},
|
|
1268
|
+
},
|
|
1269
|
+
},
|
|
1270
|
+
{
|
|
1271
|
+
fieldId: 'people',
|
|
1272
|
+
type: 'list',
|
|
1273
|
+
metadata: {
|
|
1274
|
+
item: {
|
|
1275
|
+
fieldId: 'item',
|
|
1276
|
+
type: 'composite',
|
|
1277
|
+
metadata: {
|
|
1278
|
+
fields: [
|
|
1279
|
+
{ fieldId: 'name', type: 'string' },
|
|
1280
|
+
{ fieldId: 'avatar', type: 'media' },
|
|
1281
|
+
],
|
|
1282
|
+
},
|
|
1283
|
+
},
|
|
1284
|
+
},
|
|
1285
|
+
},
|
|
1286
|
+
];
|
|
1287
|
+
const stripped = stripSeedMedia(
|
|
1288
|
+
{
|
|
1289
|
+
slides: [
|
|
1290
|
+
{ caption: 'Demo', image: { assetId: 'demo-1', url: '/demo/1.svg' } },
|
|
1291
|
+
{ caption: 'Real', image: { assetId: '3f1c5a2e-9b4d-4c7a-8e21-0d6f4b9c1a55' } },
|
|
1292
|
+
{ caption: 'Missing' },
|
|
1293
|
+
],
|
|
1294
|
+
people: [{ name: 'Ada', avatar: { assetId: 'demo-2', url: '/demo/2.svg' } }],
|
|
1295
|
+
},
|
|
1296
|
+
fields,
|
|
1297
|
+
'demo-block'
|
|
1298
|
+
);
|
|
1299
|
+
// The item whose required image was stripped goes, and so does the one that never had it.
|
|
1300
|
+
// The item carrying a real asset id stays, image and all.
|
|
1301
|
+
expect(stripped.slides).toEqual([
|
|
1302
|
+
{ caption: 'Real', image: { assetId: '3f1c5a2e-9b4d-4c7a-8e21-0d6f4b9c1a55' } },
|
|
1303
|
+
]);
|
|
1304
|
+
// An *optional* media field in a list item only costs the field, never the item.
|
|
1305
|
+
expect(stripped.people).toEqual([{ name: 'Ada' }]);
|
|
1306
|
+
|
|
1307
|
+
// At the top level of a block there is no item to drop, so the block is unseedable and the
|
|
1308
|
+
// build fails rather than seeding an entry Core refuses to publish. Same for a required media
|
|
1309
|
+
// inside a non-list `composite`: a composite is one value, so it has nothing to drop either.
|
|
1310
|
+
const topLevel = [{ fieldId: 'image', type: 'media', validators: required }];
|
|
1311
|
+
expect(() =>
|
|
1312
|
+
stripSeedMedia({ image: { assetId: 'demo-1', url: '/demo/1.svg' } }, topLevel, 'wallpaper')
|
|
1313
|
+
).toThrow(/wallpaper: cannot be seeded .* "image"/);
|
|
1314
|
+
// Absent is just as unpublishable as stripped, so it is refused the same way.
|
|
1315
|
+
expect(() => stripSeedMedia({}, topLevel, 'wallpaper')).toThrow(/"image"/);
|
|
1316
|
+
expect(() =>
|
|
1317
|
+
stripSeedMedia(
|
|
1318
|
+
{ seo: { share: { assetId: 'demo-1', url: '/demo/1.svg' } } },
|
|
1319
|
+
[
|
|
1320
|
+
{
|
|
1321
|
+
fieldId: 'seo',
|
|
1322
|
+
type: 'composite',
|
|
1323
|
+
metadata: { fields: [{ fieldId: 'share', type: 'media', validators: required }] },
|
|
1324
|
+
},
|
|
1325
|
+
],
|
|
1326
|
+
'wallpaper'
|
|
1327
|
+
)
|
|
1328
|
+
).toThrow(/"seo.share"/);
|
|
1329
|
+
});
|
|
1330
|
+
|
|
1331
|
+
it('seeds no list item that is missing a required media field', () => {
|
|
1332
|
+
// The `hero` seed is the live case: all four of the home fixture's slides require an image,
|
|
1333
|
+
// and all four carry demo imagery, so the seeded hero renders with an empty slideshow rather
|
|
1334
|
+
// than four entries Core would refuse to publish. (Its `mock.json` omits `slides` entirely,
|
|
1335
|
+
// which is the same shape an author gets on insert.)
|
|
1336
|
+
const home = scanned.manifest!.templates!.find((template) => template.schemaApiId === 'home')!;
|
|
1337
|
+
const hero = home.blocks.find((block) => block.apiId === 'hero')!;
|
|
1338
|
+
expect(hero.data.slides).toEqual([]);
|
|
1339
|
+
|
|
1340
|
+
// And the rule generally, walked against each block's own declared field types: no seed
|
|
1341
|
+
// block (or role) may carry a list item without a value for a media field the block marks
|
|
1342
|
+
// required, because Core creates these entries published.
|
|
1343
|
+
const offenders: string[] = [];
|
|
1344
|
+
const byApiId = new Map(scanned.manifest!.blocks.map((block) => [block.apiId, block.fields]));
|
|
1345
|
+
const walk = (
|
|
1346
|
+
fields: ThemeBlockManifestField[],
|
|
1347
|
+
data: Record<string, unknown>,
|
|
1348
|
+
at: string
|
|
1349
|
+
): void => {
|
|
1350
|
+
for (const field of fields) {
|
|
1351
|
+
const value = data[field.fieldId];
|
|
1352
|
+
const path = `${at}.${field.fieldId}`;
|
|
1353
|
+
if (
|
|
1354
|
+
field.type === 'media' &&
|
|
1355
|
+
field.validators?.required === true &&
|
|
1356
|
+
!Object.hasOwn(data, field.fieldId)
|
|
1357
|
+
) {
|
|
1358
|
+
offenders.push(path);
|
|
1359
|
+
}
|
|
1360
|
+
if (field.type === 'composite' && isPlainRecord(value)) {
|
|
1361
|
+
walk(field.metadata?.fields ?? [], value, path);
|
|
1362
|
+
}
|
|
1363
|
+
if (field.type === 'list' && Array.isArray(value)) {
|
|
1364
|
+
const item = field.metadata?.item;
|
|
1365
|
+
if (item?.type !== 'composite') continue;
|
|
1366
|
+
value.forEach((entry, index) => {
|
|
1367
|
+
if (isPlainRecord(entry)) walk(item.metadata?.fields ?? [], entry, `${path}[${index}]`);
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
};
|
|
1372
|
+
const seeded: Array<[string, string, Record<string, unknown>]> = [
|
|
1373
|
+
...scanned.manifest!.templates!.flatMap((template) =>
|
|
1374
|
+
template.blocks.map(
|
|
1375
|
+
(block) =>
|
|
1376
|
+
[block.apiId, `${template.routePattern} ${block.id}`, block.data] as [
|
|
1377
|
+
string,
|
|
1378
|
+
string,
|
|
1379
|
+
Record<string, unknown>,
|
|
1380
|
+
]
|
|
1381
|
+
)
|
|
1382
|
+
),
|
|
1383
|
+
['navigation', 'templateRoles.header', scanned.manifest!.templateRoles!.header!.data],
|
|
1384
|
+
['footer', 'templateRoles.footer', scanned.manifest!.templateRoles!.footer!.data],
|
|
1385
|
+
];
|
|
1386
|
+
for (const [apiId, where, data] of seeded) walk(byApiId.get(apiId) ?? [], data, where);
|
|
1387
|
+
|
|
1388
|
+
expect(offenders).toEqual([]);
|
|
1389
|
+
// Guards the scan itself: the starter declares required media in two list items
|
|
1390
|
+
// (`hero.slides[].image`, `gallery.items[].image`), and `hero` is seeded.
|
|
1391
|
+
expect([...byApiId.values()].flatMap((fields) => requiredListMediaFieldIds(fields))).toContain(
|
|
1392
|
+
'slides[].image'
|
|
1393
|
+
);
|
|
1394
|
+
});
|
|
1395
|
+
});
|
|
1396
|
+
|
|
1397
|
+
function isPlainRecord(value: unknown): value is Record<string, unknown> {
|
|
1398
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
/** Every `<list>[].<media>` path under one block whose media item is `required`. */
|
|
1402
|
+
function requiredListMediaFieldIds(fields: ThemeBlockManifestField[], prefix = ''): string[] {
|
|
1403
|
+
const out: string[] = [];
|
|
1404
|
+
for (const field of fields) {
|
|
1405
|
+
const path = prefix === '' ? field.fieldId : `${prefix}.${field.fieldId}`;
|
|
1406
|
+
if (field.type === 'media' && field.validators?.required === true) out.push(path);
|
|
1407
|
+
const item = field.metadata?.item;
|
|
1408
|
+
if (item?.type === 'composite') {
|
|
1409
|
+
out.push(...requiredListMediaFieldIds(item.metadata?.fields ?? [], `${path}[]`));
|
|
1410
|
+
}
|
|
1411
|
+
if (field.type === 'composite') {
|
|
1412
|
+
out.push(...requiredListMediaFieldIds(field.metadata?.fields ?? [], path));
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
return out;
|
|
1416
|
+
}
|