@eldrajs/theme-cli 0.0.0 → 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 +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-C6jB8_Oc.js +510 -0
- package/package.json +50 -2
- 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,425 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
canonicalAvailability,
|
|
4
|
+
canonicalAvailabilityValues,
|
|
5
|
+
deriveFacets,
|
|
6
|
+
filterItems,
|
|
7
|
+
matchesFilters,
|
|
8
|
+
matchesFiltersExcept,
|
|
9
|
+
matchesPrice,
|
|
10
|
+
} from '../../app/storefront/facets';
|
|
11
|
+
import type { ProductFacetAttributes } from '../../app/storefront/facets';
|
|
12
|
+
import type { StorefrontProductListItem } from '../../app/storefront/types';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* `facets.ts` is the one facet pass both storefront sources run — the demo over its fixture and
|
|
16
|
+
* the gateway over the page it just fetched — plus the client-side derivation of the platform's own
|
|
17
|
+
* `facets` object, so it is tested here on its own, with no source and no Vue around it. Every
|
|
18
|
+
* bound below is a *mutation proof*: flip the comparison, drop the `continue`, treat an unknown
|
|
19
|
+
* attribute as "matches nothing", count a family over its own filter, and one of these fails.
|
|
20
|
+
*/
|
|
21
|
+
function item(
|
|
22
|
+
overrides: Partial<StorefrontProductListItem> & { handle: string }
|
|
23
|
+
): StorefrontProductListItem {
|
|
24
|
+
return {
|
|
25
|
+
title: overrides.handle,
|
|
26
|
+
url: `/products/${overrides.handle}`,
|
|
27
|
+
price: { amount: 100, compareAt: null },
|
|
28
|
+
stock: 'in',
|
|
29
|
+
available: true,
|
|
30
|
+
productId: `${overrides.handle}`,
|
|
31
|
+
...overrides,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe('matchesPrice', () => {
|
|
36
|
+
const priced = (amount: number) => item({ handle: 'p', price: { amount, compareAt: null } });
|
|
37
|
+
|
|
38
|
+
it('includes both bounds — the shopper asking for 50–150 means 50 and 150 are in', () => {
|
|
39
|
+
expect(matchesPrice(priced(50), '50-150')).toBe(true);
|
|
40
|
+
expect(matchesPrice(priced(150), '50-150')).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('excludes anything outside them — the $48 bowl the live site kept showing', () => {
|
|
44
|
+
expect(matchesPrice(priced(48), '50-150')).toBe(false);
|
|
45
|
+
expect(matchesPrice(priced(151), '50-150')).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('treats an empty end as no bound, and a missing range as no filter at all', () => {
|
|
49
|
+
expect(matchesPrice(priced(10), '-150')).toBe(true);
|
|
50
|
+
expect(matchesPrice(priced(10), '50-')).toBe(false);
|
|
51
|
+
expect(matchesPrice(priced(9000), '50-')).toBe(true);
|
|
52
|
+
expect(matchesPrice(priced(9000), '-150')).toBe(false);
|
|
53
|
+
expect(matchesPrice(priced(9000), undefined)).toBe(true);
|
|
54
|
+
expect(matchesPrice(priced(9000), '-')).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('matchesFilters', () => {
|
|
59
|
+
const sweater = item({ handle: 'sweater' });
|
|
60
|
+
const knitwear: ProductFacetAttributes = {
|
|
61
|
+
category: { slug: 'knitwear', title: 'Knitwear' },
|
|
62
|
+
collections: [{ slug: 'the-winter-edit', title: 'The winter edit' }],
|
|
63
|
+
options: {
|
|
64
|
+
size: [{ value: 's' }, { value: 'm' }],
|
|
65
|
+
colour: [{ value: 'oat' }, { value: 'moss' }],
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
it('answers true for no filters and for an empty value list', () => {
|
|
70
|
+
expect(matchesFilters(sweater, undefined, knitwear)).toBe(true);
|
|
71
|
+
expect(matchesFilters(sweater, { category: [] }, knitwear)).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('ORs within one source and ANDs across sources', () => {
|
|
75
|
+
expect(matchesFilters(sweater, { 'option:size': ['l', 'm'] }, knitwear)).toBe(true);
|
|
76
|
+
expect(matchesFilters(sweater, { 'option:size': ['l', 'xl'] }, knitwear)).toBe(false);
|
|
77
|
+
expect(
|
|
78
|
+
matchesFilters(sweater, { 'option:size': ['m'], 'option:colour': ['oat'] }, knitwear)
|
|
79
|
+
).toBe(true);
|
|
80
|
+
expect(
|
|
81
|
+
matchesFilters(sweater, { 'option:size': ['m'], 'option:colour': ['clay'] }, knitwear)
|
|
82
|
+
).toBe(false);
|
|
83
|
+
expect(matchesFilters(sweater, { category: ['ceramics', 'knitwear'] }, knitwear)).toBe(true);
|
|
84
|
+
expect(matchesFilters(sweater, { category: ['ceramics'] }, knitwear)).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('filters on collection membership, which a product may have several of', () => {
|
|
88
|
+
const both: ProductFacetAttributes = {
|
|
89
|
+
collections: [{ slug: 'the-winter-edit' }, { slug: 'best-sellers' }],
|
|
90
|
+
};
|
|
91
|
+
expect(matchesFilters(sweater, { collection: ['best-sellers'] }, both)).toBe(true);
|
|
92
|
+
expect(matchesFilters(sweater, { collection: ['the-winter-edit'] }, knitwear)).toBe(true);
|
|
93
|
+
expect(matchesFilters(sweater, { collection: ['best-sellers'] }, knitwear)).toBe(false);
|
|
94
|
+
// Known-but-empty: a product in no collection matches no collection filter.
|
|
95
|
+
expect(matchesFilters(sweater, { collection: ['best-sellers'] }, { collections: [] })).toBe(
|
|
96
|
+
false
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('reads availability off the item, so a source needs no attributes at all', () => {
|
|
101
|
+
const inStock = item({ handle: 'a' });
|
|
102
|
+
const soldOut = item({ handle: 'b', stock: 'out', available: false });
|
|
103
|
+
const preorder = item({ handle: 'c', stock: 'preorder', available: false });
|
|
104
|
+
// Orderable in principle, out of stock in fact: "In stock" must still drop it, which is why
|
|
105
|
+
// `available` alone is not the test.
|
|
106
|
+
const listedButOut = item({ handle: 'd', stock: 'out', available: true });
|
|
107
|
+
|
|
108
|
+
expect(matchesFilters(inStock, { availability: ['in_stock'] })).toBe(true);
|
|
109
|
+
expect(matchesFilters(soldOut, { availability: ['in_stock'] })).toBe(false);
|
|
110
|
+
expect(matchesFilters(preorder, { availability: ['in_stock'] })).toBe(false);
|
|
111
|
+
expect(matchesFilters(listedButOut, { availability: ['in_stock'] })).toBe(false);
|
|
112
|
+
|
|
113
|
+
expect(matchesFilters(soldOut, { availability: ['out_of_stock'] })).toBe(true);
|
|
114
|
+
expect(matchesFilters(preorder, { availability: ['out_of_stock'] })).toBe(true);
|
|
115
|
+
expect(matchesFilters(inStock, { availability: ['out_of_stock'] })).toBe(false);
|
|
116
|
+
|
|
117
|
+
expect(matchesFilters(inStock, { availability: ['in_stock', 'out_of_stock'] })).toBe(true);
|
|
118
|
+
expect(matchesFilters(soldOut, { availability: ['in_stock', 'out_of_stock'] })).toBe(true);
|
|
119
|
+
|
|
120
|
+
// The spellings shared links were written with before the platform's own vocabulary landed.
|
|
121
|
+
expect(matchesFilters(inStock, { availability: ['in-stock'] })).toBe(true);
|
|
122
|
+
expect(matchesFilters(soldOut, { availability: ['in-stock'] })).toBe(false);
|
|
123
|
+
expect(matchesFilters(soldOut, { availability: ['out-of-stock'] })).toBe(true);
|
|
124
|
+
expect(matchesFilters(inStock, { availability: ['out-of-stock'] })).toBe(false);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* A value from no vocabulary at all — `backorder`, which this theme offered before the platform
|
|
129
|
+
* counted only two — is **unknown**, so the clause is ignored like every other unknown one here.
|
|
130
|
+
* Falling through to "not in stock" showed a shopper following an old link nothing but the
|
|
131
|
+
* sold-out products, under a chip quoting the word they had clicked.
|
|
132
|
+
*/
|
|
133
|
+
it('ignores an availability value it does not know rather than reading it as out of stock', () => {
|
|
134
|
+
const inStock = item({ handle: 'a' });
|
|
135
|
+
const soldOut = item({ handle: 'b', stock: 'out', available: false });
|
|
136
|
+
expect(matchesFilters(inStock, { availability: ['backorder'] })).toBe(true);
|
|
137
|
+
expect(matchesFilters(soldOut, { availability: ['backorder'] })).toBe(true);
|
|
138
|
+
// One known value beside it still decides the clause.
|
|
139
|
+
expect(matchesFilters(inStock, { availability: ['backorder', 'out_of_stock'] })).toBe(false);
|
|
140
|
+
expect(matchesFilters(soldOut, { availability: ['backorder', 'out_of_stock'] })).toBe(true);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('canonicalises the availability vocabulary, dropping what it does not know', () => {
|
|
144
|
+
expect(canonicalAvailability('in-stock')).toBe('in_stock');
|
|
145
|
+
expect(canonicalAvailability('out_of_stock')).toBe('out_of_stock');
|
|
146
|
+
expect(canonicalAvailability('backorder')).toBeNull();
|
|
147
|
+
expect(canonicalAvailabilityValues(['in-stock', 'in_stock', 'backorder'])).toEqual([
|
|
148
|
+
'in_stock',
|
|
149
|
+
]);
|
|
150
|
+
expect(canonicalAvailabilityValues(['backorder'])).toEqual([]);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('filters on price with no attributes, which is the whole gateway path', () => {
|
|
154
|
+
expect(
|
|
155
|
+
matchesFilters(item({ handle: 'p', price: { amount: 48 } }), { price: ['50-150'] })
|
|
156
|
+
).toBe(false);
|
|
157
|
+
expect(
|
|
158
|
+
matchesFilters(item({ handle: 'p', price: { amount: 50 } }), { price: ['50-150'] })
|
|
159
|
+
).toBe(true);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The rule that keeps a client-side pass honest: a source the caller has no data for is
|
|
164
|
+
* *unknown*, not *unmatched*. A backend that cannot tell which sizes a product is made in has no
|
|
165
|
+
* business emptying the grid because the shopper ticked "M" — the same doctrine the demo already
|
|
166
|
+
* applied to an unrecognised source name.
|
|
167
|
+
*/
|
|
168
|
+
it('ignores a source it has no attribute for, and an unknown source name', () => {
|
|
169
|
+
expect(matchesFilters(sweater, { 'option:size': ['xl'] })).toBe(true);
|
|
170
|
+
expect(matchesFilters(sweater, { category: ['ceramics'] })).toBe(true);
|
|
171
|
+
expect(matchesFilters(sweater, { collection: ['best-sellers'] })).toBe(true);
|
|
172
|
+
expect(matchesFilters(sweater, { 'option:colour': ['clay'] })).toBe(true);
|
|
173
|
+
expect(matchesFilters(sweater, { 'made-in': ['iceland'] }, knitwear)).toBe(true);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
/** A *known* empty list is not unknown: a product recorded as made in no sizes matches none. A
|
|
177
|
+
* key the source does not name at all stays unknown, so an option the store does not have
|
|
178
|
+
* (`option:fabric`) cannot empty the grid. */
|
|
179
|
+
it('excludes on a known-but-empty attribute, and still ignores an unnamed option key', () => {
|
|
180
|
+
expect(matchesFilters(sweater, { 'option:size': ['m'] }, { options: { size: [] } })).toBe(
|
|
181
|
+
false
|
|
182
|
+
);
|
|
183
|
+
expect(matchesFilters(sweater, { 'option:fabric': ['linen'] }, { options: { size: [] } })).toBe(
|
|
184
|
+
true
|
|
185
|
+
);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
/** A card's own swatch summary is the colour vocabulary a product list row already carries, so
|
|
189
|
+
* a source that declares no option bag still filters by colour. */
|
|
190
|
+
it('falls back to the card’s own colours for the colour option', () => {
|
|
191
|
+
const coloured = item({ handle: 'c', colours: [{ name: 'Oat', swatch: '#d8cbb0' }] });
|
|
192
|
+
expect(matchesFilters(coloured, { 'option:colour': ['oat'] })).toBe(true);
|
|
193
|
+
expect(matchesFilters(coloured, { 'option:colour': ['moss'] })).toBe(false);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe('matchesFiltersExcept', () => {
|
|
198
|
+
const attributes: ProductFacetAttributes = {
|
|
199
|
+
category: { slug: 'ceramics' },
|
|
200
|
+
options: { colour: [{ value: 'clay' }] },
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
it('judges every clause but the one named', () => {
|
|
204
|
+
const filters = { category: ['knitwear'], 'option:colour': ['clay'] };
|
|
205
|
+
const bowl = item({ handle: 'bowl' });
|
|
206
|
+
expect(matchesFilters(bowl, filters, attributes)).toBe(false);
|
|
207
|
+
expect(matchesFiltersExcept(bowl, filters, 'category', attributes)).toBe(true);
|
|
208
|
+
expect(matchesFiltersExcept(bowl, filters, 'option:colour', attributes)).toBe(false);
|
|
209
|
+
expect(matchesFiltersExcept(bowl, filters, null, attributes)).toBe(false);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
describe('filterItems', () => {
|
|
214
|
+
const items = [
|
|
215
|
+
item({ handle: 'bowl', price: { amount: 48 } }),
|
|
216
|
+
item({ handle: 'plate', price: { amount: 50 } }),
|
|
217
|
+
item({ handle: 'vase', price: { amount: 150 } }),
|
|
218
|
+
item({ handle: 'lamp', price: { amount: 151 } }),
|
|
219
|
+
];
|
|
220
|
+
|
|
221
|
+
it('keeps order and drops only what the filters exclude', () => {
|
|
222
|
+
expect(filterItems(items, { price: ['50-150'] }).map((i) => i.handle)).toEqual([
|
|
223
|
+
'plate',
|
|
224
|
+
'vase',
|
|
225
|
+
]);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('returns every item when there is nothing to filter on', () => {
|
|
229
|
+
expect(filterItems(items, undefined)).toHaveLength(4);
|
|
230
|
+
expect(filterItems(items, {})).toHaveLength(4);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* `deriveFacets` is the **fallback for the platform's own `facets` object** (`CatalogFacets` in
|
|
236
|
+
* `app/storefront/types.ts`), so what is pinned here is the contract both halves owe the filter
|
|
237
|
+
* panel: the shape, the vocabulary, and the two counting rules — a family's counts leave that
|
|
238
|
+
* family's own filter out, and the price bounds leave only price out.
|
|
239
|
+
*/
|
|
240
|
+
describe('deriveFacets', () => {
|
|
241
|
+
const CATALOGUE: Array<{
|
|
242
|
+
handle: string;
|
|
243
|
+
amount: number;
|
|
244
|
+
category: string;
|
|
245
|
+
categoryTitle: string;
|
|
246
|
+
colours: string[];
|
|
247
|
+
sizes: string[];
|
|
248
|
+
collections: string[];
|
|
249
|
+
stock?: StorefrontProductListItem['stock'];
|
|
250
|
+
}> = [
|
|
251
|
+
{
|
|
252
|
+
handle: 'sweater',
|
|
253
|
+
amount: 96,
|
|
254
|
+
category: 'knitwear',
|
|
255
|
+
categoryTitle: 'Knitwear',
|
|
256
|
+
colours: ['oat'],
|
|
257
|
+
sizes: ['s', 'm'],
|
|
258
|
+
collections: ['the-winter-edit'],
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
handle: 'cardigan',
|
|
262
|
+
amount: 164,
|
|
263
|
+
category: 'knitwear',
|
|
264
|
+
categoryTitle: 'Knitwear',
|
|
265
|
+
colours: ['moss'],
|
|
266
|
+
sizes: ['m'],
|
|
267
|
+
collections: ['the-winter-edit', 'best-sellers'],
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
handle: 'bowl',
|
|
271
|
+
amount: 48,
|
|
272
|
+
category: 'ceramics',
|
|
273
|
+
categoryTitle: 'Ceramics',
|
|
274
|
+
colours: ['clay'],
|
|
275
|
+
sizes: [],
|
|
276
|
+
collections: ['the-winter-edit'],
|
|
277
|
+
stock: 'out',
|
|
278
|
+
},
|
|
279
|
+
];
|
|
280
|
+
|
|
281
|
+
const items = CATALOGUE.map((row) =>
|
|
282
|
+
item({
|
|
283
|
+
handle: row.handle,
|
|
284
|
+
price: { amount: row.amount, compareAt: null },
|
|
285
|
+
...(row.stock === 'out' ? { stock: 'out' as const, available: false } : {}),
|
|
286
|
+
})
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
const attributesFor = (candidate: StorefrontProductListItem): ProductFacetAttributes => {
|
|
290
|
+
const row = CATALOGUE.find((entry) => entry.handle === candidate.handle)!;
|
|
291
|
+
return {
|
|
292
|
+
category: { slug: row.category, title: row.categoryTitle, id: `cat-${row.category}` },
|
|
293
|
+
collections: row.collections.map((slug) => ({ slug, title: slug, id: `col-${slug}` })),
|
|
294
|
+
options: {
|
|
295
|
+
size: row.sizes.map((size) => ({ value: size, label: size.toUpperCase() })),
|
|
296
|
+
colour: row.colours.map((colour) => ({ value: colour, label: colour, swatch: '#000' })),
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
it('answers the platform’s own shape: price bounds, terms with ids and titles, counts', () => {
|
|
302
|
+
expect(deriveFacets(items, { attributesFor })).toEqual({
|
|
303
|
+
price: { min: 48, max: 164 },
|
|
304
|
+
categories: [
|
|
305
|
+
{ id: 'cat-knitwear', slug: 'knitwear', title: 'Knitwear', count: 2 },
|
|
306
|
+
{ id: 'cat-ceramics', slug: 'ceramics', title: 'Ceramics', count: 1 },
|
|
307
|
+
],
|
|
308
|
+
collections: [
|
|
309
|
+
{ id: 'col-the-winter-edit', slug: 'the-winter-edit', title: 'the-winter-edit', count: 3 },
|
|
310
|
+
{ id: 'col-best-sellers', slug: 'best-sellers', title: 'best-sellers', count: 1 },
|
|
311
|
+
],
|
|
312
|
+
availability: { in_stock: 2, out_of_stock: 1 },
|
|
313
|
+
options: [
|
|
314
|
+
{
|
|
315
|
+
key: 'size',
|
|
316
|
+
name: 'size',
|
|
317
|
+
// No swatch anywhere in the family, so the derivation calls it `none` — exactly what a
|
|
318
|
+
// merchant's "Display as: None" answers on the live site.
|
|
319
|
+
kind: 'none',
|
|
320
|
+
values: [
|
|
321
|
+
{ value: 's', label: 'S', count: 1 },
|
|
322
|
+
{ value: 'm', label: 'M', count: 2 },
|
|
323
|
+
],
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
key: 'colour',
|
|
327
|
+
name: 'colour',
|
|
328
|
+
// Read off the values, never the key: these carry swatches, so the group is a colour one.
|
|
329
|
+
kind: 'color',
|
|
330
|
+
values: [
|
|
331
|
+
{ value: 'oat', label: 'oat', swatch: '#000', count: 1 },
|
|
332
|
+
{ value: 'moss', label: 'moss', swatch: '#000', count: 1 },
|
|
333
|
+
{ value: 'clay', label: 'clay', swatch: '#000', count: 1 },
|
|
334
|
+
],
|
|
335
|
+
},
|
|
336
|
+
],
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* The rule the whole multi-select interaction rests on (contract §1, "counts ignore own
|
|
342
|
+
* filter"): selecting "Oat" must leave the other colours countable, or the shopper can only ever
|
|
343
|
+
* narrow to one value and then has to clear it to see anything else.
|
|
344
|
+
*/
|
|
345
|
+
it('counts a family over the scope its own filter was left out of', () => {
|
|
346
|
+
const facets = deriveFacets(items, { filters: { 'option:colour': ['oat'] }, attributesFor });
|
|
347
|
+
const colours = facets.options.find((option) => option.key === 'colour')!;
|
|
348
|
+
expect(colours.values.map((value) => [value.value, value.count])).toEqual([
|
|
349
|
+
['oat', 1],
|
|
350
|
+
['moss', 1],
|
|
351
|
+
['clay', 1],
|
|
352
|
+
]);
|
|
353
|
+
// Every *other* family is counted with the colour filter applied: only the sweater is Oat.
|
|
354
|
+
expect(facets.categories).toEqual([
|
|
355
|
+
{ id: 'cat-knitwear', slug: 'knitwear', title: 'Knitwear', count: 1 },
|
|
356
|
+
{ id: 'cat-ceramics', slug: 'ceramics', title: 'Ceramics', count: 0 },
|
|
357
|
+
]);
|
|
358
|
+
expect(facets.availability).toEqual({ in_stock: 1, out_of_stock: 0 });
|
|
359
|
+
expect(facets.price).toEqual({ min: 96, max: 96 });
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
/** A value another filter excludes keeps its place in the vocabulary with a count of 0 — the
|
|
363
|
+
* panel disables it rather than letting it vanish under the shopper's pointer. */
|
|
364
|
+
it('keeps a zero-count value listed rather than dropping it', () => {
|
|
365
|
+
const facets = deriveFacets(items, { filters: { category: ['ceramics'] }, attributesFor });
|
|
366
|
+
const sizes = facets.options.find((option) => option.key === 'size')!;
|
|
367
|
+
expect(sizes.values.map((value) => [value.value, value.count])).toEqual([
|
|
368
|
+
['s', 0],
|
|
369
|
+
['m', 0],
|
|
370
|
+
]);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
/** Price bounds leave only the price filter out, so dragging a thumb never moves the track. */
|
|
374
|
+
it('spans the scope with every filter but price applied', () => {
|
|
375
|
+
expect(deriveFacets(items, { filters: { price: ['100-'] }, attributesFor }).price).toEqual({
|
|
376
|
+
min: 48,
|
|
377
|
+
max: 164,
|
|
378
|
+
});
|
|
379
|
+
expect(
|
|
380
|
+
deriveFacets(items, { filters: { category: ['knitwear'] }, attributesFor }).price
|
|
381
|
+
).toEqual({ min: 96, max: 164 });
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it('derives what the items alone can answer when no attributes are supplied', () => {
|
|
385
|
+
const cards = [
|
|
386
|
+
item({ handle: 'a', colours: [{ name: 'Oat', swatch: '#d8cbb0' }] }),
|
|
387
|
+
item({
|
|
388
|
+
handle: 'b',
|
|
389
|
+
price: { amount: 40 },
|
|
390
|
+
colours: [
|
|
391
|
+
{ name: 'Oat', swatch: '#d8cbb0' },
|
|
392
|
+
{ name: 'Moss', swatch: '#6b7a4f' },
|
|
393
|
+
],
|
|
394
|
+
}),
|
|
395
|
+
];
|
|
396
|
+
expect(deriveFacets(cards)).toEqual({
|
|
397
|
+
price: { min: 40, max: 100 },
|
|
398
|
+
categories: [],
|
|
399
|
+
collections: [],
|
|
400
|
+
availability: { in_stock: 2, out_of_stock: 0 },
|
|
401
|
+
options: [
|
|
402
|
+
{
|
|
403
|
+
key: 'colour',
|
|
404
|
+
name: 'colour',
|
|
405
|
+
kind: 'color',
|
|
406
|
+
values: [
|
|
407
|
+
{ value: 'oat', label: 'Oat', swatch: '#d8cbb0', count: 2 },
|
|
408
|
+
{ value: 'moss', label: 'Moss', swatch: '#6b7a4f', count: 1 },
|
|
409
|
+
],
|
|
410
|
+
},
|
|
411
|
+
],
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
it('answers a zero span and empty families for nothing at all', () => {
|
|
416
|
+
expect(deriveFacets([])).toEqual({
|
|
417
|
+
price: { min: 0, max: 0 },
|
|
418
|
+
categories: [],
|
|
419
|
+
collections: [],
|
|
420
|
+
availability: { in_stock: 0, out_of_stock: 0 },
|
|
421
|
+
options: [],
|
|
422
|
+
});
|
|
423
|
+
expect(deriveFacets([item({ handle: 'a' })]).options).toEqual([]);
|
|
424
|
+
});
|
|
425
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { EldraHttpError } from '@eldrajs/sdk';
|
|
3
|
+
import {
|
|
4
|
+
failureMessageKey,
|
|
5
|
+
isOutOfStock,
|
|
6
|
+
toStorefrontFailure,
|
|
7
|
+
} from '../../app/storefront/feedback';
|
|
8
|
+
|
|
9
|
+
/** A gateway refusal as the SDK throws it: an RFC 9457 problem body behind a status. */
|
|
10
|
+
function refusal(status: number, body: unknown): EldraHttpError {
|
|
11
|
+
return new EldraHttpError({ status, statusText: 'Conflict' } as Response, body);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe('toStorefrontFailure', () => {
|
|
15
|
+
it('keeps the errorId, code and status of a gateway refusal', () => {
|
|
16
|
+
const failure = toStorefrontFailure(
|
|
17
|
+
refusal(409, {
|
|
18
|
+
code: 'CONFLICT',
|
|
19
|
+
errorId: 'CART_INSUFFICIENT_STOCK',
|
|
20
|
+
detail: 'insufficient stock',
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
expect(failure.errorId).toBe('CART_INSUFFICIENT_STOCK');
|
|
25
|
+
expect(failure.code).toBe('CONFLICT');
|
|
26
|
+
expect(failure.status).toBe(409);
|
|
27
|
+
// The developer-facing text, kept for diagnosis and never shown to a shopper.
|
|
28
|
+
expect(failure.message).toContain('409');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('keeps a request that never got an answer apart from one that did', () => {
|
|
32
|
+
const offline = toStorefrontFailure(new TypeError('Failed to fetch'));
|
|
33
|
+
expect(offline.status).toBeNull();
|
|
34
|
+
expect(offline.errorId).toBeNull();
|
|
35
|
+
expect(offline.message).toBe('Failed to fetch');
|
|
36
|
+
|
|
37
|
+
// Something that is not an Error at all still produces a usable failure rather than throwing.
|
|
38
|
+
expect(toStorefrontFailure('nope').message).toBe('Something went wrong.');
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('failureMessageKey', () => {
|
|
43
|
+
it('says out of stock for a refusal about stock', () => {
|
|
44
|
+
// What the cart service actually sends: the generic `code` every conflict carries, and the
|
|
45
|
+
// `errorId` that says which conflict it was.
|
|
46
|
+
const failure = toStorefrontFailure(
|
|
47
|
+
refusal(409, { code: 'CONFLICT', errorId: 'CART_INSUFFICIENT_STOCK' })
|
|
48
|
+
);
|
|
49
|
+
expect(failureMessageKey(failure)).toBe('storefront.outOfStock');
|
|
50
|
+
expect(isOutOfStock(failure)).toBe(true);
|
|
51
|
+
|
|
52
|
+
// `code` is read as a tolerance should a refusal ever arrive without the `errorId`.
|
|
53
|
+
const idless = toStorefrontFailure(refusal(409, { code: 'CART_INSUFFICIENT_STOCK' }));
|
|
54
|
+
expect(failureMessageKey(idless)).toBe('storefront.outOfStock');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('says the item is gone for a product or variant that no longer resolves', () => {
|
|
58
|
+
for (const errorId of [
|
|
59
|
+
'CART_INVALID_PRODUCT',
|
|
60
|
+
'CART_INVALID_PRODUCT_ID',
|
|
61
|
+
'CART_INVALID_VARIANT_ID',
|
|
62
|
+
]) {
|
|
63
|
+
const failure = toStorefrontFailure(refusal(409, { errorId }));
|
|
64
|
+
expect(failureMessageKey(failure)).toBe('storefront.unavailable');
|
|
65
|
+
// Specific, but not the stock case — the page must not flip its stock line for it.
|
|
66
|
+
expect(isOutOfStock(failure)).toBe(false);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('says to reload when the cart, or the line in it, is gone', () => {
|
|
71
|
+
for (const errorId of ['CART_NOT_FOUND', 'CART_ITEM_NOT_FOUND']) {
|
|
72
|
+
expect(failureMessageKey(toStorefrontFailure(refusal(404, { errorId })))).toBe(
|
|
73
|
+
'storefront.cartOutOfDate'
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('says something generic for the cart service’s internal failures', () => {
|
|
79
|
+
// Real ids, and none of them anything a shopper can act on.
|
|
80
|
+
for (const errorId of ['CART_DB_UPDATE_ERROR', 'CART_VERSION_CONFLICT', 'CART_MARSHAL_ERROR']) {
|
|
81
|
+
expect(failureMessageKey(toStorefrontFailure(refusal(500, { errorId })))).toBe(
|
|
82
|
+
'storefront.mutationFailed'
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('falls back to the generic sentence for anything else, and for no failure at all', () => {
|
|
88
|
+
expect(failureMessageKey(toStorefrontFailure(refusal(500, { code: 'INTERNAL' })))).toBe(
|
|
89
|
+
'storefront.mutationFailed'
|
|
90
|
+
);
|
|
91
|
+
expect(failureMessageKey(toStorefrontFailure(new Error('offline')))).toBe(
|
|
92
|
+
'storefront.mutationFailed'
|
|
93
|
+
);
|
|
94
|
+
expect(failureMessageKey(null)).toBe('storefront.mutationFailed');
|
|
95
|
+
expect(isOutOfStock(null)).toBe(false);
|
|
96
|
+
});
|
|
97
|
+
});
|