@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,561 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { defineComponent, h, nextTick, ref, type PropType } from 'vue';
|
|
3
|
+
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils';
|
|
4
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
5
|
+
import { Toaster, useToast } from '@eldrajs/ui';
|
|
6
|
+
import { axe } from '../../../test/support/axe';
|
|
7
|
+
import Block from '../Block.vue';
|
|
8
|
+
import mock from '../mock.json';
|
|
9
|
+
import { mountOptions } from '../../../test/support/mountBlock';
|
|
10
|
+
import { EldraHttpError } from '@eldrajs/sdk';
|
|
11
|
+
import { createDemoStorefront, DEMO_CART_LINES } from '../../../app/storefront/demo';
|
|
12
|
+
import { createCartStore, type CartSnapshot } from '../../../app/storefront/cart';
|
|
13
|
+
import { STOREFRONT_KEY, type StorefrontSource } from '../../../app/storefront/types';
|
|
14
|
+
import type { StorefrontCartLine } from '../../../app/storefront/types';
|
|
15
|
+
|
|
16
|
+
/** Only `variant` is required at the schema level — the "genuinely minimal" fixture every rebuilt
|
|
17
|
+
* block spec covers alongside the full `mock.json`. With no `freeShippingThreshold` there is no
|
|
18
|
+
* shipping bar, and with no empty copy the empty state falls back to its own heading. */
|
|
19
|
+
const bare = { variant: 'drawer' as const };
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The block plus the one `Toaster` `app/app.vue` mounts app-wide (the Undo toast is queued by
|
|
23
|
+
* `useToast`, a module-level store, and only a mounted `Toaster` renders it), plus a stand-in for the
|
|
24
|
+
* header's bag button so "focus returns to the opener" has a real opener to return to —
|
|
25
|
+
* `blocks/navigation/Block.vue` is what plays that part on a real page.
|
|
26
|
+
*/
|
|
27
|
+
const Harness = defineComponent({
|
|
28
|
+
name: 'CartHarness',
|
|
29
|
+
props: {
|
|
30
|
+
entry: {
|
|
31
|
+
type: Object as PropType<{ id: string; data: Record<string, unknown> }>,
|
|
32
|
+
required: true,
|
|
33
|
+
},
|
|
34
|
+
storefront: { type: Object as PropType<StorefrontSource>, required: true },
|
|
35
|
+
},
|
|
36
|
+
setup(props) {
|
|
37
|
+
return () =>
|
|
38
|
+
h('div', [
|
|
39
|
+
h(
|
|
40
|
+
'button',
|
|
41
|
+
{
|
|
42
|
+
id: 'bag',
|
|
43
|
+
type: 'button',
|
|
44
|
+
'aria-haspopup': 'dialog',
|
|
45
|
+
onClick: () => {
|
|
46
|
+
props.storefront.cart.drawerOpen.value = true;
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
'Cart'
|
|
50
|
+
),
|
|
51
|
+
// The generated ambient `EldraBlockEntry<'cart'>` is a compile-time type only; the runtime
|
|
52
|
+
// shape is exactly `{ id, data }`, which is what every block spec mounts with.
|
|
53
|
+
h(Block as never, { entry: props.entry }),
|
|
54
|
+
h(Toaster),
|
|
55
|
+
]);
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const trackedWrappers: VueWrapper[] = [];
|
|
60
|
+
afterEach(() => {
|
|
61
|
+
for (const wrapper of trackedWrappers.splice(0)) wrapper.unmount();
|
|
62
|
+
// The toast queue and the modal scroll lock are both module-level in `@eldrajs/ui`.
|
|
63
|
+
useToast().clear();
|
|
64
|
+
document.documentElement.style.overflow = '';
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
async function mountCart(
|
|
68
|
+
data: Record<string, unknown>,
|
|
69
|
+
options: {
|
|
70
|
+
cartLines?: StorefrontCartLine[];
|
|
71
|
+
refuseMutations?: unknown;
|
|
72
|
+
/** Refuse only the re-add behind Undo, so the removal itself still succeeds. */
|
|
73
|
+
refuseOnly?: 'add';
|
|
74
|
+
} = {}
|
|
75
|
+
): Promise<{ wrapper: VueWrapper; storefront: StorefrontSource }> {
|
|
76
|
+
const lines = options.cartLines ?? DEMO_CART_LINES;
|
|
77
|
+
const storefront =
|
|
78
|
+
options.refuseMutations === undefined
|
|
79
|
+
? createDemoStorefront({ cartLines: lines })
|
|
80
|
+
: refusingStorefront(lines, options.refuseMutations, options.refuseOnly);
|
|
81
|
+
const base = mountOptions({ entry: { id: 'cart', data } });
|
|
82
|
+
const wrapper = mount(Harness, {
|
|
83
|
+
props: { entry: { id: 'cart', data }, storefront },
|
|
84
|
+
attachTo: document.body,
|
|
85
|
+
global: {
|
|
86
|
+
...base.global,
|
|
87
|
+
// `@vue/test-utils` stubs `<TransitionGroup>` by default, which would put a
|
|
88
|
+
// `transition-group-stub` element between the `<ul>` and its `<li>`s and break the list
|
|
89
|
+
// semantics axe checks — in a browser it renders a fragment and there is no wrapper at all.
|
|
90
|
+
// Rendering the real thing is both what the page does and what the axe gate has to see.
|
|
91
|
+
stubs: { ...base.global.stubs, transition: false, 'transition-group': false },
|
|
92
|
+
provide: {
|
|
93
|
+
...base.global.provide,
|
|
94
|
+
[STOREFRONT_KEY]: storefront,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
trackedWrappers.push(wrapper);
|
|
99
|
+
// The cart store loads itself on creation (`createCartStore` → `ops.init()`), one microtask out.
|
|
100
|
+
await flushPromises();
|
|
101
|
+
return { wrapper, storefront };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Opens the drawer the way the header does: focus the bag, then click it. `trigger('click')` only
|
|
105
|
+
* dispatches the event, so the focus has to be real for the focus-return assertion to mean
|
|
106
|
+
* anything. */
|
|
107
|
+
async function openDrawer(wrapper: VueWrapper): Promise<void> {
|
|
108
|
+
const bag = wrapper.get('#bag');
|
|
109
|
+
bag.element.focus();
|
|
110
|
+
await bag.trigger('click');
|
|
111
|
+
await flushPromises();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function accessibleNameOf(element: Element): string {
|
|
115
|
+
return element.getAttribute('aria-label') ?? (element.textContent ?? '').trim();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function focusableNames(root: Element): string[] {
|
|
119
|
+
return [...root.querySelectorAll('a[href], button, input')].map(accessibleNameOf);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The demo storefront with a cart that holds its lines but refuses every change — what the in-memory
|
|
124
|
+
* ops cannot do, and the one state these controls have nothing of their own to show: the stepper
|
|
125
|
+
* springs back and the row stays put, exactly as if the button did nothing.
|
|
126
|
+
*/
|
|
127
|
+
function refusingStorefront(
|
|
128
|
+
lines: StorefrontCartLine[],
|
|
129
|
+
thrown: unknown,
|
|
130
|
+
only?: 'add'
|
|
131
|
+
): StorefrontSource {
|
|
132
|
+
let held = lines.map((line) => ({ ...line }));
|
|
133
|
+
const snapshot = (): CartSnapshot => ({
|
|
134
|
+
lines: held.map((line) => ({ ...line })),
|
|
135
|
+
totals: { subtotal: 0, discount: null, shipping: null, tax: null, total: 0 },
|
|
136
|
+
});
|
|
137
|
+
const refuse = async (): Promise<never> => {
|
|
138
|
+
throw thrown;
|
|
139
|
+
};
|
|
140
|
+
const source = createDemoStorefront({ cartLines: lines });
|
|
141
|
+
return {
|
|
142
|
+
...source,
|
|
143
|
+
cart: createCartStore({
|
|
144
|
+
init: async () => snapshot(),
|
|
145
|
+
add: refuse,
|
|
146
|
+
setQuantity: only === 'add' ? async () => snapshot() : refuse,
|
|
147
|
+
remove:
|
|
148
|
+
only === 'add'
|
|
149
|
+
? async (lineId) => {
|
|
150
|
+
held = held.filter((line) => line.id !== lineId);
|
|
151
|
+
return snapshot();
|
|
152
|
+
}
|
|
153
|
+
: refuse,
|
|
154
|
+
applyDiscount: refuse,
|
|
155
|
+
removeDiscount: refuse,
|
|
156
|
+
checkoutUrl: ref<string | null>(null),
|
|
157
|
+
}),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** The live Undo toast the `Toaster` rendered (it teleports into the open drawer, or to `<body>`). */
|
|
162
|
+
function toastRoot(): HTMLElement | null {
|
|
163
|
+
return document.body.querySelector<HTMLElement>('[data-part="list"]');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** A `danger` toast is rendered as `role="alert"`, *beside* the polite list rather than inside it
|
|
167
|
+
* (`Toaster`), so a refusal is announced immediately instead of waiting its turn. */
|
|
168
|
+
function alertToast(): HTMLElement | null {
|
|
169
|
+
return document.body.querySelector<HTMLElement>('[role="alert"]');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
describe('cart block', () => {
|
|
173
|
+
describe('accessibility', () => {
|
|
174
|
+
it('renders the full mock.json content with no axe violations', async () => {
|
|
175
|
+
const { wrapper } = await mountCart(mock);
|
|
176
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('renders the bare, required-fields-only content with no axe violations', async () => {
|
|
180
|
+
const { wrapper } = await mountCart(bare);
|
|
181
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it.each(['drawer', 'page'] as const)(
|
|
185
|
+
'renders the %s variant with no axe violations',
|
|
186
|
+
async (variant) => {
|
|
187
|
+
const { wrapper } = await mountCart({ ...mock, variant });
|
|
188
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
189
|
+
}
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
it('has no axe violations with the drawer open', async () => {
|
|
193
|
+
const { wrapper } = await mountCart(mock);
|
|
194
|
+
await openDrawer(wrapper);
|
|
195
|
+
expect(wrapper.get('dialog').attributes('open')).toBe('');
|
|
196
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('has no axe violations with an empty cart, in either shell', async () => {
|
|
200
|
+
for (const variant of ['drawer', 'page'] as const) {
|
|
201
|
+
const { wrapper } = await mountCart({ ...mock, variant }, { cartLines: [] });
|
|
202
|
+
if (variant === 'drawer') await openDrawer(wrapper);
|
|
203
|
+
expect(wrapper.text()).toContain(mock.emptyTitle);
|
|
204
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
describe('drawer', () => {
|
|
210
|
+
it('is a modal dialog labelled by its title, opens focused on close, and stops the page scrolling', async () => {
|
|
211
|
+
const { wrapper } = await mountCart(mock);
|
|
212
|
+
await openDrawer(wrapper);
|
|
213
|
+
|
|
214
|
+
const dialog = wrapper.get('dialog');
|
|
215
|
+
expect(dialog.attributes('open')).toBe('');
|
|
216
|
+
const titleId = dialog.attributes('aria-labelledby');
|
|
217
|
+
expect(titleId).toBeTruthy();
|
|
218
|
+
expect(document.getElementById(titleId!)?.textContent).toContain('Your cart');
|
|
219
|
+
// The count sits beside the title, from the store's own line quantities (1 + 2 + 1).
|
|
220
|
+
expect(document.getElementById(titleId!)?.textContent).toContain('4');
|
|
221
|
+
|
|
222
|
+
const close = dialog.get('[data-part="close"]');
|
|
223
|
+
expect(close.attributes('aria-label')).toBe('Close Your cart');
|
|
224
|
+
expect(document.activeElement).toBe(close.element);
|
|
225
|
+
expect(document.documentElement.style.overflow).toBe('hidden');
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('closes on Esc, returning focus to the opener and the scroll to the page', async () => {
|
|
229
|
+
const { wrapper } = await mountCart(mock);
|
|
230
|
+
await openDrawer(wrapper);
|
|
231
|
+
|
|
232
|
+
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
|
|
233
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
234
|
+
await flushPromises();
|
|
235
|
+
|
|
236
|
+
expect(wrapper.get('dialog').attributes('open')).toBeUndefined();
|
|
237
|
+
expect(document.activeElement).toBe(wrapper.get('#bag').element);
|
|
238
|
+
expect(document.documentElement.style.overflow).toBe('');
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('tells the header a drawer exists for as long as it is mounted', async () => {
|
|
242
|
+
const { wrapper, storefront } = await mountCart(mock);
|
|
243
|
+
expect(storefront.cart.drawerAvailable.value).toBe(true);
|
|
244
|
+
wrapper.unmount();
|
|
245
|
+
expect(storefront.cart.drawerAvailable.value).toBe(false);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('does not claim a drawer in the page variant', async () => {
|
|
249
|
+
const { storefront } = await mountCart({ ...mock, variant: 'page' });
|
|
250
|
+
expect(storefront.cart.drawerAvailable.value).toBe(false);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('has a footer with the subtotal, the note and both actions, and none at all when empty', async () => {
|
|
254
|
+
const { wrapper } = await mountCart(mock);
|
|
255
|
+
await openDrawer(wrapper);
|
|
256
|
+
const footer = wrapper.get('dialog [data-part="footer"]');
|
|
257
|
+
expect(footer.text()).toContain('Subtotal');
|
|
258
|
+
expect(footer.text()).toContain('$210.00');
|
|
259
|
+
expect(footer.text()).toContain(mock.note);
|
|
260
|
+
expect(footer.get('a[href="/checkout/demo-cart"]').text()).toContain('Check out');
|
|
261
|
+
expect(footer.get('a[href="/cart"]').text()).toContain('View cart');
|
|
262
|
+
|
|
263
|
+
const empty = await mountCart(mock, { cartLines: [] });
|
|
264
|
+
await openDrawer(empty.wrapper);
|
|
265
|
+
expect(empty.wrapper.find('dialog [data-part="footer"]').exists()).toBe(false);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it('runs the spec’s tab order: close, item, stepper, remove, then the two footer actions', async () => {
|
|
269
|
+
const { wrapper } = await mountCart(mock);
|
|
270
|
+
await openDrawer(wrapper);
|
|
271
|
+
const names = focusableNames(wrapper.get('dialog').element);
|
|
272
|
+
|
|
273
|
+
expect(names.slice(0, 6)).toEqual([
|
|
274
|
+
'Close Your cart',
|
|
275
|
+
'Merino crew sweater',
|
|
276
|
+
'Decrease, Merino crew sweater',
|
|
277
|
+
'Quantity',
|
|
278
|
+
'Increase, Merino crew sweater',
|
|
279
|
+
'Remove Merino crew sweater, Oat / M',
|
|
280
|
+
]);
|
|
281
|
+
expect(names.slice(-2)).toEqual(['Check out', 'View cart']);
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
describe('line items', () => {
|
|
286
|
+
it('labels the list, names every stepper group and names every remove button with its variant', async () => {
|
|
287
|
+
const { wrapper } = await mountCart(mock);
|
|
288
|
+
await openDrawer(wrapper);
|
|
289
|
+
|
|
290
|
+
expect(wrapper.get('dialog ul').attributes('aria-label')).toBe('Items in your cart');
|
|
291
|
+
expect(
|
|
292
|
+
wrapper.findAll('dialog [role="group"]').map((group) => group.attributes('aria-label'))
|
|
293
|
+
).toEqual([
|
|
294
|
+
'Quantity, Merino crew sweater',
|
|
295
|
+
'Quantity, Speckled latte mug',
|
|
296
|
+
'Quantity, Walnut serving board',
|
|
297
|
+
]);
|
|
298
|
+
expect(
|
|
299
|
+
wrapper
|
|
300
|
+
.findAll('dialog [aria-label^="Remove"]')
|
|
301
|
+
.map((button) => button.attributes('aria-label'))
|
|
302
|
+
).toEqual([
|
|
303
|
+
'Remove Merino crew sweater, Oat / M',
|
|
304
|
+
'Remove Speckled latte mug, Clay',
|
|
305
|
+
'Remove Walnut serving board, Large, 45 cm',
|
|
306
|
+
]);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it('shows the unit price only above quantity 1', async () => {
|
|
310
|
+
const { wrapper } = await mountCart(mock);
|
|
311
|
+
await openDrawer(wrapper);
|
|
312
|
+
const rows = wrapper.findAll('dialog li');
|
|
313
|
+
// Merino: one of them, so no "each" line; the mug: two at $28.00.
|
|
314
|
+
expect(rows[0]!.text()).not.toContain('each');
|
|
315
|
+
expect(rows[1]!.text()).toMatch(/\$28\.00\s*each/);
|
|
316
|
+
expect(rows[1]!.text()).toContain('$56.00');
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it('sends a stepper change to the store and re-renders the line total', async () => {
|
|
320
|
+
const { wrapper, storefront } = await mountCart(mock);
|
|
321
|
+
await openDrawer(wrapper);
|
|
322
|
+
|
|
323
|
+
await wrapper.get('dialog [aria-label="Increase, Merino crew sweater"]').trigger('click');
|
|
324
|
+
await flushPromises();
|
|
325
|
+
|
|
326
|
+
expect(storefront.cart.lines.value[0]!.quantity).toBe(2);
|
|
327
|
+
expect(wrapper.findAll('dialog li')[0]!.text()).toContain('$192.00');
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it('carries the hidden "Line total" label on every line total', async () => {
|
|
331
|
+
const { wrapper } = await mountCart({ ...mock, variant: 'page' });
|
|
332
|
+
const rows = wrapper.findAll('li');
|
|
333
|
+
expect(rows).toHaveLength(3);
|
|
334
|
+
for (const row of rows) {
|
|
335
|
+
const total = row.get('[data-part="root"] [data-part="current"]');
|
|
336
|
+
expect(total.exists()).toBe(true);
|
|
337
|
+
expect(row.text()).toContain('Line total');
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it('draws the image placeholder for a line with no photo, never an empty <img>', async () => {
|
|
342
|
+
const { wrapper } = await mountCart(mock, {
|
|
343
|
+
cartLines: [{ ...DEMO_CART_LINES[0]!, image: null }],
|
|
344
|
+
});
|
|
345
|
+
await openDrawer(wrapper);
|
|
346
|
+
|
|
347
|
+
const row = wrapper.get('dialog li');
|
|
348
|
+
expect(row.findAll('img')).toEqual([]);
|
|
349
|
+
// The title beside it already names the row, so the placeholder stays decorative.
|
|
350
|
+
const placeholder = row.get('[data-part="placeholder"]');
|
|
351
|
+
expect(placeholder.attributes('aria-hidden')).toBe('true');
|
|
352
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it('moves focus to the next line and offers an Undo toast that restores the removed line', async () => {
|
|
356
|
+
const { wrapper, storefront } = await mountCart(mock);
|
|
357
|
+
await openDrawer(wrapper);
|
|
358
|
+
|
|
359
|
+
await wrapper
|
|
360
|
+
.get('dialog [aria-label="Remove Merino crew sweater, Oat / M"]')
|
|
361
|
+
.trigger('click');
|
|
362
|
+
await flushPromises();
|
|
363
|
+
|
|
364
|
+
expect(storefront.cart.lines.value.map((line) => line.title)).toEqual([
|
|
365
|
+
'Speckled latte mug',
|
|
366
|
+
'Walnut serving board',
|
|
367
|
+
]);
|
|
368
|
+
const nextTitle = wrapper.get('dialog li a[href="/products/speckled-latte-mug"]');
|
|
369
|
+
expect(document.activeElement).toBe(nextTitle.element);
|
|
370
|
+
|
|
371
|
+
const toast = toastRoot();
|
|
372
|
+
expect(toast?.textContent).toContain('Merino crew sweater removed');
|
|
373
|
+
const undo = toast!.querySelector<HTMLElement>('[data-part="action"]')!;
|
|
374
|
+
expect(accessibleNameOf(undo)).toBe('Undo');
|
|
375
|
+
// The toast must never take focus — it appeared while focus was moving to the next line.
|
|
376
|
+
expect(document.activeElement).toBe(nextTitle.element);
|
|
377
|
+
|
|
378
|
+
undo.click();
|
|
379
|
+
await flushPromises();
|
|
380
|
+
expect(storefront.cart.lines.value.map((line) => line.title)).toEqual([
|
|
381
|
+
'Merino crew sweater',
|
|
382
|
+
'Speckled latte mug',
|
|
383
|
+
'Walnut serving board',
|
|
384
|
+
]);
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* A refused change has to say so. Nothing on screen moves when the backend says no — the line is
|
|
389
|
+
* still there, the stepper is back at the quantity the store still holds — so without this the
|
|
390
|
+
* only difference between "we could not" and "that button is broken" is invisible.
|
|
391
|
+
*/
|
|
392
|
+
it('reports a refused removal and a refused quantity change, keeping the line', async () => {
|
|
393
|
+
const { wrapper, storefront } = await mountCart(mock, {
|
|
394
|
+
refuseMutations: new EldraHttpError({ status: 409, statusText: 'Conflict' } as Response, {
|
|
395
|
+
code: 'CONFLICT',
|
|
396
|
+
errorId: 'CART_INSUFFICIENT_STOCK',
|
|
397
|
+
}),
|
|
398
|
+
});
|
|
399
|
+
await openDrawer(wrapper);
|
|
400
|
+
|
|
401
|
+
await wrapper
|
|
402
|
+
.get('dialog [aria-label="Remove Merino crew sweater, Oat / M"]')
|
|
403
|
+
.trigger('click');
|
|
404
|
+
await flushPromises();
|
|
405
|
+
|
|
406
|
+
expect(storefront.cart.lines.value.map((line) => line.title)).toContain(
|
|
407
|
+
'Merino crew sweater'
|
|
408
|
+
);
|
|
409
|
+
await nextTick();
|
|
410
|
+
|
|
411
|
+
expect(alertToast()?.textContent).toContain('This item is out of stock.');
|
|
412
|
+
// No Undo offered for a removal that did not happen.
|
|
413
|
+
expect(toastRoot()?.textContent ?? '').not.toContain('removed');
|
|
414
|
+
|
|
415
|
+
useToast().clear();
|
|
416
|
+
await wrapper.get('dialog [data-part="increase"]').trigger('click');
|
|
417
|
+
await flushPromises();
|
|
418
|
+
await nextTick();
|
|
419
|
+
|
|
420
|
+
expect(alertToast()?.textContent).toContain('This item is out of stock.');
|
|
421
|
+
expect(storefront.cart.lines.value[0]?.quantity).toBe(1);
|
|
422
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* The removal toast's own Undo was just pressed and the shop refused the re-add. That toast is
|
|
427
|
+
* still standing (activating an action does not dismiss it, and its timer is paused while focus
|
|
428
|
+
* is inside the stack) and its button now has nothing left to restore, so left beside the
|
|
429
|
+
* refusal it would put two contradictory statements about one line to the shopper.
|
|
430
|
+
*/
|
|
431
|
+
it('replaces the removal toast when the undo it offered is refused', async () => {
|
|
432
|
+
const { wrapper, storefront } = await mountCart(mock, {
|
|
433
|
+
refuseOnly: 'add',
|
|
434
|
+
refuseMutations: new EldraHttpError({ status: 409, statusText: 'Conflict' } as Response, {
|
|
435
|
+
code: 'CONFLICT',
|
|
436
|
+
errorId: 'CART_INSUFFICIENT_STOCK',
|
|
437
|
+
}),
|
|
438
|
+
});
|
|
439
|
+
await openDrawer(wrapper);
|
|
440
|
+
|
|
441
|
+
await wrapper
|
|
442
|
+
.get('dialog [aria-label="Remove Merino crew sweater, Oat / M"]')
|
|
443
|
+
.trigger('click');
|
|
444
|
+
await flushPromises();
|
|
445
|
+
await nextTick();
|
|
446
|
+
expect(toastRoot()?.textContent).toContain('Merino crew sweater removed');
|
|
447
|
+
|
|
448
|
+
toastRoot()!.querySelector<HTMLElement>('[data-part="action"]')!.click();
|
|
449
|
+
await flushPromises();
|
|
450
|
+
await nextTick();
|
|
451
|
+
|
|
452
|
+
expect(alertToast()?.textContent).toContain('This item is out of stock.');
|
|
453
|
+
expect(toastRoot()?.textContent ?? '').not.toContain('removed');
|
|
454
|
+
// The line is back on screen — the restore is local and deliberate — which is exactly why the
|
|
455
|
+
// shopper has to be told the shop could not take it back.
|
|
456
|
+
expect(storefront.cart.lines.value.map((line) => line.title)).toContain(
|
|
457
|
+
'Merino crew sweater'
|
|
458
|
+
);
|
|
459
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
it('moves focus to the empty-state heading when the last line goes', async () => {
|
|
463
|
+
const { wrapper } = await mountCart(mock, { cartLines: [DEMO_CART_LINES[0]!] });
|
|
464
|
+
await openDrawer(wrapper);
|
|
465
|
+
|
|
466
|
+
await wrapper
|
|
467
|
+
.get('dialog [aria-label="Remove Merino crew sweater, Oat / M"]')
|
|
468
|
+
.trigger('click');
|
|
469
|
+
await flushPromises();
|
|
470
|
+
|
|
471
|
+
// The drawer's own `h2` carries `data-part="title"` too; the empty state's is the `h3`.
|
|
472
|
+
const heading = wrapper.get('dialog h3[data-part="title"]');
|
|
473
|
+
expect(heading.text()).toBe(mock.emptyTitle);
|
|
474
|
+
expect(document.activeElement).toBe(heading.element);
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
describe('free shipping', () => {
|
|
479
|
+
it('is a polite status in words, with the bar hidden from assistive technology', async () => {
|
|
480
|
+
const { wrapper } = await mountCart({ ...mock, variant: 'page' });
|
|
481
|
+
// `[role="status"]` also matches `FormLayout`'s own hidden announcement region, so pick the
|
|
482
|
+
// shipping one by what it says.
|
|
483
|
+
const status = wrapper
|
|
484
|
+
.findAll('[role="status"]')
|
|
485
|
+
.find((element) => element.text().includes('Free shipping'))!;
|
|
486
|
+
// $210.00 against the mock's $80.00 threshold.
|
|
487
|
+
expect(status.text()).toBe('Free shipping unlocked');
|
|
488
|
+
expect(status.attributes('aria-live')).toBeUndefined(); // role="status" is already polite
|
|
489
|
+
expect(wrapper.find('[aria-hidden="true"] > div').exists()).toBe(true);
|
|
490
|
+
expect(wrapper.find('[role="progressbar"]').exists()).toBe(false);
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
it('renders no bar at all without a threshold', async () => {
|
|
494
|
+
const { wrapper } = await mountCart({ ...bare, variant: 'page' });
|
|
495
|
+
expect(wrapper.text()).not.toContain('free shipping');
|
|
496
|
+
expect(wrapper.text()).not.toContain('Free shipping');
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
describe('page', () => {
|
|
501
|
+
it('renders one h1 with the live count, which names the section', async () => {
|
|
502
|
+
const { wrapper } = await mountCart({ ...mock, variant: 'page' });
|
|
503
|
+
const headings = wrapper.findAll('h1');
|
|
504
|
+
expect(headings).toHaveLength(1);
|
|
505
|
+
expect(headings[0]!.text()).toContain('Your cart');
|
|
506
|
+
expect(headings[0]!.text()).toContain('4 items');
|
|
507
|
+
expect(wrapper.get('section').attributes('aria-labelledby')).toBe(
|
|
508
|
+
headings[0]!.attributes('id')
|
|
509
|
+
);
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
it('hides the column headings from assistive technology', async () => {
|
|
513
|
+
const { wrapper } = await mountCart({ ...mock, variant: 'page' });
|
|
514
|
+
const headings = wrapper
|
|
515
|
+
.findAll('[aria-hidden="true"]')
|
|
516
|
+
.filter((element) => element.text().includes('Product'));
|
|
517
|
+
expect(headings).toHaveLength(1);
|
|
518
|
+
expect(headings[0]!.text()).toContain('Quantity');
|
|
519
|
+
expect(headings[0]!.text()).toContain('Total');
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
it('shows the summary aside and links Check out to the storefront checkout URL', async () => {
|
|
523
|
+
const { wrapper } = await mountCart({ ...mock, variant: 'page' });
|
|
524
|
+
const aside = wrapper.get('aside');
|
|
525
|
+
expect(aside.text()).toContain('Order summary');
|
|
526
|
+
const checkout = aside.get('a[href="/checkout/demo-cart"]');
|
|
527
|
+
expect(checkout.text()).toContain('Check out');
|
|
528
|
+
expect(checkout.element.tagName).toBe('A');
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
it('offers Continue shopping beside the heading and in the empty state', async () => {
|
|
532
|
+
const { wrapper } = await mountCart({ ...mock, variant: 'page' });
|
|
533
|
+
expect(wrapper.get(`a[href="${mock.emptyLinkHref}"]`).text()).toContain('Continue shopping');
|
|
534
|
+
|
|
535
|
+
const empty = await mountCart({ ...mock, variant: 'page' }, { cartLines: [] });
|
|
536
|
+
expect(empty.wrapper.text()).toContain(mock.emptyText);
|
|
537
|
+
expect(empty.wrapper.findAll(`a[href="${mock.emptyLinkHref}"]`).length).toBe(2);
|
|
538
|
+
expect(empty.wrapper.find('aside').exists()).toBe(false);
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
it('keeps the discount field and payment icons out of the drawer, where the spec has neither', async () => {
|
|
542
|
+
const { wrapper } = await mountCart(mock);
|
|
543
|
+
await openDrawer(wrapper);
|
|
544
|
+
expect(wrapper.find('dialog input[name="discountCode"]').exists()).toBe(false);
|
|
545
|
+
expect(wrapper.find('dialog [role="img"]').exists()).toBe(false);
|
|
546
|
+
});
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
it('has no pre-ticked upsells and no urgency copy', async () => {
|
|
550
|
+
for (const variant of ['drawer', 'page'] as const) {
|
|
551
|
+
const { wrapper } = await mountCart({ ...mock, variant });
|
|
552
|
+
if (variant === 'drawer') await openDrawer(wrapper);
|
|
553
|
+
expect(
|
|
554
|
+
wrapper.findAll('input[type="checkbox"], input[type="radio"], [role="switch"]')
|
|
555
|
+
).toEqual([]);
|
|
556
|
+
expect(wrapper.text()).not.toMatch(
|
|
557
|
+
/only today|selling fast|hurry|almost gone|left in stock|people are viewing/i
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { mount } from '@vue/test-utils';
|
|
3
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
4
|
+
import { axe } from '../../../test/support/axe';
|
|
5
|
+
import ShippingBar from '../parts/ShippingBar.vue';
|
|
6
|
+
import { mountOptions } from '../../../test/support/mountBlock';
|
|
7
|
+
|
|
8
|
+
const trackedWrappers: ReturnType<typeof mount>[] = [];
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
for (const wrapper of trackedWrappers.splice(0)) wrapper.unmount();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
/** `mountOptions` supplies the same currency/locale/messages provides a real page does, which is
|
|
14
|
+
* what the `<Price>` inside the sentence reads. */
|
|
15
|
+
function mountBar(props: { threshold?: string; subtotal: number; panel?: 'edge' | 'card' }) {
|
|
16
|
+
const base = mountOptions({ entry: { id: 'cart', data: {} } });
|
|
17
|
+
const wrapper = mount(ShippingBar, {
|
|
18
|
+
props,
|
|
19
|
+
global: base.global,
|
|
20
|
+
});
|
|
21
|
+
trackedWrappers.push(wrapper);
|
|
22
|
+
return wrapper;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function barWidth(wrapper: ReturnType<typeof mountBar>): string | undefined {
|
|
26
|
+
return wrapper.get('[aria-hidden="true"] > div').attributes('style');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe('cart shipping bar', () => {
|
|
30
|
+
it('says how much is left in words, with the amount as a formatted price', async () => {
|
|
31
|
+
// $80.00 threshold, $68.00 subtotal — the spec's own drawer example.
|
|
32
|
+
const wrapper = mountBar({ threshold: '80.00', subtotal: 68 });
|
|
33
|
+
const status = wrapper.get('[role="status"]');
|
|
34
|
+
expect(status.text()).toContain("You're");
|
|
35
|
+
expect(status.text()).toContain('$12.00');
|
|
36
|
+
expect(status.text()).toContain('away from free shipping');
|
|
37
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('fills the bar to the share of the threshold already reached, and hides it from assistive tech', () => {
|
|
41
|
+
const wrapper = mountBar({ threshold: '80.00', subtotal: 68 });
|
|
42
|
+
const track = wrapper.get('[aria-hidden="true"]');
|
|
43
|
+
expect(track.exists()).toBe(true);
|
|
44
|
+
expect(barWidth(wrapper)).toContain('width: 85%');
|
|
45
|
+
// The words, never only the bar: no ARIA progress role that could report a number instead.
|
|
46
|
+
expect(wrapper.find('[role="progressbar"]').exists()).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('switches to the unlocked message once the subtotal reaches the threshold', () => {
|
|
50
|
+
const wrapper = mountBar({ threshold: '80.00', subtotal: 210 });
|
|
51
|
+
const status = wrapper.get('[role="status"]');
|
|
52
|
+
expect(status.text()).toBe('Free shipping unlocked');
|
|
53
|
+
expect(status.classes()).toContain('text-success');
|
|
54
|
+
expect(barWidth(wrapper)).toContain('width: 100%');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('treats the threshold as reached exactly at the threshold', () => {
|
|
58
|
+
const wrapper = mountBar({ threshold: '80.00', subtotal: 80 });
|
|
59
|
+
expect(wrapper.get('[role="status"]').text()).toBe('Free shipping unlocked');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('renders nothing at all without a usable threshold', () => {
|
|
63
|
+
for (const threshold of [undefined, '', ' ', 'free', '0', '-10']) {
|
|
64
|
+
const wrapper = mountBar({ threshold, subtotal: 68 });
|
|
65
|
+
expect(wrapper.find('[role="status"]').exists(), `threshold: ${String(threshold)}`).toBe(
|
|
66
|
+
false
|
|
67
|
+
);
|
|
68
|
+
expect(wrapper.text()).toBe('');
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('reads the threshold in the same major units the cart’s own amounts use', () => {
|
|
73
|
+
// "80" and a $68.00 subtotal are both major units, so the shopper is $12.00 short — the
|
|
74
|
+
// amount itself is a `<Price>`, which takes minor units, so it is converted on the way in.
|
|
75
|
+
const wrapper = mountBar({ threshold: '80', subtotal: 68 });
|
|
76
|
+
expect(wrapper.get('[role="status"]').text()).toContain('$12.00');
|
|
77
|
+
});
|
|
78
|
+
});
|