@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,74 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
collectionSelector,
|
|
4
|
+
selectorNeedsPublish,
|
|
5
|
+
selectorSlug,
|
|
6
|
+
} from '../../app/storefront/collectionSelector';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The resolution order the three commerce blocks share (`product-carousel`,
|
|
10
|
+
* `collection-grid`, `collection-header`): the picked collection's resolved
|
|
11
|
+
* `slug`, then its bare id, then — for a block that can sit on a collection
|
|
12
|
+
* template — the route's own collection. Asserted here rather than only through
|
|
13
|
+
* the blocks, because the demo storefront answers a slug and an id equally well
|
|
14
|
+
* — so a block test cannot tell the two apart, and the order would go
|
|
15
|
+
* unguarded.
|
|
16
|
+
*/
|
|
17
|
+
const ID = '2f1b8d54-0d3a-4a6f-9a0b-7f6c1d2e3a01';
|
|
18
|
+
|
|
19
|
+
describe('collectionSelector', () => {
|
|
20
|
+
it('prefers the reference’s resolved slug over its own id', () => {
|
|
21
|
+
expect(collectionSelector({ id: ID, _type: 'collection', slug: 'winter-knitwear' })).toEqual({
|
|
22
|
+
slug: 'winter-knitwear',
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('falls back to the reference’s id when it carries no slug', () => {
|
|
27
|
+
expect(collectionSelector({ id: ID, _type: 'collection' })).toEqual({ id: ID });
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('reads a seed reference, which names its collection by slug and carries no id', () => {
|
|
31
|
+
// What `pages/home.page.json` ships and Core writes when it cannot resolve
|
|
32
|
+
// the slug to one of the organisation's own collections: the block still
|
|
33
|
+
// has a usable selector without the round trip.
|
|
34
|
+
expect(
|
|
35
|
+
collectionSelector({
|
|
36
|
+
_type: 'collection',
|
|
37
|
+
slug: 'the-winter-edit',
|
|
38
|
+
} as EldraCollectionReference)
|
|
39
|
+
).toEqual({ slug: 'the-winter-edit' });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('lets a reference with a slug beat the route', () => {
|
|
43
|
+
expect(collectionSelector({ id: ID, _type: 'collection', slug: 'picked' }, 'route')).toEqual({
|
|
44
|
+
slug: 'picked',
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('lets a stub reference beat the route too — the field overrides it', () => {
|
|
49
|
+
expect(collectionSelector({ id: ID, _type: 'collection' }, 'route')).toEqual({ id: ID });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('falls back to the route’s collection, and to nothing at all', () => {
|
|
53
|
+
expect(collectionSelector(null, 'route')).toEqual({ slug: 'route' });
|
|
54
|
+
expect(collectionSelector(null, ' ')).toBeNull();
|
|
55
|
+
expect(collectionSelector(null, null)).toBeNull();
|
|
56
|
+
expect(collectionSelector(undefined)).toBeNull();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('trims the route’s handle and ignores a reference with neither key', () => {
|
|
60
|
+
expect(collectionSelector(null, ' spaced ')).toEqual({ slug: 'spaced' });
|
|
61
|
+
expect(
|
|
62
|
+
collectionSelector({ slug: ' ' } as unknown as EldraCollectionReference, 'route')
|
|
63
|
+
).toEqual({ slug: 'route' });
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('reports the slug, and whether only an id is known', () => {
|
|
67
|
+
expect(selectorSlug({ slug: 'winter-knitwear' })).toBe('winter-knitwear');
|
|
68
|
+
expect(selectorSlug({ id: ID })).toBeNull();
|
|
69
|
+
expect(selectorSlug(null)).toBeNull();
|
|
70
|
+
expect(selectorNeedsPublish({ id: ID })).toBe(true);
|
|
71
|
+
expect(selectorNeedsPublish({ slug: 'winter-knitwear' })).toBe(false);
|
|
72
|
+
expect(selectorNeedsPublish(null)).toBe(false);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
import { nextTick, ref } from 'vue';
|
|
2
|
+
import { describe, expect, expectTypeOf, it } from 'vitest';
|
|
3
|
+
import { createDemoStorefront, demoCollectionId, PRODUCTS } from '../../app/storefront/demo';
|
|
4
|
+
import { applyVolatileSnapshots, collectVolatileTargets } from '../../app/storefront/volatile';
|
|
5
|
+
import type {
|
|
6
|
+
StorefrontCollectionInfo,
|
|
7
|
+
StorefrontCollectionSelector,
|
|
8
|
+
StorefrontOrder,
|
|
9
|
+
StorefrontProduct,
|
|
10
|
+
StorefrontProductListItem,
|
|
11
|
+
StorefrontSearchResponse,
|
|
12
|
+
} from '../../app/storefront/types';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The demo `StorefrontResult` takes one of two paths, decided by whether there is a browser
|
|
16
|
+
* (`createDemoResult`, `app/storefront/demo.ts`). Off a browser it answers inside the synchronous
|
|
17
|
+
* `immediate: true` watcher, because a server render gets one pass and a fixture that answers
|
|
18
|
+
* "later" would bake a skeleton into the prerendered HTML. In a browser it answers after its own
|
|
19
|
+
* `await nextTick()` instead, so a block sees the same `loading` → settled sequence a real read
|
|
20
|
+
* gives it.
|
|
21
|
+
*
|
|
22
|
+
* This file carries no environment docblock, so it runs in `vitest.config.ts`'s default `node`
|
|
23
|
+
* environment and takes the synchronous path: the data is already there when `createDemoResult`
|
|
24
|
+
* returns. The two ticks are kept anyway — they cost nothing, and they keep every assertion below
|
|
25
|
+
* correct under either path rather than silently depending on which one this file happens to take.
|
|
26
|
+
*/
|
|
27
|
+
async function settle(): Promise<void> {
|
|
28
|
+
await nextTick();
|
|
29
|
+
await nextTick();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('createDemoStorefront', () => {
|
|
33
|
+
it('the catalogue satisfies StorefrontProductListItem — real under pnpm typecheck', () => {
|
|
34
|
+
expectTypeOf(PRODUCTS).toEqualTypeOf<StorefrontProductListItem[]>();
|
|
35
|
+
expect(PRODUCTS).toHaveLength(12);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('contains the spec Northwind products with their prices, in major units', () => {
|
|
39
|
+
const byTitle = new Map(PRODUCTS.map((product) => [product.title, product]));
|
|
40
|
+
|
|
41
|
+
expect(byTitle.get('Merino crew sweater')?.price).toEqual({ amount: 96, compareAt: 128 });
|
|
42
|
+
expect(byTitle.get('Fisherman rib cardigan')?.price.amount).toBe(164);
|
|
43
|
+
expect(byTitle.get('Lambswool throw blanket')?.price.amount).toBe(148);
|
|
44
|
+
expect(byTitle.get('Ribbed lambswool beanie')?.price.amount).toBe(38);
|
|
45
|
+
expect(byTitle.get('Linen tea towels, pair')?.price.amount).toBe(24);
|
|
46
|
+
expect(byTitle.get('Speckled latte mug')?.price.amount).toBe(28);
|
|
47
|
+
expect(byTitle.get('Stoneware dinner plates, set of 4')?.price.amount).toBe(72);
|
|
48
|
+
expect(byTitle.get('Walnut serving board')?.price.amount).toBe(58);
|
|
49
|
+
expect(byTitle.get('Hand-thrown serving bowl')?.price.amount).toBe(64);
|
|
50
|
+
expect(byTitle.get('Glazed milk jug')?.price.amount).toBe(34);
|
|
51
|
+
expect(byTitle.get('Linen napkins, set of 4')?.price.amount).toBe(40);
|
|
52
|
+
expect(byTitle.get('Stonewashed linen throw')?.price.amount).toBe(118);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('"Linen tea towels, pair" is sold out; everything else defaults to in stock', () => {
|
|
56
|
+
const byTitle = new Map(PRODUCTS.map((product) => [product.title, product]));
|
|
57
|
+
const soldOut = byTitle.get('Linen tea towels, pair')!;
|
|
58
|
+
expect(soldOut.stock).toBe('out');
|
|
59
|
+
expect(soldOut.available).toBe(false);
|
|
60
|
+
|
|
61
|
+
const inStock = byTitle.get('Merino crew sweater')!;
|
|
62
|
+
expect(inStock.stock).toBe('in');
|
|
63
|
+
expect(inStock.available).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("the merino crew sweater's full product record has Colour and Size options", async () => {
|
|
67
|
+
const storefront = createDemoStorefront();
|
|
68
|
+
const handle = ref<string | null>('merino-crew-sweater');
|
|
69
|
+
const result = storefront.catalog.product(handle);
|
|
70
|
+
expectTypeOf(result.data.value).toEqualTypeOf<StorefrontProduct | null>();
|
|
71
|
+
await settle();
|
|
72
|
+
|
|
73
|
+
const product = result.data.value;
|
|
74
|
+
expect(product).not.toBeNull();
|
|
75
|
+
const colour = product!.options.find((option) => option.label === 'Colour');
|
|
76
|
+
// The fixture declares the merchant's own display choice, and `type` is derived from it by the
|
|
77
|
+
// same function the gateway source uses — so Storybook keeps its swatches for the reason the
|
|
78
|
+
// live site has them rather than because this fixture hard-coded the control.
|
|
79
|
+
expect(colour?.kind).toBe('color');
|
|
80
|
+
expect(colour?.type).toBe('swatches');
|
|
81
|
+
expect(colour?.values.every((value) => typeof value.swatch === 'string')).toBe(true);
|
|
82
|
+
expect(colour?.values.map((value) => value.label)).toEqual(['Oat', 'Charcoal', 'Clay', 'Moss']);
|
|
83
|
+
expect(colour?.values.find((value) => value.label === 'Moss')?.available).toBe(false);
|
|
84
|
+
expect(colour?.values.filter((value) => value.available)).toHaveLength(3);
|
|
85
|
+
|
|
86
|
+
const size = product!.options.find((option) => option.label === 'Size');
|
|
87
|
+
// `none` — a plain list of values, and what every option looked like before the kind existed.
|
|
88
|
+
expect(size?.kind).toBe('none');
|
|
89
|
+
expect(size?.type).toBe('pills');
|
|
90
|
+
expect(size?.values.map((value) => value.label)).toEqual(['XS', 'S', 'M', 'L', 'XL']);
|
|
91
|
+
expect(size?.values.find((value) => value.label === 'XL')?.available).toBe(false);
|
|
92
|
+
expect(size?.values.filter((value) => value.available)).toHaveLength(4);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('has the "Winter knitwear" collection with 48 products', async () => {
|
|
96
|
+
const storefront = createDemoStorefront();
|
|
97
|
+
const handle = ref<string | null>('winter-knitwear');
|
|
98
|
+
const result = storefront.catalog.collection(handle);
|
|
99
|
+
expectTypeOf(result.data.value).toEqualTypeOf<StorefrontCollectionInfo | null>();
|
|
100
|
+
await settle();
|
|
101
|
+
expect(result.data.value).toMatchObject({ title: 'Winter knitwear', productCount: 48 });
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('has "The winter edit" collection with 48 products', async () => {
|
|
105
|
+
const storefront = createDemoStorefront();
|
|
106
|
+
const handle = ref<string | null>('the-winter-edit');
|
|
107
|
+
const result = storefront.catalog.collection(handle);
|
|
108
|
+
await settle();
|
|
109
|
+
expect(result.data.value).toMatchObject({ title: 'The winter edit', productCount: 48 });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('order NW-10482 (shipped) matches the spec default content', async () => {
|
|
113
|
+
const storefront = createDemoStorefront();
|
|
114
|
+
const token = ref<string | null>('demo-order-token');
|
|
115
|
+
const result = storefront.orders.current(token);
|
|
116
|
+
expectTypeOf(result.data.value).toEqualTypeOf<StorefrontOrder | null>();
|
|
117
|
+
await settle();
|
|
118
|
+
|
|
119
|
+
const order = result.data.value;
|
|
120
|
+
expect(order).not.toBeNull();
|
|
121
|
+
expect(order!.number).toBe('NW-10482');
|
|
122
|
+
expect(order!.status).toBe('shipped');
|
|
123
|
+
expect(order!.placedAt).toBe('2026-09-18');
|
|
124
|
+
expect(order!.itemCount).toBe(4);
|
|
125
|
+
expect(order!.carrier).toBe('UPS Standard');
|
|
126
|
+
expect(order!.eta).toBe('Thursday 26 September');
|
|
127
|
+
expect(order!.trackingNumber).toBe('1Z 999 AA1 01 2345 6784');
|
|
128
|
+
expect(order!.totals).toEqual({
|
|
129
|
+
subtotal: 244,
|
|
130
|
+
discount: null,
|
|
131
|
+
shipping: 0,
|
|
132
|
+
tax: 19.52,
|
|
133
|
+
total: 263.52,
|
|
134
|
+
});
|
|
135
|
+
expect(order!.shippingAddress).toEqual([
|
|
136
|
+
'Maren Holt',
|
|
137
|
+
'214 Linden Street, Apt 3B',
|
|
138
|
+
'Portland, OR 97209',
|
|
139
|
+
'United States',
|
|
140
|
+
]);
|
|
141
|
+
expect(order!.payment).toEqual({ brand: 'Visa', last4: '4242' });
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('createDemoStorefront({ orderStatus }) switches the order fixture', async () => {
|
|
145
|
+
const storefront = createDemoStorefront({ orderStatus: 'cancelled' });
|
|
146
|
+
const token = ref<string | null>('demo-order-token');
|
|
147
|
+
const result = storefront.orders.current(token);
|
|
148
|
+
await settle();
|
|
149
|
+
expect(result.data.value?.status).toBe('cancelled');
|
|
150
|
+
expect(result.data.value?.cancelNote).toContain('Cancelled at your request on 19 September');
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('the "linen" search response matches only the products, journal articles and pages that mention it', async () => {
|
|
154
|
+
const storefront = createDemoStorefront();
|
|
155
|
+
const query = ref('linen');
|
|
156
|
+
const result = storefront.search.run(query);
|
|
157
|
+
expectTypeOf(result.data.value).toEqualTypeOf<StorefrontSearchResponse | null>();
|
|
158
|
+
await settle();
|
|
159
|
+
|
|
160
|
+
const response = result.data.value;
|
|
161
|
+
expect(response).not.toBeNull();
|
|
162
|
+
expect(response!.query).toBe('linen');
|
|
163
|
+
// Linen tea towels, pair · Linen napkins, set of 4 · Stonewashed linen throw.
|
|
164
|
+
expect(response!.products.map((p) => p.title)).toEqual([
|
|
165
|
+
'Linen tea towels, pair',
|
|
166
|
+
'Linen napkins, set of 4',
|
|
167
|
+
'Stonewashed linen throw',
|
|
168
|
+
]);
|
|
169
|
+
// "A visit to the Kortrijk flax mill" mentions neither "linen" nor its own category.
|
|
170
|
+
expect(response!.articles).toHaveLength(2);
|
|
171
|
+
// Both pages mention linen, one in its title and one only in its snippet.
|
|
172
|
+
expect(response!.pages).toHaveLength(2);
|
|
173
|
+
expect(response!.total).toBe(
|
|
174
|
+
response!.products.length + response!.articles.length + response!.pages.length
|
|
175
|
+
);
|
|
176
|
+
expect(response!.suggestion).toBeNull();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('matches case-insensitively on a product title', async () => {
|
|
180
|
+
const storefront = createDemoStorefront();
|
|
181
|
+
const query = ref('MERINO');
|
|
182
|
+
const result = storefront.search.run(query);
|
|
183
|
+
await settle();
|
|
184
|
+
const response = result.data.value!;
|
|
185
|
+
expect(response.products.map((p) => p.handle)).toEqual(['merino-crew-sweater']);
|
|
186
|
+
expect(response.articles).toHaveLength(0);
|
|
187
|
+
expect(response.pages).toHaveLength(0);
|
|
188
|
+
expect(response.total).toBe(1);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('an empty query returns an empty response', async () => {
|
|
192
|
+
const storefront = createDemoStorefront();
|
|
193
|
+
const query = ref('');
|
|
194
|
+
const result = storefront.search.run(query);
|
|
195
|
+
await settle();
|
|
196
|
+
expect(result.data.value).toEqual({
|
|
197
|
+
query: '',
|
|
198
|
+
total: 0,
|
|
199
|
+
products: [],
|
|
200
|
+
articles: [],
|
|
201
|
+
pages: [],
|
|
202
|
+
suggestion: null,
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('a near-miss query with no results gets a "did you mean" suggestion', async () => {
|
|
207
|
+
const storefront = createDemoStorefront();
|
|
208
|
+
const query = ref('linnen napkns');
|
|
209
|
+
const result = storefront.search.run(query);
|
|
210
|
+
await settle();
|
|
211
|
+
const response = result.data.value!;
|
|
212
|
+
expect(response.total).toBe(0);
|
|
213
|
+
expect(response.suggestion).toBe('linen napkins');
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('a query that matches nothing at all in the catalogue gets no suggestion', async () => {
|
|
217
|
+
const storefront = createDemoStorefront();
|
|
218
|
+
const query = ref('xyzxyzxyz');
|
|
219
|
+
const result = storefront.search.run(query);
|
|
220
|
+
await settle();
|
|
221
|
+
const response = result.data.value!;
|
|
222
|
+
expect(response.total).toBe(0);
|
|
223
|
+
expect(response.suggestion).toBeNull();
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('the "best-sellers" collection satisfies catalog.collectionProducts, leading with the spec\'s named products', async () => {
|
|
227
|
+
const storefront = createDemoStorefront();
|
|
228
|
+
const collection = ref<StorefrontCollectionSelector | null>({ slug: 'best-sellers' });
|
|
229
|
+
const opts = ref({ page: 1, pageSize: 4 });
|
|
230
|
+
const result = storefront.catalog.collectionProducts(collection, opts);
|
|
231
|
+
await settle();
|
|
232
|
+
const response = result.data.value;
|
|
233
|
+
expect(response).not.toBeNull();
|
|
234
|
+
expect(response!.total).toBeGreaterThanOrEqual(4);
|
|
235
|
+
expect(response!.items.length).toBe(4);
|
|
236
|
+
expect(response!.items.map((item) => item.title).slice(0, 2)).toEqual([
|
|
237
|
+
'Merino crew sweater',
|
|
238
|
+
'Speckled latte mug',
|
|
239
|
+
]);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
/** A `reference` field stores the collection's id, so the demo fixture has to
|
|
243
|
+
* answer an id the same way the gateway does — otherwise every builder preview
|
|
244
|
+
* of a picked collection would render empty. */
|
|
245
|
+
it('resolves a collection id from its own fixture, like the gateway does', async () => {
|
|
246
|
+
const storefront = createDemoStorefront();
|
|
247
|
+
const id = demoCollectionId('best-sellers');
|
|
248
|
+
expect(id).not.toBeNull();
|
|
249
|
+
const collection = ref<StorefrontCollectionSelector | null>({ id: id! });
|
|
250
|
+
const opts = ref({ page: 1, pageSize: 2 });
|
|
251
|
+
const result = storefront.catalog.collectionProducts(collection, opts);
|
|
252
|
+
await settle();
|
|
253
|
+
expect(result.data.value!.items.map((item) => item.title)).toEqual([
|
|
254
|
+
'Merino crew sweater',
|
|
255
|
+
'Speckled latte mug',
|
|
256
|
+
]);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('resolves nothing for a collection id it does not know — never an error', async () => {
|
|
260
|
+
const storefront = createDemoStorefront();
|
|
261
|
+
const collection = ref<StorefrontCollectionSelector | null>({
|
|
262
|
+
id: '00000000-0000-4000-8000-000000000000',
|
|
263
|
+
});
|
|
264
|
+
const opts = ref({ page: 1, pageSize: 2 });
|
|
265
|
+
const result = storefront.catalog.collectionProducts(collection, opts);
|
|
266
|
+
await settle();
|
|
267
|
+
expect(result.data.value).toBeNull();
|
|
268
|
+
expect(result.error.value).toBeNull();
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* D1 made `search.run(query)` honour the query text; `collectionProducts` was left behind and
|
|
273
|
+
* destructured only `{ page, pageSize }`, so in the scaffolded site and the collection sample page
|
|
274
|
+
* — both demo-backed — a filter or a sort changed the URL, the chips and the active-filter row
|
|
275
|
+
* while the grid and the `total` stayed exactly as they were, and the filter drawer's
|
|
276
|
+
* "Show N products" button always quoted the unfiltered count. These are the assertions for it,
|
|
277
|
+
* in the same shape as the `search.run` ones above: drive the real request, read the real answer.
|
|
278
|
+
*/
|
|
279
|
+
describe('collectionProducts honours sort and filters', () => {
|
|
280
|
+
async function collection(opts: {
|
|
281
|
+
page?: number;
|
|
282
|
+
pageSize?: number;
|
|
283
|
+
sort?: string;
|
|
284
|
+
filters?: Record<string, string[]>;
|
|
285
|
+
}) {
|
|
286
|
+
const storefront = createDemoStorefront();
|
|
287
|
+
const selected = ref<StorefrontCollectionSelector | null>({ slug: 'winter-knitwear' });
|
|
288
|
+
const options = ref({ page: 1, pageSize: 48, ...opts });
|
|
289
|
+
const result = storefront.catalog.collectionProducts(selected, options);
|
|
290
|
+
await settle();
|
|
291
|
+
return result.data.value!;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
it('returns the whole 48-item collection unfiltered', async () => {
|
|
295
|
+
const response = await collection({});
|
|
296
|
+
expect(response.items).toHaveLength(48);
|
|
297
|
+
expect(response.total).toBe(48);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('narrows both the items and the total for a category filter', async () => {
|
|
301
|
+
// 5 of the 12 products are knitwear, each appearing 4 times in the 48-item collection.
|
|
302
|
+
const response = await collection({ filters: { category: ['knitwear'] } });
|
|
303
|
+
expect(response.items).toHaveLength(20);
|
|
304
|
+
expect(response.total).toBe(20);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('ORs values inside one source and ANDs across sources', async () => {
|
|
308
|
+
const knitwear = await collection({ filters: { category: ['knitwear'] } });
|
|
309
|
+
const ceramics = await collection({ filters: { category: ['ceramics'] } });
|
|
310
|
+
const both = await collection({ filters: { category: ['knitwear', 'ceramics'] } });
|
|
311
|
+
expect(both.total).toBe(knitwear.total + ceramics.total);
|
|
312
|
+
|
|
313
|
+
const andACross = await collection({
|
|
314
|
+
filters: { category: ['knitwear'], 'option:size': ['m'] },
|
|
315
|
+
});
|
|
316
|
+
// Only the three apparel products are made in M, and all three are knitwear.
|
|
317
|
+
expect(andACross.total).toBe(12);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('filters by size, colour and availability', async () => {
|
|
321
|
+
expect((await collection({ filters: { 'option:size': ['m'] } })).total).toBe(12);
|
|
322
|
+
// Oat is only the merino crew sweater's colour, four times over.
|
|
323
|
+
expect((await collection({ filters: { 'option:colour': ['oat'] } })).total).toBe(4);
|
|
324
|
+
// Everything but the sold-out linen tea towels.
|
|
325
|
+
expect((await collection({ filters: { availability: ['in-stock'] } })).total).toBe(44);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it('filters by a price range in whole dollars, with either end open', async () => {
|
|
329
|
+
const upTo40 = await collection({ filters: { price: ['-40'] } });
|
|
330
|
+
expect(upTo40.items.every((item) => item.price.amount <= 40)).toBe(true);
|
|
331
|
+
const from100 = await collection({ filters: { price: ['100-'] } });
|
|
332
|
+
expect(from100.items.every((item) => item.price.amount >= 100)).toBe(true);
|
|
333
|
+
const band = await collection({ filters: { price: ['30-60'] } });
|
|
334
|
+
expect(band.items.every((item) => item.price.amount >= 30 && item.price.amount <= 60)).toBe(
|
|
335
|
+
true
|
|
336
|
+
);
|
|
337
|
+
expect(band.total).toBeGreaterThan(0);
|
|
338
|
+
expect(band.total).toBeLessThan(48);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it('ignores a filter source it does not know rather than emptying the grid', async () => {
|
|
342
|
+
expect((await collection({ filters: { 'option:fabric': ['linen'] } })).total).toBe(48);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it('sorts by price ascending and descending', async () => {
|
|
346
|
+
const asc = await collection({ sort: 'price-asc' });
|
|
347
|
+
const desc = await collection({ sort: 'price-desc' });
|
|
348
|
+
expect(asc.items[0]!.price.amount).toBe(24);
|
|
349
|
+
expect(asc.items.at(-1)!.price.amount).toBe(164);
|
|
350
|
+
expect(desc.items[0]!.price.amount).toBe(164);
|
|
351
|
+
expect(asc.items.map((item) => item.price.amount)).toEqual(
|
|
352
|
+
[...desc.items.map((item) => item.price.amount)].reverse()
|
|
353
|
+
);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it('leaves `featured` in the collection\u2019s own order and reverses it for `newest`', async () => {
|
|
357
|
+
const featured = await collection({ sort: 'featured' });
|
|
358
|
+
const newest = await collection({ sort: 'newest' });
|
|
359
|
+
const unsorted = await collection({});
|
|
360
|
+
expect(featured.items.map((item) => item.handle)).toEqual(
|
|
361
|
+
unsorted.items.map((item) => item.handle)
|
|
362
|
+
);
|
|
363
|
+
expect(newest.items.map((item) => item.handle)).toEqual(
|
|
364
|
+
[...unsorted.items.map((item) => item.handle)].reverse()
|
|
365
|
+
);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it('leads `best-selling` with the best-seller list, clones included', async () => {
|
|
369
|
+
const response = await collection({ sort: 'best-selling' });
|
|
370
|
+
// The demo's best-seller list names 6 products; each appears 4 times in the 48-item
|
|
371
|
+
// collection, so the first 24 items are exactly those six (identified by title — a clone
|
|
372
|
+
// carries a suffixed handle but the same title), and the merino crew sweater leads.
|
|
373
|
+
expect(response.items[0]!.title).toBe('Merino crew sweater');
|
|
374
|
+
const leading = new Set(response.items.slice(0, 24).map((item) => item.title));
|
|
375
|
+
expect([...leading].sort()).toEqual(
|
|
376
|
+
[
|
|
377
|
+
'Hand-thrown serving bowl',
|
|
378
|
+
'Merino crew sweater',
|
|
379
|
+
'Ribbed lambswool beanie',
|
|
380
|
+
'Speckled latte mug',
|
|
381
|
+
'Stoneware dinner plates, set of 4',
|
|
382
|
+
'Walnut serving board',
|
|
383
|
+
].sort()
|
|
384
|
+
);
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it('sorts and filters together, and pages the filtered result', async () => {
|
|
388
|
+
const response = await collection({
|
|
389
|
+
page: 2,
|
|
390
|
+
pageSize: 8,
|
|
391
|
+
sort: 'price-asc',
|
|
392
|
+
filters: { category: ['knitwear'] },
|
|
393
|
+
});
|
|
394
|
+
expect(response.total).toBe(20);
|
|
395
|
+
expect(response.items).toHaveLength(8);
|
|
396
|
+
const prices = response.items.map((item) => item.price.amount);
|
|
397
|
+
expect(prices).toEqual([...prices].sort((a, b) => a - b));
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Every count a filter group shows has to be the number of products that value returns, or the
|
|
402
|
+
* shopper is offered a filter that empties the grid. The demo derives its facets with
|
|
403
|
+
* `deriveFacets` over the whole collection, so this walks every value of every family and
|
|
404
|
+
* re-reads the collection filtered by it alone.
|
|
405
|
+
*/
|
|
406
|
+
it('counts every facet value over the collection, so the grid never offers an empty filter', async () => {
|
|
407
|
+
const response = await collection({});
|
|
408
|
+
const facets = response.facets!;
|
|
409
|
+
const clauses: Array<{ source: string; value: string; count: number }> = [
|
|
410
|
+
...facets.categories.map((term) => ({
|
|
411
|
+
source: 'category',
|
|
412
|
+
value: term.slug,
|
|
413
|
+
count: term.count,
|
|
414
|
+
})),
|
|
415
|
+
...facets.collections.map((term) => ({
|
|
416
|
+
source: 'collection',
|
|
417
|
+
value: term.slug,
|
|
418
|
+
count: term.count,
|
|
419
|
+
})),
|
|
420
|
+
...facets.options.flatMap((option) =>
|
|
421
|
+
option.values.map((value) => ({
|
|
422
|
+
source: `option:${option.key}`,
|
|
423
|
+
value: value.value,
|
|
424
|
+
count: value.count,
|
|
425
|
+
}))
|
|
426
|
+
),
|
|
427
|
+
{ source: 'availability', value: 'in_stock', count: facets.availability.in_stock },
|
|
428
|
+
{ source: 'availability', value: 'out_of_stock', count: facets.availability.out_of_stock },
|
|
429
|
+
];
|
|
430
|
+
expect(clauses.length).toBeGreaterThan(10);
|
|
431
|
+
for (const clause of clauses) {
|
|
432
|
+
const filtered = await collection({ filters: { [clause.source]: [clause.value] } });
|
|
433
|
+
expect(
|
|
434
|
+
clause.count,
|
|
435
|
+
`facet ${clause.source}=${clause.value} claims ${clause.count} but returns ${filtered.total}`
|
|
436
|
+
).toBe(filtered.total);
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
/** The collection group's own values: the winter edit holds all 48, and the curated
|
|
441
|
+
* `best-sellers` list a subset — which is what makes the group worth showing at all. */
|
|
442
|
+
it('derives the collection facet from the fixture’s own membership', async () => {
|
|
443
|
+
const facets = (await collection({})).facets!;
|
|
444
|
+
const bySlug = new Map(facets.collections.map((term) => [term.slug, term]));
|
|
445
|
+
expect(bySlug.get('the-winter-edit')?.count).toBe(48);
|
|
446
|
+
expect(bySlug.get('best-sellers')?.count).toBe(24);
|
|
447
|
+
expect(bySlug.get('the-winter-edit')?.title).toBe('The winter edit');
|
|
448
|
+
// The id is the one a `reference` field carries, so a filter value and a picked collection
|
|
449
|
+
// describe the same object.
|
|
450
|
+
expect(bySlug.get('best-sellers')?.id).toBe(demoCollectionId('best-sellers'));
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
/** The price bounds the `collection-grid`'s range slider is drawn from: the collection's own
|
|
454
|
+
* cheapest and dearest, and they do not move when the shopper drags a thumb. */
|
|
455
|
+
it('spans the collection’s own prices, and keeps the span under a price filter', async () => {
|
|
456
|
+
expect((await collection({})).facets!.price).toEqual({ min: 24, max: 164 });
|
|
457
|
+
expect((await collection({ filters: { price: ['50-100'] } })).facets!.price).toEqual({
|
|
458
|
+
min: 24,
|
|
459
|
+
max: 164,
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
describe('StorefrontRoute readers', () => {
|
|
465
|
+
it('seeds sort, columns and filters from DemoStorefrontOptions — a shared URL restored', () => {
|
|
466
|
+
const storefront = createDemoStorefront({
|
|
467
|
+
sort: 'price-asc',
|
|
468
|
+
columns: '2',
|
|
469
|
+
filters: { category: ['knitwear'], minPrice: ['20'] },
|
|
470
|
+
});
|
|
471
|
+
expect(storefront.route.sort).toBe('price-asc');
|
|
472
|
+
expect(storefront.route.columns).toBe('2');
|
|
473
|
+
expect(storefront.route.filters).toEqual({ category: ['knitwear'], minPrice: ['20'] });
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
it('defaults sort/columns to null and filters to an empty bag, like page defaults to 1', () => {
|
|
477
|
+
const storefront = createDemoStorefront();
|
|
478
|
+
expect(storefront.route.sort).toBeNull();
|
|
479
|
+
expect(storefront.route.columns).toBeNull();
|
|
480
|
+
expect(storefront.route.filters).toEqual({});
|
|
481
|
+
expect(storefront.route.page).toBe(1);
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
it('setQuery writes sort/columns/filters back the same generic way it writes q/page', () => {
|
|
485
|
+
const storefront = createDemoStorefront();
|
|
486
|
+
storefront.route.setQuery({
|
|
487
|
+
sort: 'newest',
|
|
488
|
+
columns: '4',
|
|
489
|
+
category: ['knitwear', 'ceramics'],
|
|
490
|
+
minPrice: '10',
|
|
491
|
+
});
|
|
492
|
+
expect(storefront.route.sort).toBe('newest');
|
|
493
|
+
expect(storefront.route.columns).toBe('4');
|
|
494
|
+
expect(storefront.route.filters).toEqual({
|
|
495
|
+
category: ['knitwear', 'ceramics'],
|
|
496
|
+
minPrice: ['10'],
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
// `null` clears a key, the same as it does for `q`.
|
|
500
|
+
storefront.route.setQuery({ sort: null, category: null });
|
|
501
|
+
expect(storefront.route.sort).toBeNull();
|
|
502
|
+
expect(storefront.route.filters).toEqual({ minPrice: ['10'] });
|
|
503
|
+
});
|
|
504
|
+
});
|
|
505
|
+
/**
|
|
506
|
+
* The demo half of the prerender/refresh contract. The fixture never changes, so a refresh
|
|
507
|
+
* always answers with exactly what the page already has — which is what makes it usable in a
|
|
508
|
+
* story: the path runs end to end and nothing moves on screen.
|
|
509
|
+
*/
|
|
510
|
+
describe('volatileByIds', () => {
|
|
511
|
+
it('answers with the card’s own price, availability and stock line, by the id it carries', async () => {
|
|
512
|
+
const storefront = createDemoStorefront();
|
|
513
|
+
const sweater = PRODUCTS[0]!;
|
|
514
|
+
const snapshots = await storefront.catalog.volatileByIds([sweater.productId]);
|
|
515
|
+
|
|
516
|
+
expect(snapshots).toEqual([
|
|
517
|
+
{
|
|
518
|
+
id: sweater.productId,
|
|
519
|
+
price: sweater.price,
|
|
520
|
+
available: sweater.available,
|
|
521
|
+
stock: sweater.stock,
|
|
522
|
+
},
|
|
523
|
+
]);
|
|
524
|
+
// No `inventory`, exactly like the gateway's own list-backed read.
|
|
525
|
+
expect('inventory' in snapshots[0]!).toBe(false);
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
it('drops an id the catalogue does not know, and answers nothing for nothing', async () => {
|
|
529
|
+
const storefront = createDemoStorefront();
|
|
530
|
+
const sweater = PRODUCTS[0]!;
|
|
531
|
+
|
|
532
|
+
expect(await storefront.catalog.volatileByIds(['not-a-product'])).toEqual([]);
|
|
533
|
+
expect(await storefront.catalog.volatileByIds([])).toEqual([]);
|
|
534
|
+
expect(
|
|
535
|
+
(await storefront.catalog.volatileByIds(['not-a-product', sweater.productId])).map(
|
|
536
|
+
(snapshot) => snapshot.id
|
|
537
|
+
)
|
|
538
|
+
).toEqual([sweater.productId]);
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
it('refreshing a card with its own snapshot changes nothing, object identity included', async () => {
|
|
542
|
+
const storefront = createDemoStorefront();
|
|
543
|
+
const items = PRODUCTS.slice(0, 3);
|
|
544
|
+
const snapshots = await storefront.catalog.volatileByIds(collectVolatileTargets(items));
|
|
545
|
+
expect(applyVolatileSnapshots(items, snapshots)).toBe(items);
|
|
546
|
+
});
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
it('every result carries an empty `revalidating` set — the prerender contract’s resting state', async () => {
|
|
550
|
+
const storefront = createDemoStorefront();
|
|
551
|
+
const result = storefront.catalog.product(ref('merino-crew-sweater'));
|
|
552
|
+
await settle();
|
|
553
|
+
expect(result.revalidating.value.size).toBe(0);
|
|
554
|
+
});
|
|
555
|
+
});
|