@eldrajs/theme-cli 0.0.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -0
- package/LICENSE +21 -0
- package/README.md +26 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +203 -0
- package/dist/index.d.ts +174 -0
- package/dist/index.js +3 -0
- package/dist/validate-DprFpjV7.js +535 -0
- package/package.json +50 -2
- package/template/.eldra/block-types.d.ts +429 -0
- package/template/.eldra/manifest.json +9378 -0
- package/template/.eldra/previews.json +36 -0
- package/template/.github/workflows/eldra-deploy.yml +24 -0
- package/template/.gitlab-ci.yml +16 -0
- package/template/.storybook/eldra.ts +123 -0
- package/template/.storybook/i18n.ts +23 -0
- package/template/.storybook/main.ts +59 -0
- package/template/.storybook/nuxt-link-stub.ts +23 -0
- package/template/.storybook/preview.ts +53 -0
- package/template/.storybook/shims-vue.d.ts +10 -0
- package/template/.storybook/virtual-eldra.d.ts +32 -0
- package/template/README.md +293 -0
- package/template/app/app.vue +126 -0
- package/template/app/assets/main.css +404 -0
- package/template/app/components/EldraIcon.vue +66 -0
- package/template/app/components/EldraRouterLink.vue +62 -0
- package/template/app/components/ui/UiImage.stories.ts +30 -0
- package/template/app/components/ui/UiImage.vue +224 -0
- package/template/app/components/ui/__tests__/UiImage.spec.ts +292 -0
- package/template/app/composables/iconComponent.ts +84 -0
- package/template/app/composables/iconFetcher.ts +14 -0
- package/template/app/composables/useBlockData.ts +30 -0
- package/template/app/composables/useEditing.ts +31 -0
- package/template/app/composables/useEldraIcon.ts +46 -0
- package/template/app/composables/useRevalidating.ts +69 -0
- package/template/app/composables/useRichTextScrollRegions.ts +80 -0
- package/template/app/composables/useStorefront.ts +18 -0
- package/template/app/composables/useStorefrontFeedback.ts +49 -0
- package/template/app/composables/useUiId.ts +18 -0
- package/template/app/composables/useWishlist.ts +42 -0
- package/template/app/i18n.d.ts +28 -0
- package/template/app/icons.ts +185 -0
- package/template/app/pages/[...slug].vue +134 -0
- package/template/app/plugins/eldra-i18n.ts +98 -0
- package/template/app/plugins/eldra-storefront.ts +288 -0
- package/template/app/plugins/eldra-ui-messages.ts +112 -0
- package/template/app/storefront/cart.ts +245 -0
- package/template/app/storefront/categories.ts +283 -0
- package/template/app/storefront/collectionSelector.ts +60 -0
- package/template/app/storefront/commerce.ts +58 -0
- package/template/app/storefront/demo.ts +1313 -0
- package/template/app/storefront/facets.ts +476 -0
- package/template/app/storefront/feedback.ts +122 -0
- package/template/app/storefront/gateway.ts +2256 -0
- package/template/app/storefront/history.ts +233 -0
- package/template/app/storefront/money.ts +248 -0
- package/template/app/storefront/options.ts +71 -0
- package/template/app/storefront/prerender.ts +77 -0
- package/template/app/storefront/refresh.ts +222 -0
- package/template/app/storefront/toProductCard.ts +154 -0
- package/template/app/storefront/types.ts +815 -0
- package/template/app/storefront/volatile.ts +211 -0
- package/template/app/templates.ts +544 -0
- package/template/app/utils/classes.ts +40 -0
- package/template/app/utils/links.ts +70 -0
- package/template/app/utils/pageStructure.ts +77 -0
- package/template/app/utils/pageTitle.ts +37 -0
- package/template/app/virtual-eldra.d.ts +12 -0
- package/template/bitbucket-pipelines.yml +19 -0
- package/template/blocks/announcement-bar/Block.vue +203 -0
- package/template/blocks/announcement-bar/__tests__/Block.spec.ts +227 -0
- package/template/blocks/announcement-bar/block.json +45 -0
- package/template/blocks/announcement-bar/mock.json +7 -0
- package/template/blocks/announcement-bar/preview.png +0 -0
- package/template/blocks/article/Block.vue +317 -0
- package/template/blocks/article/__tests__/Block.spec.ts +229 -0
- package/template/blocks/article/block.json +148 -0
- package/template/blocks/article/mock.json +512 -0
- package/template/blocks/article/preview.json +16 -0
- package/template/blocks/article/preview.png +0 -0
- package/template/blocks/article-list/Block.vue +343 -0
- package/template/blocks/article-list/__tests__/Block.spec.ts +279 -0
- package/template/blocks/article-list/block.json +181 -0
- package/template/blocks/article-list/mock.json +68 -0
- package/template/blocks/article-list/preview.json +84 -0
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/Block.vue +278 -0
- package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +461 -0
- package/template/blocks/breadcrumbs/block.json +89 -0
- package/template/blocks/breadcrumbs/mock.json +11 -0
- package/template/blocks/breadcrumbs/preview.json +3 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/Block.vue +372 -0
- package/template/blocks/cart/__tests__/Block.spec.ts +561 -0
- package/template/blocks/cart/__tests__/ShippingBar.spec.ts +78 -0
- package/template/blocks/cart/__tests__/Summary.spec.ts +245 -0
- package/template/blocks/cart/block.json +74 -0
- package/template/blocks/cart/mock.json +11 -0
- package/template/blocks/cart/parts/CartLines.vue +257 -0
- package/template/blocks/cart/parts/ShippingBar.vue +105 -0
- package/template/blocks/cart/parts/Summary.vue +291 -0
- package/template/blocks/cart/preview.png +0 -0
- package/template/blocks/collection-grid/Block.vue +1832 -0
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +3037 -0
- package/template/blocks/collection-grid/__tests__/groups.spec.ts +731 -0
- package/template/blocks/collection-grid/block.json +187 -0
- package/template/blocks/collection-grid/mock.json +23 -0
- package/template/blocks/collection-grid/parts/groups.ts +861 -0
- package/template/blocks/collection-grid/preview.json +7 -0
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/Block.vue +533 -0
- package/template/blocks/collection-header/__tests__/Block.spec.ts +381 -0
- package/template/blocks/collection-header/block.json +140 -0
- package/template/blocks/collection-header/mock.json +28 -0
- package/template/blocks/collection-header/preview.json +14 -0
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/contact/Block.vue +621 -0
- package/template/blocks/contact/__tests__/Block.spec.ts +347 -0
- package/template/blocks/contact/block.json +174 -0
- package/template/blocks/contact/mock.json +28 -0
- package/template/blocks/contact/preview.json +9 -0
- package/template/blocks/contact/preview.png +0 -0
- package/template/blocks/cta/Block.vue +383 -0
- package/template/blocks/cta/__tests__/Block.spec.ts +309 -0
- package/template/blocks/cta/block.json +86 -0
- package/template/blocks/cta/mock.json +10 -0
- package/template/blocks/cta/preview.json +9 -0
- package/template/blocks/cta/preview.png +0 -0
- package/template/blocks/faq/Block.vue +254 -0
- package/template/blocks/faq/__tests__/Block.spec.ts +312 -0
- package/template/blocks/faq/block.json +113 -0
- package/template/blocks/faq/mock.json +115 -0
- package/template/blocks/faq/preview.png +0 -0
- package/template/blocks/feature-grid/Block.vue +241 -0
- package/template/blocks/feature-grid/__tests__/Block.spec.ts +311 -0
- package/template/blocks/feature-grid/block.json +106 -0
- package/template/blocks/feature-grid/mock.json +29 -0
- package/template/blocks/feature-grid/preview.json +45 -0
- package/template/blocks/feature-grid/preview.png +0 -0
- package/template/blocks/footer/Block.vue +652 -0
- package/template/blocks/footer/__tests__/Block.spec.ts +700 -0
- package/template/blocks/footer/block.json +240 -0
- package/template/blocks/footer/mock.json +161 -0
- package/template/blocks/footer/preview.png +0 -0
- package/template/blocks/gallery/Block.vue +416 -0
- package/template/blocks/gallery/__tests__/Block.spec.ts +289 -0
- package/template/blocks/gallery/block.json +87 -0
- package/template/blocks/gallery/mock.json +16 -0
- package/template/blocks/gallery/preview.json +64 -0
- package/template/blocks/gallery/preview.png +0 -0
- package/template/blocks/hero/Block.vue +378 -0
- package/template/blocks/hero/__tests__/Block.spec.ts +324 -0
- package/template/blocks/hero/block.json +146 -0
- package/template/blocks/hero/mock.json +11 -0
- package/template/blocks/hero/preview.json +55 -0
- package/template/blocks/hero/preview.png +0 -0
- package/template/blocks/image/Block.vue +232 -0
- package/template/blocks/image/__tests__/Block.spec.ts +224 -0
- package/template/blocks/image/block.json +67 -0
- package/template/blocks/image/mock.json +7 -0
- package/template/blocks/image/preview.json +9 -0
- package/template/blocks/image/preview.png +0 -0
- package/template/blocks/logo-cloud/Block.vue +206 -0
- package/template/blocks/logo-cloud/__tests__/Block.spec.ts +210 -0
- package/template/blocks/logo-cloud/block.json +79 -0
- package/template/blocks/logo-cloud/mock.json +15 -0
- package/template/blocks/logo-cloud/preview.json +92 -0
- package/template/blocks/logo-cloud/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +1348 -0
- package/template/blocks/navigation/__tests__/Block.spec.ts +2030 -0
- package/template/blocks/navigation/block.json +167 -0
- package/template/blocks/navigation/mock.json +191 -0
- package/template/blocks/navigation/preview.png +0 -0
- package/template/blocks/navigation/useMegaMenuKeys.ts +276 -0
- package/template/blocks/newsletter/Block.vue +399 -0
- package/template/blocks/newsletter/__tests__/Block.spec.ts +365 -0
- package/template/blocks/newsletter/block.json +105 -0
- package/template/blocks/newsletter/mock.json +31 -0
- package/template/blocks/newsletter/preview.png +0 -0
- package/template/blocks/order-status/Block.vue +754 -0
- package/template/blocks/order-status/__tests__/Block.spec.ts +515 -0
- package/template/blocks/order-status/block.json +138 -0
- package/template/blocks/order-status/mock.json +19 -0
- package/template/blocks/order-status/preview.png +0 -0
- package/template/blocks/pricing-table/Block.vue +297 -0
- package/template/blocks/pricing-table/__tests__/Block.spec.ts +357 -0
- package/template/blocks/pricing-table/block.json +155 -0
- package/template/blocks/pricing-table/mock.json +47 -0
- package/template/blocks/pricing-table/preview.png +0 -0
- package/template/blocks/product-carousel/Block.vue +459 -0
- package/template/blocks/product-carousel/__tests__/Block.spec.ts +957 -0
- package/template/blocks/product-carousel/block.json +71 -0
- package/template/blocks/product-carousel/mock.json +9 -0
- package/template/blocks/product-carousel/preview.json +7 -0
- package/template/blocks/product-carousel/preview.png +0 -0
- package/template/blocks/product-detail/Block.vue +886 -0
- package/template/blocks/product-detail/__tests__/Block.spec.ts +1492 -0
- package/template/blocks/product-detail/__tests__/stock.spec.ts +119 -0
- package/template/blocks/product-detail/block.json +155 -0
- package/template/blocks/product-detail/mock.json +113 -0
- package/template/blocks/product-detail/parts/Gallery.vue +181 -0
- package/template/blocks/product-detail/parts/StickyBuyBar.vue +99 -0
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/product-detail/stock.ts +150 -0
- package/template/blocks/quote/Block.vue +206 -0
- package/template/blocks/quote/__tests__/Block.spec.ts +265 -0
- package/template/blocks/quote/block.json +76 -0
- package/template/blocks/quote/mock.json +9 -0
- package/template/blocks/quote/preview.json +16 -0
- package/template/blocks/quote/preview.png +0 -0
- package/template/blocks/rich-text/Block.vue +143 -0
- package/template/blocks/rich-text/__tests__/Block.spec.ts +191 -0
- package/template/blocks/rich-text/block.json +57 -0
- package/template/blocks/rich-text/mock.json +87 -0
- package/template/blocks/rich-text/preview.png +0 -0
- package/template/blocks/search/Block.vue +589 -0
- package/template/blocks/search/PopularChips.vue +40 -0
- package/template/blocks/search/TypeSection.vue +148 -0
- package/template/blocks/search/__tests__/Block.spec.ts +718 -0
- package/template/blocks/search/__tests__/results.spec.ts +166 -0
- package/template/blocks/search/block.json +102 -0
- package/template/blocks/search/mock.json +18 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/search/results.ts +85 -0
- package/template/blocks/split-content/Block.vue +195 -0
- package/template/blocks/split-content/__tests__/Block.spec.ts +225 -0
- package/template/blocks/split-content/block.json +70 -0
- package/template/blocks/split-content/mock.json +45 -0
- package/template/blocks/split-content/preview.json +58 -0
- package/template/blocks/split-content/preview.png +0 -0
- package/template/blocks/stats/Block.vue +159 -0
- package/template/blocks/stats/__tests__/Block.spec.ts +194 -0
- package/template/blocks/stats/block.json +73 -0
- package/template/blocks/stats/mock.json +12 -0
- package/template/blocks/stats/preview.png +0 -0
- package/template/blocks/tabs/Block.vue +278 -0
- package/template/blocks/tabs/__tests__/Block.spec.ts +303 -0
- package/template/blocks/tabs/block.json +97 -0
- package/template/blocks/tabs/mock.json +129 -0
- package/template/blocks/tabs/preview.json +153 -0
- package/template/blocks/tabs/preview.png +0 -0
- package/template/blocks/team/Block.vue +288 -0
- package/template/blocks/team/__tests__/Block.spec.ts +221 -0
- package/template/blocks/team/block.json +125 -0
- package/template/blocks/team/mock.json +39 -0
- package/template/blocks/team/preview.json +62 -0
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/testimonials/Block.vue +408 -0
- package/template/blocks/testimonials/__tests__/Block.spec.ts +319 -0
- package/template/blocks/testimonials/block.json +121 -0
- package/template/blocks/testimonials/mock.json +46 -0
- package/template/blocks/testimonials/preview.json +68 -0
- package/template/blocks/testimonials/preview.png +0 -0
- package/template/blocks/timeline/Block.vue +274 -0
- package/template/blocks/timeline/__tests__/Block.spec.ts +310 -0
- package/template/blocks/timeline/block.json +98 -0
- package/template/blocks/timeline/mock.json +27 -0
- package/template/blocks/timeline/preview.png +0 -0
- package/template/blocks/trust-strip/Block.vue +330 -0
- package/template/blocks/trust-strip/__tests__/Block.spec.ts +290 -0
- package/template/blocks/trust-strip/block.json +117 -0
- package/template/blocks/trust-strip/mock.json +37 -0
- package/template/blocks/trust-strip/preview.png +0 -0
- package/template/blocks/video-embed/Block.vue +354 -0
- package/template/blocks/video-embed/__tests__/Block.spec.ts +219 -0
- package/template/blocks/video-embed/__tests__/embed.spec.ts +76 -0
- package/template/blocks/video-embed/block.json +94 -0
- package/template/blocks/video-embed/embed.ts +84 -0
- package/template/blocks/video-embed/mock.json +13 -0
- package/template/blocks/video-embed/preview.json +9 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/blocks/wishlist/Block.vue +367 -0
- package/template/blocks/wishlist/__tests__/Block.spec.ts +508 -0
- package/template/blocks/wishlist/block.json +42 -0
- package/template/blocks/wishlist/mock.json +9 -0
- package/template/blocks/wishlist/preview.png +0 -0
- package/template/i18n/en-US.json +602 -0
- package/template/i18n/is-IS.json +602 -0
- package/template/nuxt.config.ts +156 -0
- package/template/package.json +56 -0
- package/template/pages/article.page.json +731 -0
- package/template/pages/cart.page.json +85 -0
- package/template/pages/category.page.json +133 -0
- package/template/pages/collection.page.json +194 -0
- package/template/pages/home.page.json +353 -0
- package/template/pages/product.page.json +323 -0
- package/template/pages/products.page.json +144 -0
- package/template/pages/search.page.json +83 -0
- package/template/pages/wishlist.page.json +88 -0
- package/template/public/apple-touch-icon.png +0 -0
- package/template/public/demo/article-cover.svg +1 -0
- package/template/public/demo/article-figure.svg +1 -0
- package/template/public/demo/avatar-1.svg +3 -0
- package/template/public/demo/avatar-2.svg +3 -0
- package/template/public/demo/avatar-3.svg +3 -0
- package/template/public/demo/avatar-4.svg +3 -0
- package/template/public/demo/avatar-5.svg +3 -0
- package/template/public/demo/avatar-6.svg +3 -0
- package/template/public/demo/avatar-7.svg +3 -0
- package/template/public/demo/avatar-8.svg +3 -0
- package/template/public/demo/collection-1.svg +1 -0
- package/template/public/demo/collection-2.svg +1 -0
- package/template/public/demo/cta-split.svg +1 -0
- package/template/public/demo/feature-1.svg +1 -0
- package/template/public/demo/feature-2.svg +1 -0
- package/template/public/demo/feature-3.svg +1 -0
- package/template/public/demo/feature-4.svg +1 -0
- package/template/public/demo/gallery-1.svg +1 -0
- package/template/public/demo/gallery-2.svg +1 -0
- package/template/public/demo/gallery-3.svg +1 -0
- package/template/public/demo/gallery-4.svg +1 -0
- package/template/public/demo/gallery-5.svg +1 -0
- package/template/public/demo/gallery-6.svg +1 -0
- package/template/public/demo/gallery-7.svg +1 -0
- package/template/public/demo/gallery-8.svg +1 -0
- package/template/public/demo/hero-slide-1.svg +1 -0
- package/template/public/demo/hero-slide-2.svg +1 -0
- package/template/public/demo/hero-slide-3.svg +1 -0
- package/template/public/demo/hero-slide-4.svg +1 -0
- package/template/public/demo/hero-wide.svg +1 -0
- package/template/public/demo/hero.svg +1 -0
- package/template/public/demo/logo-1.svg +4 -0
- package/template/public/demo/logo-2.svg +4 -0
- package/template/public/demo/logo-3.svg +4 -0
- package/template/public/demo/logo-4.svg +4 -0
- package/template/public/demo/logo-5.svg +4 -0
- package/template/public/demo/logo-6.svg +4 -0
- package/template/public/demo/logo-7.svg +4 -0
- package/template/public/demo/logo-8.svg +4 -0
- package/template/public/demo/logo.svg +3 -0
- package/template/public/demo/map.svg +1 -0
- package/template/public/demo/poster.svg +1 -0
- package/template/public/demo/product-1.svg +4 -0
- package/template/public/demo/product-10.svg +4 -0
- package/template/public/demo/product-11.svg +4 -0
- package/template/public/demo/product-12.svg +4 -0
- package/template/public/demo/product-2.svg +4 -0
- package/template/public/demo/product-3.svg +4 -0
- package/template/public/demo/product-4.svg +4 -0
- package/template/public/demo/product-5.svg +4 -0
- package/template/public/demo/product-6.svg +4 -0
- package/template/public/demo/product-7.svg +4 -0
- package/template/public/demo/product-8.svg +4 -0
- package/template/public/demo/product-9.svg +4 -0
- package/template/public/demo/product-square-1.svg +4 -0
- package/template/public/demo/product-square-2.svg +4 -0
- package/template/public/demo/product-square-3.svg +4 -0
- package/template/public/demo/product-square-4.svg +4 -0
- package/template/public/demo/product-square-5.svg +4 -0
- package/template/public/demo/product-square-6.svg +4 -0
- package/template/public/demo/quote-portrait.svg +4 -0
- package/template/public/demo/split-1.svg +1 -0
- package/template/public/demo/split-2.svg +1 -0
- package/template/public/demo/split-3.svg +1 -0
- package/template/public/demo/split-4.svg +1 -0
- package/template/public/demo/team-1.svg +4 -0
- package/template/public/demo/team-2.svg +4 -0
- package/template/public/demo/team-3.svg +4 -0
- package/template/public/demo/team-4.svg +4 -0
- package/template/public/favicon.ico +0 -0
- package/template/scripts/demo-images.mjs +393 -0
- package/template/scripts/generate-stories.mjs +156 -0
- package/template/scripts/previewHash.mjs +125 -0
- package/template/scripts/previews.mjs +149 -0
- package/template/stories/generated/announcement-bar.stories.ts +44 -0
- package/template/stories/generated/article-list.stories.ts +87 -0
- package/template/stories/generated/article.stories.ts +27 -0
- package/template/stories/generated/breadcrumbs.stories.ts +39 -0
- package/template/stories/generated/cart.stories.ts +38 -0
- package/template/stories/generated/collection-grid.stories.ts +117 -0
- package/template/stories/generated/collection-header.stories.ts +51 -0
- package/template/stories/generated/contact.stories.ts +45 -0
- package/template/stories/generated/cta.stories.ts +51 -0
- package/template/stories/generated/faq.stories.ts +56 -0
- package/template/stories/generated/feature-grid.stories.ts +69 -0
- package/template/stories/generated/footer.stories.ts +50 -0
- package/template/stories/generated/gallery.stories.ts +81 -0
- package/template/stories/generated/hero.stories.ts +75 -0
- package/template/stories/generated/image.stories.ts +99 -0
- package/template/stories/generated/logo-cloud.stories.ts +57 -0
- package/template/stories/generated/navigation.stories.ts +62 -0
- package/template/stories/generated/newsletter.stories.ts +68 -0
- package/template/stories/generated/order-status.stories.ts +32 -0
- package/template/stories/generated/pricing-table.stories.ts +44 -0
- package/template/stories/generated/product-carousel.stories.ts +75 -0
- package/template/stories/generated/product-detail.stories.ts +62 -0
- package/template/stories/generated/quote.stories.ts +69 -0
- package/template/stories/generated/rich-text.stories.ts +50 -0
- package/template/stories/generated/search.stories.ts +56 -0
- package/template/stories/generated/split-content.stories.ts +39 -0
- package/template/stories/generated/stats.stories.ts +68 -0
- package/template/stories/generated/tabs.stories.ts +45 -0
- package/template/stories/generated/team.stories.ts +45 -0
- package/template/stories/generated/testimonials.stories.ts +69 -0
- package/template/stories/generated/timeline.stories.ts +80 -0
- package/template/stories/generated/trust-strip.stories.ts +62 -0
- package/template/stories/generated/video-embed.stories.ts +63 -0
- package/template/stories/generated/wishlist.stories.ts +26 -0
- package/template/stories/pages/article.stories.ts +51 -0
- package/template/stories/pages/cart.stories.ts +56 -0
- package/template/stories/pages/category.stories.ts +56 -0
- package/template/stories/pages/collection.stories.ts +51 -0
- package/template/stories/pages/home.stories.ts +51 -0
- package/template/stories/pages/product.stories.ts +47 -0
- package/template/stories/pages/products.stories.ts +58 -0
- package/template/stories/pages/search.stories.ts +54 -0
- package/template/stories/pages/wishlist.stories.ts +53 -0
- package/template/stories/support/pageBlocks.ts +115 -0
- package/template/test/blocksEmptyData.spec.ts +52 -0
- package/template/test/carouselKeyboard.spec.ts +272 -0
- package/template/test/carouselRing.browser.spec.ts +193 -0
- package/template/test/carouselSlideWidth.browser.spec.ts +102 -0
- package/template/test/cartDrawer.spec.ts +295 -0
- package/template/test/cartToast.spec.ts +86 -0
- package/template/test/countPill.browser.spec.ts +196 -0
- package/template/test/demoImages.spec.ts +140 -0
- package/template/test/deps.spec.ts +102 -0
- package/template/test/eldraIcon.spec.ts +58 -0
- package/template/test/framing.spec.ts +76 -0
- package/template/test/i18n.spec.ts +200 -0
- package/template/test/iconComponent.spec.ts +91 -0
- package/template/test/inlineEditable.spec.ts +335 -0
- package/template/test/localePrefix.spec.ts +342 -0
- package/template/test/mainCss.spec.ts +107 -0
- package/template/test/mockGatewayContract.spec.ts +122 -0
- package/template/test/mocks/blocks.ts +20 -0
- package/template/test/mocks/breakpoints.ts +7 -0
- package/template/test/mocks/manifest.ts +11 -0
- package/template/test/moneyFormatting.spec.ts +85 -0
- package/template/test/pageTitle.spec.ts +49 -0
- package/template/test/pages/article.spec.ts +231 -0
- package/template/test/pages/category.spec.ts +185 -0
- package/template/test/pages/collection.spec.ts +396 -0
- package/template/test/pages/home.spec.ts +295 -0
- package/template/test/pages/hydration.spec.ts +557 -0
- package/template/test/pages/product.spec.ts +396 -0
- package/template/test/pages/seededPages.spec.ts +190 -0
- package/template/test/pages/ssr.spec.ts +387 -0
- package/template/test/prerenderCommerce.spec.ts +134 -0
- package/template/test/prerenderFailure.spec.ts +130 -0
- package/template/test/prerenderRefresh.browser.spec.ts +1431 -0
- package/template/test/previewsFresh.spec.ts +56 -0
- package/template/test/richText.spec.ts +164 -0
- package/template/test/richTextTypography.spec.ts +182 -0
- package/template/test/setup.ts +21 -0
- package/template/test/slugPage.spec.ts +244 -0
- package/template/test/slugPageTemplate.spec.ts +194 -0
- package/template/test/starter.spec.ts +1416 -0
- package/template/test/storefront/cart.spec.ts +404 -0
- package/template/test/storefront/categories.spec.ts +235 -0
- package/template/test/storefront/collectionSelector.spec.ts +74 -0
- package/template/test/storefront/demo.spec.ts +555 -0
- package/template/test/storefront/facets.spec.ts +425 -0
- package/template/test/storefront/feedback.spec.ts +97 -0
- package/template/test/storefront/gateway.spec.ts +2673 -0
- package/template/test/storefront/gatewayCart.spec.ts +289 -0
- package/template/test/storefront/gatewayPrerender.spec.ts +1037 -0
- package/template/test/storefront/history.spec.ts +341 -0
- package/template/test/storefront/money.spec.ts +170 -0
- package/template/test/storefront/toProductCard.spec.ts +138 -0
- package/template/test/storefront/volatile.spec.ts +284 -0
- package/template/test/support/axe.ts +14 -0
- package/template/test/support/dialog.ts +51 -0
- package/template/test/support/hydrate.ts +118 -0
- package/template/test/support/i18nText.ts +11 -0
- package/template/test/support/mockGateway.ts +1017 -0
- package/template/test/support/mountBlock.ts +194 -0
- package/template/test/support/mountPage.spec.ts +72 -0
- package/template/test/support/mountPage.ts +254 -0
- package/template/test/support/mountProbe.client.ts +69 -0
- package/template/test/support/renderSsr.ts +97 -0
- package/template/test/support/staticServer.ts +96 -0
- package/template/test/themeIcons.spec.ts +140 -0
- package/template/test/toastAnnouncement.spec.ts +133 -0
- package/template/test/tokens.spec.ts +102 -0
- package/template/test/uiMessagesPlugin.spec.ts +104 -0
- package/template/test/useBlockData.spec.ts +49 -0
- package/template/test/useEditing.spec.ts +54 -0
- package/template/test/useEldraIcon.spec.ts +126 -0
- package/template/test/useUiId.spec.ts +40 -0
- package/template/tokens.json +149 -0
- package/template/tsconfig.json +3 -0
- package/template/tsconfig.storybook.json +17 -0
- package/template/vitest-axe.d.ts +13 -0
- package/template/vitest.config.ts +44 -0
|
@@ -0,0 +1,3037 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils';
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { computed, nextTick, ref, watch, type Ref } from 'vue';
|
|
5
|
+
import { ELDRA_KEY, createEldraPreviewState } from '@eldrajs/theme-vue';
|
|
6
|
+
import { LOCALE_KEY, MESSAGES_KEY, ProductCard, type UiMessages } from '@eldrajs/ui';
|
|
7
|
+
import { axe } from '../../../test/support/axe';
|
|
8
|
+
import { mountOptions } from '../../../test/support/mountBlock';
|
|
9
|
+
import { hydrateBlock, hydrationWarnings, renderBlockHtml } from '../../../test/support/hydrate';
|
|
10
|
+
import Block from '../Block.vue';
|
|
11
|
+
import mock from '../mock.json';
|
|
12
|
+
import { createDemoStorefront, demoCollectionId, PRODUCTS } from '../../../app/storefront/demo';
|
|
13
|
+
import { createGatewayStorefront } from '../../../app/storefront/gateway';
|
|
14
|
+
import EldraRouterLink from '../../../app/components/EldraRouterLink.vue';
|
|
15
|
+
import { STOREFRONT_KEY } from '../../../app/storefront/types';
|
|
16
|
+
import type {
|
|
17
|
+
CatalogFacets,
|
|
18
|
+
StorefrontCatalog,
|
|
19
|
+
StorefrontCollectionProducts,
|
|
20
|
+
StorefrontCollectionSelector,
|
|
21
|
+
StorefrontProductListItem,
|
|
22
|
+
StorefrontResult,
|
|
23
|
+
StorefrontSource,
|
|
24
|
+
VolatileKey,
|
|
25
|
+
} from '../../../app/storefront/types';
|
|
26
|
+
import type { EldraClient } from '@eldrajs/sdk';
|
|
27
|
+
import enUS from '../../../i18n/en-US.json';
|
|
28
|
+
import isIS from '../../../i18n/is-IS.json';
|
|
29
|
+
import { enUS as uiEnUS } from '@eldrajs/ui';
|
|
30
|
+
import { isIS as uiIsIS } from '@eldrajs/ui/messages/is-IS';
|
|
31
|
+
import { createI18n } from 'vue-i18n';
|
|
32
|
+
|
|
33
|
+
/** Only the four required fields: the freshly-inserted seed, exercising every fallback default
|
|
34
|
+
* (no collection of its own — the route supplies one — no filters, no sort, no empty copy). */
|
|
35
|
+
const bare = {
|
|
36
|
+
variant: 'sidebar',
|
|
37
|
+
columns: '3',
|
|
38
|
+
pageSize: '24',
|
|
39
|
+
paginationStyle: 'load-more',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* How a store describes the scope the grid is showing (`CatalogFacets`): the price span the slider
|
|
44
|
+
* works across, the category and collection terms, the availability counts and every variant
|
|
45
|
+
* option value with its own count. `discontinued` counts zero on purpose — the panel offers it
|
|
46
|
+
* disabled rather than hiding it, which is what keeps controls from moving under the pointer.
|
|
47
|
+
*/
|
|
48
|
+
const FACETS: CatalogFacets = {
|
|
49
|
+
price: { min: 24, max: 180 },
|
|
50
|
+
categories: [
|
|
51
|
+
{ id: 'cat-knitwear', slug: 'knitwear', title: 'Knitwear', count: 18 },
|
|
52
|
+
{ id: 'cat-ceramics', slug: 'ceramics', title: 'Ceramics', count: 14 },
|
|
53
|
+
{ id: 'cat-kitchen', slug: 'kitchen', title: 'Kitchen', count: 16 },
|
|
54
|
+
{ id: 'cat-discontinued', slug: 'discontinued', title: 'Discontinued', count: 0 },
|
|
55
|
+
],
|
|
56
|
+
collections: [
|
|
57
|
+
{ id: 'col-the-winter-edit', slug: 'the-winter-edit', title: 'The winter edit', count: 48 },
|
|
58
|
+
{ id: 'col-best-sellers', slug: 'best-sellers', title: 'Best sellers', count: 24 },
|
|
59
|
+
],
|
|
60
|
+
availability: { in_stock: 41, out_of_stock: 7 },
|
|
61
|
+
options: [
|
|
62
|
+
{
|
|
63
|
+
key: 'size',
|
|
64
|
+
name: 'size',
|
|
65
|
+
kind: 'none',
|
|
66
|
+
values: [
|
|
67
|
+
{ value: 'xs', label: 'XS', count: 6 },
|
|
68
|
+
{ value: 's', label: 'S', count: 10 },
|
|
69
|
+
{ value: 'm', label: 'M', count: 14 },
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
key: 'colour',
|
|
74
|
+
name: 'colour',
|
|
75
|
+
kind: 'color',
|
|
76
|
+
values: [
|
|
77
|
+
{ value: 'oat', label: 'Oat', count: 9, swatch: '#d8cbb0' },
|
|
78
|
+
{ value: 'charcoal', label: 'Charcoal', count: 8, swatch: '#3a3a3a' },
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** The price facet's title — one string now, used both visibly and as the fieldset's hidden
|
|
85
|
+
* `<legend>` (`FilterFacet.label`). */
|
|
86
|
+
const PRICE_LEGEND = enUS.grid.price;
|
|
87
|
+
|
|
88
|
+
interface Stub {
|
|
89
|
+
source: StorefrontSource;
|
|
90
|
+
/** Flipped by a test to hold the block in its first-load state — nothing on screen yet. */
|
|
91
|
+
pending: Ref<boolean>;
|
|
92
|
+
/** Flipped by a test to hold the block in its "while filtering" state: a read in flight over
|
|
93
|
+
* results the visitor can still see. */
|
|
94
|
+
loading: Ref<boolean>;
|
|
95
|
+
/** Flipped by a test to put the grid's cards in the volatile-refresh state. */
|
|
96
|
+
revalidating: Ref<ReadonlySet<VolatileKey>>;
|
|
97
|
+
/** Set by a test to fail the read *after* it has already answered once. */
|
|
98
|
+
error: Ref<string | null>;
|
|
99
|
+
/** Every `collectionProducts` request, newest last — the grid's and the drawer's pending count. */
|
|
100
|
+
requests: Array<{ pageSize: number; sort?: string; filters?: Record<string, string[]> }>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* A storefront whose catalogue actually answers the request: the twelve Northwind products when
|
|
105
|
+
* nothing is filtered, and nothing at all as soon as any filter is applied. That is what makes
|
|
106
|
+
* "the count reads 12 products, then 0 products", "the empty state names the active filters" and
|
|
107
|
+
* "the drawer changes nothing until Show N products" real assertions rather than restatements of a
|
|
108
|
+
* fixture — the demo source (`app/storefront/demo.ts`) ignores `filters` by design.
|
|
109
|
+
*/
|
|
110
|
+
function createStub(
|
|
111
|
+
items: StorefrontProductListItem[] = PRODUCTS,
|
|
112
|
+
options: {
|
|
113
|
+
/** How many items a filtered request answers with. `0` (the default) drives the empty state. */
|
|
114
|
+
filteredCount?: number;
|
|
115
|
+
/** The facets a *filtered* request answers with — most backends compute them over the result
|
|
116
|
+
* set, so a value the shopper has ticked can stop being listed. */
|
|
117
|
+
filteredFacets?: CatalogFacets;
|
|
118
|
+
/** How the store describes its scope at all, for the families it cannot count. */
|
|
119
|
+
facets?: CatalogFacets;
|
|
120
|
+
/** The `filters` keys this scope cannot narrow by, as a storefront declares them. */
|
|
121
|
+
unfilterable?: readonly string[];
|
|
122
|
+
/** The block's own sort ids this scope cannot honour, as a storefront declares them. */
|
|
123
|
+
unsortable?: readonly string[];
|
|
124
|
+
} = {}
|
|
125
|
+
): Stub {
|
|
126
|
+
const base = createDemoStorefront();
|
|
127
|
+
const pending = ref(false);
|
|
128
|
+
const loading = ref(false);
|
|
129
|
+
const revalidating = ref<ReadonlySet<VolatileKey>>(new Set());
|
|
130
|
+
const error = ref<string | null>(null);
|
|
131
|
+
const requests: Stub['requests'] = [];
|
|
132
|
+
const filteredCount = options.filteredCount ?? 0;
|
|
133
|
+
const catalog: StorefrontCatalog = {
|
|
134
|
+
...base.catalog,
|
|
135
|
+
collectionProducts(collection, opts) {
|
|
136
|
+
watch(opts, (value) => requests.push({ ...value }), { deep: true });
|
|
137
|
+
const data = computed(() => {
|
|
138
|
+
if (collection.value === null) return null;
|
|
139
|
+
const filtered = opts.value.filters !== undefined;
|
|
140
|
+
return {
|
|
141
|
+
items: filtered ? items.slice(0, filteredCount) : items.slice(0, opts.value.pageSize),
|
|
142
|
+
total: filtered ? filteredCount : items.length,
|
|
143
|
+
facets: filtered
|
|
144
|
+
? (options.filteredFacets ?? options.facets ?? FACETS)
|
|
145
|
+
: (options.facets ?? FACETS),
|
|
146
|
+
...(options.unfilterable === undefined ? {} : { unfilterable: options.unfilterable }),
|
|
147
|
+
...(options.unsortable === undefined ? {} : { unsortable: options.unsortable }),
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
return {
|
|
151
|
+
data,
|
|
152
|
+
pending,
|
|
153
|
+
loading,
|
|
154
|
+
revalidating,
|
|
155
|
+
error,
|
|
156
|
+
refresh: async () => {},
|
|
157
|
+
} as unknown as StorefrontResult<StorefrontCollectionProducts>;
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
return { source: { ...base, catalog }, pending, loading, revalidating, error, requests };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** A storefront whose collection read is still on its very first load: `pending`, and no data at
|
|
164
|
+
* all. The one state the grid is allowed to draw skeletons in. */
|
|
165
|
+
function firstLoadSource(): StorefrontSource {
|
|
166
|
+
const base = createDemoStorefront();
|
|
167
|
+
return {
|
|
168
|
+
...base,
|
|
169
|
+
catalog: {
|
|
170
|
+
...base.catalog,
|
|
171
|
+
collectionProducts: () =>
|
|
172
|
+
({
|
|
173
|
+
data: ref(null),
|
|
174
|
+
pending: ref(true),
|
|
175
|
+
loading: ref(true),
|
|
176
|
+
revalidating: ref(new Set()),
|
|
177
|
+
error: ref(null),
|
|
178
|
+
refresh: async () => {},
|
|
179
|
+
}) as unknown as ReturnType<StorefrontCatalog['collectionProducts']>,
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** The Eldra context with edit-mode preview on, so `useEditing()` reads true — the same shape
|
|
185
|
+
* `blocks/navigation`'s spec builds. */
|
|
186
|
+
function editingContext() {
|
|
187
|
+
return {
|
|
188
|
+
client: {},
|
|
189
|
+
designTokens: { colors: {} },
|
|
190
|
+
preview: Object.assign(createEldraPreviewState(), { active: true, mode: 'edit' as const }),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const wrappers: VueWrapper[] = [];
|
|
195
|
+
afterEach(() => {
|
|
196
|
+
while (wrappers.length > 0) wrappers.pop()!.unmount();
|
|
197
|
+
});
|
|
198
|
+
/** Idempotent on a test that never faked timers in the first place — the one global cleanup for
|
|
199
|
+
* every test below that opts into `useFilterTimers()` to get past the sidebar's own
|
|
200
|
+
* `FILTER_DEBOUNCE_MS` (Block.vue), so a failure mid-test never leaks fake timers into the next
|
|
201
|
+
* one. */
|
|
202
|
+
afterEach(() => {
|
|
203
|
+
vi.useRealTimers();
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The sidebar's own filter-request debounce (`FILTER_DEBOUNCE_MS` in Block.vue — 350ms, repeated
|
|
208
|
+
* here rather than imported, since a `<script setup>` constant is not an export). A test that
|
|
209
|
+
* ticks a checkbox or drags a price bound and then reads the *request* this drives (`countLine`,
|
|
210
|
+
* `cards`, `stub.requests`, a chip's facet-matched label) calls `useFilterTimers()` before the
|
|
211
|
+
* interaction and `settleFilterDebounce()` after it; a test that only reads the *visible* state
|
|
212
|
+
* the same interaction writes at once (the checkbox itself, the chip's bare existence, the URL
|
|
213
|
+
* write) needs neither.
|
|
214
|
+
*/
|
|
215
|
+
const FILTER_DEBOUNCE_MS = 350;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* **Only `setTimeout`/`clearTimeout` are faked, never the clock.** Vitest's default
|
|
219
|
+
* `useFakeTimers()` takes `Date` and `performance` with it, so `advanceTimersByTime(350)` leaves
|
|
220
|
+
* the faked clock 350ms *ahead* of real time — and Vue's own event invoker stamps every listener
|
|
221
|
+
* with the time it was attached and silently drops an event whose timestamp is older than that
|
|
222
|
+
* (`_vts <= invoker.attached`, the guard that stops a handler bound mid-propagation from firing on
|
|
223
|
+
* the event that bound it). Any element the block renders *after* an advance therefore carries a
|
|
224
|
+
* future `attached`, and the next `trigger('click')` on it — dispatched once the clock is real
|
|
225
|
+
* again — does nothing at all: no error, no handler, no state change. That cost a long hunt
|
|
226
|
+
* through the empty state's own Clear-filters button, which looked for all the world like a
|
|
227
|
+
* product bug. The debounce only needs the two timer functions, so fake only those and the clock
|
|
228
|
+
* stays honest.
|
|
229
|
+
*/
|
|
230
|
+
function useFilterTimers(): void {
|
|
231
|
+
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Runs the armed window out and hands the test real timers back — not only in the global
|
|
236
|
+
* `afterEach` above: `axe()` schedules its own work with real timers in mind, and a run started
|
|
237
|
+
* while fake ones were still active left every *later* test's own `axe()` call failing with "Axe
|
|
238
|
+
* is already running" — a stuck module-level flag inside the library, not a timer leak this file's
|
|
239
|
+
* own cleanup could reach. Settle, then call `axe()` (or anything else timer-sensitive) only after.
|
|
240
|
+
*/
|
|
241
|
+
async function settleFilterDebounce(wrapper: VueWrapper): Promise<void> {
|
|
242
|
+
await wrapper.vm.$nextTick();
|
|
243
|
+
vi.advanceTimersByTime(FILTER_DEBOUNCE_MS);
|
|
244
|
+
await wrapper.vm.$nextTick();
|
|
245
|
+
vi.useRealTimers();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function mountGrid(
|
|
249
|
+
data: Record<string, unknown>,
|
|
250
|
+
options: { source?: StorefrontSource; attachTo?: Element; editing?: boolean } = {}
|
|
251
|
+
) {
|
|
252
|
+
const base = mountOptions({ entry: { id: 'e1', data } });
|
|
253
|
+
const wrapper = mount(Block, {
|
|
254
|
+
...base,
|
|
255
|
+
global: {
|
|
256
|
+
...base.global,
|
|
257
|
+
provide: {
|
|
258
|
+
...base.global.provide,
|
|
259
|
+
...(options.source ? { [STOREFRONT_KEY]: options.source } : {}),
|
|
260
|
+
...(options.editing ? { [ELDRA_KEY]: editingContext() } : {}),
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
...(options.attachTo ? { attachTo: options.attachTo } : {}),
|
|
264
|
+
});
|
|
265
|
+
wrappers.push(wrapper);
|
|
266
|
+
return wrapper;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** The result count — the block's polite status line. */
|
|
270
|
+
const countLine = (wrapper: VueWrapper) => wrapper.get('p[role="status"][tabindex="-1"]');
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* How many filter groups `mock.json` actually renders: Category, Size, Colour, Price, Availability.
|
|
274
|
+
* Five, from **four** rows — `options` is one row standing for every variant option the store has, so
|
|
275
|
+
* the count is not `mock.filters.length` and the spec says so rather than quietly agreeing.
|
|
276
|
+
*/
|
|
277
|
+
const SEEDED_GROUPS = 5;
|
|
278
|
+
/** The grid's single visually hidden live region for the volatile refresh. The count line above
|
|
279
|
+
* and `LoadMore`'s own "Showing N of M" are the block's other `role="status"` elements, and both
|
|
280
|
+
* are visible — this is the only hidden one. */
|
|
281
|
+
const liveRegion = (wrapper: VueWrapper) => wrapper.get('p.sr-only[role="status"]');
|
|
282
|
+
/** The grid itself: the list of product cards (never the skeleton list, which is aria-hidden). */
|
|
283
|
+
const cards = (wrapper: VueWrapper) =>
|
|
284
|
+
wrapper.findAll('ul[aria-labelledby]:not([aria-hidden]) > li');
|
|
285
|
+
const gridList = (wrapper: VueWrapper) => wrapper.get('ul[aria-labelledby]:not([aria-hidden])');
|
|
286
|
+
/** The sort/columns `Select` triggers, in DOM order — the `<button role="combobox">`, never the
|
|
287
|
+
* hidden native fallback. */
|
|
288
|
+
const comboboxes = (wrapper: VueWrapper) =>
|
|
289
|
+
wrapper.findAll('[role="combobox"]').filter((c) => c.element.tagName === 'BUTTON');
|
|
290
|
+
const filterButton = (wrapper: VueWrapper) => wrapper.get('button[aria-haspopup="dialog"]');
|
|
291
|
+
/** The filter-group disclosure triggers — a `<button>` inside an `h3`, which is what separates them
|
|
292
|
+
* from the block's other `aria-expanded` controls (the Filter button and the Selects). */
|
|
293
|
+
const groupTriggers = (wrapper: VueWrapper) => wrapper.findAll('h3 > button[aria-expanded]');
|
|
294
|
+
/** A group's panel, addressed the way assistive technology does: through `aria-controls`. */
|
|
295
|
+
function panelFor(wrapper: VueWrapper, legend: string) {
|
|
296
|
+
const trigger = groupTriggers(wrapper).find(
|
|
297
|
+
(candidate) =>
|
|
298
|
+
wrapper
|
|
299
|
+
.get(`#${candidate.attributes('aria-controls')!}`)
|
|
300
|
+
.get('legend')
|
|
301
|
+
.text() === legend
|
|
302
|
+
)!;
|
|
303
|
+
return { trigger, panel: wrapper.get(`#${trigger.attributes('aria-controls')!}`) };
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
describe('collection-grid block', () => {
|
|
307
|
+
describe('accessibility', () => {
|
|
308
|
+
it('renders the mock.json content, axe-clean', async () => {
|
|
309
|
+
const wrapper = mountGrid(mock);
|
|
310
|
+
await wrapper.vm.$nextTick();
|
|
311
|
+
expect(cards(wrapper).length).toBeGreaterThan(0);
|
|
312
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('renders the bare mock — only the required fields — axe-clean', async () => {
|
|
316
|
+
const wrapper = mountGrid(bare);
|
|
317
|
+
await wrapper.vm.$nextTick();
|
|
318
|
+
// No `filters[]`, so no Filter button, no sidebar and no drawer; the grid takes the width.
|
|
319
|
+
expect(wrapper.find('button[aria-haspopup="dialog"]').exists()).toBe(false);
|
|
320
|
+
expect(wrapper.find('aside').exists()).toBe(false);
|
|
321
|
+
expect(wrapper.find('dialog').exists()).toBe(false);
|
|
322
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it('renders each declared variant, axe-clean', async () => {
|
|
326
|
+
for (const variant of ['sidebar', 'drawer-only']) {
|
|
327
|
+
const wrapper = mountGrid({ ...mock, variant });
|
|
328
|
+
await wrapper.vm.$nextTick();
|
|
329
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('is axe-clean with the filter drawer open', async () => {
|
|
334
|
+
const wrapper = mountGrid(mock, { attachTo: document.body });
|
|
335
|
+
await wrapper.vm.$nextTick();
|
|
336
|
+
await filterButton(wrapper).trigger('click');
|
|
337
|
+
expect(wrapper.get('dialog').attributes('open')).toBe('');
|
|
338
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it('is axe-clean with zero results', async () => {
|
|
342
|
+
useFilterTimers();
|
|
343
|
+
const stub = createStub();
|
|
344
|
+
const wrapper = mountGrid(mock, { source: stub.source });
|
|
345
|
+
await wrapper.vm.$nextTick();
|
|
346
|
+
const { panel } = panelFor(wrapper, enUS.grid.legendCategory);
|
|
347
|
+
await panel.get('input[type="checkbox"]').setValue(true);
|
|
348
|
+
await settleFilterDebounce(wrapper);
|
|
349
|
+
expect(cards(wrapper)).toHaveLength(0);
|
|
350
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it('has no h1, and never renders a bound-collection-less block on the live site', async () => {
|
|
354
|
+
const wrapper = mountGrid(mock);
|
|
355
|
+
await wrapper.vm.$nextTick();
|
|
356
|
+
expect(wrapper.find('h1').exists()).toBe(false);
|
|
357
|
+
|
|
358
|
+
// Route and field both empty: nothing at all outside the editor.
|
|
359
|
+
const source = createDemoStorefront();
|
|
360
|
+
source.route.collectionHandle = null;
|
|
361
|
+
const empty = mountGrid(mock, { source });
|
|
362
|
+
expect(empty.find('section').exists()).toBe(false);
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
describe('structure', () => {
|
|
367
|
+
it('names the section with the collection and puts the grid under a hidden h2 with h3 titles', async () => {
|
|
368
|
+
const wrapper = mountGrid(mock);
|
|
369
|
+
await wrapper.vm.$nextTick();
|
|
370
|
+
|
|
371
|
+
const section = wrapper.get('section');
|
|
372
|
+
expect(section.attributes('aria-label')).toBe('Winter knitwear products');
|
|
373
|
+
|
|
374
|
+
// Not `wrapper.get('h2')`: the sidebar's own hidden "Filters" h2 (added so the filter
|
|
375
|
+
// group triggers below it have a heading to nest under) precedes this one in DOM order.
|
|
376
|
+
const h2 = wrapper
|
|
377
|
+
.findAll('h2')
|
|
378
|
+
.find((candidate) => candidate.text() === enUS.grid.products)!;
|
|
379
|
+
expect(h2.classes()).toContain('sr-only');
|
|
380
|
+
|
|
381
|
+
const titles = wrapper.findAll('h3');
|
|
382
|
+
expect(titles.some((title) => title.text() === 'Merino crew sweater')).toBe(true);
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it('labels the filter sidebar and gives it the sticky header offset', async () => {
|
|
386
|
+
const wrapper = mountGrid(mock);
|
|
387
|
+
await wrapper.vm.$nextTick();
|
|
388
|
+
const aside = wrapper.get('aside');
|
|
389
|
+
expect(aside.attributes('aria-label')).toBe(enUS.grid.filters);
|
|
390
|
+
expect(aside.classes().join(' ')).toContain('var(--eldra-header-height,0px)');
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* `mock.json` ships four rows for five groups: `options` is one row standing for every variant
|
|
395
|
+
* option the store has, which in the demo catalogue is Size and Colour.
|
|
396
|
+
*/
|
|
397
|
+
it('renders one group per filters[] entry, each a fieldset with a hidden legend', async () => {
|
|
398
|
+
const wrapper = mountGrid(mock);
|
|
399
|
+
await wrapper.vm.$nextTick();
|
|
400
|
+
// Sidebar and drawer render the same five groups, so ten triggers in the DOM.
|
|
401
|
+
expect(groupTriggers(wrapper)).toHaveLength(SEEDED_GROUPS * 2);
|
|
402
|
+
for (const legend of [
|
|
403
|
+
enUS.grid.legendCategory,
|
|
404
|
+
enUS.grid.legendSize,
|
|
405
|
+
enUS.grid.legendColour,
|
|
406
|
+
PRICE_LEGEND,
|
|
407
|
+
enUS.grid.legendAvailability,
|
|
408
|
+
]) {
|
|
409
|
+
const { trigger, panel } = panelFor(wrapper, legend);
|
|
410
|
+
expect(trigger.attributes('aria-expanded')).toBe('true');
|
|
411
|
+
expect(panel.element.tagName).toBe('FIELDSET');
|
|
412
|
+
expect(panel.get('legend').classes()).toContain('sr-only');
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* The sidebar's own `FilterPanel` draws its own visible "Filters" `h2` (`show-head`, the
|
|
418
|
+
* default) right before its `h3` group triggers; the drawer's panel draws none
|
|
419
|
+
* (`show-head="false"`), because the `Drawer` itself already supplies one — its own title,
|
|
420
|
+
* "Filter" — immediately before its triggers. Either way, a whole-page axe run's
|
|
421
|
+
* `heading-order` rule sees no skipped level under the page's own `h1`.
|
|
422
|
+
*/
|
|
423
|
+
it('gives the sidebar and the drawer a heading before their filter-group triggers, so headings never skip a level', async () => {
|
|
424
|
+
const wrapper = mountGrid(mock);
|
|
425
|
+
await wrapper.vm.$nextTick();
|
|
426
|
+
|
|
427
|
+
const triggers = groupTriggers(wrapper);
|
|
428
|
+
|
|
429
|
+
const sidebarHeading = wrapper.findAll('h2').find((el) => el.text() === enUS.grid.filters)!;
|
|
430
|
+
expect(
|
|
431
|
+
sidebarHeading.element.compareDocumentPosition(triggers[0]!.element) &
|
|
432
|
+
Node.DOCUMENT_POSITION_FOLLOWING
|
|
433
|
+
).toBeTruthy();
|
|
434
|
+
|
|
435
|
+
const drawerHeading = wrapper.get('dialog').find('h2');
|
|
436
|
+
expect(drawerHeading.text()).toBe(enUS.grid.filter);
|
|
437
|
+
expect(
|
|
438
|
+
drawerHeading.element.compareDocumentPosition(triggers[SEEDED_GROUPS]!.element) &
|
|
439
|
+
Node.DOCUMENT_POSITION_FOLLOWING
|
|
440
|
+
).toBeTruthy();
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Facet counts leave their own family's filter out, so a zero means "another filter rules this
|
|
445
|
+
* out" — and a control that disappears the moment a neighbour is ticked moves every control
|
|
446
|
+
* after it under the shopper's pointer. So it stays, disabled (contract §4).
|
|
447
|
+
*/
|
|
448
|
+
it('offers a filter value the store counts zero of disabled, not hidden', async () => {
|
|
449
|
+
const wrapper = mountGrid(mock, { source: createStub().source });
|
|
450
|
+
await wrapper.vm.$nextTick();
|
|
451
|
+
const { panel } = panelFor(wrapper, enUS.grid.legendCategory);
|
|
452
|
+
const boxes = panel.findAll('input[type="checkbox"]');
|
|
453
|
+
expect(boxes[0]!.attributes('aria-label')).toBe('Knitwear, 18 products');
|
|
454
|
+
expect(boxes.at(-1)!.attributes('aria-label')).toBe(
|
|
455
|
+
'Discontinued, 0 products, none available'
|
|
456
|
+
);
|
|
457
|
+
expect(boxes[0]!.attributes('disabled')).toBeUndefined();
|
|
458
|
+
expect(boxes.at(-1)!.attributes('disabled')).toBeDefined();
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it('drawer-only renders no sidebar at any width', async () => {
|
|
462
|
+
const wrapper = mountGrid({ ...mock, variant: 'drawer-only' });
|
|
463
|
+
await wrapper.vm.$nextTick();
|
|
464
|
+
expect(wrapper.find('aside').exists()).toBe(false);
|
|
465
|
+
expect(wrapper.find('dialog').exists()).toBe(true);
|
|
466
|
+
});
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
describe('the filter controls', () => {
|
|
470
|
+
it('a checked colour carries the ring class and a bold name', async () => {
|
|
471
|
+
const wrapper = mountGrid(mock);
|
|
472
|
+
await wrapper.vm.$nextTick();
|
|
473
|
+
const { panel } = panelFor(wrapper, enUS.grid.legendColour);
|
|
474
|
+
const row = panel.get('label');
|
|
475
|
+
const input = row.get('input[type="checkbox"]');
|
|
476
|
+
const dot = row.get('span');
|
|
477
|
+
const name = row.get('[data-part="rowLabel"]');
|
|
478
|
+
|
|
479
|
+
expect(dot.classes()).toContain('border-transparent');
|
|
480
|
+
expect(name.classes()).not.toContain('font-semibold');
|
|
481
|
+
await input.setValue(true);
|
|
482
|
+
|
|
483
|
+
expect(dot.classes()).toContain('border-text');
|
|
484
|
+
expect(name.classes()).toContain('font-semibold');
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* The demo catalogue's size option carries no size-system `group` (a Core follow-up, not sent
|
|
489
|
+
* by any storefront yet — see `facetTypeFor`), so it renders as a plain `list` facet rather
|
|
490
|
+
* than `SizeFacet`'s tiles; the tile styling itself is `@eldrajs/ui`'s own, covered there.
|
|
491
|
+
*/
|
|
492
|
+
it('renders Size as a plain list facet until the store sends a size-system group', async () => {
|
|
493
|
+
const wrapper = mountGrid(mock);
|
|
494
|
+
await wrapper.vm.$nextTick();
|
|
495
|
+
const { panel } = panelFor(wrapper, enUS.grid.legendSize);
|
|
496
|
+
const box = panel.get('input[type="checkbox"]');
|
|
497
|
+
expect((box.element as HTMLInputElement).checked).toBe(false);
|
|
498
|
+
await box.setValue(true);
|
|
499
|
+
expect((box.element as HTMLInputElement).checked).toBe(true);
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
it('a group with a selection shows a count badge named "1 selected"', async () => {
|
|
503
|
+
const wrapper = mountGrid(mock);
|
|
504
|
+
await wrapper.vm.$nextTick();
|
|
505
|
+
const { trigger, panel } = panelFor(wrapper, enUS.grid.legendCategory);
|
|
506
|
+
expect(trigger.find('[data-part="hiddenSuffix"]').exists()).toBe(false);
|
|
507
|
+
|
|
508
|
+
await panel.get('input[type="checkbox"]').setValue(true);
|
|
509
|
+
|
|
510
|
+
expect(trigger.get('[data-part="hiddenSuffix"]').text()).toBe('1 selected');
|
|
511
|
+
expect(trigger.get('[data-part="label"]').text()).toBe('1');
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
it('the Filter button opens a dialog and counts the active filters', async () => {
|
|
515
|
+
const wrapper = mountGrid(mock);
|
|
516
|
+
await wrapper.vm.$nextTick();
|
|
517
|
+
const button = filterButton(wrapper);
|
|
518
|
+
expect(button.attributes('aria-controls')).toBe(wrapper.get('dialog').attributes('id'));
|
|
519
|
+
expect(button.attributes('aria-expanded')).toBe('false');
|
|
520
|
+
expect(button.find('[data-part="hiddenSuffix"]').exists()).toBe(false);
|
|
521
|
+
|
|
522
|
+
const { panel } = panelFor(wrapper, enUS.grid.legendCategory);
|
|
523
|
+
await panel.get('input[type="checkbox"]').setValue(true);
|
|
524
|
+
|
|
525
|
+
expect(button.get('[data-part="hiddenSuffix"]').text()).toBe('1 active');
|
|
526
|
+
});
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
describe('the result count', () => {
|
|
530
|
+
it('is a polite status that reads "12 products" and "0 products" after a filter change', async () => {
|
|
531
|
+
useFilterTimers();
|
|
532
|
+
const stub = createStub();
|
|
533
|
+
const wrapper = mountGrid(mock, { source: stub.source });
|
|
534
|
+
await wrapper.vm.$nextTick();
|
|
535
|
+
expect(countLine(wrapper).text()).toBe('12 products');
|
|
536
|
+
|
|
537
|
+
const { panel } = panelFor(wrapper, enUS.grid.legendCategory);
|
|
538
|
+
await panel.get('input[type="checkbox"]').setValue(true);
|
|
539
|
+
await settleFilterDebounce(wrapper);
|
|
540
|
+
|
|
541
|
+
expect(countLine(wrapper).text()).toBe('0 products');
|
|
542
|
+
expect(countLine(wrapper).attributes('tabindex')).toBe('-1');
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* The prerender contract (`app/storefront/types.ts`): a grid the visitor can already see never
|
|
547
|
+
* goes back to skeletons. Filtering, sorting and paging all read over results that are on
|
|
548
|
+
* screen, so those results stay on screen — pulsing, never replaced and never covered — and
|
|
549
|
+
* the grid is marked busy while the count says so.
|
|
550
|
+
*/
|
|
551
|
+
it('keeps the cards, pulsing and busy, while a filter loads over results already on screen', async () => {
|
|
552
|
+
const stub = createStub();
|
|
553
|
+
const wrapper = mountGrid(mock, { source: stub.source });
|
|
554
|
+
await wrapper.vm.$nextTick();
|
|
555
|
+
const shown = cards(wrapper).length;
|
|
556
|
+
expect(shown).toBeGreaterThan(0);
|
|
557
|
+
|
|
558
|
+
// `pending` as well as `loading`: the rule is "no data", not "not pending", so a storefront
|
|
559
|
+
// that raised the skeleton flag over results the visitor can see must still not blank them.
|
|
560
|
+
stub.pending.value = true;
|
|
561
|
+
stub.loading.value = true;
|
|
562
|
+
await wrapper.vm.$nextTick();
|
|
563
|
+
|
|
564
|
+
expect(countLine(wrapper).text()).toBe(enUS.grid.updating);
|
|
565
|
+
expect(cards(wrapper)).toHaveLength(shown);
|
|
566
|
+
expect(wrapper.find('ul[aria-hidden="true"]').exists()).toBe(false);
|
|
567
|
+
expect(gridList(wrapper).attributes('aria-busy')).toBe('true');
|
|
568
|
+
// `inert` on the grid, not a `pointer-events` class, is what stops a card being clicked
|
|
569
|
+
// mid-update. jsdom has no native `inert` IDL property (a real browser sets the property and
|
|
570
|
+
// reflects the attribute), so Vue's own patch falls back to writing the attribute here —
|
|
571
|
+
// which is why the binding is `updating || undefined` rather than the bare flag: `false`
|
|
572
|
+
// would be written as the *string* `"false"` on the browser's first paint and omitted
|
|
573
|
+
// entirely by the server render, which is a hydration mismatch over nothing at all.
|
|
574
|
+
expect(gridList(wrapper).attributes('inert')).toBe('true');
|
|
575
|
+
// The pulse is the one visible "this is stale" treatment now — a card's own
|
|
576
|
+
// dimmed-value-and-spinner treatment (`revalidating`) is reserved for the volatile price/stock
|
|
577
|
+
// refresh, a different state this is not, so it stays off here.
|
|
578
|
+
expect(
|
|
579
|
+
wrapper.findAllComponents(ProductCard).every((card) => card.props('revalidating') === false)
|
|
580
|
+
).toBe(true);
|
|
581
|
+
expect(gridList(wrapper).classes()).toContain('animate-eldra-pulse-soft');
|
|
582
|
+
// Nothing is drawn over the cards and nothing is added to the DOM: the treatment is the
|
|
583
|
+
// list's own opacity, so there is no extra element to find and none to hide from assistive
|
|
584
|
+
// technology.
|
|
585
|
+
expect(gridList(wrapper).element.querySelectorAll(':scope > li')).toHaveLength(shown);
|
|
586
|
+
// Chaining is the point: the filter panel is never dimmed or disabled with the grid.
|
|
587
|
+
const aside = wrapper.get('aside');
|
|
588
|
+
expect(aside.attributes('inert')).toBeUndefined();
|
|
589
|
+
expect(aside.classes().join(' ')).not.toContain('pointer-events-none');
|
|
590
|
+
expect(aside.classes().join(' ')).not.toContain('animate-eldra-pulse-soft');
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* The motion half, asserted as the class pair rather than a computed style — jsdom parses no
|
|
595
|
+
* stylesheet, so `getComputedStyle` would answer nothing either way. `animate-eldra-pulse-soft`
|
|
596
|
+
* is the theme's own utility (`app/assets/main.css`: 0.7 ↔ 0.9, 1.4s, ease-in-out, alternate,
|
|
597
|
+
* infinite); under `prefers-reduced-motion: reduce` the animation is off and the list holds a
|
|
598
|
+
* steady 0.8 instead, which is the `motion-reduce:` pair beside it.
|
|
599
|
+
*/
|
|
600
|
+
it('pulses with a reduced-motion fallback that is a steady opacity, not a stopped animation', async () => {
|
|
601
|
+
const stub = createStub();
|
|
602
|
+
const wrapper = mountGrid(mock, { source: stub.source });
|
|
603
|
+
await wrapper.vm.$nextTick();
|
|
604
|
+
stub.pending.value = true;
|
|
605
|
+
stub.loading.value = true;
|
|
606
|
+
await wrapper.vm.$nextTick();
|
|
607
|
+
|
|
608
|
+
const classes = gridList(wrapper).classes();
|
|
609
|
+
expect(classes).toContain('animate-eldra-pulse-soft');
|
|
610
|
+
expect(classes).toContain('motion-reduce:animate-none');
|
|
611
|
+
expect(classes).toContain('motion-reduce:opacity-80');
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
it('does not pulse, and leaves the grid operable, while nothing is updating', async () => {
|
|
615
|
+
const wrapper = mountGrid(mock);
|
|
616
|
+
await wrapper.vm.$nextTick();
|
|
617
|
+
|
|
618
|
+
expect(gridList(wrapper).attributes('inert')).toBeUndefined();
|
|
619
|
+
expect(gridList(wrapper).classes()).not.toContain('animate-eldra-pulse-soft');
|
|
620
|
+
expect(gridList(wrapper).classes().join(' ')).not.toContain('motion-reduce:');
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* The pulse is gated behind `useRevalidating`'s mount flag like every other refresh treatment
|
|
625
|
+
* (`app/composables/useRevalidating.ts`), so the server never writes it and the browser's first
|
|
626
|
+
* render is the server's. A hydrating page is precisely the state that would paint it
|
|
627
|
+
* otherwise: `createGatewayResult` raises `loading` synchronously and fills `data` from the
|
|
628
|
+
* payload in the same turn, so `loading && data !== null` — the pulse's own condition — is true
|
|
629
|
+
* during the first client render and was false during the render it has to match. Both halves
|
|
630
|
+
* are asserted: absent before the tick, there after it, with the read still in flight.
|
|
631
|
+
*/
|
|
632
|
+
it('draws no pulse in the server render or the browser’s first paint', async () => {
|
|
633
|
+
const entry = { id: 'ssr-grid', data: mock as unknown as Record<string, unknown> };
|
|
634
|
+
const html = await renderBlockHtml(Block, entry, {
|
|
635
|
+
[STOREFRONT_KEY]: createStub().source,
|
|
636
|
+
});
|
|
637
|
+
expect(html).toContain('data-part="stars"'); // the cards really are in the server's markup
|
|
638
|
+
expect(html).not.toContain('animate-eldra-pulse-soft');
|
|
639
|
+
expect(html).not.toContain(enUS.grid.updating);
|
|
640
|
+
|
|
641
|
+
const client = createStub();
|
|
642
|
+
client.loading.value = true;
|
|
643
|
+
const run = hydrateBlock(Block, entry, html, { [STOREFRONT_KEY]: client.source });
|
|
644
|
+
try {
|
|
645
|
+
expect(hydrationWarnings(run)).toEqual([]);
|
|
646
|
+
expect(run.firstPaint).not.toContain('animate-eldra-pulse-soft');
|
|
647
|
+
expect(run.firstPaint).not.toContain(enUS.grid.updating);
|
|
648
|
+
|
|
649
|
+
await nextTick();
|
|
650
|
+
|
|
651
|
+
expect(client.loading.value).toBe(true);
|
|
652
|
+
expect(run.container.innerHTML).toContain('animate-eldra-pulse-soft');
|
|
653
|
+
expect(run.container.innerHTML).toContain(enUS.grid.updating);
|
|
654
|
+
} finally {
|
|
655
|
+
run.unmount();
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
it('reads "Updating…" over skeleton cards only while there is nothing to show at all', async () => {
|
|
660
|
+
const wrapper = mountGrid(mock, { source: firstLoadSource() });
|
|
661
|
+
await wrapper.vm.$nextTick();
|
|
662
|
+
|
|
663
|
+
expect(countLine(wrapper).text()).toBe(enUS.grid.updating);
|
|
664
|
+
const skeletons = wrapper.get('ul[aria-hidden="true"]');
|
|
665
|
+
expect(skeletons.findAll(':scope > li').length).toBeGreaterThan(0);
|
|
666
|
+
expect(cards(wrapper)).toHaveLength(0);
|
|
667
|
+
});
|
|
668
|
+
});
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* Chaining a run of sidebar changes sends one request, not one per tick, and the shopper sees
|
|
672
|
+
* the list is about to move from the very first one.
|
|
673
|
+
*/
|
|
674
|
+
describe('the sidebar’s own debounce', () => {
|
|
675
|
+
/** Twice the fixture, the copies given handles of their own — the cards are keyed by handle,
|
|
676
|
+
* and `pageSize` only takes the schema's own 12/24/48, so putting a real Load more on screen
|
|
677
|
+
* needs more rows rather than a smaller window. */
|
|
678
|
+
const TWO_PAGES: StorefrontProductListItem[] = [
|
|
679
|
+
...PRODUCTS,
|
|
680
|
+
...PRODUCTS.map((item) => ({
|
|
681
|
+
...item,
|
|
682
|
+
handle: `${item.handle}-2`,
|
|
683
|
+
productId: `${item.productId}-2`,
|
|
684
|
+
})),
|
|
685
|
+
];
|
|
686
|
+
|
|
687
|
+
it('three quick toggles send one request, with the final selection, and read "Updating…" the whole time', async () => {
|
|
688
|
+
useFilterTimers();
|
|
689
|
+
// A filtered answer with cards in it, so the grid is still a grid at the end of this and the
|
|
690
|
+
// pulse's own state can be read off it rather than off an empty state.
|
|
691
|
+
const stub = createStub(PRODUCTS, { filteredCount: 4 });
|
|
692
|
+
const wrapper = mountGrid(mock, { source: stub.source });
|
|
693
|
+
await wrapper.vm.$nextTick();
|
|
694
|
+
const before = stub.requests.length;
|
|
695
|
+
|
|
696
|
+
await panelFor(wrapper, enUS.grid.legendCategory)
|
|
697
|
+
.panel.get('input[type="checkbox"]')
|
|
698
|
+
.setValue(true);
|
|
699
|
+
// Armed from the very first tick — the shopper sees the list is about to move before any
|
|
700
|
+
// of the three changes has actually asked for anything.
|
|
701
|
+
expect(countLine(wrapper).text()).toBe(enUS.grid.updating);
|
|
702
|
+
expect(gridList(wrapper).attributes('aria-busy')).toBe('true');
|
|
703
|
+
expect(gridList(wrapper).classes()).toContain('animate-eldra-pulse-soft');
|
|
704
|
+
|
|
705
|
+
await panelFor(wrapper, enUS.grid.legendSize)
|
|
706
|
+
.panel.findAll('input[type="checkbox"]')[0]!
|
|
707
|
+
.setValue(true);
|
|
708
|
+
await panelFor(wrapper, enUS.grid.legendColour)
|
|
709
|
+
.panel.get('input[type="checkbox"]')
|
|
710
|
+
.setValue(true);
|
|
711
|
+
// Still nothing sent: each tick restarted the same window (a trailing debounce).
|
|
712
|
+
expect(stub.requests.length).toBe(before);
|
|
713
|
+
expect(countLine(wrapper).text()).toBe(enUS.grid.updating);
|
|
714
|
+
|
|
715
|
+
await settleFilterDebounce(wrapper);
|
|
716
|
+
|
|
717
|
+
expect(stub.requests.length).toBe(before + 1);
|
|
718
|
+
const sent = stub.requests.at(-1)!.filters!;
|
|
719
|
+
expect(Object.keys(sent).sort()).toEqual(['category', 'option:colour', 'option:size']);
|
|
720
|
+
expect(countLine(wrapper).text()).toBe('4 products');
|
|
721
|
+
expect(gridList(wrapper).attributes('aria-busy')).toBeUndefined();
|
|
722
|
+
expect(gridList(wrapper).attributes('inert')).toBeUndefined();
|
|
723
|
+
expect(gridList(wrapper).classes()).not.toContain('animate-eldra-pulse-soft');
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* The three ticks above, read from the sidebar's side: every one of them is operable while the
|
|
728
|
+
* grid is pulsing, which is the whole reason the debounce exists. The assertion is the
|
|
729
|
+
* checkboxes' own state rather than a class, because "the panel stays interactive" is about
|
|
730
|
+
* what a shopper can still change, not about what the aside is styled with.
|
|
731
|
+
*/
|
|
732
|
+
it('leaves the filter panel fully interactive while the grid is pulsing', async () => {
|
|
733
|
+
useFilterTimers();
|
|
734
|
+
const stub = createStub(PRODUCTS, { filteredCount: 4 });
|
|
735
|
+
const wrapper = mountGrid(mock, { source: stub.source });
|
|
736
|
+
await wrapper.vm.$nextTick();
|
|
737
|
+
|
|
738
|
+
const category = panelFor(wrapper, enUS.grid.legendCategory).panel.get(
|
|
739
|
+
'input[type="checkbox"]'
|
|
740
|
+
);
|
|
741
|
+
await category.setValue(true);
|
|
742
|
+
expect(gridList(wrapper).classes()).toContain('animate-eldra-pulse-soft');
|
|
743
|
+
|
|
744
|
+
const aside = wrapper.get('aside');
|
|
745
|
+
expect(aside.attributes('inert')).toBeUndefined();
|
|
746
|
+
expect(aside.classes().join(' ')).not.toContain('pointer-events-none');
|
|
747
|
+
expect(aside.classes().join(' ')).not.toContain('animate-eldra-pulse-soft');
|
|
748
|
+
// Still operable, and the second change really lands: unticking the first one puts the
|
|
749
|
+
// checkbox back and leaves the sidebar's selection empty.
|
|
750
|
+
const colour = panelFor(wrapper, enUS.grid.legendColour).panel.get('input[type="checkbox"]');
|
|
751
|
+
expect((colour.element as HTMLInputElement).disabled).toBe(false);
|
|
752
|
+
await category.setValue(false);
|
|
753
|
+
expect((category.element as HTMLInputElement).checked).toBe(false);
|
|
754
|
+
|
|
755
|
+
await settleFilterDebounce(wrapper);
|
|
756
|
+
expect(stub.requests.at(-1)?.filters).toBeUndefined();
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
/** Sort, Columns, Load more and the drawer's own apply all flush the wait immediately — see
|
|
760
|
+
* each handler's own comment in `Block.vue`. Sort is the one chosen here because it is the
|
|
761
|
+
* only one of the four that is also itself a request parameter the flushed read has to
|
|
762
|
+
* carry alongside the filter. */
|
|
763
|
+
it('a sort change during an armed window sends one immediate request carrying both', async () => {
|
|
764
|
+
const stub = createStub();
|
|
765
|
+
const wrapper = mountGrid(mock, { source: stub.source, attachTo: document.body });
|
|
766
|
+
await wrapper.vm.$nextTick();
|
|
767
|
+
// The grid's own reads, told apart from the drawer's pending count by its `pageSize: 1` —
|
|
768
|
+
// that one asks for no items at all, and it follows the sort too (only the filters and the
|
|
769
|
+
// price are debounced), so counting every request would count it as a second grid read.
|
|
770
|
+
const gridReads = (): number => stub.requests.filter((sent) => sent.pageSize !== 1).length;
|
|
771
|
+
const before = gridReads();
|
|
772
|
+
|
|
773
|
+
await panelFor(wrapper, enUS.grid.legendCategory)
|
|
774
|
+
.panel.get('input[type="checkbox"]')
|
|
775
|
+
.setValue(true);
|
|
776
|
+
expect(gridReads()).toBe(before);
|
|
777
|
+
|
|
778
|
+
// The first ArrowDown opens the listbox on the current value (Featured); the second moves to
|
|
779
|
+
// Best selling, which Enter commits — the same three presses the Select's own keyboard test
|
|
780
|
+
// above uses, and the reason two are needed rather than one.
|
|
781
|
+
const trigger = comboboxes(wrapper)[0]!;
|
|
782
|
+
trigger.element.focus();
|
|
783
|
+
await trigger.trigger('keydown', { key: 'ArrowDown' });
|
|
784
|
+
await trigger.trigger('keydown', { key: 'ArrowDown' });
|
|
785
|
+
await trigger.trigger('keydown', { key: 'Enter' });
|
|
786
|
+
|
|
787
|
+
// No fake timers at all here: the sort change applies — and the armed filter flushes with
|
|
788
|
+
// it — synchronously, with nothing to wait out.
|
|
789
|
+
expect(gridReads()).toBe(before + 1);
|
|
790
|
+
const sent = stub.requests.filter((request) => request.pageSize !== 1).at(-1)!;
|
|
791
|
+
expect(sent.sort).toBe('best-selling');
|
|
792
|
+
expect(sent.filters).toEqual({ category: ['knitwear'] });
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* **Every input of the read is held, not just `filters`.** A sidebar handler's own
|
|
797
|
+
* `publishState()` resets the page window (`pagesLoaded`) in the same turn it changes the
|
|
798
|
+
* selection, and that window is part of what the read asks for. Holding the filters alone let
|
|
799
|
+
* the reset through on its own: after a Load more press, one tick fired an immediate read for
|
|
800
|
+
* the narrowed window carrying the *old* filters — visibly replacing the cards the shopper had
|
|
801
|
+
* loaded — and the debounced one followed 350 ms later. Two requests for one tick, the first
|
|
802
|
+
* thrown away.
|
|
803
|
+
*
|
|
804
|
+
* Twenty-four products at `pageSize: '12'` is what puts a real Load more on screen; the press
|
|
805
|
+
* doubles the window to 24, and the tick after it has to come back as exactly one request, for
|
|
806
|
+
* the reset window of 12, carrying the new filter.
|
|
807
|
+
*/
|
|
808
|
+
it('sends one request for a filter ticked after Load more, carrying the reset page window', async () => {
|
|
809
|
+
useFilterTimers();
|
|
810
|
+
const stub = createStub(TWO_PAGES, { filteredCount: 4 });
|
|
811
|
+
const wrapper = mountGrid({ ...mock, pageSize: '12' }, { source: stub.source });
|
|
812
|
+
await wrapper.vm.$nextTick();
|
|
813
|
+
expect(cards(wrapper)).toHaveLength(12);
|
|
814
|
+
|
|
815
|
+
const gridReads = (): Stub['requests'] => stub.requests.filter((sent) => sent.pageSize !== 1);
|
|
816
|
+
await wrapper.get('[data-part="button"]').trigger('click');
|
|
817
|
+
await wrapper.vm.$nextTick();
|
|
818
|
+
expect(cards(wrapper)).toHaveLength(24);
|
|
819
|
+
const before = gridReads().length;
|
|
820
|
+
|
|
821
|
+
await panelFor(wrapper, enUS.grid.legendCategory)
|
|
822
|
+
.panel.get('input[type="checkbox"]')
|
|
823
|
+
.setValue(true);
|
|
824
|
+
expect(gridReads().length).toBe(before);
|
|
825
|
+
|
|
826
|
+
await settleFilterDebounce(wrapper);
|
|
827
|
+
|
|
828
|
+
expect(gridReads().length).toBe(before + 1);
|
|
829
|
+
const sent = gridReads().at(-1)!;
|
|
830
|
+
expect(sent.pageSize).toBe(12);
|
|
831
|
+
expect(sent.filters).toEqual({ category: ['knitwear'] });
|
|
832
|
+
expect(cards(wrapper)).toHaveLength(4);
|
|
833
|
+
});
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* The same gesture pair the other way round, which is the half the ordering above gets wrong:
|
|
837
|
+
* a **Load more press inside an armed window**. The press widens the page window and resolves
|
|
838
|
+
* the wait in one go, so there is one read for it, carrying both — not one for the old window
|
|
839
|
+
* and a second for the new one in the same tick.
|
|
840
|
+
*/
|
|
841
|
+
it('sends one request for a Load more pressed inside an armed window, carrying both', async () => {
|
|
842
|
+
useFilterTimers();
|
|
843
|
+
const stub = createStub(TWO_PAGES, { filteredCount: 4 });
|
|
844
|
+
const wrapper = mountGrid({ ...mock, pageSize: '12' }, { source: stub.source });
|
|
845
|
+
await wrapper.vm.$nextTick();
|
|
846
|
+
expect(cards(wrapper)).toHaveLength(12);
|
|
847
|
+
|
|
848
|
+
const gridReads = (): Stub['requests'] => stub.requests.filter((sent) => sent.pageSize !== 1);
|
|
849
|
+
const before = gridReads().length;
|
|
850
|
+
|
|
851
|
+
await panelFor(wrapper, enUS.grid.legendCategory)
|
|
852
|
+
.panel.get('input[type="checkbox"]')
|
|
853
|
+
.setValue(true);
|
|
854
|
+
expect(gridReads().length).toBe(before);
|
|
855
|
+
|
|
856
|
+
// Pressed well inside the 350ms window — nothing has settled, so the filter is still waiting.
|
|
857
|
+
await wrapper.get('[data-part="button"]').trigger('click');
|
|
858
|
+
await wrapper.vm.$nextTick();
|
|
859
|
+
|
|
860
|
+
expect(gridReads().length).toBe(before + 1);
|
|
861
|
+
const sent = gridReads().at(-1)!;
|
|
862
|
+
expect(sent.pageSize).toBe(24);
|
|
863
|
+
expect(sent.filters).toEqual({ category: ['knitwear'] });
|
|
864
|
+
await settleFilterDebounce(wrapper);
|
|
865
|
+
// And the window stays resolved: the expired timer has nothing left to send.
|
|
866
|
+
expect(gridReads().length).toBe(before + 1);
|
|
867
|
+
});
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* Columns is layout, but the state write behind it resets the page window, which *is* a request
|
|
871
|
+
* input — so a Columns change inside an armed window, after a Load more press that widened that
|
|
872
|
+
* window, is the same two-reads-for-one-gesture shape. One read, for the reset window, carrying
|
|
873
|
+
* the filter that was waiting.
|
|
874
|
+
*/
|
|
875
|
+
it('sends one request for a Columns change inside an armed window, carrying both', async () => {
|
|
876
|
+
useFilterTimers();
|
|
877
|
+
const stub = createStub(TWO_PAGES, { filteredCount: 4 });
|
|
878
|
+
const wrapper = mountGrid(
|
|
879
|
+
{ ...mock, pageSize: '12' },
|
|
880
|
+
{ source: stub.source, attachTo: document.body }
|
|
881
|
+
);
|
|
882
|
+
await wrapper.vm.$nextTick();
|
|
883
|
+
|
|
884
|
+
const gridReads = (): Stub['requests'] => stub.requests.filter((sent) => sent.pageSize !== 1);
|
|
885
|
+
await wrapper.get('[data-part="button"]').trigger('click');
|
|
886
|
+
await wrapper.vm.$nextTick();
|
|
887
|
+
expect(cards(wrapper)).toHaveLength(24);
|
|
888
|
+
|
|
889
|
+
await panelFor(wrapper, enUS.grid.legendCategory)
|
|
890
|
+
.panel.get('input[type="checkbox"]')
|
|
891
|
+
.setValue(true);
|
|
892
|
+
const before = gridReads().length;
|
|
893
|
+
|
|
894
|
+
// The Columns select is the third combobox — two sorts (top bar and toolbar), then this one.
|
|
895
|
+
const columns = comboboxes(wrapper)[2]!;
|
|
896
|
+
columns.element.focus();
|
|
897
|
+
await columns.trigger('keydown', { key: 'ArrowDown' });
|
|
898
|
+
await columns.trigger('keydown', { key: 'ArrowDown' });
|
|
899
|
+
await columns.trigger('keydown', { key: 'Enter' });
|
|
900
|
+
await wrapper.vm.$nextTick();
|
|
901
|
+
|
|
902
|
+
expect(gridReads().length).toBe(before + 1);
|
|
903
|
+
const sent = gridReads().at(-1)!;
|
|
904
|
+
expect(sent.pageSize).toBe(12);
|
|
905
|
+
expect(sent.filters).toEqual({ category: ['knitwear'] });
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* The drawer's live "Show N products" count is its own read off `pendingOptions`, and it gets
|
|
910
|
+
* the same window: ticking two boxes inside the drawer asks the store once, not twice. It is
|
|
911
|
+
* the `pageSize: 1` request in the log — the count read asks for no items at all, which is
|
|
912
|
+
* what separates it from the grid's own.
|
|
913
|
+
*/
|
|
914
|
+
it('debounces the drawer’s pending-count read the same way', async () => {
|
|
915
|
+
useFilterTimers();
|
|
916
|
+
const stub = createStub(PRODUCTS, { filteredCount: 4 });
|
|
917
|
+
const wrapper = mountGrid(mock, { source: stub.source, attachTo: document.body });
|
|
918
|
+
await wrapper.vm.$nextTick();
|
|
919
|
+
|
|
920
|
+
await filterButton(wrapper).trigger('click');
|
|
921
|
+
await wrapper.vm.$nextTick();
|
|
922
|
+
const drawer = wrapper.get('dialog');
|
|
923
|
+
const countReads = (): number => stub.requests.filter((sent) => sent.pageSize === 1).length;
|
|
924
|
+
const before = countReads();
|
|
925
|
+
|
|
926
|
+
const boxes = drawer.findAll('input[type="checkbox"]');
|
|
927
|
+
expect(boxes.length).toBeGreaterThan(1);
|
|
928
|
+
await boxes[0]!.setValue(true);
|
|
929
|
+
await boxes[1]!.setValue(true);
|
|
930
|
+
// Both ticks are visible in the drawer at once, and neither has asked the store anything.
|
|
931
|
+
expect((boxes[0]!.element as HTMLInputElement).checked).toBe(true);
|
|
932
|
+
expect((boxes[1]!.element as HTMLInputElement).checked).toBe(true);
|
|
933
|
+
expect(countReads()).toBe(before);
|
|
934
|
+
|
|
935
|
+
await settleFilterDebounce(wrapper);
|
|
936
|
+
|
|
937
|
+
expect(countReads()).toBe(before + 1);
|
|
938
|
+
// And the page itself is untouched until "Show N products" is pressed.
|
|
939
|
+
expect(countLine(wrapper).text()).toBe('12 products');
|
|
940
|
+
});
|
|
941
|
+
});
|
|
942
|
+
|
|
943
|
+
describe('the active filters', () => {
|
|
944
|
+
it('lists a removable chip per selected value, named with its group', async () => {
|
|
945
|
+
const wrapper = mountGrid(mock);
|
|
946
|
+
await wrapper.vm.$nextTick();
|
|
947
|
+
const { panel } = panelFor(wrapper, enUS.grid.legendSize);
|
|
948
|
+
await panel.findAll('input[type="checkbox"]')[2]!.setValue(true);
|
|
949
|
+
|
|
950
|
+
const list = wrapper.get(`ul[aria-label="${enUS.grid.activeFilters}"]`);
|
|
951
|
+
expect(list.text()).toContain('M');
|
|
952
|
+
expect(list.get('[data-part="removeButton"]').attributes('aria-label')).toBe(
|
|
953
|
+
'Remove filter Size: M'
|
|
954
|
+
);
|
|
955
|
+
});
|
|
956
|
+
|
|
957
|
+
it('removing a chip moves focus to the next chip', async () => {
|
|
958
|
+
const wrapper = mountGrid(mock, { attachTo: document.body });
|
|
959
|
+
await wrapper.vm.$nextTick();
|
|
960
|
+
const sizes = panelFor(wrapper, enUS.grid.legendSize).panel;
|
|
961
|
+
await sizes.findAll('input[type="checkbox"]')[0]!.setValue(true);
|
|
962
|
+
await sizes.findAll('input[type="checkbox"]')[1]!.setValue(true);
|
|
963
|
+
|
|
964
|
+
const list = wrapper.get(`ul[aria-label="${enUS.grid.activeFilters}"]`);
|
|
965
|
+
expect(list.findAll('[data-part="removeButton"]')).toHaveLength(2);
|
|
966
|
+
|
|
967
|
+
await list.findAll('[data-part="removeButton"]')[0]!.trigger('click');
|
|
968
|
+
await wrapper.vm.$nextTick();
|
|
969
|
+
|
|
970
|
+
const remaining = list.findAll('[data-part="removeButton"]');
|
|
971
|
+
expect(remaining).toHaveLength(1);
|
|
972
|
+
expect(document.activeElement).toBe(remaining[0]!.element);
|
|
973
|
+
});
|
|
974
|
+
|
|
975
|
+
/**
|
|
976
|
+
* **Clear all** lives in the sidebar panel's own head now, and the panel moves focus to its
|
|
977
|
+
* own title itself (spec → Behaviour) — a sensible place to land right beside the button that
|
|
978
|
+
* was pressed. The count still gets its own focus contract from the empty state's own **Clear
|
|
979
|
+
* filters** button, a block-drawn control (see `onClearAll`).
|
|
980
|
+
*/
|
|
981
|
+
it('Clear all empties the selection and focuses the panel’s own title', async () => {
|
|
982
|
+
const wrapper = mountGrid(mock, { attachTo: document.body });
|
|
983
|
+
await wrapper.vm.$nextTick();
|
|
984
|
+
const sizes = panelFor(wrapper, enUS.grid.legendSize).panel;
|
|
985
|
+
await sizes.findAll('input[type="checkbox"]')[0]!.setValue(true);
|
|
986
|
+
|
|
987
|
+
const clearAll = wrapper
|
|
988
|
+
.findAll('button')
|
|
989
|
+
.find((button) => button.text() === enUS.grid.clearAll)!;
|
|
990
|
+
await clearAll.trigger('click');
|
|
991
|
+
await wrapper.vm.$nextTick();
|
|
992
|
+
|
|
993
|
+
expect(wrapper.find(`ul[aria-label="${enUS.grid.activeFilters}"]`).exists()).toBe(false);
|
|
994
|
+
expect(document.activeElement).toBe(wrapper.get('aside [data-part="title"]').element);
|
|
995
|
+
});
|
|
996
|
+
|
|
997
|
+
/**
|
|
998
|
+
* The slider's own typed fields commit on `Enter`. A range contributes no chip of its own
|
|
999
|
+
* (`@eldrajs/ui`'s own `appliedFilters`: "a span has no one value a chip could take off") —
|
|
1000
|
+
* removing it is **Clear all**'s job, or the track's own — so a committed range moves the
|
|
1001
|
+
* thumbs and the fields and narrows the grid, with nothing in the applied-chips row.
|
|
1002
|
+
*/
|
|
1003
|
+
it('commits a typed price range to the thumbs and the request, with no chip of its own', async () => {
|
|
1004
|
+
useFilterTimers();
|
|
1005
|
+
const stub = createStub(PRODUCTS, { filteredCount: 4 });
|
|
1006
|
+
const wrapper = mountGrid(mock, { source: stub.source });
|
|
1007
|
+
await wrapper.vm.$nextTick();
|
|
1008
|
+
const { panel } = panelFor(wrapper, PRICE_LEGEND);
|
|
1009
|
+
|
|
1010
|
+
const min = panel.get('input[data-input="min"]');
|
|
1011
|
+
await min.trigger('focus');
|
|
1012
|
+
await min.setValue('50');
|
|
1013
|
+
await min.trigger('keydown', { key: 'Enter' });
|
|
1014
|
+
const max = panel.get('input[data-input="max"]');
|
|
1015
|
+
await max.trigger('focus');
|
|
1016
|
+
await max.setValue('150');
|
|
1017
|
+
await max.trigger('keydown', { key: 'Enter' });
|
|
1018
|
+
await settleFilterDebounce(wrapper);
|
|
1019
|
+
|
|
1020
|
+
expect(wrapper.find(`ul[aria-label="${enUS.grid.activeFilters}"]`).exists()).toBe(false);
|
|
1021
|
+
const sent = stub.requests.filter((request) => request.pageSize !== 1).at(-1)!;
|
|
1022
|
+
expect(sent.filters).toEqual({ price: ['50-150'] });
|
|
1023
|
+
expect(countLine(wrapper).text()).toBe('4 products');
|
|
1024
|
+
});
|
|
1025
|
+
|
|
1026
|
+
/** Both thumbs span the collection's own prices, from the storefront's facets — never 0 and a
|
|
1027
|
+
* round number (spec Layout → Price). */
|
|
1028
|
+
it('spans the collection’s own price bounds', async () => {
|
|
1029
|
+
const wrapper = mountGrid(mock, { source: createStub().source });
|
|
1030
|
+
await wrapper.vm.$nextTick();
|
|
1031
|
+
const { panel } = panelFor(wrapper, PRICE_LEGEND);
|
|
1032
|
+
const thumbs = panel.findAll('[role="slider"]');
|
|
1033
|
+
expect(thumbs).toHaveLength(2);
|
|
1034
|
+
expect(thumbs[0]!.attributes('aria-valuenow')).toBe('24');
|
|
1035
|
+
expect(thumbs[1]!.attributes('aria-valuenow')).toBe('180');
|
|
1036
|
+
// Spoken as money, in the store's own currency, with no decimals (spec → Behaviour: "no
|
|
1037
|
+
// decimals") — `@eldrajs/ui`'s own formatting, not the theme's `money.format`.
|
|
1038
|
+
expect(thumbs[0]!.attributes('aria-valuetext')).toBe('$24');
|
|
1039
|
+
// `@eldrajs/ui`'s own `minimumOf(facet.label)` — "Minimum " + the facet's own title.
|
|
1040
|
+
expect(thumbs[0]!.attributes('aria-label')).toBe(`Minimum ${PRICE_LEGEND}`);
|
|
1041
|
+
});
|
|
1042
|
+
|
|
1043
|
+
/** `priceSlider` off: the two typed fields alone, which is what a store whose prices sit in a
|
|
1044
|
+
* few tight clusters sets (spec Fields). */
|
|
1045
|
+
it('falls back to the two fields when the author turns the slider off', async () => {
|
|
1046
|
+
const wrapper = mountGrid({
|
|
1047
|
+
...mock,
|
|
1048
|
+
priceSlider: false,
|
|
1049
|
+
filters: [{ source: 'price', label: 'Price' }],
|
|
1050
|
+
});
|
|
1051
|
+
await wrapper.vm.$nextTick();
|
|
1052
|
+
const { panel } = panelFor(wrapper, PRICE_LEGEND);
|
|
1053
|
+
expect(panel.findAll('[role="slider"]')).toHaveLength(0);
|
|
1054
|
+
const inputs = panel.findAll('input');
|
|
1055
|
+
expect(inputs).toHaveLength(2);
|
|
1056
|
+
|
|
1057
|
+
// The two fields are the store's own money fields, so they commit on blur or `Enter` like the
|
|
1058
|
+
// slider's — not per keystroke. No chip of its own either way (a range contributes none).
|
|
1059
|
+
await inputs[0]!.setValue('50');
|
|
1060
|
+
await wrapper.vm.$nextTick();
|
|
1061
|
+
expect(wrapper.find(`ul[aria-label="${enUS.grid.activeFilters}"]`).exists()).toBe(false);
|
|
1062
|
+
|
|
1063
|
+
await inputs[0]!.trigger('blur');
|
|
1064
|
+
await wrapper.vm.$nextTick();
|
|
1065
|
+
expect(wrapper.find(`ul[aria-label="${enUS.grid.activeFilters}"]`).exists()).toBe(false);
|
|
1066
|
+
expect((inputs[0]!.element as HTMLInputElement).value).toBe('$50');
|
|
1067
|
+
});
|
|
1068
|
+
});
|
|
1069
|
+
|
|
1070
|
+
describe('the empty state', () => {
|
|
1071
|
+
it('keeps the chips, names the active filters and clears them from its own button', async () => {
|
|
1072
|
+
useFilterTimers();
|
|
1073
|
+
const stub = createStub();
|
|
1074
|
+
const wrapper = mountGrid(mock, { source: stub.source });
|
|
1075
|
+
await wrapper.vm.$nextTick();
|
|
1076
|
+
const { panel } = panelFor(wrapper, enUS.grid.legendColour);
|
|
1077
|
+
await panel.get('input[type="checkbox"]').setValue(true);
|
|
1078
|
+
await settleFilterDebounce(wrapper);
|
|
1079
|
+
|
|
1080
|
+
expect(cards(wrapper)).toHaveLength(0);
|
|
1081
|
+
expect(countLine(wrapper).text()).toBe('0 products');
|
|
1082
|
+
const chipList = wrapper.get(`ul[aria-label="${enUS.grid.activeFilters}"]`);
|
|
1083
|
+
expect(chipList.text()).toContain('Oat');
|
|
1084
|
+
expect(chipList.get('[data-part="removeButton"]').attributes('aria-label')).toBe(
|
|
1085
|
+
'Remove filter Colour: Oat'
|
|
1086
|
+
);
|
|
1087
|
+
expect(wrapper.text()).toContain(mock.emptyTitle);
|
|
1088
|
+
expect(wrapper.text()).toContain(mock.emptyText);
|
|
1089
|
+
expect(wrapper.text()).toContain('Nothing in Oat is in stock right now.');
|
|
1090
|
+
|
|
1091
|
+
const clearFilters = wrapper
|
|
1092
|
+
.findAll('button')
|
|
1093
|
+
.find((button) => button.text() === enUS.grid.clearFilters)!;
|
|
1094
|
+
await clearFilters.trigger('click');
|
|
1095
|
+
await wrapper.vm.$nextTick();
|
|
1096
|
+
|
|
1097
|
+
expect(cards(wrapper).length).toBeGreaterThan(0);
|
|
1098
|
+
expect(countLine(wrapper).text()).toBe('12 products');
|
|
1099
|
+
});
|
|
1100
|
+
});
|
|
1101
|
+
|
|
1102
|
+
describe('the grid', () => {
|
|
1103
|
+
it('columns: "4" shows 2, then 3 from 48rem and 4 only from 64rem', async () => {
|
|
1104
|
+
const wrapper = mountGrid({ ...mock, columns: '4' });
|
|
1105
|
+
await wrapper.vm.$nextTick();
|
|
1106
|
+
const grid = gridList(wrapper).classes().join(' ');
|
|
1107
|
+
expect(grid).toContain('grid-cols-2');
|
|
1108
|
+
expect(grid).toContain('@tablet:grid-cols-3');
|
|
1109
|
+
expect(grid).toContain('@content:grid-cols-4');
|
|
1110
|
+
});
|
|
1111
|
+
|
|
1112
|
+
it('columns: "2" stays at two columns at every width', async () => {
|
|
1113
|
+
const wrapper = mountGrid({ ...mock, columns: '2' });
|
|
1114
|
+
await wrapper.vm.$nextTick();
|
|
1115
|
+
const grid = gridList(wrapper).classes().join(' ');
|
|
1116
|
+
expect(grid).toContain('grid-cols-2');
|
|
1117
|
+
expect(grid).not.toContain('grid-cols-3');
|
|
1118
|
+
expect(grid).not.toContain('grid-cols-4');
|
|
1119
|
+
});
|
|
1120
|
+
|
|
1121
|
+
it('the Columns select is present only from 64rem, and only when showColumnSelect is on', async () => {
|
|
1122
|
+
const wrapper = mountGrid(mock);
|
|
1123
|
+
await wrapper.vm.$nextTick();
|
|
1124
|
+
const label = wrapper.findAll('label').find((l) => l.text() === enUS.grid.columns)!;
|
|
1125
|
+
const toolbarControls = label.element.closest('div.hidden')!;
|
|
1126
|
+
expect(toolbarControls.className).toContain('@content:flex');
|
|
1127
|
+
|
|
1128
|
+
const without = mountGrid({ ...mock, showColumnSelect: false });
|
|
1129
|
+
await without.vm.$nextTick();
|
|
1130
|
+
expect(without.findAll('label').some((l) => l.text() === enUS.grid.columns)).toBe(false);
|
|
1131
|
+
});
|
|
1132
|
+
|
|
1133
|
+
it('a sold-out card shows the outline Sold out badge and the faded image', async () => {
|
|
1134
|
+
const wrapper = mountGrid(mock);
|
|
1135
|
+
await wrapper.vm.$nextTick();
|
|
1136
|
+
const soldOut = cards(wrapper).find((card) => card.text().includes('Linen tea towels'))!;
|
|
1137
|
+
expect(soldOut.text()).toContain('Sold out');
|
|
1138
|
+
expect(soldOut.get('img').classes()).toContain('opacity-60');
|
|
1139
|
+
});
|
|
1140
|
+
|
|
1141
|
+
/**
|
|
1142
|
+
* A product's `url` is storefront-derived, not CMS-authored, and used to reach `ProductCard`
|
|
1143
|
+
* without passing `safeHref` — the one class of URL in the theme that did. It is sanitised once
|
|
1144
|
+
* now, in `toProductCardEntries` (`app/storefront/toProductCard.ts`): the card's link is
|
|
1145
|
+
* required, so an item whose URL does not survive `safeHref` is dropped outright rather than
|
|
1146
|
+
* rendered with a link to nowhere. A same-site URL still routes; an off-site one stays a plain
|
|
1147
|
+
* `<a>`.
|
|
1148
|
+
*/
|
|
1149
|
+
it('drops a product whose url is not a safe href, and only routes same-site ones', async () => {
|
|
1150
|
+
const safe = PRODUCTS[0]!;
|
|
1151
|
+
// The exact shape the guard exists for: a scheme `safeHref` rejects.
|
|
1152
|
+
const unsafe = { ...PRODUCTS[1]!, url: 'javascript:alert(1)' };
|
|
1153
|
+
const external = { ...PRODUCTS[2]!, url: 'https://elsewhere.example/p/x' };
|
|
1154
|
+
const wrapper = mountGrid(mock, {
|
|
1155
|
+
source: createStub([safe, unsafe, external]).source,
|
|
1156
|
+
});
|
|
1157
|
+
await wrapper.vm.$nextTick();
|
|
1158
|
+
|
|
1159
|
+
const rendered = cards(wrapper);
|
|
1160
|
+
expect(rendered).toHaveLength(2);
|
|
1161
|
+
expect(wrapper.text()).toContain(safe.title);
|
|
1162
|
+
expect(wrapper.text()).not.toContain(unsafe.title);
|
|
1163
|
+
expect(wrapper.text()).toContain(external.title);
|
|
1164
|
+
expect(wrapper.html()).not.toContain('javascript:');
|
|
1165
|
+
|
|
1166
|
+
const products = wrapper.findAllComponents(ProductCard);
|
|
1167
|
+
expect(products[0]!.props('linkAs')).toBe(EldraRouterLink);
|
|
1168
|
+
expect(products[1]!.props('linkAs')).toBeUndefined();
|
|
1169
|
+
});
|
|
1170
|
+
});
|
|
1171
|
+
|
|
1172
|
+
describe('paging', () => {
|
|
1173
|
+
it('load-more hides its progress bar from assistive technology and keeps focus on the button', async () => {
|
|
1174
|
+
// The demo catalogue: 48 products, 12 per step, so there is still more after the first press.
|
|
1175
|
+
const wrapper = mountGrid({ ...mock, pageSize: '12' }, { attachTo: document.body });
|
|
1176
|
+
await wrapper.vm.$nextTick();
|
|
1177
|
+
expect(cards(wrapper)).toHaveLength(12);
|
|
1178
|
+
|
|
1179
|
+
const loadMore = wrapper.get('[data-part="button"]');
|
|
1180
|
+
const bar = wrapper
|
|
1181
|
+
.findAll('div[aria-hidden="true"]')
|
|
1182
|
+
.find((div) => div.classes().includes('rounded-full'))!;
|
|
1183
|
+
expect(bar.attributes('aria-hidden')).toBe('true');
|
|
1184
|
+
|
|
1185
|
+
loadMore.element.focus();
|
|
1186
|
+
await loadMore.trigger('click');
|
|
1187
|
+
await wrapper.vm.$nextTick();
|
|
1188
|
+
|
|
1189
|
+
expect(cards(wrapper)).toHaveLength(24);
|
|
1190
|
+
expect(document.activeElement).toBe(loadMore.element);
|
|
1191
|
+
// The button stops being busy once the read answers. It has to clear off `loading`, not
|
|
1192
|
+
// `pending`: `pending` never rises for a read over cards the grid already has (the prerender
|
|
1193
|
+
// contract), so a latch cleared by it would leave the button spinning for the page's life.
|
|
1194
|
+
expect(loadMore.attributes('aria-busy')).toBeUndefined();
|
|
1195
|
+
});
|
|
1196
|
+
|
|
1197
|
+
it('pages renders a labelled Pagination of routed page links', async () => {
|
|
1198
|
+
const wrapper = mountGrid({ ...mock, paginationStyle: 'pages', pageSize: '12' });
|
|
1199
|
+
await wrapper.vm.$nextTick();
|
|
1200
|
+
const nav = wrapper.get(`nav[aria-label="${enUS.grid.pagination}"]`);
|
|
1201
|
+
const links = nav.findAll('a');
|
|
1202
|
+
expect(links.length).toBeGreaterThan(0);
|
|
1203
|
+
expect(links.some((link) => link.attributes('href') === '/collections/winter-knitwear')).toBe(
|
|
1204
|
+
true
|
|
1205
|
+
);
|
|
1206
|
+
expect(
|
|
1207
|
+
links.some((link) => link.attributes('href') === '/collections/winter-knitwear?page=2')
|
|
1208
|
+
).toBe(true);
|
|
1209
|
+
expect(nav.find('[aria-current="page"]').exists()).toBe(true);
|
|
1210
|
+
expect(wrapper.find('[data-part="button"]').exists()).toBe(false);
|
|
1211
|
+
});
|
|
1212
|
+
});
|
|
1213
|
+
|
|
1214
|
+
describe('the filter drawer', () => {
|
|
1215
|
+
it('opens from the Filter button with focus on its close button, and Esc returns focus', async () => {
|
|
1216
|
+
const wrapper = mountGrid(mock, { attachTo: document.body });
|
|
1217
|
+
await wrapper.vm.$nextTick();
|
|
1218
|
+
const button = filterButton(wrapper);
|
|
1219
|
+
button.element.focus();
|
|
1220
|
+
await button.trigger('click');
|
|
1221
|
+
|
|
1222
|
+
const dialog = wrapper.get('dialog');
|
|
1223
|
+
expect(dialog.attributes('open')).toBe('');
|
|
1224
|
+
expect(document.activeElement).toBe(dialog.get('[data-part="close"]').element);
|
|
1225
|
+
|
|
1226
|
+
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
|
|
1227
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
1228
|
+
await wrapper.vm.$nextTick();
|
|
1229
|
+
|
|
1230
|
+
expect(wrapper.get('dialog').attributes('open')).toBeUndefined();
|
|
1231
|
+
expect(document.activeElement).toBe(button.element);
|
|
1232
|
+
});
|
|
1233
|
+
|
|
1234
|
+
it('changes nothing in the results until "Show N products" is pressed', async () => {
|
|
1235
|
+
const stub = createStub();
|
|
1236
|
+
const wrapper = mountGrid(mock, { source: stub.source, attachTo: document.body });
|
|
1237
|
+
await wrapper.vm.$nextTick();
|
|
1238
|
+
expect(cards(wrapper)).toHaveLength(12);
|
|
1239
|
+
|
|
1240
|
+
await filterButton(wrapper).trigger('click');
|
|
1241
|
+
const dialog = wrapper.get('dialog');
|
|
1242
|
+
// The drawer's own copy of the groups, in `filters[]` order: [2] is Colour.
|
|
1243
|
+
const drawerColour = dialog.findAll('fieldset')[2]!;
|
|
1244
|
+
await drawerColour.get('input[type="checkbox"]').setValue(true);
|
|
1245
|
+
await wrapper.vm.$nextTick();
|
|
1246
|
+
|
|
1247
|
+
// Nothing on the page has moved: same cards, same count, and the sidebar's own (applied)
|
|
1248
|
+
// panel shows no chip — the drawer's own pending copy shows the tick it is still holding,
|
|
1249
|
+
// which is exactly the "changes nothing until applied" contract for the page, not the drawer.
|
|
1250
|
+
expect(cards(wrapper)).toHaveLength(12);
|
|
1251
|
+
expect(countLine(wrapper).text()).toBe('12 products');
|
|
1252
|
+
expect(
|
|
1253
|
+
wrapper.get('aside').find(`ul[aria-label="${enUS.grid.activeFilters}"]`).exists()
|
|
1254
|
+
).toBe(false);
|
|
1255
|
+
expect(dialog.get(`ul[aria-label="${enUS.grid.activeFilters}"]`).text()).toContain('Oat');
|
|
1256
|
+
|
|
1257
|
+
const apply = dialog
|
|
1258
|
+
.findAll('button')
|
|
1259
|
+
.find((candidate) => candidate.text().startsWith('Show '))!;
|
|
1260
|
+
await apply.trigger('click');
|
|
1261
|
+
await wrapper.vm.$nextTick();
|
|
1262
|
+
|
|
1263
|
+
expect(cards(wrapper)).toHaveLength(0);
|
|
1264
|
+
expect(countLine(wrapper).text()).toBe('0 products');
|
|
1265
|
+
// Both panels now show the same applied selection (the drawer's own pending copy matches it
|
|
1266
|
+
// too, since nothing has changed it since), so the sidebar's own chip row is addressed by
|
|
1267
|
+
// name rather than by the (now ambiguous) aria-label alone.
|
|
1268
|
+
expect(
|
|
1269
|
+
wrapper.get('aside').get(`ul[aria-label="${enUS.grid.activeFilters}"]`).text()
|
|
1270
|
+
).toContain('Oat');
|
|
1271
|
+
expect(wrapper.get('dialog').attributes('open')).toBeUndefined();
|
|
1272
|
+
});
|
|
1273
|
+
|
|
1274
|
+
it('Clear all inside the drawer clears only the pending selection', async () => {
|
|
1275
|
+
const wrapper = mountGrid(mock, { attachTo: document.body });
|
|
1276
|
+
await wrapper.vm.$nextTick();
|
|
1277
|
+
const sizes = panelFor(wrapper, enUS.grid.legendSize).panel;
|
|
1278
|
+
await sizes.findAll('input[type="checkbox"]')[2]!.setValue(true);
|
|
1279
|
+
expect(wrapper.get(`ul[aria-label="${enUS.grid.activeFilters}"]`).text()).toContain('M');
|
|
1280
|
+
|
|
1281
|
+
await filterButton(wrapper).trigger('click');
|
|
1282
|
+
const dialog = wrapper.get('dialog');
|
|
1283
|
+
const drawerClear = dialog
|
|
1284
|
+
.findAll('button')
|
|
1285
|
+
.find((button) => button.text() === enUS.grid.clearAll)!;
|
|
1286
|
+
await drawerClear.trigger('click');
|
|
1287
|
+
await wrapper.vm.$nextTick();
|
|
1288
|
+
|
|
1289
|
+
// The live chip is untouched until the shopper applies the drawer — only the sidebar's own
|
|
1290
|
+
// panel has anything to show once the drawer's own pending copy is cleared.
|
|
1291
|
+
expect(wrapper.get(`ul[aria-label="${enUS.grid.activeFilters}"]`).text()).toContain('M');
|
|
1292
|
+
});
|
|
1293
|
+
|
|
1294
|
+
/**
|
|
1295
|
+
* Regression for the foot sitting `position: static` at the end of the scrolling groups (a
|
|
1296
|
+
* shopper had to scroll the whole filter list to reach Clear all / Show N products). The foot
|
|
1297
|
+
* now lives in the Drawer's own `footer` part — a sibling of the scrolling `body`, not a
|
|
1298
|
+
* descendant of it — so it stays on screen while the groups scroll underneath, and the
|
|
1299
|
+
* panel's own copy of it is hidden rather than drawn twice.
|
|
1300
|
+
*/
|
|
1301
|
+
it('pins the foot outside the scrolling body, in the Drawer’s own footer', async () => {
|
|
1302
|
+
const wrapper = mountGrid(mock, { attachTo: document.body });
|
|
1303
|
+
await wrapper.vm.$nextTick();
|
|
1304
|
+
|
|
1305
|
+
await filterButton(wrapper).trigger('click');
|
|
1306
|
+
const dialog = wrapper.get('dialog');
|
|
1307
|
+
const body = dialog.get('[data-part="body"]');
|
|
1308
|
+
const footer = dialog.get('[data-part="footer"]');
|
|
1309
|
+
|
|
1310
|
+
// The foot is not inside the scrolling body…
|
|
1311
|
+
expect(body.element.contains(footer.element)).toBe(false);
|
|
1312
|
+
// …and the panel's own copy of it is hidden rather than removed outright, so no dead code
|
|
1313
|
+
// path is needed to suppress it — just not shown or reachable by Tab.
|
|
1314
|
+
const panelFoot = dialog.get('[data-part="foot"]');
|
|
1315
|
+
expect(panelFoot.classes()).toContain('hidden');
|
|
1316
|
+
|
|
1317
|
+
// The visible foot is the spec's 2-column grid (`auto | 1fr`) with a top rule and a
|
|
1318
|
+
// background fill, supplied by the Drawer's own chrome.
|
|
1319
|
+
expect(footer.classes()).toContain('grid');
|
|
1320
|
+
expect(footer.classes()).toContain('grid-cols-[auto_1fr]');
|
|
1321
|
+
expect(footer.classes()).not.toContain('flex');
|
|
1322
|
+
expect(footer.classes()).toContain('border-t');
|
|
1323
|
+
expect(footer.classes()).toContain('bg-background');
|
|
1324
|
+
|
|
1325
|
+
const footerButtons = footer.findAll('button');
|
|
1326
|
+
expect(footerButtons.map((button) => button.text())).toEqual([
|
|
1327
|
+
enUS.grid.clearAll,
|
|
1328
|
+
expect.stringMatching(/^Show /),
|
|
1329
|
+
]);
|
|
1330
|
+
});
|
|
1331
|
+
});
|
|
1332
|
+
|
|
1333
|
+
describe('keyboard', () => {
|
|
1334
|
+
/**
|
|
1335
|
+
* The panel now owns **Clear all** and the applied chips, both inside the sidebar's own head —
|
|
1336
|
+
* before its own group triggers, and so before the Filter button and Sort by that follow the
|
|
1337
|
+
* `<aside>` in document order. Cards and Load more still follow the toolbar, unchanged.
|
|
1338
|
+
*/
|
|
1339
|
+
it('puts the panel’s own Clear all and chips before its group triggers, then the toolbar, then the cards', async () => {
|
|
1340
|
+
const wrapper = mountGrid(mock, { attachTo: document.body });
|
|
1341
|
+
await wrapper.vm.$nextTick();
|
|
1342
|
+
// Availability → In stock, not Size → M: the demo source honours `filters` now, and 44 of the
|
|
1343
|
+
// 48 demo items are in stock, so this leaves more than one page and keeps a real Load more
|
|
1344
|
+
// button in the tab order (Size → M leaves 12, i.e. everything already shown).
|
|
1345
|
+
const availability = panelFor(wrapper, enUS.grid.legendAvailability).panel;
|
|
1346
|
+
await availability.get('[role="switch"]').trigger('click');
|
|
1347
|
+
await flushPromises();
|
|
1348
|
+
|
|
1349
|
+
const focusable = Array.from(
|
|
1350
|
+
wrapper.element.querySelectorAll<HTMLElement>('a, button, input, [tabindex]')
|
|
1351
|
+
).filter((el) => el.getAttribute('tabindex') !== '-1' && el.closest('dialog') === null);
|
|
1352
|
+
const indexOf = (el: Element) => focusable.indexOf(el as HTMLElement);
|
|
1353
|
+
|
|
1354
|
+
const sortTrigger = comboboxes(wrapper)[0]!.element;
|
|
1355
|
+
const chipRemove = wrapper.get('[data-part="removeButton"]').element;
|
|
1356
|
+
const clearAll = wrapper
|
|
1357
|
+
.findAll('button')
|
|
1358
|
+
.find((b) => b.text() === enUS.grid.clearAll)!.element;
|
|
1359
|
+
const availabilityBox = availability.get('[role="switch"]').element;
|
|
1360
|
+
const firstCardLink = cards(wrapper)[0]!.get('a').element;
|
|
1361
|
+
const loadMore = wrapper.get('[data-part="button"]').element;
|
|
1362
|
+
|
|
1363
|
+
expect(indexOf(clearAll)).toBeGreaterThan(-1);
|
|
1364
|
+
expect(indexOf(clearAll)).toBeLessThan(indexOf(chipRemove));
|
|
1365
|
+
expect(indexOf(chipRemove)).toBeLessThan(indexOf(availabilityBox));
|
|
1366
|
+
expect(indexOf(availabilityBox)).toBeLessThan(indexOf(filterButton(wrapper).element));
|
|
1367
|
+
expect(indexOf(filterButton(wrapper).element)).toBeLessThan(indexOf(sortTrigger));
|
|
1368
|
+
expect(indexOf(sortTrigger)).toBeLessThan(indexOf(firstCardLink));
|
|
1369
|
+
expect(indexOf(firstCardLink)).toBeLessThan(indexOf(loadMore));
|
|
1370
|
+
});
|
|
1371
|
+
|
|
1372
|
+
it('Space and Enter toggle a group trigger and a checkbox', async () => {
|
|
1373
|
+
const wrapper = mountGrid(mock);
|
|
1374
|
+
await wrapper.vm.$nextTick();
|
|
1375
|
+
const { trigger, panel } = panelFor(wrapper, enUS.grid.legendCategory);
|
|
1376
|
+
|
|
1377
|
+
// A native <button> activates on both keys; the click is what the browser dispatches.
|
|
1378
|
+
await trigger.trigger('click');
|
|
1379
|
+
expect(trigger.attributes('aria-expanded')).toBe('false');
|
|
1380
|
+
await trigger.trigger('click');
|
|
1381
|
+
expect(trigger.attributes('aria-expanded')).toBe('true');
|
|
1382
|
+
|
|
1383
|
+
const box = panel.get('input[type="checkbox"]');
|
|
1384
|
+
expect((box.element as HTMLInputElement).checked).toBe(false);
|
|
1385
|
+
await box.setValue(true);
|
|
1386
|
+
expect(wrapper.get(`ul[aria-label="${enUS.grid.activeFilters}"]`).exists()).toBe(true);
|
|
1387
|
+
});
|
|
1388
|
+
|
|
1389
|
+
it('the sort Select opens with ArrowDown, commits with Enter and re-sorts, and Esc closes it', async () => {
|
|
1390
|
+
const stub = createStub();
|
|
1391
|
+
const wrapper = mountGrid(mock, { source: stub.source, attachTo: document.body });
|
|
1392
|
+
await wrapper.vm.$nextTick();
|
|
1393
|
+
const trigger = comboboxes(wrapper)[0]!;
|
|
1394
|
+
expect(trigger.attributes('aria-expanded')).toBe('false');
|
|
1395
|
+
trigger.element.focus();
|
|
1396
|
+
|
|
1397
|
+
await trigger.trigger('keydown', { key: 'ArrowDown' });
|
|
1398
|
+
expect(trigger.attributes('aria-expanded')).toBe('true');
|
|
1399
|
+
expect(document.querySelector('[role="listbox"]')).toBeTruthy();
|
|
1400
|
+
|
|
1401
|
+
await trigger.trigger('keydown', { key: 'ArrowDown' });
|
|
1402
|
+
await trigger.trigger('keydown', { key: 'Enter' });
|
|
1403
|
+
expect(trigger.attributes('aria-expanded')).toBe('false');
|
|
1404
|
+
expect(trigger.text()).toContain('Best selling');
|
|
1405
|
+
expect(stub.requests.at(-1)?.filters).toBeUndefined();
|
|
1406
|
+
expect(stub.requests.some((request) => request.pageSize === 24)).toBe(true);
|
|
1407
|
+
|
|
1408
|
+
await trigger.trigger('keydown', { key: 'ArrowDown' });
|
|
1409
|
+
expect(trigger.attributes('aria-expanded')).toBe('true');
|
|
1410
|
+
await trigger.trigger('keydown', { key: 'Escape' });
|
|
1411
|
+
expect(trigger.attributes('aria-expanded')).toBe('false');
|
|
1412
|
+
expect(document.activeElement).toBe(trigger.element);
|
|
1413
|
+
expect(trigger.text()).toContain('Best selling');
|
|
1414
|
+
});
|
|
1415
|
+
});
|
|
1416
|
+
|
|
1417
|
+
describe('the storefront route', () => {
|
|
1418
|
+
it('writes every piece of state out through route.setQuery, never a router', async () => {
|
|
1419
|
+
const source = createDemoStorefront();
|
|
1420
|
+
const patches: Array<Record<string, unknown>> = [];
|
|
1421
|
+
const route = {
|
|
1422
|
+
...source.route,
|
|
1423
|
+
setQuery(patch: Record<string, string | string[] | null>) {
|
|
1424
|
+
patches.push(patch);
|
|
1425
|
+
},
|
|
1426
|
+
};
|
|
1427
|
+
const wrapper = mountGrid(mock, { source: { ...source, route } });
|
|
1428
|
+
await wrapper.vm.$nextTick();
|
|
1429
|
+
expect(patches).toHaveLength(0);
|
|
1430
|
+
|
|
1431
|
+
const { panel } = panelFor(wrapper, enUS.grid.legendCategory);
|
|
1432
|
+
await panel.get('input[type="checkbox"]').setValue(true);
|
|
1433
|
+
|
|
1434
|
+
expect(patches).toHaveLength(1);
|
|
1435
|
+
expect(patches[0]).toMatchObject({ page: null, sort: 'featured', category: ['knitwear'] });
|
|
1436
|
+
});
|
|
1437
|
+
|
|
1438
|
+
/**
|
|
1439
|
+
* **The patch is where a colliding option key did its damage**, and it is the only place that can
|
|
1440
|
+
* see this: `publishState` writes the option keys *after* the four keys it always writes, so a
|
|
1441
|
+
* source whose query key belongs to something else lands last and wins.
|
|
1442
|
+
*
|
|
1443
|
+
* A store with an option keyed `sort` therefore stripped the shopper's sort out of the URL on
|
|
1444
|
+
* every state write — any filter toggle, a column change, removing a chip, Clear all — so a shared
|
|
1445
|
+
* link fell back to the default sort and the back button lost it. One keyed `category` cleared the
|
|
1446
|
+
* category they had just ticked, which `adoptRouteState` then read back as absent, reverting the
|
|
1447
|
+
* tick on screen.
|
|
1448
|
+
*
|
|
1449
|
+
* Refusing the key where it is *read* (the author's row, the URL, the groups) left all of that
|
|
1450
|
+
* intact, and a test asserting the absent group passed straight over it — which is why this one
|
|
1451
|
+
* asserts the patch.
|
|
1452
|
+
*/
|
|
1453
|
+
it('never writes an option key that belongs to another filter or to the route', async () => {
|
|
1454
|
+
const source = createDemoStorefront();
|
|
1455
|
+
const patches: Array<Record<string, unknown>> = [];
|
|
1456
|
+
const route = {
|
|
1457
|
+
...source.route,
|
|
1458
|
+
setQuery(patch: Record<string, string | string[] | null>) {
|
|
1459
|
+
patches.push(patch);
|
|
1460
|
+
},
|
|
1461
|
+
};
|
|
1462
|
+
const catalog: StorefrontCatalog = {
|
|
1463
|
+
...source.catalog,
|
|
1464
|
+
collectionProducts(collection, opts) {
|
|
1465
|
+
const result = source.catalog.collectionProducts(collection, opts);
|
|
1466
|
+
// Two option keys the grid and the page already own — `sort` is the route's, `category` is
|
|
1467
|
+
// a filter source's — beside one that is really the store's.
|
|
1468
|
+
const data = computed(() => {
|
|
1469
|
+
const answer = result.data.value;
|
|
1470
|
+
if (answer?.facets === undefined) return answer;
|
|
1471
|
+
return {
|
|
1472
|
+
...answer,
|
|
1473
|
+
facets: {
|
|
1474
|
+
...answer.facets,
|
|
1475
|
+
options: [
|
|
1476
|
+
{
|
|
1477
|
+
key: 'sort',
|
|
1478
|
+
name: 'Sort',
|
|
1479
|
+
kind: 'none',
|
|
1480
|
+
values: [{ value: 'y', label: 'Y', count: 2 }],
|
|
1481
|
+
},
|
|
1482
|
+
{
|
|
1483
|
+
key: 'category',
|
|
1484
|
+
name: 'Kind',
|
|
1485
|
+
kind: 'none',
|
|
1486
|
+
values: [{ value: 'z', label: 'Z', count: 2 }],
|
|
1487
|
+
},
|
|
1488
|
+
...answer.facets.options,
|
|
1489
|
+
],
|
|
1490
|
+
},
|
|
1491
|
+
};
|
|
1492
|
+
});
|
|
1493
|
+
return { ...result, data };
|
|
1494
|
+
},
|
|
1495
|
+
};
|
|
1496
|
+
const wrapper = mountGrid(
|
|
1497
|
+
{ ...mock, filters: [{ source: 'category', label: 'Category' }, { source: 'options' }] },
|
|
1498
|
+
{ source: { ...source, route, catalog } }
|
|
1499
|
+
);
|
|
1500
|
+
await wrapper.vm.$nextTick();
|
|
1501
|
+
await flushPromises();
|
|
1502
|
+
|
|
1503
|
+
await panelFor(wrapper, enUS.grid.legendCategory)
|
|
1504
|
+
.panel.get('input[type="checkbox"]')
|
|
1505
|
+
.setValue(true);
|
|
1506
|
+
|
|
1507
|
+
expect(patches).toHaveLength(1);
|
|
1508
|
+
// The shopper's sort survives and the category they ticked reaches the URL — neither key was
|
|
1509
|
+
// overwritten by an option of the same name.
|
|
1510
|
+
expect(patches[0]).toMatchObject({ sort: 'featured', category: ['knitwear'] });
|
|
1511
|
+
// And the price range is still the one string the price control writes, never a selection list.
|
|
1512
|
+
expect(patches[0]!.price).toBeNull();
|
|
1513
|
+
});
|
|
1514
|
+
|
|
1515
|
+
it('reads the current page back from the route for the pages style', async () => {
|
|
1516
|
+
const source = createDemoStorefront();
|
|
1517
|
+
source.route.page = 3;
|
|
1518
|
+
const wrapper = mountGrid({ ...mock, paginationStyle: 'pages', pageSize: '12' }, { source });
|
|
1519
|
+
await wrapper.vm.$nextTick();
|
|
1520
|
+
expect(wrapper.get('[aria-current="page"]').text()).toBe('3');
|
|
1521
|
+
});
|
|
1522
|
+
|
|
1523
|
+
it('restores filters, sort and columns from a seeded route — a shared URL restores the whole grid state', async () => {
|
|
1524
|
+
const source = createDemoStorefront();
|
|
1525
|
+
source.route.filters = { category: ['knitwear'], size: ['m'] };
|
|
1526
|
+
source.route.sort = 'price-asc';
|
|
1527
|
+
source.route.columns = '2';
|
|
1528
|
+
const wrapper = mountGrid(mock, { source });
|
|
1529
|
+
await wrapper.vm.$nextTick();
|
|
1530
|
+
|
|
1531
|
+
const chips = wrapper.get(`ul[aria-label="${enUS.grid.activeFilters}"]`);
|
|
1532
|
+
expect(chips.text()).toContain('Knitwear');
|
|
1533
|
+
expect(chips.text()).toContain('M');
|
|
1534
|
+
|
|
1535
|
+
const [topBarSort, toolbarSort, columnsSelect] = comboboxes(wrapper);
|
|
1536
|
+
expect(topBarSort!.text()).toContain('Price low to high');
|
|
1537
|
+
expect(toolbarSort!.text()).toContain('Price low to high');
|
|
1538
|
+
expect(columnsSelect!.text()).toContain('2');
|
|
1539
|
+
});
|
|
1540
|
+
|
|
1541
|
+
it('ignores a seeded route sort that is not one of the block’s own sort options', async () => {
|
|
1542
|
+
const source = createDemoStorefront();
|
|
1543
|
+
source.route.sort = 'not-a-real-option';
|
|
1544
|
+
const wrapper = mountGrid(mock, { source });
|
|
1545
|
+
await wrapper.vm.$nextTick();
|
|
1546
|
+
// Falls back to the first configured option, same as no seed at all.
|
|
1547
|
+
expect(comboboxes(wrapper)[1]!.text()).toContain('Featured');
|
|
1548
|
+
});
|
|
1549
|
+
});
|
|
1550
|
+
|
|
1551
|
+
describe('one sort control per width', () => {
|
|
1552
|
+
// Container queries are invisible to jsdom, so this is a class assertion — the same shape the
|
|
1553
|
+
// Columns one above uses. Both bands render a sort `Select` (they differ in size, placement and
|
|
1554
|
+
// whether the label is visible), and exactly one of the two is ever displayed: the top bar's is
|
|
1555
|
+
// hidden from 64rem in *both* variants, and the toolbar's only appears from 64rem.
|
|
1556
|
+
it.each(['sidebar', 'drawer-only'])(
|
|
1557
|
+
'shows the top bar sort below 64rem and the toolbar sort from 64rem, never both (%s)',
|
|
1558
|
+
async (variant) => {
|
|
1559
|
+
const wrapper = mountGrid({ ...mock, variant });
|
|
1560
|
+
await wrapper.vm.$nextTick();
|
|
1561
|
+
|
|
1562
|
+
const sortLabels = wrapper
|
|
1563
|
+
.findAll('label')
|
|
1564
|
+
.filter((label) => label.text() === enUS.grid.sortBy);
|
|
1565
|
+
expect(sortLabels).toHaveLength(2);
|
|
1566
|
+
expect(comboboxes(wrapper)).toHaveLength(3); // two sorts, one Columns
|
|
1567
|
+
|
|
1568
|
+
const topBarSort = sortLabels[0]!.element.closest('[data-part="root"]') as HTMLElement;
|
|
1569
|
+
expect(topBarSort.className).toContain('@content:hidden');
|
|
1570
|
+
|
|
1571
|
+
const toolbarSort = sortLabels[1]!.element.closest('div.hidden') as HTMLElement;
|
|
1572
|
+
expect(toolbarSort.className).toContain('@content:flex');
|
|
1573
|
+
|
|
1574
|
+
// The Filter button's own bar goes from 64rem only where a sidebar takes over.
|
|
1575
|
+
const topBar = filterButton(wrapper).element.parentElement!;
|
|
1576
|
+
if (variant === 'sidebar') expect(topBar.className).toContain('@content:hidden');
|
|
1577
|
+
else expect(topBar.className).not.toContain('@content:hidden');
|
|
1578
|
+
}
|
|
1579
|
+
);
|
|
1580
|
+
});
|
|
1581
|
+
|
|
1582
|
+
describe('package messages', () => {
|
|
1583
|
+
/**
|
|
1584
|
+
* The app provides `@eldrajs/ui`'s messages as an object of *getters* over `preview.locale`
|
|
1585
|
+
* (`app/plugins/eldra-ui-messages.ts`), which is what makes a Studio locale switch reach the
|
|
1586
|
+
* package's own strings. The block re-provides that set with `removeTag` replaced, so it has to
|
|
1587
|
+
* read through rather than snapshot — a spread would freeze every package string in the block's
|
|
1588
|
+
* subtree at the mount-time locale while the block's own `useI18n()` strings kept switching.
|
|
1589
|
+
*/
|
|
1590
|
+
it('follows a locale switch for both package strings and the block’s own', async () => {
|
|
1591
|
+
useFilterTimers();
|
|
1592
|
+
const context = {
|
|
1593
|
+
client: {},
|
|
1594
|
+
designTokens: { colors: {} },
|
|
1595
|
+
preview: createEldraPreviewState(),
|
|
1596
|
+
};
|
|
1597
|
+
context.preview.locale = 'en-US';
|
|
1598
|
+
const messages = {} as UiMessages;
|
|
1599
|
+
for (const key of Object.keys(uiEnUS) as Array<keyof UiMessages>) {
|
|
1600
|
+
Object.defineProperty(messages, key, {
|
|
1601
|
+
enumerable: true,
|
|
1602
|
+
get: () => (context.preview.locale === 'is-IS' ? uiIsIS : uiEnUS)[key],
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
// The block's own strings follow the same `context.preview.locale` the hand-built package
|
|
1607
|
+
// `messages` getters above read — `app/plugins/eldra-i18n.ts`'s own wiring, reproduced here
|
|
1608
|
+
// since this spec provides its own `EldraContext` rather than `mountOptions`' default one.
|
|
1609
|
+
const i18n = createI18n({
|
|
1610
|
+
legacy: false,
|
|
1611
|
+
locale: context.preview.locale,
|
|
1612
|
+
fallbackLocale: 'en-US',
|
|
1613
|
+
messages: { 'en-US': enUS, 'is-IS': isIS },
|
|
1614
|
+
});
|
|
1615
|
+
watch(
|
|
1616
|
+
() => context.preview.locale,
|
|
1617
|
+
(locale) => {
|
|
1618
|
+
i18n.global.locale.value = locale ?? 'en-US';
|
|
1619
|
+
}
|
|
1620
|
+
);
|
|
1621
|
+
|
|
1622
|
+
const base = mountOptions({ entry: { id: 'e1', data: mock } });
|
|
1623
|
+
const wrapper = mount(Block, {
|
|
1624
|
+
...base,
|
|
1625
|
+
global: {
|
|
1626
|
+
...base.global,
|
|
1627
|
+
plugins: [i18n],
|
|
1628
|
+
provide: {
|
|
1629
|
+
...base.global.provide,
|
|
1630
|
+
[ELDRA_KEY]: context,
|
|
1631
|
+
[MESSAGES_KEY]: messages,
|
|
1632
|
+
// The store's currency is not re-provided: it does not follow the locale switch this
|
|
1633
|
+
// spec is about — it is the platform's, fixed for the life of the page — so
|
|
1634
|
+
// `mountOptions`' own provide (spread above) stands.
|
|
1635
|
+
[LOCALE_KEY]: () => context.preview.locale ?? undefined,
|
|
1636
|
+
},
|
|
1637
|
+
},
|
|
1638
|
+
});
|
|
1639
|
+
wrappers.push(wrapper);
|
|
1640
|
+
await wrapper.vm.$nextTick();
|
|
1641
|
+
|
|
1642
|
+
const sizes = panelFor(wrapper, enUS.grid.legendSize).panel;
|
|
1643
|
+
await sizes.findAll('input[type="checkbox"]')[2]!.setValue(true);
|
|
1644
|
+
await settleFilterDebounce(wrapper);
|
|
1645
|
+
// The demo source answers through its own `async load()`, so the window expiring is only
|
|
1646
|
+
// half of it: the read it releases still has to resolve before the line below is the
|
|
1647
|
+
// filtered one.
|
|
1648
|
+
await flushPromises();
|
|
1649
|
+
|
|
1650
|
+
const removeLabel = () =>
|
|
1651
|
+
wrapper.get('[data-part="removeButton"]').attributes('aria-label') ?? '';
|
|
1652
|
+
// A package string the block never writes itself: `LoadMore`'s own "Showing N of M" line.
|
|
1653
|
+
const loadMoreLine = () => wrapper.get('[data-part="status"]').text();
|
|
1654
|
+
|
|
1655
|
+
// 12 of the demo collection's 48 items are made in size M (the three apparel products, each
|
|
1656
|
+
// appearing four times — `app/storefront/demo.ts`), and the demo source honours `filters`
|
|
1657
|
+
// now, so both the package's "Showing N of M" line and the block's own count read the
|
|
1658
|
+
// *filtered* set. Before that, ticking a filter left these at 24 of 48 / 48 products.
|
|
1659
|
+
expect(removeLabel()).toBe('Remove filter Size: M');
|
|
1660
|
+
expect(loadMoreLine()).toContain('Showing 12 of 12');
|
|
1661
|
+
expect(countLine(wrapper).text()).toBe('12 products');
|
|
1662
|
+
|
|
1663
|
+
context.preview.locale = 'is-IS';
|
|
1664
|
+
await wrapper.vm.$nextTick();
|
|
1665
|
+
|
|
1666
|
+
// `mock.json`'s `options` row carries no label of its own, so the facet's title is the
|
|
1667
|
+
// theme's own string for that option key, fed into `@eldrajs/ui`'s own is-IS
|
|
1668
|
+
// `filterPanelRemoveFilter` message (the remove button is the panel's own now, not the
|
|
1669
|
+
// block's) — which is exactly what has to follow the switch. (An author who types a label
|
|
1670
|
+
// into an explicit `option:size` row gets that label in both locales, since a string a
|
|
1671
|
+
// merchant wrote is not the theme's to translate.)
|
|
1672
|
+
expect(removeLabel()).toBe(`Fjarlægja síu ${isIS.grid.legendSize}: M`);
|
|
1673
|
+
expect(loadMoreLine()).toContain('Sýni 12 af 12');
|
|
1674
|
+
expect(countLine(wrapper).text()).toBe(isIS.grid.nProducts.replace('{count}', '12'));
|
|
1675
|
+
});
|
|
1676
|
+
});
|
|
1677
|
+
|
|
1678
|
+
/**
|
|
1679
|
+
* A store whose stock cannot be read answers **no** `availability` facet rather than two zeroes
|
|
1680
|
+
* (`CatalogFacets.availability`). The group it feeds is dropped, because the alternative is
|
|
1681
|
+
* offering a shopper two counts nobody can stand behind — and a request carrying an availability
|
|
1682
|
+
* filter in that state is an error, not an empty page. Every other group still draws.
|
|
1683
|
+
*/
|
|
1684
|
+
describe('a store whose stock cannot be read', () => {
|
|
1685
|
+
const noStock: CatalogFacets = { ...FACETS };
|
|
1686
|
+
delete noStock.availability;
|
|
1687
|
+
|
|
1688
|
+
it('drops the availability group and keeps the rest of the panel', async () => {
|
|
1689
|
+
const stub = createStub(PRODUCTS, { facets: noStock });
|
|
1690
|
+
const wrapper = mountGrid(mock, { source: stub.source });
|
|
1691
|
+
await wrapper.vm.$nextTick();
|
|
1692
|
+
|
|
1693
|
+
// The sidebar and the drawer draw the same groups, so each legend appears twice.
|
|
1694
|
+
const legends = [
|
|
1695
|
+
...new Set(
|
|
1696
|
+
groupTriggers(wrapper).map((trigger) =>
|
|
1697
|
+
wrapper
|
|
1698
|
+
.get(`#${trigger.attributes('aria-controls')!}`)
|
|
1699
|
+
.get('legend')
|
|
1700
|
+
.text()
|
|
1701
|
+
)
|
|
1702
|
+
),
|
|
1703
|
+
];
|
|
1704
|
+
expect(legends).not.toContain(enUS.grid.legendAvailability);
|
|
1705
|
+
expect(legends).toEqual([
|
|
1706
|
+
enUS.grid.legendCategory,
|
|
1707
|
+
enUS.grid.legendSize,
|
|
1708
|
+
enUS.grid.legendColour,
|
|
1709
|
+
PRICE_LEGEND,
|
|
1710
|
+
]);
|
|
1711
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
1712
|
+
});
|
|
1713
|
+
});
|
|
1714
|
+
|
|
1715
|
+
/**
|
|
1716
|
+
* **A group whose scope cannot narrow by it is not offered**
|
|
1717
|
+
* (`StorefrontCollectionProducts.unfilterable`).
|
|
1718
|
+
*
|
|
1719
|
+
* Counting a family and filtering on it are different capabilities: the platform reports which
|
|
1720
|
+
* other collections a collection's products are also in, but has no parameter for the
|
|
1721
|
+
* intersection, so the `collection` group would draw real counts and then change the chips, the
|
|
1722
|
+
* URL and nothing else. The storefront says which sources its scope cannot honour and the panel
|
|
1723
|
+
* drops those groups — the author's `filters[]` row included, because an author cannot know which
|
|
1724
|
+
* scope their grid will be read in. A scope that honours the source keeps it.
|
|
1725
|
+
*/
|
|
1726
|
+
/**
|
|
1727
|
+
* **A scope the platform could not span leaves `price` out of its facets**, which is a different
|
|
1728
|
+
* answer from a span of 0 to 0: the control then falls back to the widest span this block has seen
|
|
1729
|
+
* for the collection (`loadedPriceSpan`). Written as a 0–0 span instead, the track is dead and both
|
|
1730
|
+
* fields read `$0.00` — and the fallback is wiped at the same time, because it only runs while the
|
|
1731
|
+
* facets have no span of their own.
|
|
1732
|
+
*/
|
|
1733
|
+
describe('facets with no price span', () => {
|
|
1734
|
+
const noPrice: CatalogFacets = { ...FACETS };
|
|
1735
|
+
delete noPrice.price;
|
|
1736
|
+
|
|
1737
|
+
/**
|
|
1738
|
+
* The loaded products' own span, which is what the control falls back to — written the way the
|
|
1739
|
+
* fields write it: `CurrencyInput` over the theme's whole-unit price grammar, so no fraction
|
|
1740
|
+
* digits — unlike the theme's own `formatMoney`, which keeps the currency's and is what the
|
|
1741
|
+
* chips and `<Price>` read.
|
|
1742
|
+
*/
|
|
1743
|
+
const amounts = PRODUCTS.map((item) => item.price.amount);
|
|
1744
|
+
const loadedSpan = [`$${Math.min(...amounts)}`, `$${Math.max(...amounts)}`];
|
|
1745
|
+
|
|
1746
|
+
it('spans the loaded products rather than nothing at all', async () => {
|
|
1747
|
+
const stub = createStub(PRODUCTS, { facets: noPrice });
|
|
1748
|
+
const wrapper = mountGrid(mock, { source: stub.source });
|
|
1749
|
+
await wrapper.vm.$nextTick();
|
|
1750
|
+
|
|
1751
|
+
const fields = wrapper
|
|
1752
|
+
.findAll('input[data-input]')
|
|
1753
|
+
.map((input) => (input.element as HTMLInputElement).value);
|
|
1754
|
+
// The sidebar's pair, then the drawer's copy of it. The fields are `CurrencyInput`s over the
|
|
1755
|
+
// theme's whole-unit price grammar, so they show the amount with no fraction digits — the
|
|
1756
|
+
// chips and `<Price>` keep the currency's own fraction digits.
|
|
1757
|
+
expect(fields).toEqual([...loadedSpan, ...loadedSpan]);
|
|
1758
|
+
expect(fields).not.toContain('$0');
|
|
1759
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
1760
|
+
});
|
|
1761
|
+
});
|
|
1762
|
+
|
|
1763
|
+
describe('a filter source the scope cannot narrow by', () => {
|
|
1764
|
+
const WITH_COLLECTION = {
|
|
1765
|
+
...mock,
|
|
1766
|
+
filters: [
|
|
1767
|
+
{ source: 'category', label: 'Category' },
|
|
1768
|
+
{ source: 'collection', label: 'Collection' },
|
|
1769
|
+
{ source: 'price', label: 'Price' },
|
|
1770
|
+
],
|
|
1771
|
+
};
|
|
1772
|
+
|
|
1773
|
+
const legendsOf = (wrapper: VueWrapper) => [
|
|
1774
|
+
...new Set(
|
|
1775
|
+
groupTriggers(wrapper).map((trigger) =>
|
|
1776
|
+
wrapper
|
|
1777
|
+
.get(`#${trigger.attributes('aria-controls')!}`)
|
|
1778
|
+
.get('legend')
|
|
1779
|
+
.text()
|
|
1780
|
+
)
|
|
1781
|
+
),
|
|
1782
|
+
];
|
|
1783
|
+
|
|
1784
|
+
it('keeps the group in a scope that honours it', async () => {
|
|
1785
|
+
useFilterTimers();
|
|
1786
|
+
const stub = createStub();
|
|
1787
|
+
const wrapper = mountGrid(WITH_COLLECTION, { source: stub.source });
|
|
1788
|
+
await wrapper.vm.$nextTick();
|
|
1789
|
+
|
|
1790
|
+
expect(legendsOf(wrapper)).toEqual([
|
|
1791
|
+
enUS.grid.legendCategory,
|
|
1792
|
+
enUS.grid.legendCollection,
|
|
1793
|
+
PRICE_LEGEND,
|
|
1794
|
+
]);
|
|
1795
|
+
// And it filters: ticking a value reaches the request, once its own debounce settles.
|
|
1796
|
+
const { panel } = panelFor(wrapper, enUS.grid.legendCollection);
|
|
1797
|
+
await panel.get('input[type="checkbox"]').setValue(true);
|
|
1798
|
+
await settleFilterDebounce(wrapper);
|
|
1799
|
+
expect(stub.requests.at(-1)?.filters?.collection).toEqual(['the-winter-edit']);
|
|
1800
|
+
});
|
|
1801
|
+
|
|
1802
|
+
it('drops the group, and its chip, in a scope that cannot', async () => {
|
|
1803
|
+
const stub = createStub(PRODUCTS, { unfilterable: ['collection'] });
|
|
1804
|
+
const wrapper = mountGrid(WITH_COLLECTION, { source: stub.source });
|
|
1805
|
+
await wrapper.vm.$nextTick();
|
|
1806
|
+
|
|
1807
|
+
expect(legendsOf(wrapper)).toEqual([enUS.grid.legendCategory, PRICE_LEGEND]);
|
|
1808
|
+
expect(wrapper.text()).not.toContain('Collection');
|
|
1809
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
1810
|
+
});
|
|
1811
|
+
|
|
1812
|
+
/**
|
|
1813
|
+
* A shared link can still carry the key — the source is filterable in another scope, so neither
|
|
1814
|
+
* the request nor the query string is rewritten — and the chip is what would otherwise promise
|
|
1815
|
+
* a filter this scope ignores.
|
|
1816
|
+
*/
|
|
1817
|
+
it('shows no chip for a value a shared link carries for it', async () => {
|
|
1818
|
+
const stub = createStub(PRODUCTS, { filteredCount: 4, unfilterable: ['collection'] });
|
|
1819
|
+
const source: StorefrontSource = {
|
|
1820
|
+
...stub.source,
|
|
1821
|
+
route: { ...stub.source.route, filters: { collection: ['the-winter-edit'] } },
|
|
1822
|
+
};
|
|
1823
|
+
const wrapper = mountGrid(WITH_COLLECTION, { source });
|
|
1824
|
+
await wrapper.vm.$nextTick();
|
|
1825
|
+
|
|
1826
|
+
expect(wrapper.find(`ul[aria-label="${enUS.grid.activeFilters}"]`).exists()).toBe(false);
|
|
1827
|
+
expect(filterButton(wrapper).find('[data-part="hiddenSuffix"]').exists()).toBe(false);
|
|
1828
|
+
// Still sent — this stub answers a filtered request with four of the twelve — because the
|
|
1829
|
+
// storefront that declared the source unfilterable is the one already ignoring it, and the
|
|
1830
|
+
// key is meaningful in a scope that can honour it.
|
|
1831
|
+
expect(cards(wrapper)).toHaveLength(4);
|
|
1832
|
+
});
|
|
1833
|
+
});
|
|
1834
|
+
|
|
1835
|
+
/**
|
|
1836
|
+
* **A "Sort by" option the scope cannot honour is dropped the same way** (`StorefrontCollectionProducts.unsortable`).
|
|
1837
|
+
* `mock.json` seeds `best-selling` alongside `featured`/`price-asc`/`price-desc`/`newest`; the
|
|
1838
|
+
* platform gateway reads no sales data to order by, so a storefront built on it declares the id
|
|
1839
|
+
* rather than leaving a control that moves the selected value and the URL and changes nothing in
|
|
1840
|
+
* the grid.
|
|
1841
|
+
*/
|
|
1842
|
+
describe('a sort id the scope cannot honour', () => {
|
|
1843
|
+
const optionLabels = () =>
|
|
1844
|
+
[...document.querySelectorAll('[role="option"]')].map((el) => el.textContent?.trim());
|
|
1845
|
+
|
|
1846
|
+
it('offers it in a scope that honours it (the demo)', async () => {
|
|
1847
|
+
const stub = createStub();
|
|
1848
|
+
const wrapper = mountGrid(mock, { source: stub.source, attachTo: document.body });
|
|
1849
|
+
await wrapper.vm.$nextTick();
|
|
1850
|
+
const trigger = comboboxes(wrapper)[0]!;
|
|
1851
|
+
trigger.element.focus();
|
|
1852
|
+
await trigger.trigger('keydown', { key: 'ArrowDown' });
|
|
1853
|
+
|
|
1854
|
+
expect(optionLabels()).toEqual([
|
|
1855
|
+
'Featured',
|
|
1856
|
+
'Best selling',
|
|
1857
|
+
'Price low to high',
|
|
1858
|
+
'Price high to low',
|
|
1859
|
+
'Newest',
|
|
1860
|
+
]);
|
|
1861
|
+
});
|
|
1862
|
+
|
|
1863
|
+
it('drops it, and the author’s own row for it, in a scope that cannot', async () => {
|
|
1864
|
+
const stub = createStub(PRODUCTS, { unsortable: ['best-selling'] });
|
|
1865
|
+
const wrapper = mountGrid(mock, { source: stub.source, attachTo: document.body });
|
|
1866
|
+
await wrapper.vm.$nextTick();
|
|
1867
|
+
const trigger = comboboxes(wrapper)[0]!;
|
|
1868
|
+
trigger.element.focus();
|
|
1869
|
+
await trigger.trigger('keydown', { key: 'ArrowDown' });
|
|
1870
|
+
|
|
1871
|
+
expect(optionLabels()).toEqual([
|
|
1872
|
+
'Featured',
|
|
1873
|
+
'Price low to high',
|
|
1874
|
+
'Price high to low',
|
|
1875
|
+
'Newest',
|
|
1876
|
+
]);
|
|
1877
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
1878
|
+
});
|
|
1879
|
+
|
|
1880
|
+
/** The same fallback a `route.sort` this block never configured already takes — see "ignores a
|
|
1881
|
+
* seeded route sort that is not one of the block's own sort options" above. */
|
|
1882
|
+
it('falls back to the first remaining option when a shared URL names it', async () => {
|
|
1883
|
+
const stub = createStub(PRODUCTS, { unsortable: ['best-selling'] });
|
|
1884
|
+
const source: StorefrontSource = {
|
|
1885
|
+
...stub.source,
|
|
1886
|
+
route: { ...stub.source.route, sort: 'best-selling' },
|
|
1887
|
+
};
|
|
1888
|
+
const wrapper = mountGrid(mock, { source });
|
|
1889
|
+
await wrapper.vm.$nextTick();
|
|
1890
|
+
|
|
1891
|
+
expect(comboboxes(wrapper)[1]!.text()).toContain('Featured');
|
|
1892
|
+
expect(stub.requests.some((request) => request.sort === 'best-selling')).toBe(false);
|
|
1893
|
+
});
|
|
1894
|
+
|
|
1895
|
+
/**
|
|
1896
|
+
* The end of that same fallback: an author whose only configured row is an id this scope
|
|
1897
|
+
* declares unsortable leaves nothing to fall back *to*. The control is hidden either way, so
|
|
1898
|
+
* the only thing left to get right is the request — it must stop carrying the id the same
|
|
1899
|
+
* answer just said cannot be honoured, exactly as the configured-list settling does for an id
|
|
1900
|
+
* this block never configured at all.
|
|
1901
|
+
*/
|
|
1902
|
+
it('sends no sort at all when the scope can honour none of the configured options', async () => {
|
|
1903
|
+
const stub = createStub(PRODUCTS, { unsortable: ['best-selling'] });
|
|
1904
|
+
const wrapper = mountGrid(
|
|
1905
|
+
{ ...mock, sortOptions: [{ option: 'best-selling', label: 'Best selling' }] },
|
|
1906
|
+
{ source: stub.source }
|
|
1907
|
+
);
|
|
1908
|
+
await wrapper.vm.$nextTick();
|
|
1909
|
+
await flushPromises();
|
|
1910
|
+
|
|
1911
|
+
// No Sort control is drawn — only the Columns select is left.
|
|
1912
|
+
expect(comboboxes(wrapper)).toHaveLength(1);
|
|
1913
|
+
// The scope's answer really did reach the request: the read was re-issued *because* the id
|
|
1914
|
+
// was dropped, and the re-issued one carries no sort at all. `requests` records changes, not
|
|
1915
|
+
// the first value, so an id left in place would leave it empty rather than wrong — which is
|
|
1916
|
+
// why the length is asserted beside the value.
|
|
1917
|
+
expect(stub.requests.length).toBeGreaterThan(0);
|
|
1918
|
+
expect(stub.requests.at(-1)!.sort).toBeUndefined();
|
|
1919
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
1920
|
+
});
|
|
1921
|
+
});
|
|
1922
|
+
|
|
1923
|
+
/**
|
|
1924
|
+
* **`options`** — one `filters[]` row standing for every variant option the store has, labelled and
|
|
1925
|
+
* ordered by the store itself. It exists because a merchant's option keys are theirs, not the
|
|
1926
|
+
* theme's: an author cannot list `option:size`/`option:colour` by hand without knowing what the
|
|
1927
|
+
* store sells by, and a store that adds `fabric` next season would otherwise need the page edited
|
|
1928
|
+
* before shoppers could filter by it.
|
|
1929
|
+
*/
|
|
1930
|
+
describe('the `options` filter source', () => {
|
|
1931
|
+
/** Three option keys, one of them not in this theme's own strings and one with nothing in it. */
|
|
1932
|
+
const THREE_OPTIONS: CatalogFacets = {
|
|
1933
|
+
...FACETS,
|
|
1934
|
+
options: [
|
|
1935
|
+
{
|
|
1936
|
+
key: 'size',
|
|
1937
|
+
name: 'size',
|
|
1938
|
+
kind: 'none',
|
|
1939
|
+
values: [{ value: 'm', label: 'M', count: 4 }],
|
|
1940
|
+
},
|
|
1941
|
+
{
|
|
1942
|
+
key: 'fabric',
|
|
1943
|
+
name: 'Fabric',
|
|
1944
|
+
kind: 'custom',
|
|
1945
|
+
metadata: 'fabric',
|
|
1946
|
+
values: [
|
|
1947
|
+
{ value: 'linen', label: 'Linen', count: 7 },
|
|
1948
|
+
{ value: 'wool', label: 'Wool', count: 2 },
|
|
1949
|
+
],
|
|
1950
|
+
},
|
|
1951
|
+
{
|
|
1952
|
+
key: 'colour',
|
|
1953
|
+
name: 'colour',
|
|
1954
|
+
values: [{ value: 'oat', label: 'Oat', count: 9, swatch: '#d8cbb0' }],
|
|
1955
|
+
},
|
|
1956
|
+
// A key the store names but has no values for — nothing to offer, so no group.
|
|
1957
|
+
{ key: 'finish', name: 'Finish', values: [] },
|
|
1958
|
+
],
|
|
1959
|
+
};
|
|
1960
|
+
|
|
1961
|
+
const WITH_OPTIONS = {
|
|
1962
|
+
...mock,
|
|
1963
|
+
filters: [{ source: 'category', label: 'Category' }, { source: 'options' }],
|
|
1964
|
+
};
|
|
1965
|
+
|
|
1966
|
+
/** The group titles in the sidebar, in order. */
|
|
1967
|
+
function sidebarLabels(wrapper: VueWrapper): string[] {
|
|
1968
|
+
return wrapper
|
|
1969
|
+
.get('aside')
|
|
1970
|
+
.findAll('h3 button')
|
|
1971
|
+
.map((button) => button.find('span').text());
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
it('draws one group per option key the facets answer, in their order', async () => {
|
|
1975
|
+
const stub = createStub(PRODUCTS, { facets: THREE_OPTIONS });
|
|
1976
|
+
const wrapper = mountGrid(WITH_OPTIONS, { source: stub.source });
|
|
1977
|
+
await wrapper.vm.$nextTick();
|
|
1978
|
+
// Size and Colour by this theme's own strings (the two keys it has words for), `Fabric` by the
|
|
1979
|
+
// store's own facet name — the only place a merchant's option name exists.
|
|
1980
|
+
expect(sidebarLabels(wrapper)).toEqual([
|
|
1981
|
+
'Category',
|
|
1982
|
+
enUS.grid.legendSize,
|
|
1983
|
+
'Fabric',
|
|
1984
|
+
enUS.grid.legendColour,
|
|
1985
|
+
]);
|
|
1986
|
+
});
|
|
1987
|
+
|
|
1988
|
+
it('draws no group for an option key with no values', async () => {
|
|
1989
|
+
const stub = createStub(PRODUCTS, { facets: THREE_OPTIONS });
|
|
1990
|
+
const wrapper = mountGrid(WITH_OPTIONS, { source: stub.source });
|
|
1991
|
+
await wrapper.vm.$nextTick();
|
|
1992
|
+
expect(sidebarLabels(wrapper)).not.toContain('Finish');
|
|
1993
|
+
});
|
|
1994
|
+
|
|
1995
|
+
/** Swatches are a colour the store sent as data, and the dot is the only control that can show
|
|
1996
|
+
* one — so an option carrying them is a colour group whatever it is keyed. */
|
|
1997
|
+
it('draws a swatch option as colour dots and the rest as pills', async () => {
|
|
1998
|
+
const stub = createStub(PRODUCTS, { facets: THREE_OPTIONS });
|
|
1999
|
+
const wrapper = mountGrid(WITH_OPTIONS, { source: stub.source });
|
|
2000
|
+
await wrapper.vm.$nextTick();
|
|
2001
|
+
const colour = panelFor(wrapper, enUS.grid.legendColour).panel;
|
|
2002
|
+
expect(colour.find('[data-part="swatch"]').exists()).toBe(true);
|
|
2003
|
+
const fabric = panelFor(wrapper, 'Fabric').panel;
|
|
2004
|
+
expect(fabric.find('[data-part="swatch"]').exists()).toBe(false);
|
|
2005
|
+
expect(fabric.findAll('input[type="checkbox"]')).toHaveLength(2);
|
|
2006
|
+
});
|
|
2007
|
+
|
|
2008
|
+
/**
|
|
2009
|
+
* An explicit row **wins** for its key: that is how an author pins one option's position in the
|
|
2010
|
+
* panel or renames its group, while `options` still covers everything else the store sells by.
|
|
2011
|
+
*/
|
|
2012
|
+
it('lets an explicit option row override the label and the position', async () => {
|
|
2013
|
+
const stub = createStub(PRODUCTS, { facets: THREE_OPTIONS });
|
|
2014
|
+
const wrapper = mountGrid(
|
|
2015
|
+
{
|
|
2016
|
+
...mock,
|
|
2017
|
+
filters: [
|
|
2018
|
+
{ source: 'option:fabric', label: 'Material' },
|
|
2019
|
+
{ source: 'category', label: 'Category' },
|
|
2020
|
+
{ source: 'options' },
|
|
2021
|
+
],
|
|
2022
|
+
},
|
|
2023
|
+
{ source: stub.source }
|
|
2024
|
+
);
|
|
2025
|
+
await wrapper.vm.$nextTick();
|
|
2026
|
+
expect(sidebarLabels(wrapper)).toEqual([
|
|
2027
|
+
'Material',
|
|
2028
|
+
'Category',
|
|
2029
|
+
enUS.grid.legendSize,
|
|
2030
|
+
enUS.grid.legendColour,
|
|
2031
|
+
]);
|
|
2032
|
+
});
|
|
2033
|
+
|
|
2034
|
+
/** `?colour=oat&size=m` — the same bare-key URL the explicit sources always wrote, both ways. */
|
|
2035
|
+
it('round-trips every option key through the query string', async () => {
|
|
2036
|
+
const source = createDemoStorefront({ filters: { colour: ['oat'], size: ['m'] } });
|
|
2037
|
+
const wrapper = mountGrid(WITH_OPTIONS, { source });
|
|
2038
|
+
await wrapper.vm.$nextTick();
|
|
2039
|
+
await flushPromises();
|
|
2040
|
+
await wrapper.vm.$nextTick();
|
|
2041
|
+
|
|
2042
|
+
const ticked = (legend: string) =>
|
|
2043
|
+
panelFor(wrapper, legend)
|
|
2044
|
+
.panel.findAll('input[type="checkbox"]')
|
|
2045
|
+
.filter((box) => (box.element as HTMLInputElement).checked).length;
|
|
2046
|
+
expect(ticked(enUS.grid.legendColour)).toBe(1);
|
|
2047
|
+
expect(ticked(enUS.grid.legendSize)).toBe(1);
|
|
2048
|
+
|
|
2049
|
+
// And back out: untick the size and the key is cleared, the colour left alone.
|
|
2050
|
+
const sizes = panelFor(wrapper, enUS.grid.legendSize).panel;
|
|
2051
|
+
const checked = sizes
|
|
2052
|
+
.findAll('input[type="checkbox"]')
|
|
2053
|
+
.find((box) => (box.element as HTMLInputElement).checked)!;
|
|
2054
|
+
await checked.setValue(false);
|
|
2055
|
+
await wrapper.vm.$nextTick();
|
|
2056
|
+
expect(source.route.filters.size).toBeUndefined();
|
|
2057
|
+
expect(source.route.filters.colour).toEqual(['oat']);
|
|
2058
|
+
});
|
|
2059
|
+
|
|
2060
|
+
/**
|
|
2061
|
+
* **An option key that would take a query key something else already owns is refused**, with a
|
|
2062
|
+
* dev warning naming it. The grid's own filters own `?category=`, `?collection=`, `?price=` and
|
|
2063
|
+
* `?availability=`; the storefront route owns `?q=`, `?page=`, `?token=`, `?sort=` and
|
|
2064
|
+
* `?columns=` before a block sees them at all (`app/plugins/eldra-storefront.ts`).
|
|
2065
|
+
*
|
|
2066
|
+
* Both collisions are silent and ugly. A key shadowing a filter source reads the *same* query key
|
|
2067
|
+
* as that source, so one `?category=ceramics` would go out as a `categoryId` **and** an
|
|
2068
|
+
* `option=category:ceramics`, AND-ed, emptying the grid — and ticking a category would then write
|
|
2069
|
+
* that key twice in one patch, un-applying the filter on the next read. A key shadowing a route
|
|
2070
|
+
* field (`sort` above all) is never readable from the URL at all, while every state write would
|
|
2071
|
+
* clear the shopper's sort out of it.
|
|
2072
|
+
*
|
|
2073
|
+
* Namespacing the key was the alternative and was not taken: the query key is a shareable,
|
|
2074
|
+
* shopper-visible part of the URL, and inventing `?opt_category=` for one store means a link no
|
|
2075
|
+
* other spelling of this theme reads. One group fewer, every other filter exactly right.
|
|
2076
|
+
*/
|
|
2077
|
+
it('refuses an option key that collides with a reserved query key', async () => {
|
|
2078
|
+
const stub = createStub(PRODUCTS, {
|
|
2079
|
+
facets: {
|
|
2080
|
+
...FACETS,
|
|
2081
|
+
options: [
|
|
2082
|
+
{
|
|
2083
|
+
key: 'category',
|
|
2084
|
+
name: 'Category',
|
|
2085
|
+
kind: 'none',
|
|
2086
|
+
values: [{ value: 'x', label: 'X', count: 2 }],
|
|
2087
|
+
},
|
|
2088
|
+
{
|
|
2089
|
+
key: 'sort',
|
|
2090
|
+
name: 'Sort',
|
|
2091
|
+
kind: 'none',
|
|
2092
|
+
values: [{ value: 'y', label: 'Y', count: 2 }],
|
|
2093
|
+
},
|
|
2094
|
+
{
|
|
2095
|
+
key: 'fabric',
|
|
2096
|
+
name: 'Fabric',
|
|
2097
|
+
kind: 'none',
|
|
2098
|
+
values: [{ value: 'linen', label: 'Linen', count: 7 }],
|
|
2099
|
+
},
|
|
2100
|
+
],
|
|
2101
|
+
},
|
|
2102
|
+
});
|
|
2103
|
+
const wrapper = mountGrid(WITH_OPTIONS, { source: stub.source });
|
|
2104
|
+
await wrapper.vm.$nextTick();
|
|
2105
|
+
// `Fabric` is offered; the two colliding keys are not — and `Category` on screen is the grid's
|
|
2106
|
+
// own category group, not the store's option of the same name.
|
|
2107
|
+
expect(sidebarLabels(wrapper)).toEqual(['Category', 'Fabric']);
|
|
2108
|
+
expect(panelFor(wrapper, enUS.grid.legendCategory).panel.findAll('label').length).toBe(
|
|
2109
|
+
FACETS.categories.length
|
|
2110
|
+
);
|
|
2111
|
+
});
|
|
2112
|
+
|
|
2113
|
+
/**
|
|
2114
|
+
* An **explicit** `option:<key>` row is refused by the same rule, wherever the author put it —
|
|
2115
|
+
* and the store really does have that option here, so the row is dropped by the guard rather than
|
|
2116
|
+
* by the ordinary "a group with no values is not a group" rule.
|
|
2117
|
+
*/
|
|
2118
|
+
it('refuses a colliding key an author named explicitly', async () => {
|
|
2119
|
+
const stub = createStub(PRODUCTS, {
|
|
2120
|
+
facets: {
|
|
2121
|
+
...FACETS,
|
|
2122
|
+
options: [
|
|
2123
|
+
...FACETS.options,
|
|
2124
|
+
{
|
|
2125
|
+
key: 'sort',
|
|
2126
|
+
name: 'Sort',
|
|
2127
|
+
kind: 'none',
|
|
2128
|
+
values: [{ value: 'y', label: 'Y', count: 2 }],
|
|
2129
|
+
},
|
|
2130
|
+
],
|
|
2131
|
+
},
|
|
2132
|
+
});
|
|
2133
|
+
const wrapper = mountGrid(
|
|
2134
|
+
{
|
|
2135
|
+
...mock,
|
|
2136
|
+
filters: [
|
|
2137
|
+
{ source: 'option:sort', label: 'Sort by fabric' },
|
|
2138
|
+
{ source: 'category', label: 'Category' },
|
|
2139
|
+
],
|
|
2140
|
+
},
|
|
2141
|
+
{ source: stub.source }
|
|
2142
|
+
);
|
|
2143
|
+
await wrapper.vm.$nextTick();
|
|
2144
|
+
expect(sidebarLabels(wrapper)).toEqual(['Category']);
|
|
2145
|
+
});
|
|
2146
|
+
|
|
2147
|
+
/**
|
|
2148
|
+
* A query key that is not a filter at all — a campaign tag, an analytics parameter — must not
|
|
2149
|
+
* become `option:ref`, draw a chip and go out in the request: a filter nobody set, promised to
|
|
2150
|
+
* the shopper in their own URL. Only a key the store actually has an option for is read.
|
|
2151
|
+
*/
|
|
2152
|
+
it('ignores a query key the store has no option for', async () => {
|
|
2153
|
+
const source = createDemoStorefront({ filters: { ref: ['newsletter'] } });
|
|
2154
|
+
const wrapper = mountGrid(WITH_OPTIONS, { source });
|
|
2155
|
+
await wrapper.vm.$nextTick();
|
|
2156
|
+
await flushPromises();
|
|
2157
|
+
expect(wrapper.find(`ul[aria-label="${enUS.grid.activeFilters}"]`).exists()).toBe(false);
|
|
2158
|
+
});
|
|
2159
|
+
});
|
|
2160
|
+
|
|
2161
|
+
/**
|
|
2162
|
+
* **The catalogue scope** (`scope: "catalogue"`) — the `/products` page. The same block, reading
|
|
2163
|
+
* `catalog.products` instead of `catalog.collectionProducts`: no collection to bind, no
|
|
2164
|
+
* "pick a collection" hint, paging links at `/products`, and the Collection group offered because
|
|
2165
|
+
* that scope really can narrow by one.
|
|
2166
|
+
*/
|
|
2167
|
+
describe('the catalogue scope', () => {
|
|
2168
|
+
const CATALOGUE = {
|
|
2169
|
+
...mock,
|
|
2170
|
+
scope: 'catalogue',
|
|
2171
|
+
paginationStyle: 'pages',
|
|
2172
|
+
pageSize: '12',
|
|
2173
|
+
filters: [
|
|
2174
|
+
{ source: 'category', label: 'Category' },
|
|
2175
|
+
{ source: 'collection', label: 'Collection' },
|
|
2176
|
+
],
|
|
2177
|
+
};
|
|
2178
|
+
|
|
2179
|
+
it('lists the catalogue with no collection bound, axe-clean', async () => {
|
|
2180
|
+
const wrapper = mountGrid(CATALOGUE);
|
|
2181
|
+
await wrapper.vm.$nextTick();
|
|
2182
|
+
await flushPromises();
|
|
2183
|
+
expect(cards(wrapper).length).toBeGreaterThan(0);
|
|
2184
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
2185
|
+
});
|
|
2186
|
+
|
|
2187
|
+
/** The landmark names the plain noun rather than a collection it is not showing. */
|
|
2188
|
+
it('names its section Products rather than a collection', async () => {
|
|
2189
|
+
const wrapper = mountGrid(CATALOGUE);
|
|
2190
|
+
await wrapper.vm.$nextTick();
|
|
2191
|
+
expect(wrapper.get('section[aria-label]').attributes('aria-label')).toBe(enUS.grid.products);
|
|
2192
|
+
});
|
|
2193
|
+
|
|
2194
|
+
/** Nothing to bind, so nothing to hint about — the editor hint is for a *collection* grid whose
|
|
2195
|
+
* collection the author has not picked. */
|
|
2196
|
+
it('shows no "pick a collection" hint in the editor', async () => {
|
|
2197
|
+
const wrapper = mountGrid(CATALOGUE, { editing: true });
|
|
2198
|
+
await wrapper.vm.$nextTick();
|
|
2199
|
+
expect(wrapper.text()).not.toContain(enUS.grid.noCollectionLabel);
|
|
2200
|
+
});
|
|
2201
|
+
|
|
2202
|
+
it('pages at /products rather than at a collection path', async () => {
|
|
2203
|
+
const wrapper = mountGrid(CATALOGUE);
|
|
2204
|
+
await wrapper.vm.$nextTick();
|
|
2205
|
+
await flushPromises();
|
|
2206
|
+
const hrefs = wrapper
|
|
2207
|
+
.get('nav[aria-label]')
|
|
2208
|
+
.findAll('a')
|
|
2209
|
+
.map((anchor) => anchor.attributes('href'));
|
|
2210
|
+
expect(hrefs).toContain('/products?page=2');
|
|
2211
|
+
expect(hrefs.every((href) => href === undefined || !href.startsWith('/collections'))).toBe(
|
|
2212
|
+
true
|
|
2213
|
+
);
|
|
2214
|
+
});
|
|
2215
|
+
|
|
2216
|
+
/**
|
|
2217
|
+
* The Collection group is the one that differs between the two scopes: a collection's own product
|
|
2218
|
+
* list cannot intersect two collections and declares the source `unfilterable`, while the
|
|
2219
|
+
* catalogue-wide list takes a `collectionId` — so here the group is drawn and the filter applies.
|
|
2220
|
+
*/
|
|
2221
|
+
it('offers the Collection group, which really narrows the catalogue', async () => {
|
|
2222
|
+
useFilterTimers();
|
|
2223
|
+
const source = createDemoStorefront();
|
|
2224
|
+
const wrapper = mountGrid(CATALOGUE, { source });
|
|
2225
|
+
await wrapper.vm.$nextTick();
|
|
2226
|
+
await flushPromises();
|
|
2227
|
+
|
|
2228
|
+
const { panel } = panelFor(wrapper, enUS.grid.legendCollection);
|
|
2229
|
+
const before = Number(/^\d+/.exec(countLine(wrapper).text())?.[0] ?? '0');
|
|
2230
|
+
await panel.findAll('input[type="checkbox"]').at(-1)!.setValue(true);
|
|
2231
|
+
await settleFilterDebounce(wrapper);
|
|
2232
|
+
await flushPromises();
|
|
2233
|
+
const after = Number(/^\d+/.exec(countLine(wrapper).text())?.[0] ?? '0');
|
|
2234
|
+
expect(before).toBeGreaterThan(0);
|
|
2235
|
+
expect(after).toBeGreaterThan(0);
|
|
2236
|
+
expect(after).toBeLessThan(before);
|
|
2237
|
+
});
|
|
2238
|
+
});
|
|
2239
|
+
|
|
2240
|
+
describe('a selected value the facets stop listing', () => {
|
|
2241
|
+
/**
|
|
2242
|
+
* Facets are normally computed over the current result set, so ticking one value can remove
|
|
2243
|
+
* another from the response. The chips are derived from the selection, never from the facets,
|
|
2244
|
+
* so an applied filter is always visible and always removable — otherwise it would keep
|
|
2245
|
+
* narrowing every request with no control left to undo it (and with results still non-empty
|
|
2246
|
+
* there is no empty-state "Clear filters" button to fall back on either).
|
|
2247
|
+
*/
|
|
2248
|
+
const withoutColour: CatalogFacets = {
|
|
2249
|
+
...FACETS,
|
|
2250
|
+
options: FACETS.options.filter((option) => option.key !== 'colour'),
|
|
2251
|
+
};
|
|
2252
|
+
|
|
2253
|
+
it('still renders its chip, and the chip removes it', async () => {
|
|
2254
|
+
useFilterTimers();
|
|
2255
|
+
const stub = createStub(PRODUCTS, { filteredCount: 4, filteredFacets: withoutColour });
|
|
2256
|
+
const wrapper = mountGrid(mock, { source: stub.source });
|
|
2257
|
+
await wrapper.vm.$nextTick();
|
|
2258
|
+
|
|
2259
|
+
const { panel } = panelFor(wrapper, enUS.grid.legendColour);
|
|
2260
|
+
await panel.get('input[type="checkbox"]').setValue(true);
|
|
2261
|
+
await settleFilterDebounce(wrapper);
|
|
2262
|
+
|
|
2263
|
+
// Results are non-empty, so there is no empty state to escape through.
|
|
2264
|
+
expect(cards(wrapper)).toHaveLength(4);
|
|
2265
|
+
expect(countLine(wrapper).text()).toBe('4 products');
|
|
2266
|
+
|
|
2267
|
+
// The facets no longer describe the value, so it is labelled by its raw value — and it is
|
|
2268
|
+
// still a chip, still in the group, and still counted on the Filter button.
|
|
2269
|
+
const list = wrapper.get(`ul[aria-label="${enUS.grid.activeFilters}"]`);
|
|
2270
|
+
expect(list.text()).toContain('oat');
|
|
2271
|
+
expect(filterButton(wrapper).get('[data-part="hiddenSuffix"]').text()).toBe('1 active');
|
|
2272
|
+
expect(
|
|
2273
|
+
panelFor(wrapper, enUS.grid.legendColour).panel.findAll('input[type="checkbox"]')
|
|
2274
|
+
).toHaveLength(1);
|
|
2275
|
+
|
|
2276
|
+
await list.get('[data-part="removeButton"]').trigger('click');
|
|
2277
|
+
await wrapper.vm.$nextTick();
|
|
2278
|
+
|
|
2279
|
+
expect(wrapper.find(`ul[aria-label="${enUS.grid.activeFilters}"]`).exists()).toBe(false);
|
|
2280
|
+
expect(countLine(wrapper).text()).toBe('12 products');
|
|
2281
|
+
expect(stub.requests.at(-1)?.filters).toBeUndefined();
|
|
2282
|
+
});
|
|
2283
|
+
|
|
2284
|
+
it('Clear all clears it too', async () => {
|
|
2285
|
+
useFilterTimers();
|
|
2286
|
+
const stub = createStub(PRODUCTS, { filteredCount: 4, filteredFacets: withoutColour });
|
|
2287
|
+
const wrapper = mountGrid(mock, { source: stub.source, attachTo: document.body });
|
|
2288
|
+
await wrapper.vm.$nextTick();
|
|
2289
|
+
|
|
2290
|
+
const { panel } = panelFor(wrapper, enUS.grid.legendColour);
|
|
2291
|
+
await panel.get('input[type="checkbox"]').setValue(true);
|
|
2292
|
+
await settleFilterDebounce(wrapper);
|
|
2293
|
+
expect(wrapper.get(`ul[aria-label="${enUS.grid.activeFilters}"]`).text()).toContain('oat');
|
|
2294
|
+
|
|
2295
|
+
const clearAll = wrapper
|
|
2296
|
+
.findAll('button')
|
|
2297
|
+
.find((button) => button.text() === enUS.grid.clearAll)!;
|
|
2298
|
+
await clearAll.trigger('click');
|
|
2299
|
+
await wrapper.vm.$nextTick();
|
|
2300
|
+
|
|
2301
|
+
expect(wrapper.find(`ul[aria-label="${enUS.grid.activeFilters}"]`).exists()).toBe(false);
|
|
2302
|
+
expect(countLine(wrapper).text()).toBe('12 products');
|
|
2303
|
+
// Clear all moves focus to the panel's own title (see "focuses the panel's own title" above).
|
|
2304
|
+
expect(document.activeElement).toBe(wrapper.get('aside [data-part="title"]').element);
|
|
2305
|
+
});
|
|
2306
|
+
});
|
|
2307
|
+
|
|
2308
|
+
/**
|
|
2309
|
+
* Which collection the grid shows (spec `Starter blocks`): the `collection`
|
|
2310
|
+
* `reference` field an author picks in Studio — which stores the collection's
|
|
2311
|
+
* **id** — then the collection template's own route segment. The picked
|
|
2312
|
+
* collection overrides the route; its resolved `slug` is used when the value
|
|
2313
|
+
* carries one, and its bare id otherwise (a page builder draft overlay, a
|
|
2314
|
+
* depth-0 read, or an archived collection, all of which read as the bare
|
|
2315
|
+
* stub). The `collectionHandle` string field the block shipped with is retired
|
|
2316
|
+
* as of version 3 (Core keeps its content as `collectionHandle__v2`) and is
|
|
2317
|
+
* not read here even when an entry still carries it.
|
|
2318
|
+
*/
|
|
2319
|
+
describe('the collection source', () => {
|
|
2320
|
+
const WINTER = demoCollectionId('winter-knitwear')!;
|
|
2321
|
+
|
|
2322
|
+
/** The collection the grid actually asked the storefront for. */
|
|
2323
|
+
function requestedFor(data: Record<string, unknown>, routeHandle: string | null = null) {
|
|
2324
|
+
const asked: Array<StorefrontCollectionSelector | null> = [];
|
|
2325
|
+
const base = createDemoStorefront();
|
|
2326
|
+
base.route.collectionHandle = routeHandle;
|
|
2327
|
+
const source: StorefrontSource = {
|
|
2328
|
+
...base,
|
|
2329
|
+
catalog: {
|
|
2330
|
+
...base.catalog,
|
|
2331
|
+
collectionProducts(collection, opts) {
|
|
2332
|
+
asked.push(collection.value);
|
|
2333
|
+
return base.catalog.collectionProducts(collection, opts);
|
|
2334
|
+
},
|
|
2335
|
+
},
|
|
2336
|
+
};
|
|
2337
|
+
mountGrid(data, { source });
|
|
2338
|
+
return asked;
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2341
|
+
it('uses the reference’s resolved slug', () => {
|
|
2342
|
+
expect(
|
|
2343
|
+
requestedFor({
|
|
2344
|
+
...mock,
|
|
2345
|
+
collection: { id: WINTER, _type: 'collection', slug: 'best-sellers' },
|
|
2346
|
+
})
|
|
2347
|
+
).toContainEqual({ slug: 'best-sellers' });
|
|
2348
|
+
});
|
|
2349
|
+
|
|
2350
|
+
it('asks by id for a stub reference', () => {
|
|
2351
|
+
expect(
|
|
2352
|
+
requestedFor({ ...mock, collection: { id: WINTER, _type: 'collection' } })
|
|
2353
|
+
).toContainEqual({ id: WINTER });
|
|
2354
|
+
});
|
|
2355
|
+
|
|
2356
|
+
it('reads a seed reference, which names the collection by slug and carries no id', () => {
|
|
2357
|
+
// What `pages/collection.page.json` ships and Core writes when it cannot
|
|
2358
|
+
// resolve the slug against the organisation's catalog.
|
|
2359
|
+
expect(
|
|
2360
|
+
requestedFor({ ...mock, collection: { _type: 'collection', slug: 'best-sellers' } })
|
|
2361
|
+
).toContainEqual({ slug: 'best-sellers' });
|
|
2362
|
+
});
|
|
2363
|
+
|
|
2364
|
+
it('falls back to the route when no collection is picked', () => {
|
|
2365
|
+
expect(requestedFor({ ...mock, collection: null }, 'the-winter-edit')).toContainEqual({
|
|
2366
|
+
slug: 'the-winter-edit',
|
|
2367
|
+
});
|
|
2368
|
+
});
|
|
2369
|
+
|
|
2370
|
+
it('ignores a retired collectionHandle an entry still carries', () => {
|
|
2371
|
+
// The handle field is gone: a value left behind by the old schema must not
|
|
2372
|
+
// stand in for a collection nobody can see in Studio any more, and must
|
|
2373
|
+
// not shadow the route the template resolved.
|
|
2374
|
+
const asked = requestedFor({ ...mock, collectionHandle: 'best-sellers' }, 'the-winter-edit');
|
|
2375
|
+
expect(asked).not.toContainEqual({ slug: 'best-sellers' });
|
|
2376
|
+
expect(asked).toContainEqual({ slug: 'the-winter-edit' });
|
|
2377
|
+
});
|
|
2378
|
+
|
|
2379
|
+
it('lets the picked collection override the route', () => {
|
|
2380
|
+
const asked = requestedFor(
|
|
2381
|
+
{ ...mock, collection: { id: WINTER, _type: 'collection' } },
|
|
2382
|
+
'the-winter-edit'
|
|
2383
|
+
);
|
|
2384
|
+
expect(asked).toContainEqual({ id: WINTER });
|
|
2385
|
+
expect(asked).not.toContainEqual({ slug: 'the-winter-edit' });
|
|
2386
|
+
});
|
|
2387
|
+
|
|
2388
|
+
it('still renders a collection the storefront can only find by id', async () => {
|
|
2389
|
+
const wrapper = mountGrid({ ...mock, collection: { id: WINTER, _type: 'collection' } });
|
|
2390
|
+
await flushPromises();
|
|
2391
|
+
expect(cards(wrapper).length).toBeGreaterThan(0);
|
|
2392
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
2393
|
+
});
|
|
2394
|
+
});
|
|
2395
|
+
|
|
2396
|
+
describe('the editor', () => {
|
|
2397
|
+
/** An id no storefront can resolve: a freshly picked collection before the
|
|
2398
|
+
* page is published, or one that has since been archived. */
|
|
2399
|
+
const UNRESOLVABLE = { id: '00000000-0000-4000-8000-000000000000', _type: 'collection' };
|
|
2400
|
+
|
|
2401
|
+
it('shows the publish hint when only an unresolvable collection id is known', async () => {
|
|
2402
|
+
const source = createDemoStorefront();
|
|
2403
|
+
source.route.collectionHandle = null;
|
|
2404
|
+
const wrapper = mountGrid({ ...mock, collection: UNRESOLVABLE }, { source, editing: true });
|
|
2405
|
+
await flushPromises();
|
|
2406
|
+
expect(wrapper.text()).toContain(enUS.storefront.unresolvedCollectionLabel);
|
|
2407
|
+
expect(wrapper.text()).toContain(enUS.storefront.unresolvedCollectionHelp);
|
|
2408
|
+
expect(wrapper.text()).not.toContain(enUS.grid.noCollectionLabel);
|
|
2409
|
+
expect(wrapper.find('ul').exists()).toBe(false);
|
|
2410
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
2411
|
+
});
|
|
2412
|
+
|
|
2413
|
+
it('never shows that hint to a live visitor — the block renders its own empty grid instead', async () => {
|
|
2414
|
+
const source = createDemoStorefront();
|
|
2415
|
+
source.route.collectionHandle = null;
|
|
2416
|
+
const wrapper = mountGrid({ ...mock, collection: UNRESOLVABLE }, { source });
|
|
2417
|
+
await flushPromises();
|
|
2418
|
+
expect(wrapper.text()).not.toContain(enUS.storefront.unresolvedCollectionLabel);
|
|
2419
|
+
expect(cards(wrapper)).toHaveLength(0);
|
|
2420
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
2421
|
+
});
|
|
2422
|
+
|
|
2423
|
+
it('shows the "Choose a collection" hint when no collection is bound', async () => {
|
|
2424
|
+
const source = createDemoStorefront();
|
|
2425
|
+
source.route.collectionHandle = null;
|
|
2426
|
+
const base = mountOptions({ entry: { id: 'e1', data: mock } });
|
|
2427
|
+
const wrapper = mount(Block, {
|
|
2428
|
+
...base,
|
|
2429
|
+
global: {
|
|
2430
|
+
...base.global,
|
|
2431
|
+
provide: {
|
|
2432
|
+
...base.global.provide,
|
|
2433
|
+
[STOREFRONT_KEY]: source,
|
|
2434
|
+
[ELDRA_KEY]: editingContext(),
|
|
2435
|
+
},
|
|
2436
|
+
},
|
|
2437
|
+
});
|
|
2438
|
+
wrappers.push(wrapper);
|
|
2439
|
+
await wrapper.vm.$nextTick();
|
|
2440
|
+
expect(wrapper.text()).toContain(enUS.grid.noCollectionLabel);
|
|
2441
|
+
expect(wrapper.text()).toContain(enUS.grid.noCollectionHelp);
|
|
2442
|
+
expect(wrapper.find('ul').exists()).toBe(false);
|
|
2443
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
2444
|
+
});
|
|
2445
|
+
});
|
|
2446
|
+
|
|
2447
|
+
/**
|
|
2448
|
+
* The prerendered page's live refresh (`app/storefront/types.ts`, `app/storefront/refresh.ts`):
|
|
2449
|
+
* the HTML shipped with real prices and stock lines, and a few hundred milliseconds after mount
|
|
2450
|
+
* the storefront swaps in the backend's current ones. The grid never redraws for it — every card
|
|
2451
|
+
* keeps its value, dims it and carries a spinner — and the whole grid says so once rather than
|
|
2452
|
+
* letting 24 cards hold 48 live regions between them.
|
|
2453
|
+
*/
|
|
2454
|
+
describe('the volatile refresh', () => {
|
|
2455
|
+
it('keeps every card, marks its price and stock line busy, and draws no skeleton', async () => {
|
|
2456
|
+
const stub = createStub();
|
|
2457
|
+
const wrapper = mountGrid(mock, { source: stub.source });
|
|
2458
|
+
await wrapper.vm.$nextTick();
|
|
2459
|
+
const shown = cards(wrapper).length;
|
|
2460
|
+
expect(shown).toBeGreaterThan(0);
|
|
2461
|
+
|
|
2462
|
+
stub.revalidating.value = new Set(['price', 'stock']);
|
|
2463
|
+
await wrapper.vm.$nextTick();
|
|
2464
|
+
|
|
2465
|
+
expect(cards(wrapper)).toHaveLength(shown);
|
|
2466
|
+
expect(wrapper.find('ul[aria-hidden="true"]').exists()).toBe(false);
|
|
2467
|
+
expect(wrapper.text()).toContain(PRODUCTS[0]!.title);
|
|
2468
|
+
|
|
2469
|
+
const busy = wrapper.findAll('[data-part="root"][aria-busy="true"]');
|
|
2470
|
+
expect(busy.length).toBeGreaterThanOrEqual(shown);
|
|
2471
|
+
expect(wrapper.findAll('[data-part="spinner"]').length).toBeGreaterThanOrEqual(shown);
|
|
2472
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
2473
|
+
});
|
|
2474
|
+
|
|
2475
|
+
it('announces once for the whole grid, after mount, and never per card', async () => {
|
|
2476
|
+
const stub = createStub();
|
|
2477
|
+
const wrapper = mountGrid(mock, { source: stub.source });
|
|
2478
|
+
await wrapper.vm.$nextTick();
|
|
2479
|
+
|
|
2480
|
+
// Mounted and empty first: a live region that arrives already holding its message is
|
|
2481
|
+
// announced unreliably, which is exactly what a prerendered page would produce if the block
|
|
2482
|
+
// read `revalidating` straight through instead of flipping it after mount.
|
|
2483
|
+
expect(liveRegion(wrapper).text()).toBe('');
|
|
2484
|
+
|
|
2485
|
+
stub.revalidating.value = new Set(['price']);
|
|
2486
|
+
await wrapper.vm.$nextTick();
|
|
2487
|
+
|
|
2488
|
+
expect(liveRegion(wrapper).text()).toBe(enUS.storefront.updatingValues);
|
|
2489
|
+
expect(wrapper.findAll('p.sr-only[role="status"]')).toHaveLength(1);
|
|
2490
|
+
// `announce: false` on every card — the per-value regions are gone, not merely empty.
|
|
2491
|
+
expect(wrapper.findAll('[data-part="srStatus"]')).toHaveLength(0);
|
|
2492
|
+
expect(
|
|
2493
|
+
wrapper.findAllComponents(ProductCard).every((card) => card.props('announce') === false)
|
|
2494
|
+
).toBe(true);
|
|
2495
|
+
|
|
2496
|
+
stub.revalidating.value = new Set();
|
|
2497
|
+
await wrapper.vm.$nextTick();
|
|
2498
|
+
expect(liveRegion(wrapper).text()).toBe('');
|
|
2499
|
+
});
|
|
2500
|
+
|
|
2501
|
+
it('keeps the cards when the read fails over results the visitor can already see', async () => {
|
|
2502
|
+
const stub = createStub();
|
|
2503
|
+
const wrapper = mountGrid(mock, { source: stub.source });
|
|
2504
|
+
await wrapper.vm.$nextTick();
|
|
2505
|
+
const shown = cards(wrapper).length;
|
|
2506
|
+
|
|
2507
|
+
stub.error.value = 'gateway exploded';
|
|
2508
|
+
await wrapper.vm.$nextTick();
|
|
2509
|
+
|
|
2510
|
+
expect(cards(wrapper)).toHaveLength(shown);
|
|
2511
|
+
expect(wrapper.text()).not.toContain(enUS.storefront.error);
|
|
2512
|
+
});
|
|
2513
|
+
});
|
|
2514
|
+
|
|
2515
|
+
/**
|
|
2516
|
+
* The block over the *real* gateway storefront, not a stub of it.
|
|
2517
|
+
*
|
|
2518
|
+
* `/collections/the-winter-edit?sort=featured&columns=3&price=50-150` still showed the
|
|
2519
|
+
* $48 "Speckled stoneware bowl": the block read the range off the URL and sent it correctly, and
|
|
2520
|
+
* `createGatewayStorefront` dropped every facet before its list read, so the grid answered with the
|
|
2521
|
+
* unfiltered collection under a URL, chips and an active-filter row that all said otherwise. This
|
|
2522
|
+
* is that URL, end to end — the block's own seeding, the `minPrice`/`maxPrice` parameters the
|
|
2523
|
+
* gateway now sends, the platform's own `total` and its `facets` — with only the HTTP call faked.
|
|
2524
|
+
*
|
|
2525
|
+
* The store sells in krónur, which have no minor unit, so the parameters this asserts read as the
|
|
2526
|
+
* same numbers the shopper typed; `test/storefront/gateway.spec.ts` is where the conversion itself
|
|
2527
|
+
* is pinned.
|
|
2528
|
+
*/
|
|
2529
|
+
describe('over the gateway storefront, with a price range in the URL', () => {
|
|
2530
|
+
const CATALOGUE: Array<{ slug: string; title: string; price: number }> = [
|
|
2531
|
+
{ slug: 'speckled-stoneware-bowl', title: 'Speckled stoneware bowl', price: 48 },
|
|
2532
|
+
{ slug: 'linen-waffle-throw', title: 'Linen waffle throw', price: 50 },
|
|
2533
|
+
{ slug: 'merino-crew-sweater', title: 'Merino crew sweater', price: 96 },
|
|
2534
|
+
{ slug: 'cashmere-wrap', title: 'Cashmere wrap', price: 150 },
|
|
2535
|
+
{ slug: 'shearling-slippers', title: 'Shearling slippers', price: 151 },
|
|
2536
|
+
];
|
|
2537
|
+
|
|
2538
|
+
/** The gateway's own filtering: the `minPrice`/`maxPrice` parameters, inclusive both ends. */
|
|
2539
|
+
function gatewayRows(query: Record<string, unknown>) {
|
|
2540
|
+
const min = query.minPrice as number | undefined;
|
|
2541
|
+
const max = query.maxPrice as number | undefined;
|
|
2542
|
+
return CATALOGUE.filter(
|
|
2543
|
+
(row) => (min === undefined || row.price >= min) && (max === undefined || row.price <= max)
|
|
2544
|
+
);
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2547
|
+
function gatewaySource(filters: Record<string, string[]>): StorefrontSource {
|
|
2548
|
+
const client = {
|
|
2549
|
+
catalog: {
|
|
2550
|
+
listCollectionProducts: async (_slug: string, query: Record<string, unknown>) => {
|
|
2551
|
+
const page = (query.page as number | undefined) ?? 1;
|
|
2552
|
+
const pageSize = (query.pageSize as number | undefined) ?? 24;
|
|
2553
|
+
const matching = gatewayRows(query);
|
|
2554
|
+
const start = (page - 1) * pageSize;
|
|
2555
|
+
const rows = matching.slice(start, start + pageSize).map((row) => ({
|
|
2556
|
+
id: `${row.slug}::default`,
|
|
2557
|
+
slug: row.slug,
|
|
2558
|
+
title: row.title,
|
|
2559
|
+
status: 'ACTIVE',
|
|
2560
|
+
minPrice: row.price,
|
|
2561
|
+
maxPrice: row.price,
|
|
2562
|
+
totalVariants: 1,
|
|
2563
|
+
}));
|
|
2564
|
+
return {
|
|
2565
|
+
data: rows,
|
|
2566
|
+
// The platform's own span, counted with every filter *except* price applied — which
|
|
2567
|
+
// is why the track still spans the whole collection under a range.
|
|
2568
|
+
facets: {
|
|
2569
|
+
price: { min: 48, max: 151 },
|
|
2570
|
+
categories: [],
|
|
2571
|
+
collections: [],
|
|
2572
|
+
availability: { in_stock: CATALOGUE.length, out_of_stock: 0 },
|
|
2573
|
+
options: [],
|
|
2574
|
+
},
|
|
2575
|
+
meta: {
|
|
2576
|
+
page,
|
|
2577
|
+
pageSize,
|
|
2578
|
+
total: matching.length,
|
|
2579
|
+
totalPages: 1,
|
|
2580
|
+
rows: rows.length,
|
|
2581
|
+
hasNext: false,
|
|
2582
|
+
hasPrev: false,
|
|
2583
|
+
},
|
|
2584
|
+
};
|
|
2585
|
+
},
|
|
2586
|
+
},
|
|
2587
|
+
} as unknown as EldraClient;
|
|
2588
|
+
return createGatewayStorefront(client, {
|
|
2589
|
+
commerce: { currency: 'ISK', taxInclusivePricing: true, defaultTaxRate: 0.24 },
|
|
2590
|
+
route: {
|
|
2591
|
+
productHandle: null,
|
|
2592
|
+
collectionHandle: 'the-winter-edit',
|
|
2593
|
+
orderToken: null,
|
|
2594
|
+
query: null,
|
|
2595
|
+
page: 1,
|
|
2596
|
+
sort: 'featured',
|
|
2597
|
+
columns: '3',
|
|
2598
|
+
filters,
|
|
2599
|
+
setQuery: () => {},
|
|
2600
|
+
},
|
|
2601
|
+
});
|
|
2602
|
+
}
|
|
2603
|
+
|
|
2604
|
+
it('drops the $48 card and counts only what the range keeps', async () => {
|
|
2605
|
+
const wrapper = mountGrid(mock, {
|
|
2606
|
+
source: gatewaySource({ price: ['50-150'] }),
|
|
2607
|
+
});
|
|
2608
|
+
await flushPromises();
|
|
2609
|
+
await wrapper.vm.$nextTick();
|
|
2610
|
+
|
|
2611
|
+
const titles = cards(wrapper).map((card) => card.get('a').text());
|
|
2612
|
+
expect(titles).toEqual(['Linen waffle throw', 'Merino crew sweater', 'Cashmere wrap']);
|
|
2613
|
+
expect(wrapper.text()).not.toContain('Speckled stoneware bowl');
|
|
2614
|
+
expect(countLine(wrapper).text()).toBe('3 products');
|
|
2615
|
+
expect(wrapper.get('[data-part="status"]').text()).toContain('Showing 3 of 3');
|
|
2616
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
2617
|
+
});
|
|
2618
|
+
|
|
2619
|
+
it('shows the whole collection again once the range is gone', async () => {
|
|
2620
|
+
const wrapper = mountGrid(mock, { source: gatewaySource({}) });
|
|
2621
|
+
await flushPromises();
|
|
2622
|
+
await wrapper.vm.$nextTick();
|
|
2623
|
+
|
|
2624
|
+
expect(cards(wrapper)).toHaveLength(CATALOGUE.length);
|
|
2625
|
+
expect(countLine(wrapper).text()).toBe('5 products');
|
|
2626
|
+
});
|
|
2627
|
+
});
|
|
2628
|
+
|
|
2629
|
+
/**
|
|
2630
|
+
* **The query string a filtered view is linkable by** (contract §4):
|
|
2631
|
+
* `?price=1200-4800&category=ceramics&collection=the-winter-edit&colour=oat&availability=in_stock`.
|
|
2632
|
+
*
|
|
2633
|
+
* One key per group, written through the one writer a block may call (`route.setQuery`) — no
|
|
2634
|
+
* router, no Nuxt global in `blocks/**` — and read back out of `route.filters` on the next page
|
|
2635
|
+
* load. The prerendered page is always the unfiltered one, so this is the whole of how a
|
|
2636
|
+
* filtered view survives being shared.
|
|
2637
|
+
*/
|
|
2638
|
+
describe('the query string a filtered view is linkable by', () => {
|
|
2639
|
+
const FILTERED = {
|
|
2640
|
+
...mock,
|
|
2641
|
+
filters: [
|
|
2642
|
+
{ source: 'category', label: 'Category' },
|
|
2643
|
+
{ source: 'collection', label: 'Collection' },
|
|
2644
|
+
{ source: 'option:colour', label: 'Colour' },
|
|
2645
|
+
{ source: 'price', label: 'Price' },
|
|
2646
|
+
{ source: 'availability', label: 'Availability' },
|
|
2647
|
+
],
|
|
2648
|
+
};
|
|
2649
|
+
|
|
2650
|
+
/**
|
|
2651
|
+
* The demo route writes a `setQuery` patch straight back into `route.filters`, which is what
|
|
2652
|
+
* a real page does by way of the URL. Availability is a `toggle` facet now — a real
|
|
2653
|
+
* `<button role="switch">`, not a checkbox — so its own row is clicked rather than ticked; its
|
|
2654
|
+
* decorative hidden `<input type="checkbox">` is never the interactive element.
|
|
2655
|
+
*/
|
|
2656
|
+
function tick(wrapper: VueWrapper, legend: string, index = 0) {
|
|
2657
|
+
const { panel } = panelFor(wrapper, legend);
|
|
2658
|
+
const switches = panel.findAll('[role="switch"]');
|
|
2659
|
+
if (switches.length > 0) return switches[index]!.trigger('click');
|
|
2660
|
+
return panel.findAll('input[type="checkbox"]')[index]!.setValue(true);
|
|
2661
|
+
}
|
|
2662
|
+
|
|
2663
|
+
it('writes one key per group and the price as a single range', async () => {
|
|
2664
|
+
const source = createDemoStorefront();
|
|
2665
|
+
const wrapper = mountGrid(FILTERED, { source });
|
|
2666
|
+
await wrapper.vm.$nextTick();
|
|
2667
|
+
|
|
2668
|
+
// The price first: the facets' span narrows with every other filter applied (it is counted
|
|
2669
|
+
// with every filter but price), so a floor typed after them would be clamped into whatever
|
|
2670
|
+
// the remaining products cost.
|
|
2671
|
+
const min = panelFor(wrapper, PRICE_LEGEND).panel.get('input[data-input="min"]');
|
|
2672
|
+
await min.trigger('focus');
|
|
2673
|
+
await min.setValue('50');
|
|
2674
|
+
await min.trigger('keydown', { key: 'Enter' });
|
|
2675
|
+
await wrapper.vm.$nextTick();
|
|
2676
|
+
await tick(wrapper, enUS.grid.legendCategory);
|
|
2677
|
+
await tick(wrapper, enUS.grid.legendCollection);
|
|
2678
|
+
await tick(wrapper, enUS.grid.legendColour);
|
|
2679
|
+
await tick(wrapper, enUS.grid.legendAvailability);
|
|
2680
|
+
await wrapper.vm.$nextTick();
|
|
2681
|
+
|
|
2682
|
+
expect(source.route.filters).toEqual({
|
|
2683
|
+
category: ['knitwear'],
|
|
2684
|
+
collection: ['the-winter-edit'],
|
|
2685
|
+
colour: ['oat'],
|
|
2686
|
+
availability: ['in_stock'],
|
|
2687
|
+
price: ['50-'],
|
|
2688
|
+
});
|
|
2689
|
+
});
|
|
2690
|
+
|
|
2691
|
+
it('clears a key the shopper empties rather than leaving it in the URL', async () => {
|
|
2692
|
+
const source = createDemoStorefront();
|
|
2693
|
+
const wrapper = mountGrid(FILTERED, { source });
|
|
2694
|
+
await wrapper.vm.$nextTick();
|
|
2695
|
+
|
|
2696
|
+
await tick(wrapper, enUS.grid.legendCategory);
|
|
2697
|
+
expect(source.route.filters.category).toEqual(['knitwear']);
|
|
2698
|
+
|
|
2699
|
+
const list = wrapper.get(`ul[aria-label="${enUS.grid.activeFilters}"]`);
|
|
2700
|
+
await list.get('[data-part="removeButton"]').trigger('click');
|
|
2701
|
+
await wrapper.vm.$nextTick();
|
|
2702
|
+
|
|
2703
|
+
expect(source.route.filters.category).toBeUndefined();
|
|
2704
|
+
expect(source.route.filters).toEqual({});
|
|
2705
|
+
});
|
|
2706
|
+
|
|
2707
|
+
/**
|
|
2708
|
+
* **A shared `?category=<parent>` link**, end to end, on a source answering public contract
|
|
2709
|
+
* 3.8.0's shape: the URL seeds the selection, the parent row is ticked, its children are drawn
|
|
2710
|
+
* implied, the request carries the parent and the grid shows the products of its children — which
|
|
2711
|
+
* is the whole promise of offering a parent row at all. The demo storefront is that source: it
|
|
2712
|
+
* places and rolls up its own category facet *and* expands a ticked parent the way the platform's
|
|
2713
|
+
* `categoryId` does (`app/storefront/facets.ts`'s `categoryTermsOf` and `matchesClause`). The
|
|
2714
|
+
* pre-3.8.0 shape, where the panel offers no parent row at all, is below.
|
|
2715
|
+
*/
|
|
2716
|
+
it('restores a parent category from the URL and shows its children’s products', async () => {
|
|
2717
|
+
const source = createDemoStorefront({ filters: { category: ['home'] } });
|
|
2718
|
+
const wrapper = mountGrid(FILTERED, { source });
|
|
2719
|
+
await wrapper.vm.$nextTick();
|
|
2720
|
+
await flushPromises();
|
|
2721
|
+
await wrapper.vm.$nextTick();
|
|
2722
|
+
|
|
2723
|
+
const { panel } = panelFor(wrapper, enUS.grid.legendCategory);
|
|
2724
|
+
const boxes = panel.findAll('input[type="checkbox"]');
|
|
2725
|
+
const labelOf = (index: number) => panel.findAll('label')[index]!.text().replace(/\s+/g, ' ');
|
|
2726
|
+
|
|
2727
|
+
// `Home` ticked, and the two categories under it ticked-and-inoperable: the request names the
|
|
2728
|
+
// parent, so a child is not a filter the shopper can remove from there.
|
|
2729
|
+
const home = boxes.findIndex((_, index) => labelOf(index).startsWith('Home'));
|
|
2730
|
+
expect(home).toBeGreaterThanOrEqual(0);
|
|
2731
|
+
expect((boxes[home]!.element as HTMLInputElement).checked).toBe(true);
|
|
2732
|
+
const implied = panel.findAll('[role="group"] input[type="checkbox"]');
|
|
2733
|
+
expect(implied.length).toBeGreaterThan(0);
|
|
2734
|
+
for (const box of implied) {
|
|
2735
|
+
expect((box.element as HTMLInputElement).checked).toBe(true);
|
|
2736
|
+
expect(box.attributes('disabled')).toBeDefined();
|
|
2737
|
+
}
|
|
2738
|
+
|
|
2739
|
+
// And the grid is really filtered: the count is the children's products, not the whole
|
|
2740
|
+
// collection, which is what a parent row nothing could expand would have shown.
|
|
2741
|
+
const unfiltered = mountGrid(FILTERED, { source: createDemoStorefront() });
|
|
2742
|
+
await unfiltered.vm.$nextTick();
|
|
2743
|
+
await flushPromises();
|
|
2744
|
+
const totalOf = (view: VueWrapper) => Number(/^\d+/.exec(countLine(view).text())?.[0] ?? '0');
|
|
2745
|
+
expect(totalOf(wrapper)).toBeGreaterThan(0);
|
|
2746
|
+
expect(totalOf(wrapper)).toBeLessThan(totalOf(unfiltered));
|
|
2747
|
+
expect(cards(wrapper).length).toBeGreaterThan(0);
|
|
2748
|
+
|
|
2749
|
+
// Untick the parent and the URL loses the key altogether — the round trip in both directions.
|
|
2750
|
+
await boxes[home]!.setValue(false);
|
|
2751
|
+
await wrapper.vm.$nextTick();
|
|
2752
|
+
expect(source.route.filters.category).toBeUndefined();
|
|
2753
|
+
});
|
|
2754
|
+
|
|
2755
|
+
/**
|
|
2756
|
+
* **The same link against a pre-3.8.0 gateway**, where the family is flat — `categoryCounts` is
|
|
2757
|
+
* absent, so the facets count assigned categories only and a `categoryId` matches direct
|
|
2758
|
+
* membership only.
|
|
2759
|
+
*
|
|
2760
|
+
* The panel must then offer **no parent row at all**: not indented, not rolled up, nothing
|
|
2761
|
+
* implied. A `Tableware` row there is a filter that gateway cannot honour, so ticking it would
|
|
2762
|
+
* empty the grid under a chip claiming otherwise — the one defect this whole server-side filter
|
|
2763
|
+
* path exists to remove. What the shopper gets instead is the flat family the grid always had,
|
|
2764
|
+
* plus a chip for whatever the URL carried, which stays removable.
|
|
2765
|
+
*/
|
|
2766
|
+
it('offers no parent row at all against a source that counts assignments', async () => {
|
|
2767
|
+
const stub = createStub(PRODUCTS, {
|
|
2768
|
+
filteredCount: 4,
|
|
2769
|
+
facets: {
|
|
2770
|
+
...FACETS,
|
|
2771
|
+
// Placed terms, but **no** `categoryCounts` — the shape a 3.7.0 gateway answers once the
|
|
2772
|
+
// theme has a tree from anywhere. The placement alone must not buy a parent row.
|
|
2773
|
+
categories: [
|
|
2774
|
+
{ id: 'cat-cup', slug: 'cup', title: 'Cup', count: 6, parentId: 'cat-tableware' },
|
|
2775
|
+
{
|
|
2776
|
+
id: 'cat-tableware',
|
|
2777
|
+
slug: 'tableware',
|
|
2778
|
+
title: 'Tableware',
|
|
2779
|
+
count: 0,
|
|
2780
|
+
parentId: null,
|
|
2781
|
+
},
|
|
2782
|
+
],
|
|
2783
|
+
},
|
|
2784
|
+
});
|
|
2785
|
+
const wrapper = mountGrid(FILTERED, { source: stub.source });
|
|
2786
|
+
await wrapper.vm.$nextTick();
|
|
2787
|
+
await flushPromises();
|
|
2788
|
+
|
|
2789
|
+
const { panel } = panelFor(wrapper, enUS.grid.legendCategory);
|
|
2790
|
+
// No nested group, no indent, no implied child — and both values are ordinary checkboxes.
|
|
2791
|
+
expect(panel.findAll('[role="group"]')).toHaveLength(0);
|
|
2792
|
+
expect(panel.findAll('label').map((label) => label.text().replace(/\s+/g, ' '))).toEqual([
|
|
2793
|
+
'Cup6',
|
|
2794
|
+
'Tableware0',
|
|
2795
|
+
]);
|
|
2796
|
+
expect(
|
|
2797
|
+
panel
|
|
2798
|
+
.findAll('input[type="checkbox"]')
|
|
2799
|
+
.every((box) => !(box.element as HTMLInputElement).checked)
|
|
2800
|
+
).toBe(true);
|
|
2801
|
+
});
|
|
2802
|
+
|
|
2803
|
+
/**
|
|
2804
|
+
* A link shared before the platform's `in_stock` vocabulary landed. The pass still reads the
|
|
2805
|
+
* old spelling, so the grid filters — but the block has to fold it into the current one, or
|
|
2806
|
+
* the switch reads off (an untranslated, unmatched value) and the chip quotes the raw word.
|
|
2807
|
+
* There is no separate "out of stock" control to offer any more (spec → Variants, `toggle`
|
|
2808
|
+
* facet: one switch, never a checkbox pair) — "In stock only" is the whole family now.
|
|
2809
|
+
*/
|
|
2810
|
+
it('folds a legacy availability spelling into the vocabulary the panel offers', async () => {
|
|
2811
|
+
const source = createDemoStorefront({ filters: { availability: ['in-stock'] } });
|
|
2812
|
+
const wrapper = mountGrid(FILTERED, { source });
|
|
2813
|
+
await wrapper.vm.$nextTick();
|
|
2814
|
+
await flushPromises();
|
|
2815
|
+
|
|
2816
|
+
const toggle = panelFor(wrapper, enUS.grid.legendAvailability).panel.get('[role="switch"]');
|
|
2817
|
+
expect(toggle.attributes('aria-checked')).toBe('true');
|
|
2818
|
+
expect(wrapper.get(`ul[aria-label="${enUS.grid.activeFilters}"]`).text()).toContain(
|
|
2819
|
+
enUS.grid.availabilityInStock
|
|
2820
|
+
);
|
|
2821
|
+
expect(wrapper.text()).not.toContain('in-stock');
|
|
2822
|
+
// And the request carries the current spelling, so the next write leaves a current URL.
|
|
2823
|
+
expect(source.route.filters.availability).toEqual(['in-stock']);
|
|
2824
|
+
await toggle.trigger('click');
|
|
2825
|
+
await wrapper.vm.$nextTick();
|
|
2826
|
+
expect(source.route.filters.availability).toBeUndefined();
|
|
2827
|
+
});
|
|
2828
|
+
|
|
2829
|
+
/** The other half of the round trip: the same bag, on a fresh page load, restores the whole
|
|
2830
|
+
* panel — the ticked values, the thumbs and the chips — and filters the first request. */
|
|
2831
|
+
it('restores the panel and the request from that query on the next load', async () => {
|
|
2832
|
+
const source = createDemoStorefront({
|
|
2833
|
+
filters: {
|
|
2834
|
+
category: ['knitwear'],
|
|
2835
|
+
collection: ['the-winter-edit'],
|
|
2836
|
+
colour: ['oat'],
|
|
2837
|
+
availability: ['in_stock'],
|
|
2838
|
+
price: ['50-150'],
|
|
2839
|
+
},
|
|
2840
|
+
});
|
|
2841
|
+
const wrapper = mountGrid(FILTERED, { source });
|
|
2842
|
+
await wrapper.vm.$nextTick();
|
|
2843
|
+
await flushPromises();
|
|
2844
|
+
|
|
2845
|
+
const checked = (legend: string) =>
|
|
2846
|
+
panelFor(wrapper, legend)
|
|
2847
|
+
.panel.findAll('input[type="checkbox"]')
|
|
2848
|
+
.filter((box) => (box.element as HTMLInputElement).checked).length;
|
|
2849
|
+
expect(checked(enUS.grid.legendCategory)).toBe(1);
|
|
2850
|
+
expect(checked(enUS.grid.legendCollection)).toBe(1);
|
|
2851
|
+
expect(checked(enUS.grid.legendColour)).toBe(1);
|
|
2852
|
+
expect(checked(enUS.grid.legendAvailability)).toBe(1);
|
|
2853
|
+
|
|
2854
|
+
const thumbs = panelFor(wrapper, PRICE_LEGEND).panel.findAll('[role="slider"]');
|
|
2855
|
+
expect(thumbs[0]!.attributes('aria-valuenow')).toBe('50');
|
|
2856
|
+
expect(thumbs[1]!.attributes('aria-valuenow')).toBe('150');
|
|
2857
|
+
|
|
2858
|
+
// The visible chip text is just the value's own label; the facet name rides in its remove
|
|
2859
|
+
// button's aria-label instead (see the dedicated "names each remove button" coverage in
|
|
2860
|
+
// `@eldrajs/ui`). A range contributes no chip of its own — the thumbs above are what show
|
|
2861
|
+
// the applied price.
|
|
2862
|
+
const chips = wrapper.get(`ul[aria-label="${enUS.grid.activeFilters}"]`).text();
|
|
2863
|
+
expect(chips).toContain('Knitwear');
|
|
2864
|
+
expect(chips).toContain('The winter edit');
|
|
2865
|
+
expect(chips).toContain('Oat');
|
|
2866
|
+
expect(chips).not.toContain('$50');
|
|
2867
|
+
|
|
2868
|
+
// And the grid itself is filtered — the demo source applies the same pass the gateway does.
|
|
2869
|
+
expect(countLine(wrapper).text()).toBe('4 products');
|
|
2870
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
2871
|
+
});
|
|
2872
|
+
});
|
|
2873
|
+
|
|
2874
|
+
/**
|
|
2875
|
+
* **A price range the shopper applied survives the next nudge of either thumb** — over the real
|
|
2876
|
+
* demo storefront, because the bug this pins only exists in the composition.
|
|
2877
|
+
*
|
|
2878
|
+
* The facets' price span is counted with every filter *except* price (contract §1), so ticking a
|
|
2879
|
+
* colour narrows it; the track is then widened back to hold the shopper's own bounds, or their
|
|
2880
|
+
* range would read back as the one price the remaining products cost. On
|
|
2881
|
+
* `?price=50-150&colour=oat` the track's extent therefore *is* 50–150, both thumbs sit on "an
|
|
2882
|
+
* end", and deriving both bounds from the pair read the untouched one as "no bound": one
|
|
2883
|
+
* ArrowRight on the minimum wrote `51-` and the ceiling was gone from the URL, the chip and the
|
|
2884
|
+
* request while the track still ended at 150.
|
|
2885
|
+
*/
|
|
2886
|
+
describe('an applied price range, with another group narrowing the facets', () => {
|
|
2887
|
+
function applied() {
|
|
2888
|
+
return createDemoStorefront({ filters: { price: ['50-150'], colour: ['oat'] } });
|
|
2889
|
+
}
|
|
2890
|
+
|
|
2891
|
+
function priceThumbs(wrapper: VueWrapper) {
|
|
2892
|
+
return panelFor(wrapper, PRICE_LEGEND).panel.findAll('[role="slider"]');
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2895
|
+
it('renders the thumbs at the applied values, not at the catalogue’s own ends', async () => {
|
|
2896
|
+
const source = applied();
|
|
2897
|
+
const wrapper = mountGrid(mock, { source });
|
|
2898
|
+
await wrapper.vm.$nextTick();
|
|
2899
|
+
await flushPromises();
|
|
2900
|
+
|
|
2901
|
+
const thumbs = priceThumbs(wrapper);
|
|
2902
|
+
expect(thumbs[0]!.attributes('aria-valuenow')).toBe('50');
|
|
2903
|
+
expect(thumbs[1]!.attributes('aria-valuenow')).toBe('150');
|
|
2904
|
+
// A range contributes no chip of its own — the thumbs above are what show the applied price.
|
|
2905
|
+
expect(wrapper.get(`ul[aria-label="${enUS.grid.activeFilters}"]`).text()).not.toContain('$');
|
|
2906
|
+
});
|
|
2907
|
+
|
|
2908
|
+
it('keeps the ceiling when the minimum is nudged', async () => {
|
|
2909
|
+
const source = applied();
|
|
2910
|
+
const wrapper = mountGrid(mock, { source });
|
|
2911
|
+
await wrapper.vm.$nextTick();
|
|
2912
|
+
await flushPromises();
|
|
2913
|
+
|
|
2914
|
+
const min = priceThumbs(wrapper)[0]!;
|
|
2915
|
+
await min.trigger('keydown', { key: 'ArrowRight' });
|
|
2916
|
+
await min.trigger('keyup', { key: 'ArrowRight' });
|
|
2917
|
+
await wrapper.vm.$nextTick();
|
|
2918
|
+
|
|
2919
|
+
expect(source.route.filters.price).toEqual(['51-150']);
|
|
2920
|
+
});
|
|
2921
|
+
|
|
2922
|
+
it('keeps the floor when the maximum is nudged', async () => {
|
|
2923
|
+
const source = applied();
|
|
2924
|
+
const wrapper = mountGrid(mock, { source });
|
|
2925
|
+
await wrapper.vm.$nextTick();
|
|
2926
|
+
await flushPromises();
|
|
2927
|
+
|
|
2928
|
+
const max = priceThumbs(wrapper)[1]!;
|
|
2929
|
+
await max.trigger('keydown', { key: 'ArrowLeft' });
|
|
2930
|
+
await max.trigger('keyup', { key: 'ArrowLeft' });
|
|
2931
|
+
await wrapper.vm.$nextTick();
|
|
2932
|
+
|
|
2933
|
+
expect(source.route.filters.price).toEqual(['50-149']);
|
|
2934
|
+
});
|
|
2935
|
+
|
|
2936
|
+
/** And the bound can still be dropped on purpose: a thumb the shopper takes all the way out is
|
|
2937
|
+
* "no bound", which is the gesture the rule above must not swallow. */
|
|
2938
|
+
it('still drops a bound dragged out to the catalogue’s own end', async () => {
|
|
2939
|
+
const source = createDemoStorefront({ filters: { price: ['50-150'] } });
|
|
2940
|
+
const wrapper = mountGrid(mock, { source });
|
|
2941
|
+
await wrapper.vm.$nextTick();
|
|
2942
|
+
await flushPromises();
|
|
2943
|
+
|
|
2944
|
+
const min = priceThumbs(wrapper)[0]!;
|
|
2945
|
+
await min.trigger('keydown', { key: 'Home' });
|
|
2946
|
+
await min.trigger('keyup', { key: 'Home' });
|
|
2947
|
+
await wrapper.vm.$nextTick();
|
|
2948
|
+
|
|
2949
|
+
expect(source.route.filters.price).toEqual(['-150']);
|
|
2950
|
+
});
|
|
2951
|
+
});
|
|
2952
|
+
|
|
2953
|
+
/**
|
|
2954
|
+
* The other direction of the URL round-trip: a query the block did not write.
|
|
2955
|
+
*
|
|
2956
|
+
* Back/Forward, a shared link to the same collection with a different range, and — the one that
|
|
2957
|
+
* made the deployed site's filters inert — arriving on a **prerendered** page, where Nuxt hydrates
|
|
2958
|
+
* under the payload's query-less path and only restores the real URL once the app has mounted. A
|
|
2959
|
+
* block that seeds its filter state once and never looks again shows the unfiltered collection
|
|
2960
|
+
* forever, under chips and a URL that say otherwise.
|
|
2961
|
+
*/
|
|
2962
|
+
describe('a query change the block did not make', () => {
|
|
2963
|
+
it('adopts it: the request, the count and the price inputs all follow', async () => {
|
|
2964
|
+
const stub = createStub(PRODUCTS, { filteredCount: 4 });
|
|
2965
|
+
const wrapper = mountGrid(mock, { source: stub.source });
|
|
2966
|
+
await wrapper.vm.$nextTick();
|
|
2967
|
+
expect(countLine(wrapper).text()).toBe('12 products');
|
|
2968
|
+
expect(stub.requests.at(-1)?.filters).toBeUndefined();
|
|
2969
|
+
|
|
2970
|
+
stub.source.route.filters = { price: ['50-150'] };
|
|
2971
|
+
await wrapper.vm.$nextTick();
|
|
2972
|
+
await flushPromises();
|
|
2973
|
+
|
|
2974
|
+
expect(stub.requests.at(-1)?.filters).toEqual({ price: ['50-150'] });
|
|
2975
|
+
expect(countLine(wrapper).text()).toBe('4 products');
|
|
2976
|
+
// The sidebar's slider fields are the applied state and read the range as money; the
|
|
2977
|
+
// drawer's are its pending copy, seeded from the applied state only when it opens, so until
|
|
2978
|
+
// then they read the catalogue's own span — which is what "no bound" looks like.
|
|
2979
|
+
const priceInputs = wrapper
|
|
2980
|
+
.findAll('input[data-input]')
|
|
2981
|
+
.map((input) => (input.element as HTMLInputElement).value);
|
|
2982
|
+
expect(priceInputs).toEqual(['$50', '$150', '$24', '$180']);
|
|
2983
|
+
// A range contributes no chip of its own — the fields above are what show the applied price.
|
|
2984
|
+
expect(wrapper.find(`ul[aria-label="${enUS.grid.activeFilters}"]`).exists()).toBe(false);
|
|
2985
|
+
});
|
|
2986
|
+
|
|
2987
|
+
it('follows a sort and a column count out of the URL too', async () => {
|
|
2988
|
+
const stub = createStub(PRODUCTS, { filteredCount: 4 });
|
|
2989
|
+
const wrapper = mountGrid(mock, { source: stub.source });
|
|
2990
|
+
await wrapper.vm.$nextTick();
|
|
2991
|
+
|
|
2992
|
+
stub.source.route.sort = 'price-desc';
|
|
2993
|
+
stub.source.route.columns = '4';
|
|
2994
|
+
await wrapper.vm.$nextTick();
|
|
2995
|
+
await flushPromises();
|
|
2996
|
+
|
|
2997
|
+
expect(stub.requests.at(-1)?.sort).toBe('price-desc');
|
|
2998
|
+
expect(gridList(wrapper).classes().join(' ')).toContain('4');
|
|
2999
|
+
});
|
|
3000
|
+
|
|
3001
|
+
/** The block's own writes go out through `setQuery`, come back as a route change, and stop. */
|
|
3002
|
+
it('does not re-request when the change is the block’s own round-trip', async () => {
|
|
3003
|
+
useFilterTimers();
|
|
3004
|
+
const stub = createStub(PRODUCTS, { filteredCount: 4 });
|
|
3005
|
+
const wrapper = mountGrid(mock, { source: stub.source });
|
|
3006
|
+
await wrapper.vm.$nextTick();
|
|
3007
|
+
|
|
3008
|
+
const before = stub.requests.length;
|
|
3009
|
+
const { panel } = panelFor(wrapper, enUS.grid.legendCategory);
|
|
3010
|
+
await panel.get('input[type="checkbox"]').setValue(true);
|
|
3011
|
+
// The tick's own write comes back as a route change *before* the debounced read goes out, so
|
|
3012
|
+
// this is also where `adoptRouteState` gets the chance to flush the window it did not arm —
|
|
3013
|
+
// which would send the request early and, worse, a second one once the window expired.
|
|
3014
|
+
await settleFilterDebounce(wrapper);
|
|
3015
|
+
await flushPromises();
|
|
3016
|
+
await wrapper.vm.$nextTick();
|
|
3017
|
+
await flushPromises();
|
|
3018
|
+
|
|
3019
|
+
// Exactly one: the shopper's tick. Reading the URL back must not mint a second request for the
|
|
3020
|
+
// state the block just wrote — an unguarded re-seed does, on every filter the shopper touches.
|
|
3021
|
+
expect(stub.requests.length).toBe(before + 1);
|
|
3022
|
+
expect(stub.requests.at(-1)?.filters).toEqual({ category: ['knitwear'] });
|
|
3023
|
+
});
|
|
3024
|
+
});
|
|
3025
|
+
});
|
|
3026
|
+
|
|
3027
|
+
describe('collection-grid — card width on a phone', () => {
|
|
3028
|
+
it('lets the grid track, not the card, decide a card width (two columns fit a phone)', async () => {
|
|
3029
|
+
const wrapper = mountGrid(mock);
|
|
3030
|
+
await wrapper.vm.$nextTick();
|
|
3031
|
+
// The card's own root is the list item's first element; `cards()` answers the items.
|
|
3032
|
+
const root = cards(wrapper)[0]!.element.firstElementChild as HTMLElement;
|
|
3033
|
+
expect(root.className).toContain('min-w-0');
|
|
3034
|
+
expect(root.className).not.toMatch(/\bmin-w-56\b/);
|
|
3035
|
+
wrapper.unmount();
|
|
3036
|
+
});
|
|
3037
|
+
});
|