@eldrajs/theme-cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- package/LICENSE +21 -0
- package/README.md +27 -2
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +203 -0
- package/dist/index.d.ts +174 -0
- package/dist/index.js +3 -0
- package/dist/validate-C6jB8_Oc.js +510 -0
- package/package.json +56 -3
- package/template/.eldra/block-types.d.ts +429 -0
- package/template/.eldra/manifest.json +9377 -0
- package/template/.eldra/previews.json +36 -0
- package/template/.github/workflows/eldra-deploy.yml +24 -0
- package/template/.gitlab-ci.yml +16 -0
- package/template/.storybook/eldra.ts +123 -0
- package/template/.storybook/i18n.ts +23 -0
- package/template/.storybook/main.ts +59 -0
- package/template/.storybook/nuxt-link-stub.ts +23 -0
- package/template/.storybook/preview.ts +52 -0
- package/template/.storybook/shims-vue.d.ts +10 -0
- package/template/.storybook/virtual-eldra.d.ts +27 -0
- package/template/README.md +288 -0
- package/template/app/app.vue +126 -0
- package/template/app/assets/main.css +404 -0
- package/template/app/components/EldraIcon.vue +66 -0
- package/template/app/components/EldraRouterLink.vue +62 -0
- package/template/app/components/ui/UiImage.stories.ts +30 -0
- package/template/app/components/ui/UiImage.vue +224 -0
- package/template/app/components/ui/__tests__/UiImage.spec.ts +292 -0
- package/template/app/composables/iconComponent.ts +84 -0
- package/template/app/composables/iconFetcher.ts +14 -0
- package/template/app/composables/useBlockData.ts +30 -0
- package/template/app/composables/useEditing.ts +31 -0
- package/template/app/composables/useEldraIcon.ts +46 -0
- package/template/app/composables/useRevalidating.ts +69 -0
- package/template/app/composables/useRichTextScrollRegions.ts +80 -0
- package/template/app/composables/useStorefront.ts +18 -0
- package/template/app/composables/useStorefrontFeedback.ts +49 -0
- package/template/app/composables/useUiId.ts +18 -0
- package/template/app/composables/useWishlist.ts +42 -0
- package/template/app/i18n.d.ts +28 -0
- package/template/app/icons.ts +185 -0
- package/template/app/pages/[...slug].vue +134 -0
- package/template/app/plugins/eldra-i18n.ts +98 -0
- package/template/app/plugins/eldra-storefront.ts +288 -0
- package/template/app/plugins/eldra-ui-messages.ts +112 -0
- package/template/app/storefront/cart.ts +245 -0
- package/template/app/storefront/categories.ts +283 -0
- package/template/app/storefront/collectionSelector.ts +60 -0
- package/template/app/storefront/commerce.ts +58 -0
- package/template/app/storefront/demo.ts +1313 -0
- package/template/app/storefront/facets.ts +476 -0
- package/template/app/storefront/feedback.ts +122 -0
- package/template/app/storefront/gateway.ts +2256 -0
- package/template/app/storefront/history.ts +233 -0
- package/template/app/storefront/money.ts +247 -0
- package/template/app/storefront/options.ts +71 -0
- package/template/app/storefront/prerender.ts +77 -0
- package/template/app/storefront/refresh.ts +222 -0
- package/template/app/storefront/toProductCard.ts +154 -0
- package/template/app/storefront/types.ts +815 -0
- package/template/app/storefront/volatile.ts +211 -0
- package/template/app/templates.ts +544 -0
- package/template/app/utils/classes.ts +40 -0
- package/template/app/utils/links.ts +70 -0
- package/template/app/utils/pageStructure.ts +77 -0
- package/template/app/utils/pageTitle.ts +37 -0
- package/template/app/virtual-eldra.d.ts +12 -0
- package/template/bitbucket-pipelines.yml +19 -0
- package/template/blocks/announcement-bar/Block.vue +203 -0
- package/template/blocks/announcement-bar/__tests__/Block.spec.ts +227 -0
- package/template/blocks/announcement-bar/block.json +45 -0
- package/template/blocks/announcement-bar/mock.json +7 -0
- package/template/blocks/announcement-bar/preview.png +0 -0
- package/template/blocks/article/Block.vue +317 -0
- package/template/blocks/article/__tests__/Block.spec.ts +229 -0
- package/template/blocks/article/block.json +148 -0
- package/template/blocks/article/mock.json +512 -0
- package/template/blocks/article/preview.json +16 -0
- package/template/blocks/article/preview.png +0 -0
- package/template/blocks/article-list/Block.vue +343 -0
- package/template/blocks/article-list/__tests__/Block.spec.ts +279 -0
- package/template/blocks/article-list/block.json +181 -0
- package/template/blocks/article-list/mock.json +68 -0
- package/template/blocks/article-list/preview.json +84 -0
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/Block.vue +278 -0
- package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +461 -0
- package/template/blocks/breadcrumbs/block.json +89 -0
- package/template/blocks/breadcrumbs/mock.json +11 -0
- package/template/blocks/breadcrumbs/preview.json +3 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/Block.vue +372 -0
- package/template/blocks/cart/__tests__/Block.spec.ts +561 -0
- package/template/blocks/cart/__tests__/ShippingBar.spec.ts +78 -0
- package/template/blocks/cart/__tests__/Summary.spec.ts +245 -0
- package/template/blocks/cart/block.json +74 -0
- package/template/blocks/cart/mock.json +11 -0
- package/template/blocks/cart/parts/CartLines.vue +257 -0
- package/template/blocks/cart/parts/ShippingBar.vue +105 -0
- package/template/blocks/cart/parts/Summary.vue +291 -0
- package/template/blocks/cart/preview.png +0 -0
- package/template/blocks/collection-grid/Block.vue +1832 -0
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +3037 -0
- package/template/blocks/collection-grid/__tests__/groups.spec.ts +731 -0
- package/template/blocks/collection-grid/block.json +187 -0
- package/template/blocks/collection-grid/mock.json +23 -0
- package/template/blocks/collection-grid/parts/groups.ts +861 -0
- package/template/blocks/collection-grid/preview.json +7 -0
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/Block.vue +533 -0
- package/template/blocks/collection-header/__tests__/Block.spec.ts +381 -0
- package/template/blocks/collection-header/block.json +140 -0
- package/template/blocks/collection-header/mock.json +28 -0
- package/template/blocks/collection-header/preview.json +14 -0
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/contact/Block.vue +621 -0
- package/template/blocks/contact/__tests__/Block.spec.ts +347 -0
- package/template/blocks/contact/block.json +174 -0
- package/template/blocks/contact/mock.json +28 -0
- package/template/blocks/contact/preview.json +9 -0
- package/template/blocks/contact/preview.png +0 -0
- package/template/blocks/cta/Block.vue +383 -0
- package/template/blocks/cta/__tests__/Block.spec.ts +309 -0
- package/template/blocks/cta/block.json +86 -0
- package/template/blocks/cta/mock.json +10 -0
- package/template/blocks/cta/preview.json +9 -0
- package/template/blocks/cta/preview.png +0 -0
- package/template/blocks/faq/Block.vue +254 -0
- package/template/blocks/faq/__tests__/Block.spec.ts +312 -0
- package/template/blocks/faq/block.json +113 -0
- package/template/blocks/faq/mock.json +115 -0
- package/template/blocks/faq/preview.png +0 -0
- package/template/blocks/feature-grid/Block.vue +241 -0
- package/template/blocks/feature-grid/__tests__/Block.spec.ts +311 -0
- package/template/blocks/feature-grid/block.json +106 -0
- package/template/blocks/feature-grid/mock.json +29 -0
- package/template/blocks/feature-grid/preview.json +45 -0
- package/template/blocks/feature-grid/preview.png +0 -0
- package/template/blocks/footer/Block.vue +652 -0
- package/template/blocks/footer/__tests__/Block.spec.ts +700 -0
- package/template/blocks/footer/block.json +240 -0
- package/template/blocks/footer/mock.json +161 -0
- package/template/blocks/footer/preview.png +0 -0
- package/template/blocks/gallery/Block.vue +416 -0
- package/template/blocks/gallery/__tests__/Block.spec.ts +289 -0
- package/template/blocks/gallery/block.json +87 -0
- package/template/blocks/gallery/mock.json +16 -0
- package/template/blocks/gallery/preview.json +64 -0
- package/template/blocks/gallery/preview.png +0 -0
- package/template/blocks/hero/Block.vue +378 -0
- package/template/blocks/hero/__tests__/Block.spec.ts +324 -0
- package/template/blocks/hero/block.json +146 -0
- package/template/blocks/hero/mock.json +11 -0
- package/template/blocks/hero/preview.json +55 -0
- package/template/blocks/hero/preview.png +0 -0
- package/template/blocks/image/Block.vue +232 -0
- package/template/blocks/image/__tests__/Block.spec.ts +224 -0
- package/template/blocks/image/block.json +67 -0
- package/template/blocks/image/mock.json +7 -0
- package/template/blocks/image/preview.json +9 -0
- package/template/blocks/image/preview.png +0 -0
- package/template/blocks/logo-cloud/Block.vue +206 -0
- package/template/blocks/logo-cloud/__tests__/Block.spec.ts +210 -0
- package/template/blocks/logo-cloud/block.json +79 -0
- package/template/blocks/logo-cloud/mock.json +15 -0
- package/template/blocks/logo-cloud/preview.json +92 -0
- package/template/blocks/logo-cloud/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +1348 -0
- package/template/blocks/navigation/__tests__/Block.spec.ts +2030 -0
- package/template/blocks/navigation/block.json +167 -0
- package/template/blocks/navigation/mock.json +191 -0
- package/template/blocks/navigation/preview.png +0 -0
- package/template/blocks/navigation/useMegaMenuKeys.ts +276 -0
- package/template/blocks/newsletter/Block.vue +399 -0
- package/template/blocks/newsletter/__tests__/Block.spec.ts +365 -0
- package/template/blocks/newsletter/block.json +105 -0
- package/template/blocks/newsletter/mock.json +31 -0
- package/template/blocks/newsletter/preview.png +0 -0
- package/template/blocks/order-status/Block.vue +754 -0
- package/template/blocks/order-status/__tests__/Block.spec.ts +515 -0
- package/template/blocks/order-status/block.json +138 -0
- package/template/blocks/order-status/mock.json +19 -0
- package/template/blocks/order-status/preview.png +0 -0
- package/template/blocks/pricing-table/Block.vue +297 -0
- package/template/blocks/pricing-table/__tests__/Block.spec.ts +357 -0
- package/template/blocks/pricing-table/block.json +155 -0
- package/template/blocks/pricing-table/mock.json +47 -0
- package/template/blocks/pricing-table/preview.png +0 -0
- package/template/blocks/product-carousel/Block.vue +459 -0
- package/template/blocks/product-carousel/__tests__/Block.spec.ts +957 -0
- package/template/blocks/product-carousel/block.json +71 -0
- package/template/blocks/product-carousel/mock.json +9 -0
- package/template/blocks/product-carousel/preview.json +7 -0
- package/template/blocks/product-carousel/preview.png +0 -0
- package/template/blocks/product-detail/Block.vue +886 -0
- package/template/blocks/product-detail/__tests__/Block.spec.ts +1495 -0
- package/template/blocks/product-detail/__tests__/stock.spec.ts +119 -0
- package/template/blocks/product-detail/block.json +155 -0
- package/template/blocks/product-detail/mock.json +113 -0
- package/template/blocks/product-detail/parts/Gallery.vue +181 -0
- package/template/blocks/product-detail/parts/StickyBuyBar.vue +99 -0
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/product-detail/stock.ts +150 -0
- package/template/blocks/quote/Block.vue +206 -0
- package/template/blocks/quote/__tests__/Block.spec.ts +265 -0
- package/template/blocks/quote/block.json +76 -0
- package/template/blocks/quote/mock.json +9 -0
- package/template/blocks/quote/preview.json +16 -0
- package/template/blocks/quote/preview.png +0 -0
- package/template/blocks/rich-text/Block.vue +143 -0
- package/template/blocks/rich-text/__tests__/Block.spec.ts +191 -0
- package/template/blocks/rich-text/block.json +57 -0
- package/template/blocks/rich-text/mock.json +87 -0
- package/template/blocks/rich-text/preview.png +0 -0
- package/template/blocks/search/Block.vue +589 -0
- package/template/blocks/search/PopularChips.vue +40 -0
- package/template/blocks/search/TypeSection.vue +148 -0
- package/template/blocks/search/__tests__/Block.spec.ts +718 -0
- package/template/blocks/search/__tests__/results.spec.ts +166 -0
- package/template/blocks/search/block.json +102 -0
- package/template/blocks/search/mock.json +18 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/search/results.ts +85 -0
- package/template/blocks/split-content/Block.vue +195 -0
- package/template/blocks/split-content/__tests__/Block.spec.ts +225 -0
- package/template/blocks/split-content/block.json +70 -0
- package/template/blocks/split-content/mock.json +45 -0
- package/template/blocks/split-content/preview.json +58 -0
- package/template/blocks/split-content/preview.png +0 -0
- package/template/blocks/stats/Block.vue +159 -0
- package/template/blocks/stats/__tests__/Block.spec.ts +194 -0
- package/template/blocks/stats/block.json +73 -0
- package/template/blocks/stats/mock.json +12 -0
- package/template/blocks/stats/preview.png +0 -0
- package/template/blocks/tabs/Block.vue +278 -0
- package/template/blocks/tabs/__tests__/Block.spec.ts +303 -0
- package/template/blocks/tabs/block.json +97 -0
- package/template/blocks/tabs/mock.json +129 -0
- package/template/blocks/tabs/preview.json +153 -0
- package/template/blocks/tabs/preview.png +0 -0
- package/template/blocks/team/Block.vue +288 -0
- package/template/blocks/team/__tests__/Block.spec.ts +221 -0
- package/template/blocks/team/block.json +125 -0
- package/template/blocks/team/mock.json +39 -0
- package/template/blocks/team/preview.json +62 -0
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/testimonials/Block.vue +408 -0
- package/template/blocks/testimonials/__tests__/Block.spec.ts +319 -0
- package/template/blocks/testimonials/block.json +121 -0
- package/template/blocks/testimonials/mock.json +46 -0
- package/template/blocks/testimonials/preview.json +68 -0
- package/template/blocks/testimonials/preview.png +0 -0
- package/template/blocks/timeline/Block.vue +274 -0
- package/template/blocks/timeline/__tests__/Block.spec.ts +310 -0
- package/template/blocks/timeline/block.json +98 -0
- package/template/blocks/timeline/mock.json +27 -0
- package/template/blocks/timeline/preview.png +0 -0
- package/template/blocks/trust-strip/Block.vue +330 -0
- package/template/blocks/trust-strip/__tests__/Block.spec.ts +290 -0
- package/template/blocks/trust-strip/block.json +117 -0
- package/template/blocks/trust-strip/mock.json +37 -0
- package/template/blocks/trust-strip/preview.png +0 -0
- package/template/blocks/video-embed/Block.vue +354 -0
- package/template/blocks/video-embed/__tests__/Block.spec.ts +219 -0
- package/template/blocks/video-embed/__tests__/embed.spec.ts +76 -0
- package/template/blocks/video-embed/block.json +94 -0
- package/template/blocks/video-embed/embed.ts +84 -0
- package/template/blocks/video-embed/mock.json +13 -0
- package/template/blocks/video-embed/preview.json +9 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/blocks/wishlist/Block.vue +367 -0
- package/template/blocks/wishlist/__tests__/Block.spec.ts +508 -0
- package/template/blocks/wishlist/block.json +42 -0
- package/template/blocks/wishlist/mock.json +9 -0
- package/template/blocks/wishlist/preview.png +0 -0
- package/template/i18n/en-US.json +602 -0
- package/template/i18n/is-IS.json +602 -0
- package/template/nuxt.config.ts +148 -0
- package/template/package.json +55 -0
- package/template/pages/article.page.json +731 -0
- package/template/pages/cart.page.json +85 -0
- package/template/pages/category.page.json +133 -0
- package/template/pages/collection.page.json +194 -0
- package/template/pages/home.page.json +353 -0
- package/template/pages/product.page.json +323 -0
- package/template/pages/products.page.json +144 -0
- package/template/pages/search.page.json +83 -0
- package/template/pages/wishlist.page.json +88 -0
- package/template/public/demo/article-cover.svg +1 -0
- package/template/public/demo/article-figure.svg +1 -0
- package/template/public/demo/avatar-1.svg +3 -0
- package/template/public/demo/avatar-2.svg +3 -0
- package/template/public/demo/avatar-3.svg +3 -0
- package/template/public/demo/avatar-4.svg +3 -0
- package/template/public/demo/avatar-5.svg +3 -0
- package/template/public/demo/avatar-6.svg +3 -0
- package/template/public/demo/avatar-7.svg +3 -0
- package/template/public/demo/avatar-8.svg +3 -0
- package/template/public/demo/collection-1.svg +1 -0
- package/template/public/demo/collection-2.svg +1 -0
- package/template/public/demo/cta-split.svg +1 -0
- package/template/public/demo/feature-1.svg +1 -0
- package/template/public/demo/feature-2.svg +1 -0
- package/template/public/demo/feature-3.svg +1 -0
- package/template/public/demo/feature-4.svg +1 -0
- package/template/public/demo/gallery-1.svg +1 -0
- package/template/public/demo/gallery-2.svg +1 -0
- package/template/public/demo/gallery-3.svg +1 -0
- package/template/public/demo/gallery-4.svg +1 -0
- package/template/public/demo/gallery-5.svg +1 -0
- package/template/public/demo/gallery-6.svg +1 -0
- package/template/public/demo/gallery-7.svg +1 -0
- package/template/public/demo/gallery-8.svg +1 -0
- package/template/public/demo/hero-slide-1.svg +1 -0
- package/template/public/demo/hero-slide-2.svg +1 -0
- package/template/public/demo/hero-slide-3.svg +1 -0
- package/template/public/demo/hero-slide-4.svg +1 -0
- package/template/public/demo/hero-wide.svg +1 -0
- package/template/public/demo/hero.svg +1 -0
- package/template/public/demo/logo-1.svg +4 -0
- package/template/public/demo/logo-2.svg +4 -0
- package/template/public/demo/logo-3.svg +4 -0
- package/template/public/demo/logo-4.svg +4 -0
- package/template/public/demo/logo-5.svg +4 -0
- package/template/public/demo/logo-6.svg +4 -0
- package/template/public/demo/logo-7.svg +4 -0
- package/template/public/demo/logo-8.svg +4 -0
- package/template/public/demo/logo.svg +3 -0
- package/template/public/demo/map.svg +1 -0
- package/template/public/demo/poster.svg +1 -0
- package/template/public/demo/product-1.svg +4 -0
- package/template/public/demo/product-10.svg +4 -0
- package/template/public/demo/product-11.svg +4 -0
- package/template/public/demo/product-12.svg +4 -0
- package/template/public/demo/product-2.svg +4 -0
- package/template/public/demo/product-3.svg +4 -0
- package/template/public/demo/product-4.svg +4 -0
- package/template/public/demo/product-5.svg +4 -0
- package/template/public/demo/product-6.svg +4 -0
- package/template/public/demo/product-7.svg +4 -0
- package/template/public/demo/product-8.svg +4 -0
- package/template/public/demo/product-9.svg +4 -0
- package/template/public/demo/product-square-1.svg +4 -0
- package/template/public/demo/product-square-2.svg +4 -0
- package/template/public/demo/product-square-3.svg +4 -0
- package/template/public/demo/product-square-4.svg +4 -0
- package/template/public/demo/product-square-5.svg +4 -0
- package/template/public/demo/product-square-6.svg +4 -0
- package/template/public/demo/quote-portrait.svg +4 -0
- package/template/public/demo/split-1.svg +1 -0
- package/template/public/demo/split-2.svg +1 -0
- package/template/public/demo/split-3.svg +1 -0
- package/template/public/demo/split-4.svg +1 -0
- package/template/public/demo/team-1.svg +4 -0
- package/template/public/demo/team-2.svg +4 -0
- package/template/public/demo/team-3.svg +4 -0
- package/template/public/demo/team-4.svg +4 -0
- package/template/scripts/demo-images.mjs +393 -0
- package/template/scripts/generate-stories.mjs +156 -0
- package/template/scripts/previewHash.mjs +125 -0
- package/template/scripts/previews.mjs +149 -0
- package/template/stories/generated/announcement-bar.stories.ts +44 -0
- package/template/stories/generated/article-list.stories.ts +87 -0
- package/template/stories/generated/article.stories.ts +27 -0
- package/template/stories/generated/breadcrumbs.stories.ts +39 -0
- package/template/stories/generated/cart.stories.ts +38 -0
- package/template/stories/generated/collection-grid.stories.ts +117 -0
- package/template/stories/generated/collection-header.stories.ts +51 -0
- package/template/stories/generated/contact.stories.ts +45 -0
- package/template/stories/generated/cta.stories.ts +51 -0
- package/template/stories/generated/faq.stories.ts +56 -0
- package/template/stories/generated/feature-grid.stories.ts +69 -0
- package/template/stories/generated/footer.stories.ts +50 -0
- package/template/stories/generated/gallery.stories.ts +81 -0
- package/template/stories/generated/hero.stories.ts +75 -0
- package/template/stories/generated/image.stories.ts +99 -0
- package/template/stories/generated/logo-cloud.stories.ts +57 -0
- package/template/stories/generated/navigation.stories.ts +62 -0
- package/template/stories/generated/newsletter.stories.ts +68 -0
- package/template/stories/generated/order-status.stories.ts +32 -0
- package/template/stories/generated/pricing-table.stories.ts +44 -0
- package/template/stories/generated/product-carousel.stories.ts +75 -0
- package/template/stories/generated/product-detail.stories.ts +62 -0
- package/template/stories/generated/quote.stories.ts +69 -0
- package/template/stories/generated/rich-text.stories.ts +50 -0
- package/template/stories/generated/search.stories.ts +56 -0
- package/template/stories/generated/split-content.stories.ts +39 -0
- package/template/stories/generated/stats.stories.ts +68 -0
- package/template/stories/generated/tabs.stories.ts +45 -0
- package/template/stories/generated/team.stories.ts +45 -0
- package/template/stories/generated/testimonials.stories.ts +69 -0
- package/template/stories/generated/timeline.stories.ts +80 -0
- package/template/stories/generated/trust-strip.stories.ts +62 -0
- package/template/stories/generated/video-embed.stories.ts +63 -0
- package/template/stories/generated/wishlist.stories.ts +26 -0
- package/template/stories/pages/article.stories.ts +51 -0
- package/template/stories/pages/cart.stories.ts +56 -0
- package/template/stories/pages/category.stories.ts +56 -0
- package/template/stories/pages/collection.stories.ts +51 -0
- package/template/stories/pages/home.stories.ts +51 -0
- package/template/stories/pages/product.stories.ts +47 -0
- package/template/stories/pages/products.stories.ts +58 -0
- package/template/stories/pages/search.stories.ts +54 -0
- package/template/stories/pages/wishlist.stories.ts +53 -0
- package/template/stories/support/pageBlocks.ts +115 -0
- package/template/test/blocksEmptyData.spec.ts +52 -0
- package/template/test/carouselKeyboard.spec.ts +272 -0
- package/template/test/carouselRing.browser.spec.ts +193 -0
- package/template/test/carouselSlideWidth.browser.spec.ts +102 -0
- package/template/test/cartDrawer.spec.ts +295 -0
- package/template/test/cartToast.spec.ts +86 -0
- package/template/test/countPill.browser.spec.ts +196 -0
- package/template/test/demoImages.spec.ts +140 -0
- package/template/test/deps.spec.ts +102 -0
- package/template/test/eldraIcon.spec.ts +58 -0
- package/template/test/framing.spec.ts +76 -0
- package/template/test/i18n.spec.ts +200 -0
- package/template/test/iconComponent.spec.ts +91 -0
- package/template/test/inlineEditable.spec.ts +334 -0
- package/template/test/localePrefix.spec.ts +342 -0
- package/template/test/mainCss.spec.ts +107 -0
- package/template/test/mockGatewayContract.spec.ts +122 -0
- package/template/test/mocks/blocks.ts +20 -0
- package/template/test/mocks/breakpoints.ts +7 -0
- package/template/test/mocks/manifest.ts +11 -0
- package/template/test/moneyFormatting.spec.ts +89 -0
- package/template/test/pageTitle.spec.ts +49 -0
- package/template/test/pages/article.spec.ts +231 -0
- package/template/test/pages/category.spec.ts +185 -0
- package/template/test/pages/collection.spec.ts +396 -0
- package/template/test/pages/home.spec.ts +295 -0
- package/template/test/pages/hydration.spec.ts +557 -0
- package/template/test/pages/product.spec.ts +396 -0
- package/template/test/pages/seededPages.spec.ts +190 -0
- package/template/test/pages/ssr.spec.ts +393 -0
- package/template/test/prerenderCommerce.spec.ts +134 -0
- package/template/test/prerenderFailure.spec.ts +130 -0
- package/template/test/prerenderRefresh.browser.spec.ts +1431 -0
- package/template/test/previewsFresh.spec.ts +56 -0
- package/template/test/richText.spec.ts +161 -0
- package/template/test/richTextTypography.spec.ts +182 -0
- package/template/test/setup.ts +21 -0
- package/template/test/slugPage.spec.ts +244 -0
- package/template/test/slugPageTemplate.spec.ts +194 -0
- package/template/test/starter.spec.ts +1416 -0
- package/template/test/storefront/cart.spec.ts +404 -0
- package/template/test/storefront/categories.spec.ts +235 -0
- package/template/test/storefront/collectionSelector.spec.ts +74 -0
- package/template/test/storefront/demo.spec.ts +555 -0
- package/template/test/storefront/facets.spec.ts +425 -0
- package/template/test/storefront/feedback.spec.ts +97 -0
- package/template/test/storefront/gateway.spec.ts +2673 -0
- package/template/test/storefront/gatewayCart.spec.ts +289 -0
- package/template/test/storefront/gatewayPrerender.spec.ts +1037 -0
- package/template/test/storefront/history.spec.ts +341 -0
- package/template/test/storefront/money.spec.ts +171 -0
- package/template/test/storefront/toProductCard.spec.ts +138 -0
- package/template/test/storefront/volatile.spec.ts +284 -0
- package/template/test/support/axe.ts +14 -0
- package/template/test/support/dialog.ts +51 -0
- package/template/test/support/hydrate.ts +118 -0
- package/template/test/support/i18nText.ts +11 -0
- package/template/test/support/mockGateway.ts +1017 -0
- package/template/test/support/mountBlock.ts +194 -0
- package/template/test/support/mountPage.spec.ts +72 -0
- package/template/test/support/mountPage.ts +254 -0
- package/template/test/support/mountProbe.client.ts +69 -0
- package/template/test/support/renderSsr.ts +97 -0
- package/template/test/support/staticServer.ts +96 -0
- package/template/test/themeIcons.spec.ts +140 -0
- package/template/test/toastAnnouncement.spec.ts +133 -0
- package/template/test/tokens.spec.ts +102 -0
- package/template/test/uiMessagesPlugin.spec.ts +104 -0
- package/template/test/useBlockData.spec.ts +46 -0
- package/template/test/useEditing.spec.ts +54 -0
- package/template/test/useEldraIcon.spec.ts +126 -0
- package/template/test/useUiId.spec.ts +40 -0
- package/template/tokens.json +149 -0
- package/template/tsconfig.json +3 -0
- package/template/tsconfig.storybook.json +17 -0
- package/template/vitest-axe.d.ts +13 -0
- package/template/vitest.config.ts +44 -0
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
//
|
|
3
|
+
// jsdom rather than the suite's default node environment, for one reason: the wishlist's cross-tab
|
|
4
|
+
// sync is a `window` `storage` listener, and `window`/`StorageEvent` only exist here. Every
|
|
5
|
+
// `localStorage` in this file is still the in-memory stub installed below — `setLocalStorage`
|
|
6
|
+
// redefines the global, so jsdom's own implementation is never what is being tested, and the two
|
|
7
|
+
// "storage is absent/throwing" cases stay exactly as honest as they were under node.
|
|
8
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
9
|
+
import { createHistoryStore, createWishlistStore, hashMessage } from '../../app/storefront/history';
|
|
10
|
+
|
|
11
|
+
function memoryStorage(): Storage {
|
|
12
|
+
const map = new Map<string, string>();
|
|
13
|
+
return {
|
|
14
|
+
getItem: (key: string) => map.get(key) ?? null,
|
|
15
|
+
setItem: (key: string, value: string) => {
|
|
16
|
+
map.set(key, value);
|
|
17
|
+
},
|
|
18
|
+
removeItem: (key: string) => {
|
|
19
|
+
map.delete(key);
|
|
20
|
+
},
|
|
21
|
+
clear: () => map.clear(),
|
|
22
|
+
key: (index: number) => Array.from(map.keys())[index] ?? null,
|
|
23
|
+
get length() {
|
|
24
|
+
return map.size;
|
|
25
|
+
},
|
|
26
|
+
} as Storage;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function throwingStorage(): Storage {
|
|
30
|
+
const explode = () => {
|
|
31
|
+
throw new Error('localStorage is blocked');
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
getItem: explode,
|
|
35
|
+
setItem: explode,
|
|
36
|
+
removeItem: explode,
|
|
37
|
+
clear: explode,
|
|
38
|
+
key: explode,
|
|
39
|
+
length: 0,
|
|
40
|
+
} as Storage;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function setLocalStorage(value: Storage | undefined): void {
|
|
44
|
+
Object.defineProperty(globalThis, 'localStorage', { value, configurable: true, writable: true });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe('createHistoryStore', () => {
|
|
48
|
+
beforeEach(() => {
|
|
49
|
+
setLocalStorage(memoryStorage());
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('recordView adds the newest handle to the front', () => {
|
|
53
|
+
const history = createHistoryStore();
|
|
54
|
+
history.recordView('merino-crew-sweater');
|
|
55
|
+
history.recordView('speckled-latte-mug');
|
|
56
|
+
expect(history.recentlyViewed.value).toEqual(['speckled-latte-mug', 'merino-crew-sweater']);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('recordView caps the list at 12, dropping the oldest', () => {
|
|
60
|
+
const history = createHistoryStore();
|
|
61
|
+
for (let i = 1; i <= 13; i += 1) history.recordView(`product-${i}`);
|
|
62
|
+
expect(history.recentlyViewed.value).toHaveLength(12);
|
|
63
|
+
expect(history.recentlyViewed.value[0]).toBe('product-13');
|
|
64
|
+
expect(history.recentlyViewed.value).not.toContain('product-1');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('recordView moves an already-viewed handle to the front instead of duplicating it', () => {
|
|
68
|
+
const history = createHistoryStore();
|
|
69
|
+
history.recordView('a');
|
|
70
|
+
history.recordView('b');
|
|
71
|
+
history.recordView('a');
|
|
72
|
+
expect(history.recentlyViewed.value).toEqual(['a', 'b']);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('clearViews empties the list', () => {
|
|
76
|
+
const history = createHistoryStore();
|
|
77
|
+
history.recordView('a');
|
|
78
|
+
history.clearViews();
|
|
79
|
+
expect(history.recentlyViewed.value).toEqual([]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('persists recently-viewed across store instances via localStorage', () => {
|
|
83
|
+
createHistoryStore().recordView('merino-crew-sweater');
|
|
84
|
+
const reloaded = createHistoryStore();
|
|
85
|
+
expect(reloaded.recentlyViewed.value).toEqual(['merino-crew-sweater']);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('initialRecentlyViewed overrides whatever localStorage already holds', () => {
|
|
89
|
+
createHistoryStore().recordView('stale');
|
|
90
|
+
const history = createHistoryStore({ initialRecentlyViewed: ['fresh'] });
|
|
91
|
+
expect(history.recentlyViewed.value).toEqual(['fresh']);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('dismissAnnouncement keys the dismissal by a hash of the message', () => {
|
|
95
|
+
const history = createHistoryStore();
|
|
96
|
+
const message = 'Free shipping over $80';
|
|
97
|
+
expect(history.isAnnouncementDismissed(message)).toBe(false);
|
|
98
|
+
history.dismissAnnouncement(message);
|
|
99
|
+
expect(history.isAnnouncementDismissed(message)).toBe(true);
|
|
100
|
+
expect(history.isAnnouncementDismissed('A different message')).toBe(false);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('hashMessage is stable for identical text and differs for different text', () => {
|
|
104
|
+
expect(hashMessage('Free shipping over $80')).toBe(hashMessage('Free shipping over $80'));
|
|
105
|
+
expect(hashMessage('Free shipping over $80')).not.toBe(hashMessage('30-day returns'));
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('degrades to empty state instead of throwing when localStorage is absent', () => {
|
|
109
|
+
setLocalStorage(undefined);
|
|
110
|
+
const history = createHistoryStore();
|
|
111
|
+
expect(history.recentlyViewed.value).toEqual([]);
|
|
112
|
+
expect(() => history.recordView('a')).not.toThrow();
|
|
113
|
+
expect(() => history.dismissAnnouncement('x')).not.toThrow();
|
|
114
|
+
expect(history.isAnnouncementDismissed('x')).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('degrades to empty state instead of throwing when localStorage itself throws', () => {
|
|
118
|
+
setLocalStorage(throwingStorage());
|
|
119
|
+
const history = createHistoryStore();
|
|
120
|
+
expect(history.recentlyViewed.value).toEqual([]);
|
|
121
|
+
expect(() => history.recordView('a')).not.toThrow();
|
|
122
|
+
expect(() => history.dismissAnnouncement('x')).not.toThrow();
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
/** The key `createWishlistStore` persists under (`app/storefront/history.ts`). */
|
|
127
|
+
const WISHLIST_STORAGE_KEY = 'eldra.storefront.wishlist';
|
|
128
|
+
|
|
129
|
+
describe('createWishlistStore', () => {
|
|
130
|
+
beforeEach(() => {
|
|
131
|
+
setLocalStorage(memoryStorage());
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
/** Every `storage` registration or removal on `window` since the spy went up. */
|
|
135
|
+
function storageCalls(spy: { mock: { calls: unknown[][] } }): unknown[][] {
|
|
136
|
+
return spy.mock.calls.filter(([type]) => type === 'storage');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* **First two in this describe on purpose.** They count `window.addEventListener('storage')`, and
|
|
141
|
+
* the listener they are about is module level: registered for the first store that hydrates and
|
|
142
|
+
* dropped by the last one to release. A test above them that hydrated a store and never released
|
|
143
|
+
* it would leave it up and make both of these vacuous.
|
|
144
|
+
*
|
|
145
|
+
* Why there is one listener rather than one per store: `useStorefront()` builds a fallback demo
|
|
146
|
+
* storefront *per calling component* when nothing is provided — every Storybook story and every
|
|
147
|
+
* block mount does that — so a listener per store would leave one behind for each, each holding a
|
|
148
|
+
* dead `items` ref and re-reading storage on every event.
|
|
149
|
+
*/
|
|
150
|
+
it('registers one storage listener for any number of stores, and drops it with the last release', () => {
|
|
151
|
+
const add = vi.spyOn(window, 'addEventListener');
|
|
152
|
+
const remove = vi.spyOn(window, 'removeEventListener');
|
|
153
|
+
try {
|
|
154
|
+
const first = createWishlistStore();
|
|
155
|
+
const second = createWishlistStore();
|
|
156
|
+
first.hydrate();
|
|
157
|
+
second.hydrate();
|
|
158
|
+
expect(storageCalls(add)).toHaveLength(1);
|
|
159
|
+
|
|
160
|
+
// One consumer gone, one still interested: the listener stays.
|
|
161
|
+
first.release();
|
|
162
|
+
expect(storageCalls(remove)).toHaveLength(0);
|
|
163
|
+
|
|
164
|
+
second.release();
|
|
165
|
+
expect(storageCalls(remove)).toHaveLength(1);
|
|
166
|
+
|
|
167
|
+
// And a store hydrating afterwards registers it again rather than going deaf.
|
|
168
|
+
const third = createWishlistStore();
|
|
169
|
+
third.hydrate();
|
|
170
|
+
expect(storageCalls(add)).toHaveLength(2);
|
|
171
|
+
third.release();
|
|
172
|
+
} finally {
|
|
173
|
+
add.mockRestore();
|
|
174
|
+
remove.mockRestore();
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
/** A mutation reads storage for itself but must not subscribe: nothing would ever release what it
|
|
179
|
+
* registered. */
|
|
180
|
+
it('registers nothing for a store nobody hydrated, mutations included', () => {
|
|
181
|
+
const add = vi.spyOn(window, 'addEventListener');
|
|
182
|
+
try {
|
|
183
|
+
const wishlist = createWishlistStore();
|
|
184
|
+
wishlist.toggle('merino-crew-sweater');
|
|
185
|
+
wishlist.remove('merino-crew-sweater');
|
|
186
|
+
wishlist.clear();
|
|
187
|
+
expect(storageCalls(add)).toHaveLength(0);
|
|
188
|
+
} finally {
|
|
189
|
+
add.mockRestore();
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
/** A released store stops following other tabs — the leak this closes. */
|
|
194
|
+
it('stops following the storage event once released', () => {
|
|
195
|
+
const wishlist = createWishlistStore();
|
|
196
|
+
wishlist.hydrate();
|
|
197
|
+
localStorage.setItem(WISHLIST_STORAGE_KEY, JSON.stringify(['from-another-tab']));
|
|
198
|
+
window.dispatchEvent(new StorageEvent('storage', { key: WISHLIST_STORAGE_KEY }));
|
|
199
|
+
expect(wishlist.items.value).toEqual(['from-another-tab']);
|
|
200
|
+
|
|
201
|
+
wishlist.release();
|
|
202
|
+
localStorage.setItem(WISHLIST_STORAGE_KEY, JSON.stringify(['later']));
|
|
203
|
+
window.dispatchEvent(new StorageEvent('storage', { key: WISHLIST_STORAGE_KEY }));
|
|
204
|
+
expect(wishlist.items.value).toEqual(['from-another-tab']);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* The hydration gate (`app/storefront/history.ts`, `app/composables/useWishlist.ts`): a fresh
|
|
209
|
+
* store knows nothing, whatever the browser already holds, until `hydrate()` — which is what
|
|
210
|
+
* keeps a visitor's saved list out of the HTML a build wrote and makes the browser's first render
|
|
211
|
+
* of that file identical to it. Asserted first because every test below depends on it.
|
|
212
|
+
*/
|
|
213
|
+
it('starts empty and stays empty until hydrate(), even with a saved list in storage', () => {
|
|
214
|
+
createWishlistStore().toggle('merino-crew-sweater');
|
|
215
|
+
|
|
216
|
+
const wishlist = createWishlistStore();
|
|
217
|
+
expect(wishlist.items.value).toEqual([]);
|
|
218
|
+
expect(wishlist.count.value).toBe(0);
|
|
219
|
+
expect(wishlist.has('merino-crew-sweater')).toBe(false);
|
|
220
|
+
|
|
221
|
+
wishlist.hydrate();
|
|
222
|
+
expect(wishlist.items.value).toEqual(['merino-crew-sweater']);
|
|
223
|
+
expect(wishlist.count.value).toBe(1);
|
|
224
|
+
expect(wishlist.has('merino-crew-sweater')).toBe(true);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('hydrate is idempotent and does not discard changes made since', () => {
|
|
228
|
+
createWishlistStore().toggle('stored');
|
|
229
|
+
const wishlist = createWishlistStore();
|
|
230
|
+
wishlist.hydrate();
|
|
231
|
+
wishlist.toggle('added');
|
|
232
|
+
wishlist.hydrate();
|
|
233
|
+
expect(wishlist.items.value).toEqual(['added', 'stored']);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('toggle adds a handle not yet in the wishlist, newest first, and says it is now saved', () => {
|
|
237
|
+
const wishlist = createWishlistStore();
|
|
238
|
+
wishlist.hydrate();
|
|
239
|
+
expect(wishlist.has('merino-crew-sweater')).toBe(false);
|
|
240
|
+
expect(wishlist.toggle('merino-crew-sweater')).toBe(true);
|
|
241
|
+
expect(wishlist.toggle('speckled-latte-mug')).toBe(true);
|
|
242
|
+
expect(wishlist.has('merino-crew-sweater')).toBe(true);
|
|
243
|
+
expect(wishlist.items.value).toEqual(['speckled-latte-mug', 'merino-crew-sweater']);
|
|
244
|
+
expect(wishlist.count.value).toBe(2);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it('toggle removes a handle already in the wishlist, and says it is no longer saved', () => {
|
|
248
|
+
const wishlist = createWishlistStore();
|
|
249
|
+
wishlist.hydrate();
|
|
250
|
+
wishlist.toggle('merino-crew-sweater');
|
|
251
|
+
expect(wishlist.toggle('merino-crew-sweater')).toBe(false);
|
|
252
|
+
expect(wishlist.has('merino-crew-sweater')).toBe(false);
|
|
253
|
+
expect(wishlist.items.value).toEqual([]);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('remove drops one handle and ignores one that was never saved', () => {
|
|
257
|
+
const wishlist = createWishlistStore();
|
|
258
|
+
wishlist.hydrate();
|
|
259
|
+
wishlist.toggle('a');
|
|
260
|
+
wishlist.toggle('b');
|
|
261
|
+
wishlist.remove('a');
|
|
262
|
+
expect(wishlist.items.value).toEqual(['b']);
|
|
263
|
+
expect(() => wishlist.remove('never-saved')).not.toThrow();
|
|
264
|
+
expect(wishlist.items.value).toEqual(['b']);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('clear empties the list, in storage as well as in memory', () => {
|
|
268
|
+
const wishlist = createWishlistStore();
|
|
269
|
+
wishlist.hydrate();
|
|
270
|
+
wishlist.toggle('a');
|
|
271
|
+
wishlist.clear();
|
|
272
|
+
expect(wishlist.items.value).toEqual([]);
|
|
273
|
+
const reloaded = createWishlistStore();
|
|
274
|
+
reloaded.hydrate();
|
|
275
|
+
expect(reloaded.items.value).toEqual([]);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it('persists across store instances via localStorage', () => {
|
|
279
|
+
createWishlistStore().toggle('merino-crew-sweater');
|
|
280
|
+
const reloaded = createWishlistStore();
|
|
281
|
+
reloaded.hydrate();
|
|
282
|
+
expect(reloaded.has('merino-crew-sweater')).toBe(true);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* The defect the mutations' own `hydrate()` call closes: a toggle on a store nobody hydrated
|
|
287
|
+
* would otherwise write `[handle]` over whatever the browser already held, silently emptying a
|
|
288
|
+
* shopper's saved list the first time they pressed a heart.
|
|
289
|
+
*/
|
|
290
|
+
it('a mutation on an un-hydrated store keeps the stored list instead of replacing it', () => {
|
|
291
|
+
createWishlistStore().toggle('stored');
|
|
292
|
+
const fresh = createWishlistStore();
|
|
293
|
+
fresh.toggle('added');
|
|
294
|
+
expect(fresh.items.value).toEqual(['added', 'stored']);
|
|
295
|
+
const reloaded = createWishlistStore();
|
|
296
|
+
reloaded.hydrate();
|
|
297
|
+
expect(reloaded.items.value).toEqual(['added', 'stored']);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('follows the storage event so another tab saving a product reaches this one', () => {
|
|
301
|
+
const wishlist = createWishlistStore();
|
|
302
|
+
wishlist.hydrate();
|
|
303
|
+
expect(wishlist.items.value).toEqual([]);
|
|
304
|
+
|
|
305
|
+
// What another tab's write leaves behind, and the event the browser then fires here.
|
|
306
|
+
localStorage.setItem(WISHLIST_STORAGE_KEY, JSON.stringify(['from-another-tab']));
|
|
307
|
+
window.dispatchEvent(new StorageEvent('storage', { key: WISHLIST_STORAGE_KEY }));
|
|
308
|
+
expect(wishlist.items.value).toEqual(['from-another-tab']);
|
|
309
|
+
|
|
310
|
+
// `key: null` is the whole origin's storage being cleared, which includes this key.
|
|
311
|
+
localStorage.removeItem(WISHLIST_STORAGE_KEY);
|
|
312
|
+
window.dispatchEvent(new StorageEvent('storage', { key: null }));
|
|
313
|
+
expect(wishlist.items.value).toEqual([]);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('ignores a storage event about another key', () => {
|
|
317
|
+
const wishlist = createWishlistStore();
|
|
318
|
+
wishlist.hydrate();
|
|
319
|
+
wishlist.toggle('mine');
|
|
320
|
+
localStorage.setItem(WISHLIST_STORAGE_KEY, JSON.stringify(['overwritten']));
|
|
321
|
+
window.dispatchEvent(new StorageEvent('storage', { key: 'eldra.storefront.recentlyViewed' }));
|
|
322
|
+
expect(wishlist.items.value).toEqual(['mine']);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it('degrades to empty state instead of throwing when localStorage is absent', () => {
|
|
326
|
+
setLocalStorage(undefined);
|
|
327
|
+
const wishlist = createWishlistStore();
|
|
328
|
+
expect(() => wishlist.hydrate()).not.toThrow();
|
|
329
|
+
expect(wishlist.items.value).toEqual([]);
|
|
330
|
+
expect(() => wishlist.toggle('a')).not.toThrow();
|
|
331
|
+
expect(() => wishlist.clear()).not.toThrow();
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it('degrades to empty state instead of throwing when localStorage itself throws', () => {
|
|
335
|
+
setLocalStorage(throwingStorage());
|
|
336
|
+
const wishlist = createWishlistStore();
|
|
337
|
+
expect(() => wishlist.hydrate()).not.toThrow();
|
|
338
|
+
expect(wishlist.items.value).toEqual([]);
|
|
339
|
+
expect(() => wishlist.toggle('a')).not.toThrow();
|
|
340
|
+
});
|
|
341
|
+
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { formatCurrency } from '@eldrajs/ui';
|
|
3
|
+
import {
|
|
4
|
+
currencyLabel,
|
|
5
|
+
DEFAULT_LOCALE,
|
|
6
|
+
formatMoney,
|
|
7
|
+
roundMoney,
|
|
8
|
+
toMinorUnits,
|
|
9
|
+
} from '../../app/storefront/money';
|
|
10
|
+
|
|
11
|
+
describe('formatMoney', () => {
|
|
12
|
+
it('formats a major-unit amount as itself', () => {
|
|
13
|
+
// The live defect: a catalog price of 28 is $28.00, not $0.28.
|
|
14
|
+
expect(formatMoney(28, 'USD')).toBe('$28.00');
|
|
15
|
+
expect(formatMoney(96.5, 'USD')).toBe('$96.50');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The currency's own fraction count, used as **both** the maximum and the minimum — a displayed
|
|
20
|
+
* price pads, which is the sixth argument `formatCurrency` takes and the one thing this module
|
|
21
|
+
* asks of it beyond the private library's own contract. Without the minimum, `$96` would sit
|
|
22
|
+
* above `$96.50` in a cart; without the maximum, a króna would grow a fraction it has no minor
|
|
23
|
+
* unit for.
|
|
24
|
+
*/
|
|
25
|
+
it('takes the fraction digits from the currency, as both the cap and the padding', () => {
|
|
26
|
+
expect(formatMoney(28, 'ISK', 'is-IS')).not.toMatch(/[.,]\d/);
|
|
27
|
+
expect(formatMoney(28, 'ISK', 'is-IS')).toContain('28');
|
|
28
|
+
// Not even for an amount that has a fraction: krónur have no minor unit to show one in, and
|
|
29
|
+
// so nothing to pad to either.
|
|
30
|
+
expect(formatMoney(28.4, 'ISK', 'en-US')).toBe('kr\u00a028');
|
|
31
|
+
expect(formatMoney(28, 'USD', 'en-US')).toBe('$28.00');
|
|
32
|
+
expect(formatMoney(28.5, 'USD', 'en-US')).toBe('$28.50');
|
|
33
|
+
expect(formatMoney(28.567, 'USD', 'en-US')).toBe('$28.57');
|
|
34
|
+
// The same formatter called the private library's way pads nothing — proof the padding is
|
|
35
|
+
// this module's argument, not a change to the package's own contract.
|
|
36
|
+
expect(formatCurrency(28, 'en-US', 'USD')).toBe('$28');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('formats in the store’s currency, not the locale’s', () => {
|
|
40
|
+
// An Icelandic page of a store that sells in dollars shows dollars, with Icelandic grouping.
|
|
41
|
+
expect(formatMoney(4800, 'USD', 'is-IS')).toContain('4.800');
|
|
42
|
+
expect(formatMoney(4800, 'ISK', 'en-US')).toMatch(/4,800/);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The sign, not the digits: this module used to build its own
|
|
47
|
+
* `Intl.NumberFormat({ style: 'currency' })`, which writes the **wide** sign — so a button label
|
|
48
|
+
* read "ISK 2,800" beside a `<Price>` reading "kr 2,800" for the same money. Both now go through
|
|
49
|
+
* `@eldrajs/ui`'s `formatCurrency`, so there is one sign on the page.
|
|
50
|
+
*/
|
|
51
|
+
it('writes the currency’s narrow sign, the same one every <Price> writes', () => {
|
|
52
|
+
expect(formatMoney(2800, 'ISK', 'en-US')).toBe('kr\u00a02,800');
|
|
53
|
+
expect(formatMoney(2800, 'ISK', 'is-IS')).toBe('2.800\u00a0kr.');
|
|
54
|
+
expect(formatMoney(28, 'USD', 'en-US')).toBe('$28.00');
|
|
55
|
+
// `is-IS` writes `$` for dollars narrow, where its wide sign is the code itself.
|
|
56
|
+
expect(formatMoney(28, 'USD', 'is-IS')).toBe('28,00\u00a0$');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('is `@eldrajs/ui`’s own `formatCurrency`, not a second copy of it', () => {
|
|
60
|
+
// Asserted as an identity across every usable pair the theme can see — with the same narrow
|
|
61
|
+
// sign and the same fraction arguments this module passes — so the day the package's
|
|
62
|
+
// formatter changes, this module follows it instead of drifting from it.
|
|
63
|
+
for (const [currency, digits] of [
|
|
64
|
+
['ISK', 0],
|
|
65
|
+
['USD', 2],
|
|
66
|
+
['EUR', 2],
|
|
67
|
+
] as const) {
|
|
68
|
+
for (const locale of ['en-US', 'is-IS']) {
|
|
69
|
+
expect(formatMoney(2800.5, currency, locale)).toBe(
|
|
70
|
+
formatCurrency(2800.5, locale, currency, true, digits, digits)
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('defaults only the locale — never the currency', () => {
|
|
77
|
+
expect(formatMoney(28, 'USD')).toBe(formatMoney(28, 'USD', DEFAULT_LOCALE));
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('renders a plain number for a store that publishes no currency', () => {
|
|
81
|
+
// No currency is not a currency to guess at: a `$` in front of 4800 ISK is a wrong price,
|
|
82
|
+
// while a bare 4.800 is an incomplete one. And it must not throw — this runs inside
|
|
83
|
+
// `computed`s, where a throw takes the whole block down.
|
|
84
|
+
expect(formatMoney(4800, undefined, 'is-IS')).toBe('4.800');
|
|
85
|
+
expect(formatMoney(4800, undefined, 'en-US')).toBe('4,800');
|
|
86
|
+
expect(formatMoney(4800, undefined)).not.toContain('$');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('falls back to a plain decimal and the raw code rather than throwing', () => {
|
|
90
|
+
// `formatCurrency` throws `RangeError` on a code `Intl` does not know, exactly as the private
|
|
91
|
+
// helper it ports does — so the guard is this module's, and it is the same shape `<Price>`
|
|
92
|
+
// falls back to for the identical failure.
|
|
93
|
+
expect(formatMoney(28, 'XYZ1')).toBe('28 XYZ1');
|
|
94
|
+
expect(formatMoney(4800, 'XYZ1')).toBe('4,800 XYZ1');
|
|
95
|
+
expect(() => formatCurrency(28, 'en-US', 'XYZ1')).toThrow(RangeError);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('the formatter cache', () => {
|
|
100
|
+
it('keeps one currency-and-locale pair from answering for another', () => {
|
|
101
|
+
// `resolveFormat` memoizes `Intl.NumberFormat` per pair, which is the one way this module could
|
|
102
|
+
// start returning a cached answer for the wrong store or the wrong page.
|
|
103
|
+
expect(formatMoney(1234.5, 'USD', 'en-US')).toBe('$1,234.50');
|
|
104
|
+
expect(formatMoney(1234.5, 'USD', 'is-IS')).toBe(formatMoney(1234.5, 'USD', 'is-IS'));
|
|
105
|
+
expect(formatMoney(1234.5, 'USD', 'is-IS')).not.toBe('$1,234.50');
|
|
106
|
+
expect(formatMoney(1234, 'ISK', 'is-IS')).toContain('kr');
|
|
107
|
+
expect(formatMoney(1234.5, 'USD', 'en-US')).toBe('$1,234.50');
|
|
108
|
+
// And the digits each pair resolves stay its own.
|
|
109
|
+
expect(toMinorUnits(28, 'USD', 'en-US')).toBe(2800);
|
|
110
|
+
expect(toMinorUnits(28, 'ISK', 'en-US')).toBe(28);
|
|
111
|
+
expect(toMinorUnits(28, 'USD', 'en-US')).toBe(2800);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('toMinorUnits', () => {
|
|
116
|
+
it('converts for @eldrajs/ui’s minor-unit money inputs', () => {
|
|
117
|
+
expect(toMinorUnits(28, 'USD')).toBe(2800);
|
|
118
|
+
expect(toMinorUnits(96.5, 'USD')).toBe(9650);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('uses the currency’s own minor-unit count, not a hard-coded hundred', () => {
|
|
122
|
+
expect(toMinorUnits(28, 'ISK', 'is-IS')).toBe(28);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('falls back to two digits with no currency, the same scale <Price> does', () => {
|
|
126
|
+
// `currencyFractionDigits` answers 2 for an absent/unknown code, so the amount this produces
|
|
127
|
+
// and the amount the `<Price>` reading it renders agree even with nothing published.
|
|
128
|
+
expect(toMinorUnits(28, undefined)).toBe(2800);
|
|
129
|
+
expect(toMinorUnits(28, 'XYZ1')).toBe(2800);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('rounds, so a float amount never becomes a fractional minor unit', () => {
|
|
133
|
+
expect(toMinorUnits(8.2 * 3, 'USD')).toBe(2460);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe('currencyLabel', () => {
|
|
138
|
+
it('names the currency as code plus its narrow sign, in the given locale', () => {
|
|
139
|
+
// The sign is the one the page's own prices carry: `kr.` on an Icelandic page, `kr` on an
|
|
140
|
+
// English one (the narrow sign for krónur — the wide one there *is* the code).
|
|
141
|
+
expect(currencyLabel('ISK', 'is-IS')).toBe('ISK kr.');
|
|
142
|
+
expect(currencyLabel('ISK', 'en-US')).toBe('ISK kr');
|
|
143
|
+
expect(currencyLabel('USD', 'en-US')).toBe('USD $');
|
|
144
|
+
expect(currencyLabel('USD', 'is-IS')).toBe('USD $');
|
|
145
|
+
expect(currencyLabel('EUR', 'en-US')).toBe('EUR €');
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('falls back to the code alone when the locale has no sign distinct from it', () => {
|
|
149
|
+
// `CHF` is written as its own code in both the locales this theme ships, and `CHF CHF` would
|
|
150
|
+
// be noise. (Krónur used to land here on an `en-US` page; the narrow sign gave it a `kr`.)
|
|
151
|
+
expect(currencyLabel('CHF', 'en-US')).toBe('CHF');
|
|
152
|
+
expect(currencyLabel('CHF', 'is-IS')).toBe('CHF');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('falls back to the code alone for a code Intl does not recognise, rather than throwing', () => {
|
|
156
|
+
expect(currencyLabel('XYZ1')).toBe('XYZ1');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('defaults only the locale — never the code', () => {
|
|
160
|
+
expect(currencyLabel('USD')).toBe(currencyLabel('USD', DEFAULT_LOCALE));
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe('roundMoney', () => {
|
|
165
|
+
it('rounds a computed sum back to two decimals', () => {
|
|
166
|
+
// $8.20 × 3 is 24.599999999999998 in floating point, and a total built from it drifts on.
|
|
167
|
+
expect(8.2 * 3).not.toBe(24.6);
|
|
168
|
+
expect(roundMoney(8.2 * 3)).toBe(24.6);
|
|
169
|
+
expect(roundMoney(0.1 + 0.2)).toBe(0.3);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { toMinorUnits } from '../../app/storefront/money';
|
|
3
|
+
import { toProductCard, toProductCardEntries } from '../../app/storefront/toProductCard';
|
|
4
|
+
import type { StorefrontProductListItem } from '../../app/storefront/types';
|
|
5
|
+
|
|
6
|
+
function baseItem(overrides: Partial<StorefrontProductListItem> = {}): StorefrontProductListItem {
|
|
7
|
+
return {
|
|
8
|
+
handle: 'merino-crew-sweater',
|
|
9
|
+
title: 'Merino crew sweater',
|
|
10
|
+
url: '/products/merino-crew-sweater',
|
|
11
|
+
featuredImage: { src: '/demo/product-1.svg', alt: 'Merino crew sweater' },
|
|
12
|
+
price: { amount: 96, compareAt: null },
|
|
13
|
+
rating: { value: 4.5, count: 126 },
|
|
14
|
+
colours: [{ name: 'Oat', swatch: '#d8cbb0' }],
|
|
15
|
+
stock: 'in',
|
|
16
|
+
available: true,
|
|
17
|
+
productId: 'merino-crew-sweater',
|
|
18
|
+
...overrides,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** `toProductCard` returns `null` for an item whose `url` is not a safe href — see the
|
|
23
|
+
* "rejects" cases below. Every other case in this file expects a card, so this narrows once. */
|
|
24
|
+
function expectCard(...args: Parameters<typeof toProductCard>) {
|
|
25
|
+
const card = toProductCard(...args);
|
|
26
|
+
expect(card).not.toBeNull();
|
|
27
|
+
return card!;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('toProductCard', () => {
|
|
31
|
+
it('maps title, url, featuredImage, rating, colours, stock and available straight through', () => {
|
|
32
|
+
const card = expectCard(baseItem());
|
|
33
|
+
expect(card.title).toBe('Merino crew sweater');
|
|
34
|
+
expect(card.url).toBe('/products/merino-crew-sweater');
|
|
35
|
+
expect(card.featuredImage).toEqual({ src: '/demo/product-1.svg', alt: 'Merino crew sweater' });
|
|
36
|
+
expect(card.rating).toEqual({ value: 4.5, count: 126 });
|
|
37
|
+
expect(card.colours).toEqual([{ name: 'Oat', swatch: '#d8cbb0' }]);
|
|
38
|
+
expect(card.stock).toBe('in');
|
|
39
|
+
expect(card.available).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('converts price.amount and compareAt into the minor units the card reads', () => {
|
|
43
|
+
const card = expectCard(baseItem({ price: { amount: 96, compareAt: 128, from: true } }));
|
|
44
|
+
expect(card.price).toEqual({ amount: 9600, compareAt: 12800, from: true });
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('leaves a missing compareAt missing rather than converting it to 0', () => {
|
|
48
|
+
expect(expectCard(baseItem({ price: { amount: 96 } })).price.compareAt).toBeUndefined();
|
|
49
|
+
expect(expectCard(baseItem({ price: { amount: 96, compareAt: null } })).price.compareAt).toBe(
|
|
50
|
+
null
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('converts with the currency a caller hands it, not a hard-coded hundred', () => {
|
|
55
|
+
// `ISK` has no minor unit, so 96 krónur stays 96 — the reason this is a conversion and not
|
|
56
|
+
// a `* 100`.
|
|
57
|
+
const card = expectCard(baseItem({ price: { amount: 96 } }), {
|
|
58
|
+
minorUnits: (amount) => toMinorUnits(amount, 'ISK'),
|
|
59
|
+
});
|
|
60
|
+
expect(card.price.amount).toBe(96);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('renders no featuredImage as null, not undefined', () => {
|
|
64
|
+
const card = expectCard(baseItem({ featuredImage: undefined }));
|
|
65
|
+
expect(card.featuredImage).toBeNull();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('derives badge: { variant: "sale" } when compareAt is greater than amount', () => {
|
|
69
|
+
const card = expectCard(baseItem({ price: { amount: 9600, compareAt: 12800 } }));
|
|
70
|
+
expect(card.badge).toEqual({ variant: 'sale' });
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('derives no badge when compareAt equals amount', () => {
|
|
74
|
+
const card = expectCard(baseItem({ price: { amount: 9600, compareAt: 9600 } }));
|
|
75
|
+
expect(card.badge).toBeNull();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('derives no badge when compareAt is less than amount', () => {
|
|
79
|
+
const card = expectCard(baseItem({ price: { amount: 9600, compareAt: 4800 } }));
|
|
80
|
+
expect(card.badge).toBeNull();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('derives no badge when there is no compareAt at all', () => {
|
|
84
|
+
const card = expectCard(baseItem({ price: { amount: 9600, compareAt: null } }));
|
|
85
|
+
expect(card.badge).toBeNull();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// `item.url` is storefront-derived (a gateway response or the demo fixture), and
|
|
89
|
+
// `ProductCardProduct.url` is required — the card always renders a link, so there is no
|
|
90
|
+
// "card without a link" state. So an unusable URL means no card, which is what these lock in.
|
|
91
|
+
describe('the url trust boundary', () => {
|
|
92
|
+
it.each([
|
|
93
|
+
['a javascript: URL', 'javascript:alert(1)'],
|
|
94
|
+
['a data: URL', 'data:text/html,<script>alert(1)</script>'],
|
|
95
|
+
['a protocol-relative URL', '//evil.example/p/x'],
|
|
96
|
+
['a backslash path', '/products\\..\\admin'],
|
|
97
|
+
['an empty string', ''],
|
|
98
|
+
['whitespace only', ' '],
|
|
99
|
+
])('returns null for %s', (_label, url) => {
|
|
100
|
+
expect(toProductCard(baseItem({ url }))).toBeNull();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('keeps an ordinary path and an absolute http(s) URL', () => {
|
|
104
|
+
expect(expectCard(baseItem({ url: '/products/x' })).url).toBe('/products/x');
|
|
105
|
+
expect(expectCard(baseItem({ url: 'https://shop.example/p/x' })).url).toBe(
|
|
106
|
+
'https://shop.example/p/x'
|
|
107
|
+
);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('toProductCardEntries', () => {
|
|
113
|
+
it('drops the unusable items, keeps order, and reports whether each link routes', () => {
|
|
114
|
+
const entries = toProductCardEntries([
|
|
115
|
+
baseItem({ handle: 'a', url: '/products/a' }),
|
|
116
|
+
baseItem({ handle: 'bad', url: 'javascript:alert(1)' }),
|
|
117
|
+
baseItem({ handle: 'b', url: 'https://elsewhere.example/p/b' }),
|
|
118
|
+
]);
|
|
119
|
+
|
|
120
|
+
expect(entries.map((entry) => entry.item.handle)).toEqual(['a', 'b']);
|
|
121
|
+
expect(entries.map((entry) => entry.internal)).toEqual([true, false]);
|
|
122
|
+
expect(entries.map((entry) => entry.product.url)).toEqual([
|
|
123
|
+
'/products/a',
|
|
124
|
+
'https://elsewhere.example/p/b',
|
|
125
|
+
]);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('carries the sanitised href on the item too, so a caller never re-reads the raw one', () => {
|
|
129
|
+
const [entry] = toProductCardEntries([baseItem({ url: ' /products/a ' })]);
|
|
130
|
+
expect(entry!.item.url).toBe('/products/a');
|
|
131
|
+
expect(entry!.product.url).toBe('/products/a');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('accepts null/undefined and returns no entries', () => {
|
|
135
|
+
expect(toProductCardEntries(null)).toEqual([]);
|
|
136
|
+
expect(toProductCardEntries(undefined)).toEqual([]);
|
|
137
|
+
});
|
|
138
|
+
});
|