@eldrajs/theme-cli 0.0.0 → 0.2.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 +77 -0
- package/LICENSE +21 -0
- package/README.md +26 -1
- 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-DprFpjV7.js +535 -0
- package/package.json +50 -2
- package/template/.eldra/block-types.d.ts +429 -0
- package/template/.eldra/manifest.json +9378 -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 +53 -0
- package/template/.storybook/shims-vue.d.ts +10 -0
- package/template/.storybook/virtual-eldra.d.ts +32 -0
- package/template/README.md +293 -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 +248 -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 +1492 -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 +156 -0
- package/template/package.json +56 -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/apple-touch-icon.png +0 -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/public/favicon.ico +0 -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 +335 -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 +85 -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 +387 -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 +164 -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 +170 -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 +49 -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,194 @@
|
|
|
1
|
+
import { defineComponent, h, reactive } from 'vue';
|
|
2
|
+
import { createI18n } from 'vue-i18n';
|
|
3
|
+
import {
|
|
4
|
+
createEldraClient,
|
|
5
|
+
normalizeThemeDesignTokens,
|
|
6
|
+
type EldraClient,
|
|
7
|
+
} from '@eldrajs/theme-core';
|
|
8
|
+
import { flattenMessages } from '@eldrajs/theme-core/i18n';
|
|
9
|
+
// `@eldrajs/theme-vue`'s single bundled entry also re-exports `EldraBlockZone`
|
|
10
|
+
// / `EldraLayout`, which import `virtual:eldra/blocks` /
|
|
11
|
+
// `virtual:eldra/manifest` / `virtual:eldra/breakpoints` at the top level —
|
|
12
|
+
// normally supplied only by `@eldrajs/vite-plugin-theme`'s Vite plugin
|
|
13
|
+
// during a real theme build. `vitest.config.ts` aliases all three to mocks
|
|
14
|
+
// under `test/mocks/`, so importing the package by name here works the same
|
|
15
|
+
// as it does in real app code (`app/composables/useEditing.ts`,
|
|
16
|
+
// `app/composables/useBlockData.ts`) — no relative reach into the theme-vue
|
|
17
|
+
// package's own source and no per-spec `vi.mock('@eldrajs/theme-vue', …)`
|
|
18
|
+
// needed. This matters beyond tidiness: `eldra-theme init` copies this
|
|
19
|
+
// starter (including `test/`) into a customer's project verbatim, where no
|
|
20
|
+
// monorepo sibling exists to reach into at all.
|
|
21
|
+
import {
|
|
22
|
+
createEldraLinkState,
|
|
23
|
+
createEldraLocaleState,
|
|
24
|
+
createEldraPreviewState,
|
|
25
|
+
ELDRA_KEY,
|
|
26
|
+
type EldraContext,
|
|
27
|
+
type EldraLinkState,
|
|
28
|
+
type EldraLocaleState,
|
|
29
|
+
} from '@eldrajs/theme-vue';
|
|
30
|
+
import { CURRENCY_KEY, LOCALE_KEY, MESSAGES_KEY, enUS as uiEnUS } from '@eldrajs/ui';
|
|
31
|
+
import { isIS as uiIsIS } from '@eldrajs/ui/messages/is-IS';
|
|
32
|
+
import { createDemoStorefront } from '../../app/storefront/demo';
|
|
33
|
+
import { STOREFRONT_KEY, type StorefrontCommerce } from '../../app/storefront/types';
|
|
34
|
+
import enUSMessages from '../../i18n/en-US.json';
|
|
35
|
+
import isISMessages from '../../i18n/is-IS.json';
|
|
36
|
+
|
|
37
|
+
const STARTER_DEFAULT_LOCALE = 'en-US';
|
|
38
|
+
|
|
39
|
+
/** The package's own default message set for a content locale — mirrors `app/plugins/
|
|
40
|
+
* eldra-ui-messages.ts`'s `uiPackageMessagesFor`. A test fixes its locale at mount time (no Studio
|
|
41
|
+
* bridge, no live switch — see `[LOCALE_KEY]` below), so a plain lookup is all this needs. */
|
|
42
|
+
function uiMessagesFor(locale: string): typeof uiEnUS {
|
|
43
|
+
return locale === 'is-IS' ? uiIsIS : uiEnUS;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The single place a block's test environment mimics the site — mirrors
|
|
48
|
+
* `.storybook/eldra.ts` + `.storybook/nuxt-link-stub.ts` (the Storybook
|
|
49
|
+
* decorator), so a block sees the same shape of `EldraContext` under
|
|
50
|
+
* `mount()` as it does as a story or on a real page: a client (never
|
|
51
|
+
* called — tests pass `entry` data directly), read mode (`preview.active`
|
|
52
|
+
* stays `false` — `createEldraPreviewState()`'s default, there is no Studio
|
|
53
|
+
* bridge in tests either), and a fixed content locale.
|
|
54
|
+
*
|
|
55
|
+
* `provideEldra()` (`@eldrajs/theme-vue`) can't be reused directly here: it
|
|
56
|
+
* calls Vue's `provide()`, which needs an active component instance during
|
|
57
|
+
* `setup()`. `mount()`'s `global.provide` takes the context object itself,
|
|
58
|
+
* so this assembles the same shape by hand instead.
|
|
59
|
+
*
|
|
60
|
+
* No gateway and no `virtual:eldra/messages` here either — `vue-i18n` is installed straight from
|
|
61
|
+
* the starter's own two locale files (`global.plugins`), the same way `.storybook/i18n.ts` does for
|
|
62
|
+
* Storybook, so a block's `useI18n()` call resolves. Fixed at mount time, like every other provide
|
|
63
|
+
* here: a spec that needs the switch to be *live* builds its own `createI18n()` call and its own
|
|
64
|
+
* watcher the way `blocks/collection-grid/__tests__/Block.spec.ts`'s "follows a locale switch" spec
|
|
65
|
+
* does, rather than this shared helper carrying reactive plumbing every other caller pays for.
|
|
66
|
+
*/
|
|
67
|
+
export function mountOptions(
|
|
68
|
+
props: { entry: { id: string; data: Record<string, unknown> } },
|
|
69
|
+
options: {
|
|
70
|
+
locale?: string;
|
|
71
|
+
links?: Partial<EldraLinkState>;
|
|
72
|
+
/**
|
|
73
|
+
* Which content locale this page is, and how a destination is spelled in it. One unprefixed
|
|
74
|
+
* site by default — what a single-locale store is, and what every block spec but
|
|
75
|
+
* `test/localePrefix.spec.ts` is about.
|
|
76
|
+
*/
|
|
77
|
+
locales?: Partial<EldraLocaleState>;
|
|
78
|
+
/**
|
|
79
|
+
* What the store sells in, for a spec about money: the demo store's own `DEMO_COMMERCE` (US
|
|
80
|
+
* dollars) by default, `null` for a store that publishes no currency at all. Both the
|
|
81
|
+
* storefront's `commerce` and `@eldrajs/ui`'s `CURRENCY_KEY` come from this one value, the
|
|
82
|
+
* same way the two plugins take both from one runtime-config read on a real page.
|
|
83
|
+
*/
|
|
84
|
+
commerce?: StorefrontCommerce | null;
|
|
85
|
+
} = {}
|
|
86
|
+
): {
|
|
87
|
+
props: { entry: { id: string; data: Record<string, unknown> } };
|
|
88
|
+
global: {
|
|
89
|
+
plugins: unknown[];
|
|
90
|
+
provide: Record<symbol, unknown>;
|
|
91
|
+
components: Record<string, unknown>;
|
|
92
|
+
stubs: Record<string, unknown>;
|
|
93
|
+
};
|
|
94
|
+
} {
|
|
95
|
+
const locale = options.locale ?? STARTER_DEFAULT_LOCALE;
|
|
96
|
+
const context = createTestEldraContext(locale, options.links, options.locales);
|
|
97
|
+
// The same priority `app/plugins/eldra-i18n.ts` reads: a page's
|
|
98
|
+
// own `locales.active` — the locale its URL prefix names, or the one Studio is driving — wins
|
|
99
|
+
// over the plain `locale` this mount was given, so a spec that overrides `options.locales.active`
|
|
100
|
+
// (rather than `options.locale`) still gets translated output in that locale.
|
|
101
|
+
const effectiveLocale = context.locales?.active ?? context.preview.locale ?? locale;
|
|
102
|
+
const storefront = createDemoStorefront({ commerce: options.commerce });
|
|
103
|
+
const i18n = createI18n({
|
|
104
|
+
legacy: false,
|
|
105
|
+
locale: effectiveLocale,
|
|
106
|
+
fallbackLocale: STARTER_DEFAULT_LOCALE,
|
|
107
|
+
messages: { 'en-US': enUSMessages, 'is-IS': isISMessages },
|
|
108
|
+
});
|
|
109
|
+
return {
|
|
110
|
+
props,
|
|
111
|
+
global: {
|
|
112
|
+
plugins: [i18n],
|
|
113
|
+
provide: {
|
|
114
|
+
[ELDRA_KEY]: context,
|
|
115
|
+
// The same wiring `app/plugins/eldra-ui-messages.ts` does on a real
|
|
116
|
+
// page: `@eldrajs/ui`'s own strings and number locale follow the
|
|
117
|
+
// content locale, and its store currency comes from the store — the
|
|
118
|
+
// platform's answer there, the demo source's own here — never from the
|
|
119
|
+
// locale.
|
|
120
|
+
[MESSAGES_KEY]: uiMessagesFor(effectiveLocale),
|
|
121
|
+
[LOCALE_KEY]: effectiveLocale,
|
|
122
|
+
[CURRENCY_KEY]: storefront.commerce?.currency,
|
|
123
|
+
// The same wiring `app/plugins/eldra-storefront.ts` does on a real page: a commerce block
|
|
124
|
+
// reads `useStorefront()`, never the client directly, so every block test sees the
|
|
125
|
+
// Northwind demo catalogue (`app/storefront/demo.ts`) instead of a live gateway.
|
|
126
|
+
[STOREFRONT_KEY]: storefront,
|
|
127
|
+
},
|
|
128
|
+
// `components`, not only `stubs`: blocks route an internal destination
|
|
129
|
+
// through `app/components/EldraRouterLink.vue`, whose template writes
|
|
130
|
+
// the `<NuxtLink>` tag — a name only a *registered* component resolves.
|
|
131
|
+
components: { NuxtLink: NuxtLinkStub },
|
|
132
|
+
stubs: { NuxtLink: NuxtLinkStub },
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function createTestEldraContext(
|
|
138
|
+
locale = 'en-US',
|
|
139
|
+
links: Partial<EldraLinkState> = {},
|
|
140
|
+
locales: Partial<EldraLocaleState> = {}
|
|
141
|
+
): EldraContext {
|
|
142
|
+
const context: EldraContext = {
|
|
143
|
+
client: createTestEldraClient(),
|
|
144
|
+
designTokens: reactive(normalizeThemeDesignTokens({ colors: {} })),
|
|
145
|
+
// Nothing here reads `context.messages` directly — a block calls `useI18n()`, which resolves
|
|
146
|
+
// through `mountOptions`' own `global.plugins` instead — but `EldraContext['messages']` is a
|
|
147
|
+
// required field (`@eldrajs/theme-vue`), so a hand-built context needs one. The real catalogue,
|
|
148
|
+
// not an empty one: `app/plugins/eldra-ui-messages.ts`'s own per-key override lookup reads
|
|
149
|
+
// `context.messages.locales[locale]?.['ui.<key>']`, and a spec that provides this context
|
|
150
|
+
// straight to that plugin's logic (none does today, but the shape should hold) gets the same
|
|
151
|
+
// answer a real page would.
|
|
152
|
+
messages: reactive({
|
|
153
|
+
defaultLocale: STARTER_DEFAULT_LOCALE,
|
|
154
|
+
locales: {
|
|
155
|
+
'en-US': flattenMessages(enUSMessages),
|
|
156
|
+
'is-IS': flattenMessages(isISMessages),
|
|
157
|
+
},
|
|
158
|
+
}),
|
|
159
|
+
// Empty by default, exactly as a page that has resolved nothing yet: every
|
|
160
|
+
// `link` value then resolves to a label with no href. A spec that wants a
|
|
161
|
+
// real destination passes the site's own route templates and targets, the
|
|
162
|
+
// way `@eldrajs/theme-nuxt` fills them from the resolved route.
|
|
163
|
+
links: Object.assign(createEldraLinkState(), links),
|
|
164
|
+
locales: Object.assign(createEldraLocaleState(), locales),
|
|
165
|
+
preview: createEldraPreviewState(),
|
|
166
|
+
};
|
|
167
|
+
context.preview.locale = locale;
|
|
168
|
+
return context;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function createTestEldraClient(): EldraClient {
|
|
172
|
+
return createEldraClient({ gatewayUrl: 'https://vitest.invalid', orgId: 'vitest' });
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Storybook has no Nuxt runtime to resolve the `<NuxtLink>` global; neither
|
|
177
|
+
* does a plain `mount()` outside a Nuxt build. Renders a plain `<a>` from
|
|
178
|
+
* the same `to` prop Nuxt's real component reads — all a test needs, it
|
|
179
|
+
* never navigates.
|
|
180
|
+
*/
|
|
181
|
+
const NuxtLinkStub = defineComponent({
|
|
182
|
+
name: 'NuxtLink',
|
|
183
|
+
props: {
|
|
184
|
+
to: { type: [String, Object], default: '' },
|
|
185
|
+
},
|
|
186
|
+
setup(props, { slots }) {
|
|
187
|
+
return () =>
|
|
188
|
+
h(
|
|
189
|
+
'a',
|
|
190
|
+
{ href: typeof props.to === 'string' ? props.to : JSON.stringify(props.to) },
|
|
191
|
+
slots.default?.()
|
|
192
|
+
);
|
|
193
|
+
},
|
|
194
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
//
|
|
3
|
+
// `mountPage` is exercised for real by `test/pages/*.spec.ts`, but it is a
|
|
4
|
+
// foundation contract other tests depend on verbatim — this proves the
|
|
5
|
+
// harness itself splits a fixture into the same three landmark regions
|
|
6
|
+
// `app/pages/[...slug].vue` renders (`app/utils/pageStructure.ts`) and fails
|
|
7
|
+
// loudly on an unknown apiId, using three of the starter's existing blocks as
|
|
8
|
+
// a stand-in fixture (this file does not assert anything about
|
|
9
|
+
// `navigation`/`hero`/`footer` beyond "they rendered where expected").
|
|
10
|
+
import { describe, expect, it } from 'vitest';
|
|
11
|
+
import heroMock from '../../blocks/hero/mock.json';
|
|
12
|
+
import footerMock from '../../blocks/footer/mock.json';
|
|
13
|
+
import navigationMock from '../../blocks/navigation/mock.json';
|
|
14
|
+
import { mountPage } from './mountPage';
|
|
15
|
+
|
|
16
|
+
describe('mountPage', () => {
|
|
17
|
+
it('renders the fixture in the route\u2019s three landmark regions, in order', async () => {
|
|
18
|
+
const wrapper = await mountPage({
|
|
19
|
+
blocks: [
|
|
20
|
+
{ apiId: 'navigation', id: 'nav-1', data: navigationMock },
|
|
21
|
+
{ apiId: 'hero', id: 'hero-1', data: heroMock },
|
|
22
|
+
{ apiId: 'footer', id: 'footer-1', data: footerMock },
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const main = wrapper.get('main#main');
|
|
27
|
+
// The header leads the list, so it renders *before* `<main>`; the footer trails it, so it
|
|
28
|
+
// renders after — see `app/utils/pageStructure.ts`. Only the hero is inside.
|
|
29
|
+
const banner = wrapper.element.querySelector('header')!;
|
|
30
|
+
const contentinfo = wrapper.element.querySelector('footer')!;
|
|
31
|
+
expect(banner).not.toBeNull();
|
|
32
|
+
expect(contentinfo).not.toBeNull();
|
|
33
|
+
expect(main.element.contains(banner)).toBe(false);
|
|
34
|
+
expect(main.element.contains(contentinfo)).toBe(false);
|
|
35
|
+
|
|
36
|
+
const heading = main.find('h1');
|
|
37
|
+
expect(heading.exists()).toBe(true);
|
|
38
|
+
expect(heading.text()).toBe(heroMock.heading);
|
|
39
|
+
|
|
40
|
+
// Order, not just presence: banner → main → contentinfo in the rendered document.
|
|
41
|
+
expect(
|
|
42
|
+
banner.compareDocumentPosition(main.element) & Node.DOCUMENT_POSITION_FOLLOWING
|
|
43
|
+
).toBeTruthy();
|
|
44
|
+
expect(
|
|
45
|
+
main.element.compareDocumentPosition(contentinfo) & Node.DOCUMENT_POSITION_FOLLOWING
|
|
46
|
+
).toBeTruthy();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('keeps a block that is not leading structure inside <main>', async () => {
|
|
50
|
+
// The partition is positional: only a *leading* run of announcement-bar/navigation is the
|
|
51
|
+
// banner, and only a *trailing* `footer` is the contentinfo.
|
|
52
|
+
const wrapper = await mountPage({
|
|
53
|
+
blocks: [
|
|
54
|
+
{ apiId: 'hero', id: 'hero-1', data: heroMock },
|
|
55
|
+
{ apiId: 'footer', id: 'footer-1', data: footerMock },
|
|
56
|
+
{ apiId: 'navigation', id: 'nav-1', data: navigationMock },
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const main = wrapper.get('main#main');
|
|
61
|
+
// The `footer` is not last, and the `navigation` does not lead — both stay inside `<main>`.
|
|
62
|
+
expect(main.element.querySelector('footer')).not.toBeNull();
|
|
63
|
+
expect(main.element.querySelector('header')).not.toBeNull();
|
|
64
|
+
expect(wrapper.element.children).toHaveLength(1);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('throws a clear error for an apiId with no registered Block.vue', async () => {
|
|
68
|
+
await expect(
|
|
69
|
+
mountPage({ blocks: [{ apiId: 'does-not-exist', id: 'x', data: {} }] })
|
|
70
|
+
).rejects.toThrow(/no Block\.vue registered for apiId "does-not-exist"/);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { defineComponent, h, nextTick } from 'vue';
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils';
|
|
3
|
+
import { expect } from 'vitest';
|
|
4
|
+
import { Link } from '@eldrajs/ui';
|
|
5
|
+
import EldraRouterLink from '../../app/components/EldraRouterLink.vue';
|
|
6
|
+
import { useI18n } from 'vue-i18n';
|
|
7
|
+
import { mountOptions } from './mountBlock';
|
|
8
|
+
import { STOREFRONT_KEY, type StorefrontSource } from '../../app/storefront/types';
|
|
9
|
+
// The apiId → Block.vue map lives in `stories/support/pageBlocks.ts`, shared with
|
|
10
|
+
// `stories/pages/*.stories.ts` — see that file's own doc comment for why it
|
|
11
|
+
// is not declared here directly (keeping `test/**` out of the shipped
|
|
12
|
+
// Storybook build) and not under `app/utils/` (keeping blocks' own template
|
|
13
|
+
// type errors out of `nuxi typecheck`).
|
|
14
|
+
import { renderPageFixtureRegions } from '../../stories/support/pageBlocks';
|
|
15
|
+
|
|
16
|
+
// One definition of the fixture shape, shared with the page stories (see `pageBlocks.ts`).
|
|
17
|
+
export type { PageFixture, PageFixtureBlock } from '../../stories/support/pageBlocks';
|
|
18
|
+
import type { PageFixture } from '../../stories/support/pageBlocks';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Renders a `pages/<name>.page.json`-shaped fixture exactly as
|
|
22
|
+
* `app/pages/[...slug].vue` renders a real page: the leading structure
|
|
23
|
+
* blocks (`announcement-bar`, `navigation`) first, then every remaining
|
|
24
|
+
* block in order inside one `<main id="main">`, then a trailing `footer` —
|
|
25
|
+
* three sibling landmark regions (`banner` / `main` / `contentinfo`), which
|
|
26
|
+
* is what makes `app/app.vue`'s "Skip to content" link actually skip the
|
|
27
|
+
* navigation. The partition rule lives in `app/utils/pageStructure.ts` and
|
|
28
|
+
* the rendering half in `stories/support/pageBlocks.ts`
|
|
29
|
+
* (`renderPageFixtureRegions`), both shared with the route and the page
|
|
30
|
+
* stories, so a page spec can never drift from the page's real shape.
|
|
31
|
+
* Every block gets the same `EldraContext`/UI
|
|
32
|
+
* messages/locale/currency a real page and `mountBlock.ts`'s `mountOptions`
|
|
33
|
+
* already provide, so a page-level spec sees exactly what a single-block
|
|
34
|
+
* spec does, just with several blocks rendered together.
|
|
35
|
+
*
|
|
36
|
+
* `options.attachTo` forwards to `mount()` — needed by any spec that asserts real focus movement
|
|
37
|
+
* (`document.activeElement`), which jsdom only tracks for elements connected to `document`.
|
|
38
|
+
*
|
|
39
|
+
* `options.storefront`, when given, replaces the default `createDemoStorefront()` a block reads
|
|
40
|
+
* through `useStorefront()` — for a page-level spec that needs a route/query seed
|
|
41
|
+
* `mountOptions()`'s own default does not carry (e.g. `collectionHandle`/`productHandle`/`query`
|
|
42
|
+
* seeded through `createDemoStorefront()`'s own options, or a hand-built stub). It only reaches a
|
|
43
|
+
* block through `storefront.route`/`storefront.catalog`, etc.: a shopper-selected filter is the
|
|
44
|
+
* block's own state, so a spec that needs an applied filter drives the real control instead.
|
|
45
|
+
*/
|
|
46
|
+
export async function mountPage(
|
|
47
|
+
fixture: PageFixture,
|
|
48
|
+
options: { attachTo?: Element; storefront?: StorefrontSource } = {}
|
|
49
|
+
): Promise<VueWrapper> {
|
|
50
|
+
const Page = defineComponent({
|
|
51
|
+
name: 'MountPageHarness',
|
|
52
|
+
setup() {
|
|
53
|
+
return () => renderPageFixtureRegions(fixture, 'mountPage');
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const { global } = mountOptions({ entry: { id: '', data: {} } });
|
|
58
|
+
if (options.storefront !== undefined) {
|
|
59
|
+
global.provide[STOREFRONT_KEY] = options.storefront;
|
|
60
|
+
}
|
|
61
|
+
const wrapper = mount(Page, { global, attachTo: options.attachTo });
|
|
62
|
+
await nextTick();
|
|
63
|
+
return wrapper;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* `app/app.vue`'s skip link, rendered ahead of the same three page regions `mountPage` renders.
|
|
68
|
+
*
|
|
69
|
+
* The skip link itself lives outside `pages/[...slug].vue` (it must reach the not-found and error
|
|
70
|
+
* shells too), so `mountPage` alone never renders it. Every page spec needs it for one assertion —
|
|
71
|
+
* that "Skip to content" is the first thing a visitor tabs to and that following it lands them
|
|
72
|
+
* *past* the header — which is only meaningful now the header is a sibling of `<main>` rather than
|
|
73
|
+
* its first child. The markup is copied verbatim from `app/app.vue` (that file is Nuxt-only:
|
|
74
|
+
* `<NuxtPage />`), exactly as `stories/pages/*.stories.ts` copy it, for the same reason.
|
|
75
|
+
*
|
|
76
|
+
* Always attached to `document.body`: the assertions this exists for are about focus and document
|
|
77
|
+
* order.
|
|
78
|
+
*/
|
|
79
|
+
export async function mountPageWithSkipLink(
|
|
80
|
+
fixture: PageFixture,
|
|
81
|
+
options: { storefront?: StorefrontSource } = {}
|
|
82
|
+
): Promise<VueWrapper> {
|
|
83
|
+
const Page = defineComponent({
|
|
84
|
+
name: 'MountPageWithSkipLinkHarness',
|
|
85
|
+
setup() {
|
|
86
|
+
const { t } = useI18n();
|
|
87
|
+
return () => [
|
|
88
|
+
h(
|
|
89
|
+
Link,
|
|
90
|
+
{
|
|
91
|
+
href: '#main',
|
|
92
|
+
as: EldraRouterLink,
|
|
93
|
+
variant: 'standalone',
|
|
94
|
+
classes: {
|
|
95
|
+
root: 'bg-primary text-primary-contrast rounded-md sr-only px-4 py-2 focus:not-sr-only focus:fixed focus:top-4 focus:left-4 focus:z-50',
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
() => t('nav.skipToContent')
|
|
99
|
+
),
|
|
100
|
+
...renderPageFixtureRegions(fixture, 'mountPageWithSkipLink'),
|
|
101
|
+
];
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const { global } = mountOptions({ entry: { id: '', data: {} } });
|
|
106
|
+
if (options.storefront !== undefined) {
|
|
107
|
+
global.provide[STOREFRONT_KEY] = options.storefront;
|
|
108
|
+
}
|
|
109
|
+
const wrapper = mount(Page, { global, attachTo: document.body });
|
|
110
|
+
await nextTick();
|
|
111
|
+
return wrapper;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The same fixture with one link authored onto its header.
|
|
116
|
+
*
|
|
117
|
+
* The seeded header carries no links and no call to action — a theme cannot know an organisation's
|
|
118
|
+
* own destinations, so it ships none (`pages/*.page.json`). With nothing to
|
|
119
|
+
* put in the drawer the header draws no Menu button and no drawer at all
|
|
120
|
+
* (`blocks/navigation/Block.vue`), so a page spec about the *mobile menu* has to author a header
|
|
121
|
+
* first: the drawer is the mobile route to a header a merchant has filled in, and that is the state
|
|
122
|
+
* worth asserting about. Everything else about the page is untouched.
|
|
123
|
+
*/
|
|
124
|
+
export function withAuthoredHeaderLink(fixture: PageFixture): PageFixture {
|
|
125
|
+
return {
|
|
126
|
+
...fixture,
|
|
127
|
+
blocks: fixture.blocks.map((block) =>
|
|
128
|
+
block.apiId === 'navigation'
|
|
129
|
+
? {
|
|
130
|
+
...block,
|
|
131
|
+
data: {
|
|
132
|
+
...block.data,
|
|
133
|
+
links: [{ kind: 'url', url: '/journal', label: 'Journal' }],
|
|
134
|
+
},
|
|
135
|
+
}
|
|
136
|
+
: block
|
|
137
|
+
),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Every block's own root element, in document order, flattened back across the three regions:
|
|
143
|
+
* the header blocks, then `<main id="main">`'s children, then the footer block.
|
|
144
|
+
*
|
|
145
|
+
* A page spec's "block N sits on ground X / renders heading Y" assertions are written against the
|
|
146
|
+
* fixture's own block order, which is exactly this list — `fixture.blocks[i]` renders
|
|
147
|
+
* `pageBlockRoots(wrapper)[i]`. Reading it off `main.children` (which is what these specs did
|
|
148
|
+
* while the route rendered everything inside `<main>`) would now silently drop the header and
|
|
149
|
+
* footer.
|
|
150
|
+
*
|
|
151
|
+
* A block may render more than one element: the header renders its bar plus the box that holds the
|
|
152
|
+
* flow the fixed bar is not in (`data-eldra-header-spacer`). Layout, not a block root — and here,
|
|
153
|
+
* where the fixture mounts block components directly rather than inside the block zone's own
|
|
154
|
+
* wrapper, it would otherwise shift every index after the header by one.
|
|
155
|
+
*/
|
|
156
|
+
export function pageBlockRoots(wrapper: VueWrapper): Element[] {
|
|
157
|
+
const isBlockRoot = (element: Element): boolean =>
|
|
158
|
+
!element.hasAttribute('data-eldra-header-spacer');
|
|
159
|
+
const roots: Element[] = [];
|
|
160
|
+
for (const child of wrapper.element.children) {
|
|
161
|
+
if (child.tagName === 'MAIN') roots.push(...[...child.children].filter(isBlockRoot));
|
|
162
|
+
// `A` is `mountPageWithSkipLink`'s own link, not a block.
|
|
163
|
+
else if (child.tagName !== 'A' && isBlockRoot(child)) roots.push(child);
|
|
164
|
+
}
|
|
165
|
+
return roots;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The three landmarks a scaffolded page must expose: exactly one `banner`, one `main` and one
|
|
170
|
+
* `contentinfo`, in that document order.
|
|
171
|
+
*
|
|
172
|
+
* `<header>` and `<footer>` only carry the `banner`/`contentinfo` role while they are *not*
|
|
173
|
+
* descendants of a sectioning element (HTML-AAM), so "there is a `<header>` element" is not the
|
|
174
|
+
* assertion — "it is a sibling of `<main>`, not inside it" is. Shared by all four page specs
|
|
175
|
+
* because it is the same invariant for every page, and it is the one the route template's
|
|
176
|
+
* partition (`app/utils/pageStructure.ts`) exists to hold.
|
|
177
|
+
*/
|
|
178
|
+
export function expectPageLandmarks(wrapper: VueWrapper): void {
|
|
179
|
+
const root = wrapper.element;
|
|
180
|
+
|
|
181
|
+
const mains = root.querySelectorAll('main');
|
|
182
|
+
expect(mains).toHaveLength(1);
|
|
183
|
+
const main = mains[0]!;
|
|
184
|
+
expect(main.id).toBe('main');
|
|
185
|
+
|
|
186
|
+
const banners = [...root.querySelectorAll('header')].filter(
|
|
187
|
+
(el) => el.closest('main, article, aside, nav, section') === null
|
|
188
|
+
);
|
|
189
|
+
expect(
|
|
190
|
+
banners,
|
|
191
|
+
'exactly one top-level <header> (the `banner` landmark) — a <header> inside <main> carries no ' +
|
|
192
|
+
'landmark role at all, which is what `app/utils/pageStructure.ts` exists to prevent'
|
|
193
|
+
).toHaveLength(1);
|
|
194
|
+
|
|
195
|
+
const contentinfos = [...root.querySelectorAll('footer')].filter(
|
|
196
|
+
(el) => el.closest('main, article, aside, nav, section') === null
|
|
197
|
+
);
|
|
198
|
+
expect(contentinfos, 'exactly one top-level <footer> (the `contentinfo` landmark)').toHaveLength(
|
|
199
|
+
1
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
// Document order: banner → main → contentinfo.
|
|
203
|
+
expect(banners[0]!.compareDocumentPosition(main) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
|
204
|
+
expect(
|
|
205
|
+
main.compareDocumentPosition(contentinfos[0]!) & Node.DOCUMENT_POSITION_FOLLOWING
|
|
206
|
+
).toBeTruthy();
|
|
207
|
+
|
|
208
|
+
// Neither is inside `<main>` — the exact regression this guards.
|
|
209
|
+
expect(main.contains(banners[0]!)).toBe(false);
|
|
210
|
+
expect(main.contains(contentinfos[0]!)).toBe(false);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* The skip link's contract: it is the first focusable element on the page, and following it lands
|
|
215
|
+
* the visitor *after* the header — i.e. every focusable element inside the `banner` precedes
|
|
216
|
+
* `#main` in document order, so "Skip to content" really does skip the navigation.
|
|
217
|
+
*
|
|
218
|
+
* Takes a wrapper from `mountPageWithSkipLink`.
|
|
219
|
+
*/
|
|
220
|
+
export function expectSkipLinkLandsAfterTheHeader(wrapper: VueWrapper): void {
|
|
221
|
+
const root = wrapper.element;
|
|
222
|
+
const focusable = [...root.querySelectorAll(FOCUSABLE_SELECTOR)];
|
|
223
|
+
expect(focusable.length).toBeGreaterThan(1);
|
|
224
|
+
|
|
225
|
+
const skipLink = focusable[0]!;
|
|
226
|
+
expect(skipLink.textContent).toBe('Skip to content');
|
|
227
|
+
expect(skipLink.getAttribute('href')).toBe('#main');
|
|
228
|
+
|
|
229
|
+
const main = root.querySelector('main#main')!;
|
|
230
|
+
const banner = [...root.querySelectorAll('header')].find(
|
|
231
|
+
(el) => el.closest('main, article, aside, nav, section') === null
|
|
232
|
+
)!;
|
|
233
|
+
expect(banner).toBeDefined();
|
|
234
|
+
expect(main.contains(banner)).toBe(false);
|
|
235
|
+
|
|
236
|
+
const headerFocusable = [...banner.querySelectorAll(FOCUSABLE_SELECTOR)];
|
|
237
|
+
expect(headerFocusable.length).toBeGreaterThan(0);
|
|
238
|
+
for (const el of headerFocusable) {
|
|
239
|
+
expect(
|
|
240
|
+
el.compareDocumentPosition(main) & Node.DOCUMENT_POSITION_FOLLOWING,
|
|
241
|
+
'the skip link target must follow every focusable element in the header, or "Skip to ' +
|
|
242
|
+
'content" lands the visitor before the navigation it exists to skip'
|
|
243
|
+
).toBeTruthy();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* A focusable element by the same rule the package's own components rely on: no positive
|
|
249
|
+
* `tabindex` appears anywhere in this starter (`global-constraints.md` "Focus"), so DOM order
|
|
250
|
+
* among these is tab order.
|
|
251
|
+
*/
|
|
252
|
+
export const FOCUSABLE_SELECTOR =
|
|
253
|
+
'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), ' +
|
|
254
|
+
'textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { defineNuxtPlugin } from 'nuxt/app';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Test-only instrumentation: `prerenderRefresh.browser.spec.ts` copies this file into the generated
|
|
5
|
+
* site's `app/plugins/` before it builds it. It lives under `test/support/`, and the starter has no
|
|
6
|
+
* such plugin of its own — so `eldra-theme init` does copy this file (it copies the whole starter,
|
|
7
|
+
* `test/` included) but copies it **inert**, where no Nuxt build ever looks at it. Nothing a
|
|
8
|
+
* customer ships contains it; only this spec's tmpdir copy has it installed.
|
|
9
|
+
*
|
|
10
|
+
* It counts how many times each **block component instance** is created and mounted in the
|
|
11
|
+
* browser, keyed by the entry it was handed. A request log cannot tell a second render of one
|
|
12
|
+
* block apart from a second block asking the same question; an instance counter can, which is what
|
|
13
|
+
* makes it the right instrument for "is this block subtree being built twice across hydration?".
|
|
14
|
+
*
|
|
15
|
+
* Creations and mounts are counted separately, and the creation count is the one that matters. A
|
|
16
|
+
* block's storefront reads are created in `setup`, so a second *creation* is a second round of
|
|
17
|
+
* reads even when that instance never reaches the DOM — and it does not: the page Nuxt throws away
|
|
18
|
+
* mid-hydration is a `<Suspense>` branch discarded before its `mounted` hooks flush, which is why
|
|
19
|
+
* the defect this spec guards showed up as two identical request bursts with every block still
|
|
20
|
+
* mounted exactly once.
|
|
21
|
+
*
|
|
22
|
+
* A global mixin is the cheapest hook that sees every component, including the lazily imported
|
|
23
|
+
* block chunks that land after `app:mounted`. Every component carrying an entry-shaped `entry`
|
|
24
|
+
* prop is recorded (the block components, and any part a block hands its entry to), so the spec
|
|
25
|
+
* can pick the ones it means by component name rather than trusting this file's guess.
|
|
26
|
+
*
|
|
27
|
+
* It also exposes `__eldraPush`, which drives the router from outside the page. A spec can click
|
|
28
|
+
* its way to every destination the site links to; it cannot click its way to one the site has no
|
|
29
|
+
* link for, and "an unknown route is answered without asking the gateway" is exactly a destination
|
|
30
|
+
* of that kind.
|
|
31
|
+
*/
|
|
32
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
33
|
+
const created: Record<string, number> = {};
|
|
34
|
+
const mounted: Record<string, number> = {};
|
|
35
|
+
const probe = window as unknown as {
|
|
36
|
+
__eldraCreated: Record<string, number>;
|
|
37
|
+
__eldraMounted: Record<string, number>;
|
|
38
|
+
__eldraPush: (path: string) => Promise<unknown>;
|
|
39
|
+
};
|
|
40
|
+
probe.__eldraCreated = created;
|
|
41
|
+
probe.__eldraMounted = mounted;
|
|
42
|
+
// A client-side navigation the page carries no link to — an unknown route. A spec cannot click
|
|
43
|
+
// its way to one, and driving the router from outside is the only way to exercise what a static
|
|
44
|
+
// build must answer without the gateway.
|
|
45
|
+
probe.__eldraPush = (path) => nuxtApp.$router.push(path);
|
|
46
|
+
|
|
47
|
+
const countInto = (counts: Record<string, number>, instance: Record<string, unknown>): void => {
|
|
48
|
+
const entry = instance.entry;
|
|
49
|
+
if (typeof entry !== 'object' || entry === null) return;
|
|
50
|
+
const { id, schemaApiId } = entry as {
|
|
51
|
+
id?: unknown;
|
|
52
|
+
schemaApiId?: unknown;
|
|
53
|
+
};
|
|
54
|
+
if (typeof id !== 'string') return;
|
|
55
|
+
const options = instance.$options as { __name?: string; name?: string };
|
|
56
|
+
const name = options.__name ?? options.name ?? 'anonymous';
|
|
57
|
+
const key = `${name}|${typeof schemaApiId === 'string' ? schemaApiId : '?'}|${id}`;
|
|
58
|
+
counts[key] = (counts[key] ?? 0) + 1;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
nuxtApp.vueApp.mixin({
|
|
62
|
+
created(this: Record<string, unknown>) {
|
|
63
|
+
countInto(created, this);
|
|
64
|
+
},
|
|
65
|
+
mounted(this: Record<string, unknown>) {
|
|
66
|
+
countInto(mounted, this);
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
});
|