@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.
Files changed (485) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/LICENSE +21 -0
  3. package/README.md +26 -1
  4. package/dist/cli.d.ts +1 -0
  5. package/dist/cli.js +203 -0
  6. package/dist/index.d.ts +174 -0
  7. package/dist/index.js +3 -0
  8. package/dist/validate-DprFpjV7.js +535 -0
  9. package/package.json +50 -2
  10. package/template/.eldra/block-types.d.ts +429 -0
  11. package/template/.eldra/manifest.json +9378 -0
  12. package/template/.eldra/previews.json +36 -0
  13. package/template/.github/workflows/eldra-deploy.yml +24 -0
  14. package/template/.gitlab-ci.yml +16 -0
  15. package/template/.storybook/eldra.ts +123 -0
  16. package/template/.storybook/i18n.ts +23 -0
  17. package/template/.storybook/main.ts +59 -0
  18. package/template/.storybook/nuxt-link-stub.ts +23 -0
  19. package/template/.storybook/preview.ts +53 -0
  20. package/template/.storybook/shims-vue.d.ts +10 -0
  21. package/template/.storybook/virtual-eldra.d.ts +32 -0
  22. package/template/README.md +293 -0
  23. package/template/app/app.vue +126 -0
  24. package/template/app/assets/main.css +404 -0
  25. package/template/app/components/EldraIcon.vue +66 -0
  26. package/template/app/components/EldraRouterLink.vue +62 -0
  27. package/template/app/components/ui/UiImage.stories.ts +30 -0
  28. package/template/app/components/ui/UiImage.vue +224 -0
  29. package/template/app/components/ui/__tests__/UiImage.spec.ts +292 -0
  30. package/template/app/composables/iconComponent.ts +84 -0
  31. package/template/app/composables/iconFetcher.ts +14 -0
  32. package/template/app/composables/useBlockData.ts +30 -0
  33. package/template/app/composables/useEditing.ts +31 -0
  34. package/template/app/composables/useEldraIcon.ts +46 -0
  35. package/template/app/composables/useRevalidating.ts +69 -0
  36. package/template/app/composables/useRichTextScrollRegions.ts +80 -0
  37. package/template/app/composables/useStorefront.ts +18 -0
  38. package/template/app/composables/useStorefrontFeedback.ts +49 -0
  39. package/template/app/composables/useUiId.ts +18 -0
  40. package/template/app/composables/useWishlist.ts +42 -0
  41. package/template/app/i18n.d.ts +28 -0
  42. package/template/app/icons.ts +185 -0
  43. package/template/app/pages/[...slug].vue +134 -0
  44. package/template/app/plugins/eldra-i18n.ts +98 -0
  45. package/template/app/plugins/eldra-storefront.ts +288 -0
  46. package/template/app/plugins/eldra-ui-messages.ts +112 -0
  47. package/template/app/storefront/cart.ts +245 -0
  48. package/template/app/storefront/categories.ts +283 -0
  49. package/template/app/storefront/collectionSelector.ts +60 -0
  50. package/template/app/storefront/commerce.ts +58 -0
  51. package/template/app/storefront/demo.ts +1313 -0
  52. package/template/app/storefront/facets.ts +476 -0
  53. package/template/app/storefront/feedback.ts +122 -0
  54. package/template/app/storefront/gateway.ts +2256 -0
  55. package/template/app/storefront/history.ts +233 -0
  56. package/template/app/storefront/money.ts +248 -0
  57. package/template/app/storefront/options.ts +71 -0
  58. package/template/app/storefront/prerender.ts +77 -0
  59. package/template/app/storefront/refresh.ts +222 -0
  60. package/template/app/storefront/toProductCard.ts +154 -0
  61. package/template/app/storefront/types.ts +815 -0
  62. package/template/app/storefront/volatile.ts +211 -0
  63. package/template/app/templates.ts +544 -0
  64. package/template/app/utils/classes.ts +40 -0
  65. package/template/app/utils/links.ts +70 -0
  66. package/template/app/utils/pageStructure.ts +77 -0
  67. package/template/app/utils/pageTitle.ts +37 -0
  68. package/template/app/virtual-eldra.d.ts +12 -0
  69. package/template/bitbucket-pipelines.yml +19 -0
  70. package/template/blocks/announcement-bar/Block.vue +203 -0
  71. package/template/blocks/announcement-bar/__tests__/Block.spec.ts +227 -0
  72. package/template/blocks/announcement-bar/block.json +45 -0
  73. package/template/blocks/announcement-bar/mock.json +7 -0
  74. package/template/blocks/announcement-bar/preview.png +0 -0
  75. package/template/blocks/article/Block.vue +317 -0
  76. package/template/blocks/article/__tests__/Block.spec.ts +229 -0
  77. package/template/blocks/article/block.json +148 -0
  78. package/template/blocks/article/mock.json +512 -0
  79. package/template/blocks/article/preview.json +16 -0
  80. package/template/blocks/article/preview.png +0 -0
  81. package/template/blocks/article-list/Block.vue +343 -0
  82. package/template/blocks/article-list/__tests__/Block.spec.ts +279 -0
  83. package/template/blocks/article-list/block.json +181 -0
  84. package/template/blocks/article-list/mock.json +68 -0
  85. package/template/blocks/article-list/preview.json +84 -0
  86. package/template/blocks/article-list/preview.png +0 -0
  87. package/template/blocks/breadcrumbs/Block.vue +278 -0
  88. package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +461 -0
  89. package/template/blocks/breadcrumbs/block.json +89 -0
  90. package/template/blocks/breadcrumbs/mock.json +11 -0
  91. package/template/blocks/breadcrumbs/preview.json +3 -0
  92. package/template/blocks/breadcrumbs/preview.png +0 -0
  93. package/template/blocks/cart/Block.vue +372 -0
  94. package/template/blocks/cart/__tests__/Block.spec.ts +561 -0
  95. package/template/blocks/cart/__tests__/ShippingBar.spec.ts +78 -0
  96. package/template/blocks/cart/__tests__/Summary.spec.ts +245 -0
  97. package/template/blocks/cart/block.json +74 -0
  98. package/template/blocks/cart/mock.json +11 -0
  99. package/template/blocks/cart/parts/CartLines.vue +257 -0
  100. package/template/blocks/cart/parts/ShippingBar.vue +105 -0
  101. package/template/blocks/cart/parts/Summary.vue +291 -0
  102. package/template/blocks/cart/preview.png +0 -0
  103. package/template/blocks/collection-grid/Block.vue +1832 -0
  104. package/template/blocks/collection-grid/__tests__/Block.spec.ts +3037 -0
  105. package/template/blocks/collection-grid/__tests__/groups.spec.ts +731 -0
  106. package/template/blocks/collection-grid/block.json +187 -0
  107. package/template/blocks/collection-grid/mock.json +23 -0
  108. package/template/blocks/collection-grid/parts/groups.ts +861 -0
  109. package/template/blocks/collection-grid/preview.json +7 -0
  110. package/template/blocks/collection-grid/preview.png +0 -0
  111. package/template/blocks/collection-header/Block.vue +533 -0
  112. package/template/blocks/collection-header/__tests__/Block.spec.ts +381 -0
  113. package/template/blocks/collection-header/block.json +140 -0
  114. package/template/blocks/collection-header/mock.json +28 -0
  115. package/template/blocks/collection-header/preview.json +14 -0
  116. package/template/blocks/collection-header/preview.png +0 -0
  117. package/template/blocks/contact/Block.vue +621 -0
  118. package/template/blocks/contact/__tests__/Block.spec.ts +347 -0
  119. package/template/blocks/contact/block.json +174 -0
  120. package/template/blocks/contact/mock.json +28 -0
  121. package/template/blocks/contact/preview.json +9 -0
  122. package/template/blocks/contact/preview.png +0 -0
  123. package/template/blocks/cta/Block.vue +383 -0
  124. package/template/blocks/cta/__tests__/Block.spec.ts +309 -0
  125. package/template/blocks/cta/block.json +86 -0
  126. package/template/blocks/cta/mock.json +10 -0
  127. package/template/blocks/cta/preview.json +9 -0
  128. package/template/blocks/cta/preview.png +0 -0
  129. package/template/blocks/faq/Block.vue +254 -0
  130. package/template/blocks/faq/__tests__/Block.spec.ts +312 -0
  131. package/template/blocks/faq/block.json +113 -0
  132. package/template/blocks/faq/mock.json +115 -0
  133. package/template/blocks/faq/preview.png +0 -0
  134. package/template/blocks/feature-grid/Block.vue +241 -0
  135. package/template/blocks/feature-grid/__tests__/Block.spec.ts +311 -0
  136. package/template/blocks/feature-grid/block.json +106 -0
  137. package/template/blocks/feature-grid/mock.json +29 -0
  138. package/template/blocks/feature-grid/preview.json +45 -0
  139. package/template/blocks/feature-grid/preview.png +0 -0
  140. package/template/blocks/footer/Block.vue +652 -0
  141. package/template/blocks/footer/__tests__/Block.spec.ts +700 -0
  142. package/template/blocks/footer/block.json +240 -0
  143. package/template/blocks/footer/mock.json +161 -0
  144. package/template/blocks/footer/preview.png +0 -0
  145. package/template/blocks/gallery/Block.vue +416 -0
  146. package/template/blocks/gallery/__tests__/Block.spec.ts +289 -0
  147. package/template/blocks/gallery/block.json +87 -0
  148. package/template/blocks/gallery/mock.json +16 -0
  149. package/template/blocks/gallery/preview.json +64 -0
  150. package/template/blocks/gallery/preview.png +0 -0
  151. package/template/blocks/hero/Block.vue +378 -0
  152. package/template/blocks/hero/__tests__/Block.spec.ts +324 -0
  153. package/template/blocks/hero/block.json +146 -0
  154. package/template/blocks/hero/mock.json +11 -0
  155. package/template/blocks/hero/preview.json +55 -0
  156. package/template/blocks/hero/preview.png +0 -0
  157. package/template/blocks/image/Block.vue +232 -0
  158. package/template/blocks/image/__tests__/Block.spec.ts +224 -0
  159. package/template/blocks/image/block.json +67 -0
  160. package/template/blocks/image/mock.json +7 -0
  161. package/template/blocks/image/preview.json +9 -0
  162. package/template/blocks/image/preview.png +0 -0
  163. package/template/blocks/logo-cloud/Block.vue +206 -0
  164. package/template/blocks/logo-cloud/__tests__/Block.spec.ts +210 -0
  165. package/template/blocks/logo-cloud/block.json +79 -0
  166. package/template/blocks/logo-cloud/mock.json +15 -0
  167. package/template/blocks/logo-cloud/preview.json +92 -0
  168. package/template/blocks/logo-cloud/preview.png +0 -0
  169. package/template/blocks/navigation/Block.vue +1348 -0
  170. package/template/blocks/navigation/__tests__/Block.spec.ts +2030 -0
  171. package/template/blocks/navigation/block.json +167 -0
  172. package/template/blocks/navigation/mock.json +191 -0
  173. package/template/blocks/navigation/preview.png +0 -0
  174. package/template/blocks/navigation/useMegaMenuKeys.ts +276 -0
  175. package/template/blocks/newsletter/Block.vue +399 -0
  176. package/template/blocks/newsletter/__tests__/Block.spec.ts +365 -0
  177. package/template/blocks/newsletter/block.json +105 -0
  178. package/template/blocks/newsletter/mock.json +31 -0
  179. package/template/blocks/newsletter/preview.png +0 -0
  180. package/template/blocks/order-status/Block.vue +754 -0
  181. package/template/blocks/order-status/__tests__/Block.spec.ts +515 -0
  182. package/template/blocks/order-status/block.json +138 -0
  183. package/template/blocks/order-status/mock.json +19 -0
  184. package/template/blocks/order-status/preview.png +0 -0
  185. package/template/blocks/pricing-table/Block.vue +297 -0
  186. package/template/blocks/pricing-table/__tests__/Block.spec.ts +357 -0
  187. package/template/blocks/pricing-table/block.json +155 -0
  188. package/template/blocks/pricing-table/mock.json +47 -0
  189. package/template/blocks/pricing-table/preview.png +0 -0
  190. package/template/blocks/product-carousel/Block.vue +459 -0
  191. package/template/blocks/product-carousel/__tests__/Block.spec.ts +957 -0
  192. package/template/blocks/product-carousel/block.json +71 -0
  193. package/template/blocks/product-carousel/mock.json +9 -0
  194. package/template/blocks/product-carousel/preview.json +7 -0
  195. package/template/blocks/product-carousel/preview.png +0 -0
  196. package/template/blocks/product-detail/Block.vue +886 -0
  197. package/template/blocks/product-detail/__tests__/Block.spec.ts +1492 -0
  198. package/template/blocks/product-detail/__tests__/stock.spec.ts +119 -0
  199. package/template/blocks/product-detail/block.json +155 -0
  200. package/template/blocks/product-detail/mock.json +113 -0
  201. package/template/blocks/product-detail/parts/Gallery.vue +181 -0
  202. package/template/blocks/product-detail/parts/StickyBuyBar.vue +99 -0
  203. package/template/blocks/product-detail/preview.png +0 -0
  204. package/template/blocks/product-detail/stock.ts +150 -0
  205. package/template/blocks/quote/Block.vue +206 -0
  206. package/template/blocks/quote/__tests__/Block.spec.ts +265 -0
  207. package/template/blocks/quote/block.json +76 -0
  208. package/template/blocks/quote/mock.json +9 -0
  209. package/template/blocks/quote/preview.json +16 -0
  210. package/template/blocks/quote/preview.png +0 -0
  211. package/template/blocks/rich-text/Block.vue +143 -0
  212. package/template/blocks/rich-text/__tests__/Block.spec.ts +191 -0
  213. package/template/blocks/rich-text/block.json +57 -0
  214. package/template/blocks/rich-text/mock.json +87 -0
  215. package/template/blocks/rich-text/preview.png +0 -0
  216. package/template/blocks/search/Block.vue +589 -0
  217. package/template/blocks/search/PopularChips.vue +40 -0
  218. package/template/blocks/search/TypeSection.vue +148 -0
  219. package/template/blocks/search/__tests__/Block.spec.ts +718 -0
  220. package/template/blocks/search/__tests__/results.spec.ts +166 -0
  221. package/template/blocks/search/block.json +102 -0
  222. package/template/blocks/search/mock.json +18 -0
  223. package/template/blocks/search/preview.png +0 -0
  224. package/template/blocks/search/results.ts +85 -0
  225. package/template/blocks/split-content/Block.vue +195 -0
  226. package/template/blocks/split-content/__tests__/Block.spec.ts +225 -0
  227. package/template/blocks/split-content/block.json +70 -0
  228. package/template/blocks/split-content/mock.json +45 -0
  229. package/template/blocks/split-content/preview.json +58 -0
  230. package/template/blocks/split-content/preview.png +0 -0
  231. package/template/blocks/stats/Block.vue +159 -0
  232. package/template/blocks/stats/__tests__/Block.spec.ts +194 -0
  233. package/template/blocks/stats/block.json +73 -0
  234. package/template/blocks/stats/mock.json +12 -0
  235. package/template/blocks/stats/preview.png +0 -0
  236. package/template/blocks/tabs/Block.vue +278 -0
  237. package/template/blocks/tabs/__tests__/Block.spec.ts +303 -0
  238. package/template/blocks/tabs/block.json +97 -0
  239. package/template/blocks/tabs/mock.json +129 -0
  240. package/template/blocks/tabs/preview.json +153 -0
  241. package/template/blocks/tabs/preview.png +0 -0
  242. package/template/blocks/team/Block.vue +288 -0
  243. package/template/blocks/team/__tests__/Block.spec.ts +221 -0
  244. package/template/blocks/team/block.json +125 -0
  245. package/template/blocks/team/mock.json +39 -0
  246. package/template/blocks/team/preview.json +62 -0
  247. package/template/blocks/team/preview.png +0 -0
  248. package/template/blocks/testimonials/Block.vue +408 -0
  249. package/template/blocks/testimonials/__tests__/Block.spec.ts +319 -0
  250. package/template/blocks/testimonials/block.json +121 -0
  251. package/template/blocks/testimonials/mock.json +46 -0
  252. package/template/blocks/testimonials/preview.json +68 -0
  253. package/template/blocks/testimonials/preview.png +0 -0
  254. package/template/blocks/timeline/Block.vue +274 -0
  255. package/template/blocks/timeline/__tests__/Block.spec.ts +310 -0
  256. package/template/blocks/timeline/block.json +98 -0
  257. package/template/blocks/timeline/mock.json +27 -0
  258. package/template/blocks/timeline/preview.png +0 -0
  259. package/template/blocks/trust-strip/Block.vue +330 -0
  260. package/template/blocks/trust-strip/__tests__/Block.spec.ts +290 -0
  261. package/template/blocks/trust-strip/block.json +117 -0
  262. package/template/blocks/trust-strip/mock.json +37 -0
  263. package/template/blocks/trust-strip/preview.png +0 -0
  264. package/template/blocks/video-embed/Block.vue +354 -0
  265. package/template/blocks/video-embed/__tests__/Block.spec.ts +219 -0
  266. package/template/blocks/video-embed/__tests__/embed.spec.ts +76 -0
  267. package/template/blocks/video-embed/block.json +94 -0
  268. package/template/blocks/video-embed/embed.ts +84 -0
  269. package/template/blocks/video-embed/mock.json +13 -0
  270. package/template/blocks/video-embed/preview.json +9 -0
  271. package/template/blocks/video-embed/preview.png +0 -0
  272. package/template/blocks/wishlist/Block.vue +367 -0
  273. package/template/blocks/wishlist/__tests__/Block.spec.ts +508 -0
  274. package/template/blocks/wishlist/block.json +42 -0
  275. package/template/blocks/wishlist/mock.json +9 -0
  276. package/template/blocks/wishlist/preview.png +0 -0
  277. package/template/i18n/en-US.json +602 -0
  278. package/template/i18n/is-IS.json +602 -0
  279. package/template/nuxt.config.ts +156 -0
  280. package/template/package.json +56 -0
  281. package/template/pages/article.page.json +731 -0
  282. package/template/pages/cart.page.json +85 -0
  283. package/template/pages/category.page.json +133 -0
  284. package/template/pages/collection.page.json +194 -0
  285. package/template/pages/home.page.json +353 -0
  286. package/template/pages/product.page.json +323 -0
  287. package/template/pages/products.page.json +144 -0
  288. package/template/pages/search.page.json +83 -0
  289. package/template/pages/wishlist.page.json +88 -0
  290. package/template/public/apple-touch-icon.png +0 -0
  291. package/template/public/demo/article-cover.svg +1 -0
  292. package/template/public/demo/article-figure.svg +1 -0
  293. package/template/public/demo/avatar-1.svg +3 -0
  294. package/template/public/demo/avatar-2.svg +3 -0
  295. package/template/public/demo/avatar-3.svg +3 -0
  296. package/template/public/demo/avatar-4.svg +3 -0
  297. package/template/public/demo/avatar-5.svg +3 -0
  298. package/template/public/demo/avatar-6.svg +3 -0
  299. package/template/public/demo/avatar-7.svg +3 -0
  300. package/template/public/demo/avatar-8.svg +3 -0
  301. package/template/public/demo/collection-1.svg +1 -0
  302. package/template/public/demo/collection-2.svg +1 -0
  303. package/template/public/demo/cta-split.svg +1 -0
  304. package/template/public/demo/feature-1.svg +1 -0
  305. package/template/public/demo/feature-2.svg +1 -0
  306. package/template/public/demo/feature-3.svg +1 -0
  307. package/template/public/demo/feature-4.svg +1 -0
  308. package/template/public/demo/gallery-1.svg +1 -0
  309. package/template/public/demo/gallery-2.svg +1 -0
  310. package/template/public/demo/gallery-3.svg +1 -0
  311. package/template/public/demo/gallery-4.svg +1 -0
  312. package/template/public/demo/gallery-5.svg +1 -0
  313. package/template/public/demo/gallery-6.svg +1 -0
  314. package/template/public/demo/gallery-7.svg +1 -0
  315. package/template/public/demo/gallery-8.svg +1 -0
  316. package/template/public/demo/hero-slide-1.svg +1 -0
  317. package/template/public/demo/hero-slide-2.svg +1 -0
  318. package/template/public/demo/hero-slide-3.svg +1 -0
  319. package/template/public/demo/hero-slide-4.svg +1 -0
  320. package/template/public/demo/hero-wide.svg +1 -0
  321. package/template/public/demo/hero.svg +1 -0
  322. package/template/public/demo/logo-1.svg +4 -0
  323. package/template/public/demo/logo-2.svg +4 -0
  324. package/template/public/demo/logo-3.svg +4 -0
  325. package/template/public/demo/logo-4.svg +4 -0
  326. package/template/public/demo/logo-5.svg +4 -0
  327. package/template/public/demo/logo-6.svg +4 -0
  328. package/template/public/demo/logo-7.svg +4 -0
  329. package/template/public/demo/logo-8.svg +4 -0
  330. package/template/public/demo/logo.svg +3 -0
  331. package/template/public/demo/map.svg +1 -0
  332. package/template/public/demo/poster.svg +1 -0
  333. package/template/public/demo/product-1.svg +4 -0
  334. package/template/public/demo/product-10.svg +4 -0
  335. package/template/public/demo/product-11.svg +4 -0
  336. package/template/public/demo/product-12.svg +4 -0
  337. package/template/public/demo/product-2.svg +4 -0
  338. package/template/public/demo/product-3.svg +4 -0
  339. package/template/public/demo/product-4.svg +4 -0
  340. package/template/public/demo/product-5.svg +4 -0
  341. package/template/public/demo/product-6.svg +4 -0
  342. package/template/public/demo/product-7.svg +4 -0
  343. package/template/public/demo/product-8.svg +4 -0
  344. package/template/public/demo/product-9.svg +4 -0
  345. package/template/public/demo/product-square-1.svg +4 -0
  346. package/template/public/demo/product-square-2.svg +4 -0
  347. package/template/public/demo/product-square-3.svg +4 -0
  348. package/template/public/demo/product-square-4.svg +4 -0
  349. package/template/public/demo/product-square-5.svg +4 -0
  350. package/template/public/demo/product-square-6.svg +4 -0
  351. package/template/public/demo/quote-portrait.svg +4 -0
  352. package/template/public/demo/split-1.svg +1 -0
  353. package/template/public/demo/split-2.svg +1 -0
  354. package/template/public/demo/split-3.svg +1 -0
  355. package/template/public/demo/split-4.svg +1 -0
  356. package/template/public/demo/team-1.svg +4 -0
  357. package/template/public/demo/team-2.svg +4 -0
  358. package/template/public/demo/team-3.svg +4 -0
  359. package/template/public/demo/team-4.svg +4 -0
  360. package/template/public/favicon.ico +0 -0
  361. package/template/scripts/demo-images.mjs +393 -0
  362. package/template/scripts/generate-stories.mjs +156 -0
  363. package/template/scripts/previewHash.mjs +125 -0
  364. package/template/scripts/previews.mjs +149 -0
  365. package/template/stories/generated/announcement-bar.stories.ts +44 -0
  366. package/template/stories/generated/article-list.stories.ts +87 -0
  367. package/template/stories/generated/article.stories.ts +27 -0
  368. package/template/stories/generated/breadcrumbs.stories.ts +39 -0
  369. package/template/stories/generated/cart.stories.ts +38 -0
  370. package/template/stories/generated/collection-grid.stories.ts +117 -0
  371. package/template/stories/generated/collection-header.stories.ts +51 -0
  372. package/template/stories/generated/contact.stories.ts +45 -0
  373. package/template/stories/generated/cta.stories.ts +51 -0
  374. package/template/stories/generated/faq.stories.ts +56 -0
  375. package/template/stories/generated/feature-grid.stories.ts +69 -0
  376. package/template/stories/generated/footer.stories.ts +50 -0
  377. package/template/stories/generated/gallery.stories.ts +81 -0
  378. package/template/stories/generated/hero.stories.ts +75 -0
  379. package/template/stories/generated/image.stories.ts +99 -0
  380. package/template/stories/generated/logo-cloud.stories.ts +57 -0
  381. package/template/stories/generated/navigation.stories.ts +62 -0
  382. package/template/stories/generated/newsletter.stories.ts +68 -0
  383. package/template/stories/generated/order-status.stories.ts +32 -0
  384. package/template/stories/generated/pricing-table.stories.ts +44 -0
  385. package/template/stories/generated/product-carousel.stories.ts +75 -0
  386. package/template/stories/generated/product-detail.stories.ts +62 -0
  387. package/template/stories/generated/quote.stories.ts +69 -0
  388. package/template/stories/generated/rich-text.stories.ts +50 -0
  389. package/template/stories/generated/search.stories.ts +56 -0
  390. package/template/stories/generated/split-content.stories.ts +39 -0
  391. package/template/stories/generated/stats.stories.ts +68 -0
  392. package/template/stories/generated/tabs.stories.ts +45 -0
  393. package/template/stories/generated/team.stories.ts +45 -0
  394. package/template/stories/generated/testimonials.stories.ts +69 -0
  395. package/template/stories/generated/timeline.stories.ts +80 -0
  396. package/template/stories/generated/trust-strip.stories.ts +62 -0
  397. package/template/stories/generated/video-embed.stories.ts +63 -0
  398. package/template/stories/generated/wishlist.stories.ts +26 -0
  399. package/template/stories/pages/article.stories.ts +51 -0
  400. package/template/stories/pages/cart.stories.ts +56 -0
  401. package/template/stories/pages/category.stories.ts +56 -0
  402. package/template/stories/pages/collection.stories.ts +51 -0
  403. package/template/stories/pages/home.stories.ts +51 -0
  404. package/template/stories/pages/product.stories.ts +47 -0
  405. package/template/stories/pages/products.stories.ts +58 -0
  406. package/template/stories/pages/search.stories.ts +54 -0
  407. package/template/stories/pages/wishlist.stories.ts +53 -0
  408. package/template/stories/support/pageBlocks.ts +115 -0
  409. package/template/test/blocksEmptyData.spec.ts +52 -0
  410. package/template/test/carouselKeyboard.spec.ts +272 -0
  411. package/template/test/carouselRing.browser.spec.ts +193 -0
  412. package/template/test/carouselSlideWidth.browser.spec.ts +102 -0
  413. package/template/test/cartDrawer.spec.ts +295 -0
  414. package/template/test/cartToast.spec.ts +86 -0
  415. package/template/test/countPill.browser.spec.ts +196 -0
  416. package/template/test/demoImages.spec.ts +140 -0
  417. package/template/test/deps.spec.ts +102 -0
  418. package/template/test/eldraIcon.spec.ts +58 -0
  419. package/template/test/framing.spec.ts +76 -0
  420. package/template/test/i18n.spec.ts +200 -0
  421. package/template/test/iconComponent.spec.ts +91 -0
  422. package/template/test/inlineEditable.spec.ts +335 -0
  423. package/template/test/localePrefix.spec.ts +342 -0
  424. package/template/test/mainCss.spec.ts +107 -0
  425. package/template/test/mockGatewayContract.spec.ts +122 -0
  426. package/template/test/mocks/blocks.ts +20 -0
  427. package/template/test/mocks/breakpoints.ts +7 -0
  428. package/template/test/mocks/manifest.ts +11 -0
  429. package/template/test/moneyFormatting.spec.ts +85 -0
  430. package/template/test/pageTitle.spec.ts +49 -0
  431. package/template/test/pages/article.spec.ts +231 -0
  432. package/template/test/pages/category.spec.ts +185 -0
  433. package/template/test/pages/collection.spec.ts +396 -0
  434. package/template/test/pages/home.spec.ts +295 -0
  435. package/template/test/pages/hydration.spec.ts +557 -0
  436. package/template/test/pages/product.spec.ts +396 -0
  437. package/template/test/pages/seededPages.spec.ts +190 -0
  438. package/template/test/pages/ssr.spec.ts +387 -0
  439. package/template/test/prerenderCommerce.spec.ts +134 -0
  440. package/template/test/prerenderFailure.spec.ts +130 -0
  441. package/template/test/prerenderRefresh.browser.spec.ts +1431 -0
  442. package/template/test/previewsFresh.spec.ts +56 -0
  443. package/template/test/richText.spec.ts +164 -0
  444. package/template/test/richTextTypography.spec.ts +182 -0
  445. package/template/test/setup.ts +21 -0
  446. package/template/test/slugPage.spec.ts +244 -0
  447. package/template/test/slugPageTemplate.spec.ts +194 -0
  448. package/template/test/starter.spec.ts +1416 -0
  449. package/template/test/storefront/cart.spec.ts +404 -0
  450. package/template/test/storefront/categories.spec.ts +235 -0
  451. package/template/test/storefront/collectionSelector.spec.ts +74 -0
  452. package/template/test/storefront/demo.spec.ts +555 -0
  453. package/template/test/storefront/facets.spec.ts +425 -0
  454. package/template/test/storefront/feedback.spec.ts +97 -0
  455. package/template/test/storefront/gateway.spec.ts +2673 -0
  456. package/template/test/storefront/gatewayCart.spec.ts +289 -0
  457. package/template/test/storefront/gatewayPrerender.spec.ts +1037 -0
  458. package/template/test/storefront/history.spec.ts +341 -0
  459. package/template/test/storefront/money.spec.ts +170 -0
  460. package/template/test/storefront/toProductCard.spec.ts +138 -0
  461. package/template/test/storefront/volatile.spec.ts +284 -0
  462. package/template/test/support/axe.ts +14 -0
  463. package/template/test/support/dialog.ts +51 -0
  464. package/template/test/support/hydrate.ts +118 -0
  465. package/template/test/support/i18nText.ts +11 -0
  466. package/template/test/support/mockGateway.ts +1017 -0
  467. package/template/test/support/mountBlock.ts +194 -0
  468. package/template/test/support/mountPage.spec.ts +72 -0
  469. package/template/test/support/mountPage.ts +254 -0
  470. package/template/test/support/mountProbe.client.ts +69 -0
  471. package/template/test/support/renderSsr.ts +97 -0
  472. package/template/test/support/staticServer.ts +96 -0
  473. package/template/test/themeIcons.spec.ts +140 -0
  474. package/template/test/toastAnnouncement.spec.ts +133 -0
  475. package/template/test/tokens.spec.ts +102 -0
  476. package/template/test/uiMessagesPlugin.spec.ts +104 -0
  477. package/template/test/useBlockData.spec.ts +49 -0
  478. package/template/test/useEditing.spec.ts +54 -0
  479. package/template/test/useEldraIcon.spec.ts +126 -0
  480. package/template/test/useUiId.spec.ts +40 -0
  481. package/template/tokens.json +149 -0
  482. package/template/tsconfig.json +3 -0
  483. package/template/tsconfig.storybook.json +17 -0
  484. package/template/vitest-axe.d.ts +13 -0
  485. package/template/vitest.config.ts +44 -0
@@ -0,0 +1,1492 @@
1
+ // @vitest-environment jsdom
2
+ import { flushPromises, mount } from '@vue/test-utils';
3
+ import { computed, defineComponent, h, nextTick, ref } from 'vue';
4
+ import { ELDRA_KEY, type EldraLocaleState } from '@eldrajs/theme-vue';
5
+ import { EldraHttpError } from '@eldrajs/sdk';
6
+ import { useToast, type ToastAction } from '@eldrajs/ui';
7
+ import { afterEach, describe, expect, it } from 'vitest';
8
+ import { axe } from '../../../test/support/axe';
9
+ import { mountOptions } from '../../../test/support/mountBlock';
10
+ import { createDemoStorefront } from '../../../app/storefront/demo';
11
+ import { optionDisplayType } from '../../../app/storefront/options';
12
+ import { createCartStore, type CartOps, type CartSnapshot } from '../../../app/storefront/cart';
13
+ import {
14
+ STOREFRONT_KEY,
15
+ type StorefrontCommerce,
16
+ type StorefrontProduct,
17
+ type StorefrontResult,
18
+ type VolatileKey,
19
+ } from '../../../app/storefront/types';
20
+ import enUS from '../../../i18n/en-US.json';
21
+ import isIS from '../../../i18n/is-IS.json';
22
+ import { formatMoney } from '../../../app/storefront/money';
23
+ import Block from '../Block.vue';
24
+ import mock from '../mock.json';
25
+
26
+ /** The genuinely minimal fixture: only the fields the block requires. */
27
+ const bare = { variant: 'gallery-left' as const };
28
+
29
+ const VARIANTS = ['gallery-left', 'gallery-right'] as const;
30
+
31
+ /**
32
+ * A demo storefront whose product is patched on the way out. The Northwind catalogue
33
+ * (`app/storefront/demo.ts`) has no low-stock and no made-to-order
34
+ * product, so the two states that need one are reached by overlaying the fields on the demo product
35
+ * rather than by editing that shared fixture: the block reads exactly the same shape either way.
36
+ */
37
+ function storefrontWith(patch: Partial<StorefrontProduct> = {}) {
38
+ const source = createDemoStorefront();
39
+ return {
40
+ ...source,
41
+ catalog: {
42
+ ...source.catalog,
43
+ product: (handle: Parameters<typeof source.catalog.product>[0]) => {
44
+ const result = source.catalog.product(handle);
45
+ return {
46
+ ...result,
47
+ data: computed(() => (result.data.value ? { ...result.data.value, ...patch } : null)),
48
+ };
49
+ },
50
+ },
51
+ };
52
+ }
53
+
54
+ function mountBlock(
55
+ data: Record<string, unknown>,
56
+ options: {
57
+ editing?: boolean;
58
+ attach?: boolean;
59
+ storefront?: ReturnType<typeof storefrontWith>;
60
+ productHandle?: string | null;
61
+ /** The page's content locale — `en-US` unless a spec is about another one's formatting. */
62
+ locale?: string;
63
+ /** What the store sells in; the demo store's US dollars unless a spec says otherwise. */
64
+ commerce?: StorefrontCommerce | null;
65
+ /** The page's locale routing — one unprefixed site unless a spec is about a prefixed one. */
66
+ locales?: Partial<EldraLocaleState>;
67
+ } = {}
68
+ ) {
69
+ const base = mountOptions(
70
+ { entry: { id: 'e1', data } },
71
+ { locale: options.locale, commerce: options.commerce, locales: options.locales }
72
+ );
73
+ const storefront = options.storefront ?? storefrontWith();
74
+ if (options.productHandle !== undefined) storefront.route.productHandle = options.productHandle;
75
+ const opts = {
76
+ ...base,
77
+ // Focus tracking (`document.activeElement`) only works for a tree attached to the document.
78
+ ...(options.attach === false ? {} : { attachTo: document.body }),
79
+ global: {
80
+ ...base.global,
81
+ provide: {
82
+ ...base.global.provide,
83
+ [STOREFRONT_KEY]: storefront,
84
+ },
85
+ },
86
+ };
87
+ if (options.editing) {
88
+ const context = opts.global.provide[ELDRA_KEY] as {
89
+ preview: { active: boolean; mode: string };
90
+ };
91
+ context.preview.active = true;
92
+ context.preview.mode = 'edit';
93
+ }
94
+ return mount(Block, opts);
95
+ }
96
+
97
+ async function mountReady(
98
+ data: Record<string, unknown>,
99
+ options: Parameters<typeof mountBlock>[1] = {}
100
+ ) {
101
+ const wrapper = mountBlock(data, options);
102
+ await flushPromises();
103
+ await nextTick();
104
+ return wrapper;
105
+ }
106
+
107
+ type Wrapper = Awaited<ReturnType<typeof mountReady>>;
108
+
109
+ /** The gallery's own strip. Scoped by its name so the `Lightbox`'s own thumbnails ("Go to image n")
110
+ * are never counted once the viewer is open. */
111
+ function thumbnails(wrapper: Wrapper) {
112
+ return wrapper.findAll('button[aria-label^="Show image"]');
113
+ }
114
+ function zoomButton(wrapper: Wrapper) {
115
+ return wrapper.get('button[aria-haspopup="dialog"]');
116
+ }
117
+ function lightbox(wrapper: Wrapper) {
118
+ return wrapper.get('dialog[aria-label="Merino crew sweater, images"]');
119
+ }
120
+ function statusLine(wrapper: Wrapper) {
121
+ return wrapper.get('[role="status"][aria-live="polite"]');
122
+ }
123
+ function addToCart(wrapper: Wrapper) {
124
+ return wrapper.get('button[type="submit"]');
125
+ }
126
+ /**
127
+ * One option as a storefront would hand it over: the merchant's facts, with `type` **derived** by the
128
+ * same function both storefront sources use. Writing `type` by hand here would make every render
129
+ * assertion below blind to a regression in that derivation — which is exactly the defect that let a
130
+ * `color` option with no colours reach the swatch picker.
131
+ */
132
+ function option(
133
+ fixture: Omit<StorefrontProduct['options'][number], 'type'>
134
+ ): StorefrontProduct['options'][number] {
135
+ return { ...fixture, type: optionDisplayType(fixture.kind, fixture.values) };
136
+ }
137
+
138
+ function optionByLabel(wrapper: Wrapper, label: string) {
139
+ return wrapper
140
+ .findAll('label')
141
+ .find((candidate) => candidate.text().startsWith(label))!
142
+ .get<HTMLInputElement>('input[type="radio"]');
143
+ }
144
+
145
+ afterEach(() => {
146
+ delete (globalThis as { IntersectionObserver?: unknown }).IntersectionObserver;
147
+ // `useToast` is a module-level queue in `@eldrajs/ui`; a toast left in it would leak into the
148
+ // next test.
149
+ useToast().clear();
150
+ // So would a saved wishlist: it is `localStorage`, which jsdom keeps for the whole file, and the
151
+ // store hydrates from it on mount (`app/composables/useWishlist.ts`).
152
+ localStorage.clear();
153
+ });
154
+
155
+ /** A gateway refusal as `@eldrajs/sdk` throws it, problem body and all. */
156
+ function refusal(body: unknown): EldraHttpError {
157
+ return new EldraHttpError({ status: 409, statusText: 'Conflict' } as Response, body);
158
+ }
159
+
160
+ function emptyCart(): CartSnapshot {
161
+ return {
162
+ lines: [],
163
+ totals: { subtotal: 0, discount: null, shipping: null, tax: null, total: 0 },
164
+ };
165
+ }
166
+
167
+ /**
168
+ * The demo storefront with a cart whose `add` refuses — the one thing the in-memory demo ops cannot
169
+ * do, and the state the whole buy box has to behave in: the gateway answered, it said no, and the
170
+ * page looks exactly as it did a moment ago unless the block says otherwise.
171
+ */
172
+ function storefrontWithRefusingCart(thrown: unknown, patch: Partial<StorefrontProduct> = {}) {
173
+ const source = storefrontWith(patch);
174
+ const ops: CartOps = {
175
+ init: async () => emptyCart(),
176
+ add: async () => {
177
+ throw thrown;
178
+ },
179
+ setQuantity: async () => emptyCart(),
180
+ remove: async () => emptyCart(),
181
+ applyDiscount: async () => ({ ack: { ok: false, reason: 'invalid' as const } }),
182
+ removeDiscount: async () => emptyCart(),
183
+ checkoutUrl: ref<string | null>(null),
184
+ };
185
+ return { ...source, cart: createCartStore(ops) };
186
+ }
187
+
188
+ /**
189
+ * The demo storefront with a cart whose `add` stays in flight until the test releases it — the one
190
+ * state `cart.pending` is actually `true` in once the page is up.
191
+ */
192
+ function storefrontWithHangingAdd(patch: Partial<StorefrontProduct> = {}): {
193
+ storefront: ReturnType<typeof storefrontWith>;
194
+ release: () => void;
195
+ } {
196
+ const source = storefrontWith(patch);
197
+ let release = (): void => {};
198
+ const ops: CartOps = {
199
+ init: async () => emptyCart(),
200
+ add: () =>
201
+ new Promise<CartSnapshot>((resolve) => {
202
+ release = () => resolve(emptyCart());
203
+ }),
204
+ setQuantity: async () => emptyCart(),
205
+ remove: async () => emptyCart(),
206
+ applyDiscount: async () => ({ ack: { ok: false, reason: 'invalid' as const } }),
207
+ removeDiscount: async () => emptyCart(),
208
+ checkoutUrl: ref<string | null>(null),
209
+ };
210
+ return { storefront: { ...source, cart: createCartStore(ops) }, release: () => release() };
211
+ }
212
+
213
+ /** What the single app-wide `Toaster` would render: the live queue, newest last. */
214
+ function toasts(): Array<{ title: string; variant: string }> {
215
+ return useToast().toasts.value.map((item) => ({ title: item.title, variant: item.variant }));
216
+ }
217
+
218
+ /** The one queued toast's action, as the `Toaster` would render it — a link or a button. */
219
+ function toastAction(): ToastAction | undefined {
220
+ return useToast().toasts.value[0]?.action;
221
+ }
222
+
223
+ describe('add to cart feedback', () => {
224
+ /**
225
+ * **The other half of the hydration gate.** `cart.pending` is shopper state, so the buy box reads
226
+ * it behind `cartBusy` — `mounted && cart.pending` — and the gate is what keeps it out of the
227
+ * first client render (`test/prerenderRefresh.browser.spec.ts` is the guard for that half). The
228
+ * gate must not cost the state itself: once the page is up, a slow add has to show as busy, which
229
+ * is exactly what "Add to cart does nothing" was about.
230
+ *
231
+ * Nothing pinned that direction, so `cartBusy` could be reduced to `false` — dropping the
232
+ * `&& cart.pending` half, or the whole computed — with the entire suite still green. This is what
233
+ * fails then: a mounted wrapper is already past `onMounted`, so `cartBusy` is `cart.pending`, and
234
+ * `Button`'s own `loading` treatment (`[data-part="spinner"]` plus `aria-busy`) is what a shopper
235
+ * sees while the request is out.
236
+ */
237
+ it('marks the Add to cart button busy while the add is in flight, and clears it after', async () => {
238
+ const { storefront, release } = storefrontWithHangingAdd();
239
+ const wrapper = await mountReady(mock, { storefront });
240
+
241
+ // Nothing in flight: no spinner, not busy.
242
+ expect(addToCart(wrapper).find('[data-part="spinner"]').exists()).toBe(false);
243
+ expect(addToCart(wrapper).attributes('aria-busy')).toBeUndefined();
244
+
245
+ await wrapper.get('form').trigger('submit');
246
+
247
+ expect(addToCart(wrapper).find('[data-part="spinner"]').exists()).toBe(true);
248
+ expect(addToCart(wrapper).attributes('aria-busy')).toBe('true');
249
+
250
+ release();
251
+ await flushPromises();
252
+ await nextTick();
253
+
254
+ expect(addToCart(wrapper).find('[data-part="spinner"]').exists()).toBe(false);
255
+ expect(addToCart(wrapper).attributes('aria-busy')).toBeUndefined();
256
+ wrapper.unmount();
257
+ });
258
+
259
+ /**
260
+ * The defect this guards: the block awaited `cart.add`, the button's `:loading` flipped back, and
261
+ * a 409 `CART_INSUFFICIENT_STOCK` reached nothing a shopper could see — "Add to cart does
262
+ * nothing". The copy is the specific one, because the refusal named its cause.
263
+ */
264
+ it('says the item is out of stock when the gateway refuses the add for stock', async () => {
265
+ const storefront = storefrontWithRefusingCart(
266
+ refusal({
267
+ code: 'CONFLICT',
268
+ errorId: 'CART_INSUFFICIENT_STOCK',
269
+ detail: 'insufficient stock',
270
+ })
271
+ );
272
+ const wrapper = await mountReady(mock, { storefront });
273
+ expect(statusLine(wrapper).text()).toContain('In stock, ready to ship');
274
+
275
+ await wrapper.get('form').trigger('submit');
276
+ await flushPromises();
277
+ await nextTick();
278
+
279
+ expect(toasts()).toEqual([{ title: 'This item is out of stock.', variant: 'danger' }]);
280
+ // …and the page stops offering a button that cannot work: the spec's own sold-out state.
281
+ expect(statusLine(wrapper).text()).toContain('Sold out in Oat / XS');
282
+ expect(addToCart(wrapper).text()).toContain('Notify me');
283
+ expect(wrapper.find('[role="spinbutton"]').exists()).toBe(false);
284
+ expect(await axe(wrapper.element)).toHaveNoViolations();
285
+ });
286
+
287
+ it('says something generic for a refusal it has no words for, and leaves the stock line alone', async () => {
288
+ const storefront = storefrontWithRefusingCart(refusal({ code: 'INTERNAL' }));
289
+ const wrapper = await mountReady(mock, { storefront });
290
+
291
+ await wrapper.get('form').trigger('submit');
292
+ await flushPromises();
293
+ await nextTick();
294
+
295
+ expect(toasts()).toEqual([
296
+ { title: 'Something went wrong. Please try again.', variant: 'danger' },
297
+ ]);
298
+ // Nothing was learned about stock, so nothing about stock changes.
299
+ expect(statusLine(wrapper).text()).toContain('In stock, ready to ship');
300
+ expect(addToCart(wrapper).text()).toContain('Add to cart · $96.00');
301
+ });
302
+
303
+ it('reports a request that never reached the gateway the same generic way', async () => {
304
+ const storefront = storefrontWithRefusingCart(new TypeError('Failed to fetch'));
305
+ const wrapper = await mountReady(mock, { storefront });
306
+
307
+ await wrapper.get('form').trigger('submit');
308
+ await flushPromises();
309
+
310
+ expect(toasts()).toEqual([
311
+ { title: 'Something went wrong. Please try again.', variant: 'danger' },
312
+ ]);
313
+ });
314
+
315
+ it('presses the refused button twice without stacking two toasts', async () => {
316
+ const storefront = storefrontWithRefusingCart(refusal({ code: 'INTERNAL' }));
317
+ const wrapper = await mountReady(mock, { storefront });
318
+
319
+ await wrapper.get('form').trigger('submit');
320
+ await flushPromises();
321
+ await wrapper.get('form').trigger('submit');
322
+ await flushPromises();
323
+
324
+ expect(toasts()).toHaveLength(1);
325
+ });
326
+
327
+ it('lets the stock line recover when a fresher product read disagrees', async () => {
328
+ const storefront = storefrontWithRefusingCart(
329
+ refusal({ code: 'CONFLICT', errorId: 'CART_INSUFFICIENT_STOCK' })
330
+ );
331
+ const wrapper = await mountReady(mock, { storefront });
332
+ await wrapper.get('form').trigger('submit');
333
+ await flushPromises();
334
+ await nextTick();
335
+ expect(addToCart(wrapper).text()).toContain('Notify me');
336
+
337
+ // Another variant chosen is not the variant the backend refused.
338
+ await optionByLabel(wrapper, 'L').setValue();
339
+ await nextTick();
340
+ expect(addToCart(wrapper).text()).toContain('Add to cart · $96.00');
341
+ expect(statusLine(wrapper).text()).toContain('In stock, ready to ship');
342
+ });
343
+
344
+ /**
345
+ * Success is confirmed by a toast and **not** by opening the drawer — the design spec's own rule for
346
+ * the Drawer primitive ("a Toast (not the drawer) to confirm 'Added to cart' unless the shopper
347
+ * asked to see the cart"): a modal over the page takes the focus and the scroll position of someone
348
+ * who pressed one button while reading a product.
349
+ */
350
+ it('confirms a successful add with a toast, leaving the drawer closed', async () => {
351
+ const storefront = storefrontWith();
352
+ storefront.cart.drawerAvailable.value = true;
353
+ const wrapper = await mountReady(mock, { storefront });
354
+
355
+ await wrapper.get('form').trigger('submit');
356
+ await flushPromises();
357
+
358
+ expect(storefront.cart.lines.value).toHaveLength(1);
359
+ expect(toasts()).toEqual([{ title: 'Added to cart', variant: 'success' }]);
360
+ expect(storefront.cart.drawerOpen.value).toBe(false);
361
+ });
362
+
363
+ it('offers the cart from the toast, opening the hosted drawer when one is live', async () => {
364
+ const storefront = storefrontWith();
365
+ storefront.cart.drawerAvailable.value = true;
366
+ const wrapper = await mountReady(mock, { storefront });
367
+
368
+ await wrapper.get('form').trigger('submit');
369
+ await flushPromises();
370
+
371
+ // The shopper asking to see the cart is the spec's own exception — and the only thing that opens
372
+ // the drawer here.
373
+ const action = toastAction();
374
+ expect(action?.label).toBe('View cart');
375
+ expect(action).not.toHaveProperty('href');
376
+ (action as { onActivate: () => void }).onActivate();
377
+ expect(storefront.cart.drawerOpen.value).toBe(true);
378
+ });
379
+
380
+ it('offers /cart from the toast when no drawer is mounted', async () => {
381
+ const storefront = storefrontWith();
382
+ const wrapper = await mountReady(mock, { storefront });
383
+
384
+ await wrapper.get('form').trigger('submit');
385
+ await flushPromises();
386
+
387
+ expect(toasts()).toEqual([{ title: 'Added to cart', variant: 'success' }]);
388
+ // The same destination the header's bag has without a live drawer.
389
+ expect(toastAction()).toEqual({ label: 'View cart', href: '/cart' });
390
+ expect(storefront.cart.drawerOpen.value).toBe(false);
391
+ });
392
+ });
393
+
394
+ describe('product-detail block', () => {
395
+ it('renders the demo product from mock.json with no axe violations', async () => {
396
+ const wrapper = await mountReady(mock);
397
+ expect(wrapper.text()).toContain('Merino crew sweater');
398
+ expect(wrapper.text()).toContain('$96.00');
399
+ expect(wrapper.text()).toContain('Knitwear');
400
+ expect(wrapper.text()).toContain('Free delivery over $80.');
401
+ expect(await axe(wrapper.element)).toHaveNoViolations();
402
+ });
403
+
404
+ it('renders the bare fixture — no perks, no tabs, no size guide — axe-clean', async () => {
405
+ const wrapper = await mountReady(bare);
406
+ expect(wrapper.text()).toContain('Merino crew sweater');
407
+ expect(wrapper.find('[role="tablist"]').exists()).toBe(false);
408
+ expect(wrapper.text()).not.toContain('Size guide');
409
+ expect(await axe(wrapper.element)).toHaveNoViolations();
410
+ });
411
+
412
+ it.each(VARIANTS)('renders the %s variant with no axe violations', async (variant) => {
413
+ const wrapper = await mountReady({ ...mock, variant });
414
+ expect(await axe(wrapper.element)).toHaveNoViolations();
415
+ });
416
+
417
+ it('mirrors gallery-right visually while keeping gallery-then-info reading order', async () => {
418
+ for (const variant of VARIANTS) {
419
+ const wrapper = await mountReady({ ...mock, variant });
420
+ const gallery = wrapper.get('[role="group"][aria-label="Product images"]');
421
+ const info = wrapper.get('[role="group"][aria-label="Product information"]');
422
+ // DOM order never changes …
423
+ expect(
424
+ gallery.element.compareDocumentPosition(info.element) & Node.DOCUMENT_POSITION_FOLLOWING
425
+ ).toBeTruthy();
426
+ // … only which column each one is painted in.
427
+ expect(gallery.classes()).toContain(
428
+ variant === 'gallery-right' ? '@tablet:order-2' : '@tablet:order-1'
429
+ );
430
+ expect(info.classes()).toContain(
431
+ variant === 'gallery-right' ? '@tablet:order-1' : '@tablet:order-2'
432
+ );
433
+ }
434
+ });
435
+
436
+ it('has exactly one h1, the product title, and it labels the section', async () => {
437
+ const wrapper = await mountReady(mock);
438
+ const headings = wrapper.findAll('h1');
439
+ expect(headings).toHaveLength(1);
440
+ expect(headings[0]!.text()).toBe('Merino crew sweater');
441
+ const section = wrapper.get('section');
442
+ expect(section.attributes('aria-labelledby')).toBe(headings[0]!.attributes('id'));
443
+ });
444
+
445
+ it('computes the saving badge from the two prices', async () => {
446
+ const wrapper = await mountReady(mock);
447
+ // The demo product is $96.00, was $128.00.
448
+ expect(wrapper.text()).toContain('Save $32.00');
449
+ expect(wrapper.text()).toContain('$128.00');
450
+ });
451
+
452
+ it('renders a whole-unit price as itself, not as a hundredth of it', async () => {
453
+ // The catalog sends money in major units (`app/storefront/types.ts`), so a $28.00 product
454
+ // arrives as `28` — dividing it again rendered "$0.28" on a live store.
455
+ const wrapper = await mountReady(mock, {
456
+ storefront: storefrontWith({ price: { amount: 28, compareAt: null } }),
457
+ });
458
+ expect(wrapper.text()).toContain('$28.00');
459
+ expect(wrapper.text()).not.toContain('$0.28');
460
+ // The same amount inside the button's own label, which formats it rather than rendering
461
+ // `<Price>`: the two must agree.
462
+ expect(addToCart(wrapper).text()).toContain('Add to cart · $28.00');
463
+ });
464
+
465
+ /**
466
+ * The store's currency is the platform's, and the page's number formatting is the content
467
+ * locale's — two separate decisions, which this is the one spec that exercises together. An
468
+ * Icelandic page of a store selling in krónur reads "2.800 kr.", never "$2,800.00" and never a
469
+ * bare "2.800": the amount inside the button's label and the `<Price>` above it both come from
470
+ * the same provide (`CURRENCY_KEY`), so they cannot disagree.
471
+ */
472
+ it('formats money in the store’s currency and the page’s locale', async () => {
473
+ const wrapper = await mountReady(mock, {
474
+ locale: 'is-IS',
475
+ commerce: { currency: 'ISK', taxInclusivePricing: true, defaultTaxRate: 0.24 },
476
+ storefront: storefrontWith({ price: { amount: 2800, compareAt: null } }),
477
+ });
478
+
479
+ const price = formatMoney(2800, 'ISK', 'is-IS');
480
+ expect(price).toMatch(/^2\.800\s?kr\.$/u);
481
+ // The label the shopper reads on the button, interpolated from the Icelandic message set.
482
+ expect(addToCart(wrapper).text()).toContain(isIS.product.addToCart.replace('{price}', price));
483
+ expect(addToCart(wrapper).text()).not.toContain('$');
484
+ // And every `<Price>` the block renders — the one above the button and the quick-add bar's —
485
+ // reads the same amount, because both take the currency from the same provide. (Asserted on
486
+ // the price parts, not the block's whole text: the authored copy in `mock.json` mentions a
487
+ // free-delivery threshold in dollars, which is content, not a formatted price.)
488
+ const rendered = wrapper.findAll('[data-part="current"]').map((part) => part.text());
489
+ expect(rendered.length).toBeGreaterThan(0);
490
+ for (const amount of rendered) {
491
+ expect(amount).toBe(price);
492
+ // A zero-decimal currency grows no invented decimals, whichever side formatted it.
493
+ expect(amount).not.toContain(',00');
494
+ }
495
+ });
496
+
497
+ /**
498
+ * The same store on an **English** page: the button's label and the `<Price>` above it both write `ISK 2,800`.
499
+ */
500
+ it('writes the store currency’s wide sign on a page in another locale', async () => {
501
+ const wrapper = await mountReady(mock, {
502
+ locale: 'en-US',
503
+ commerce: { currency: 'ISK', taxInclusivePricing: true, defaultTaxRate: 0.24 },
504
+ storefront: storefrontWith({ price: { amount: 2800, compareAt: null } }),
505
+ });
506
+
507
+ expect(formatMoney(2800, 'ISK', 'en-US')).toBe('ISK\u00a02,800');
508
+ expect(addToCart(wrapper).text()).toContain(
509
+ enUS.product.addToCart.replace('{price}', 'ISK\u00a02,800')
510
+ );
511
+ const rendered = wrapper.findAll('[data-part="current"]').map((part) => part.text());
512
+ expect(rendered.length).toBeGreaterThan(0);
513
+ for (const amount of rendered) {
514
+ expect(amount).toBe('ISK\u00a02,800');
515
+ }
516
+ // Not the narrow sign, in either half.
517
+ expect(wrapper.text()).not.toContain('kr\u00a02,800');
518
+ });
519
+
520
+ /**
521
+ * And the other end of it: a store that has not configured commerce publishes no currency, and
522
+ * the page must then show its prices as numbers. A guessed symbol is a *wrong* price — `$4.800`
523
+ * in front of an amount in krónur — where a bare `4.800` is merely an incomplete one, so the
524
+ * theme provides no currency rather than letting one be assumed, and `@eldrajs/ui` guesses none
525
+ * of its own. Both halves of the block's money obey it: the `<Price>` and the button's own
526
+ * formatted label.
527
+ */
528
+ it('renders prices as plain numbers when the store publishes no currency', async () => {
529
+ const wrapper = await mountReady(mock, {
530
+ commerce: null,
531
+ storefront: storefrontWith({ price: { amount: 96, compareAt: null } }),
532
+ });
533
+
534
+ for (const part of wrapper.findAll('[data-part="current"]')) {
535
+ expect(part.text()).toBe('96');
536
+ }
537
+ expect(addToCart(wrapper).text()).toContain('Add to cart · 96');
538
+ expect(addToCart(wrapper).text()).not.toContain('$');
539
+ });
540
+
541
+ it('hides the rating below three reviews and when the field is off', async () => {
542
+ const withRating = await mountReady(mock);
543
+ expect(withRating.get('a[href="#reviews"]').exists()).toBe(true);
544
+
545
+ const fieldOff = await mountReady({ ...mock, showRating: false });
546
+ expect(fieldOff.find('a[href="#reviews"]').exists()).toBe(false);
547
+
548
+ const tooFew = await mountReady(mock, {
549
+ storefront: storefrontWith({ rating: { value: 4.5, count: 2 } }),
550
+ });
551
+ expect(tooFew.find('a[href="#reviews"]').exists()).toBe(false);
552
+ });
553
+
554
+ /**
555
+ * **`showCategory` is one label, not a trail.** The trail — Home down to the category — belongs to
556
+ * `breadcrumbs`, which is also on by default, and drawing the whole trail here as well put the
557
+ * same levels on the page twice inside two `<nav>`s both named "Breadcrumb". A product two levels
558
+ * deep in the demo's tree (`speckled-latte-mug`: Home › Ceramics) is what tells the two apart:
559
+ * only the leaf is drawn, and there is no breadcrumb landmark in this block at all.
560
+ */
561
+ it('names the product’s own category once, as a label and not a trail', async () => {
562
+ const wrapper = await mountReady(
563
+ { ...mock, productHandle: 'speckled-latte-mug' },
564
+ { productHandle: 'speckled-latte-mug' }
565
+ );
566
+ const categoryLinks = wrapper
567
+ .findAll('a')
568
+ .filter((link) => link.attributes('href')?.startsWith('/categories/') === true);
569
+ // The leaf's own **canonical** path, which is the only path its page answers: the ancestors are
570
+ // in it, and it is still one link rather than a trail.
571
+ expect(categoryLinks.map((link) => link.attributes('href'))).toEqual([
572
+ '/categories/home/ceramics',
573
+ ]);
574
+ expect(categoryLinks[0]!.text()).toBe('Ceramics');
575
+ expect(wrapper.find('nav[aria-label="Breadcrumb"]').exists()).toBe(false);
576
+ expect(await axe(wrapper.element)).toHaveNoViolations();
577
+ });
578
+
579
+ it('drops the category label when showCategory is off', async () => {
580
+ const wrapper = await mountReady(
581
+ { ...mock, productHandle: 'speckled-latte-mug', showCategory: false },
582
+ { productHandle: 'speckled-latte-mug' }
583
+ );
584
+ expect(wrapper.html()).not.toContain('/products?category=');
585
+ expect(wrapper.find('nav[aria-label="Breadcrumb"]').exists()).toBe(false);
586
+ });
587
+
588
+ describe('gallery', () => {
589
+ it('names every thumbnail by position and alt text, marking the current one', async () => {
590
+ const wrapper = await mountReady(mock);
591
+ const buttons = thumbnails(wrapper);
592
+ expect(buttons.length).toBeGreaterThan(1);
593
+ buttons.forEach((button, index) => {
594
+ expect(button.attributes('aria-label')).toBe(
595
+ `Show image ${index + 1} of ${buttons.length}: ${
596
+ index === 0 ? 'Merino crew sweater' : 'Merino crew sweater, alternate view'
597
+ }`
598
+ );
599
+ });
600
+ expect(buttons[0]!.attributes('aria-current')).toBe('true');
601
+ expect(buttons[1]!.attributes('aria-current')).toBeUndefined();
602
+ });
603
+
604
+ it('moves the current thumbnail, the index pill and the zoom name together', async () => {
605
+ const wrapper = await mountReady(mock);
606
+ const buttons = thumbnails(wrapper);
607
+ expect(zoomButton(wrapper).attributes('aria-label')).toBe(
608
+ `Zoom image 1 of ${buttons.length}`
609
+ );
610
+ expect(wrapper.text()).toContain(`1 / ${buttons.length}`);
611
+
612
+ await buttons[1]!.trigger('click');
613
+ expect(thumbnails(wrapper)[1]!.attributes('aria-current')).toBe('true');
614
+ expect(thumbnails(wrapper)[0]!.attributes('aria-current')).toBeUndefined();
615
+ expect(zoomButton(wrapper).attributes('aria-label')).toBe(
616
+ `Zoom image 2 of ${buttons.length}`
617
+ );
618
+ expect(wrapper.text()).toContain(`2 / ${buttons.length}`);
619
+ });
620
+
621
+ it('opens the viewer from zoom, arrows between images, and Esc returns focus', async () => {
622
+ const wrapper = await mountReady(mock);
623
+ const zoom = zoomButton(wrapper);
624
+ zoom.element.focus();
625
+ await zoom.trigger('click');
626
+ await nextTick();
627
+
628
+ const dialog = lightbox(wrapper);
629
+ expect(dialog.attributes('open')).toBe('');
630
+ expect(await axe(wrapper.element)).toHaveNoViolations();
631
+
632
+ const count = thumbnails(wrapper).length;
633
+ expect(dialog.text()).toContain(`1 / ${count}`);
634
+ await dialog.trigger('keydown', { key: 'ArrowRight' });
635
+ expect(dialog.text()).toContain(`2 / ${count}`);
636
+ await dialog.trigger('keydown', { key: 'ArrowLeft' });
637
+ expect(dialog.text()).toContain(`1 / ${count}`);
638
+
639
+ document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
640
+ await new Promise((resolve) => setTimeout(resolve));
641
+ await nextTick();
642
+ expect(lightbox(wrapper).attributes('open')).toBeUndefined();
643
+ expect(document.activeElement).toBe(zoom.element);
644
+ });
645
+ });
646
+
647
+ describe('variant pickers', () => {
648
+ it('gives each block instance its own radio groups, so two on a page never collide', async () => {
649
+ // Two separate `mount()` calls each get their own Vue app, so `useId()` — scoped per app —
650
+ // would trivially "differ" for the wrong reason (both would actually start again at `v-1`).
651
+ // Mounting both blocks as siblings under one app is what proves real-page uniqueness: one
652
+ // `useId()` sequence, shared, the way a real page's single app renders every block.
653
+ const storefront = storefrontWith();
654
+ const Host = defineComponent({
655
+ render: () =>
656
+ h('div', [
657
+ h(Block, { entry: { id: 'e1', data: mock } }),
658
+ h(Block, { entry: { id: 'e2', data: mock } }),
659
+ ]),
660
+ });
661
+ const base = mountOptions({ entry: { id: 'e1', data: mock } });
662
+ const wrapper = mount(Host, {
663
+ ...base,
664
+ attachTo: document.body,
665
+ global: {
666
+ ...base.global,
667
+ provide: {
668
+ ...base.global.provide,
669
+ [STOREFRONT_KEY]: storefront,
670
+ },
671
+ },
672
+ });
673
+ await flushPromises();
674
+ await nextTick();
675
+
676
+ // Scoped by component instance, not `<form>`: the block also renders a second, unrelated
677
+ // `FormLayout`-backed form for its back-in-stock notice, so counting `<form>` elements would
678
+ // count that too.
679
+ const blocks = wrapper.findAllComponents(Block);
680
+ expect(blocks).toHaveLength(2);
681
+ const firstColour = blocks[0]!.get<HTMLInputElement>('input[type="radio"]');
682
+ const secondColour = blocks[1]!.get<HTMLInputElement>('input[type="radio"]');
683
+ expect(firstColour.element.checked).toBe(true);
684
+ expect(secondColour.element.checked).toBe(true);
685
+ // A unique native `name` (via `useUiId()`) is what isolates the groups — `legend` is what
686
+ // keeps the visible/accessible text reading "Colour", never the id.
687
+ expect(firstColour.element.name).not.toBe(secondColour.element.name);
688
+ expect(firstColour.element.name).not.toBe('');
689
+ expect(blocks[0]!.get('legend').text()).toContain('Colour');
690
+
691
+ // Choosing in the second block leaves the first block's selection checked.
692
+ const secondBlockRadios = blocks[1]!.findAll<HTMLInputElement>('input[type="radio"]');
693
+ await secondBlockRadios[1]!.setValue();
694
+ expect(secondBlockRadios[1]!.element.checked).toBe(true);
695
+ expect(firstColour.element.checked).toBe(true);
696
+ });
697
+
698
+ it('keeps sold-out options selectable, named ", sold out", and never pre-selected', async () => {
699
+ const wrapper = await mountReady(mock);
700
+ const moss = optionByLabel(wrapper, 'Moss');
701
+ const xl = optionByLabel(wrapper, 'XL');
702
+ for (const option of [moss, xl]) {
703
+ expect(option.attributes('disabled')).toBeUndefined();
704
+ expect(option.element.checked).toBe(false);
705
+ }
706
+ expect(
707
+ wrapper
708
+ .findAll('label')
709
+ .find((label) => label.text().startsWith('Moss'))!
710
+ .text()
711
+ ).toContain(', sold out');
712
+ // The default selection is the first *available* value of each option.
713
+ expect(optionByLabel(wrapper, 'Oat').element.checked).toBe(true);
714
+ expect(optionByLabel(wrapper, 'XS').element.checked).toBe(true);
715
+ });
716
+
717
+ it('announces the new stock state politely on change without moving focus', async () => {
718
+ const wrapper = await mountReady(mock);
719
+ const status = statusLine(wrapper);
720
+ expect(status.text()).toContain('In stock, ready to ship');
721
+
722
+ const wishlist = wrapper.get('button[aria-pressed]');
723
+ wishlist.element.focus();
724
+ await optionByLabel(wrapper, 'XL').setValue();
725
+ await nextTick();
726
+
727
+ expect(statusLine(wrapper).text()).toContain('Sold out in Oat / XL');
728
+ expect(statusLine(wrapper).text()).toContain('We restock knitwear every 6 to 8 weeks.');
729
+ expect(document.activeElement).toBe(wishlist.element);
730
+ expect(await axe(wrapper.element)).toHaveNoViolations();
731
+ });
732
+
733
+ it('shows the size guide link beside the size pills only when both fields are set', async () => {
734
+ const wrapper = await mountReady({ ...mock, sizeGuideHref: '/pages/size-guide' });
735
+ expect(wrapper.get('a[href="/pages/size-guide"]').text()).toBe('Size guide');
736
+
737
+ // `sizeGuideHref` ships empty in the seed (no dead demo link) — `mock` on its own already
738
+ // exercises that default.
739
+ const noHref = await mountReady(mock);
740
+ expect(noHref.find('a[href="/pages/size-guide"]').exists()).toBe(false);
741
+ });
742
+
743
+ /**
744
+ * **The merchant's "Display as" choice is what picks the control.** The storefront maps the
745
+ * option's own `kind` to `type` (`app/storefront/options.ts`) and the picker draws from that, so
746
+ * these three cases are the whole rule a theme has to honour: `color` is circles, `none` and
747
+ * `custom` are pills, and the option's *name* is never consulted — the guess that used to be the
748
+ * only way to get colour circles out of this block.
749
+ *
750
+ * The row carries the kind (and a `custom` option's name) as data attributes, which is the hook a
751
+ * customer's own fork branches on instead of matching a translated label.
752
+ */
753
+ it('draws the colour option as swatches and the size option as pills', async () => {
754
+ const wrapper = await mountReady(mock);
755
+ const rows = wrapper.findAll('[data-option-kind]');
756
+
757
+ expect(rows.map((row) => row.attributes('data-option-kind'))).toEqual(['color', 'none']);
758
+ // The colour disc is the swatch part, and its one per-item colour is an inline style from the
759
+ // store's own data.
760
+ const swatches = rows[0]!.findAll('[data-part="swatch"]');
761
+ expect(swatches).toHaveLength(4);
762
+ expect(swatches[0]!.attributes('style')).toContain('rgb(216, 203, 176)');
763
+ // Its accessible name is the colour's own name, visually hidden inside the label.
764
+ expect(rows[0]!.findAll('label')[0]!.text()).toBe('Oat');
765
+ // Pills have no disc at all, and their label is the visible text.
766
+ expect(rows[1]!.findAll('[data-part="swatch"]')).toHaveLength(0);
767
+ expect(rows[1]!.findAll('label')[0]!.text()).toBe('XS');
768
+ expect(rows.every((row) => row.attributes('data-option-metadata') === undefined)).toBe(true);
769
+ });
770
+
771
+ /**
772
+ * The defect the `kind` field exists to remove, at the rendering layer: an option a merchant
773
+ * named "Colour" and left on None is a list of words. The values even carry colours here — a
774
+ * store that set them and then switched the option back — and the picker still draws pills,
775
+ * because what is shown follows the merchant's choice and nothing else.
776
+ */
777
+ it('draws pills for an option named for a colour whose kind is none', async () => {
778
+ const wrapper = await mountReady(mock, {
779
+ storefront: storefrontWith({
780
+ options: [
781
+ option({
782
+ name: 'colour',
783
+ label: 'Colour',
784
+ kind: 'none',
785
+ values: [
786
+ { value: 'oat', label: 'Oat', swatch: '#d8cbb0', available: true },
787
+ { value: 'moss', label: 'Moss', swatch: '#6b7a4f', available: true },
788
+ ],
789
+ }),
790
+ ],
791
+ }),
792
+ });
793
+
794
+ const row = wrapper.get('[data-option-kind="none"]');
795
+ expect(row.findAll('[data-part="swatch"]')).toHaveLength(0);
796
+ expect(row.findAll('label').map((label) => label.text())).toEqual(['Oat', 'Moss']);
797
+ expect(await axe(wrapper.element)).toHaveNoViolations();
798
+ });
799
+
800
+ it('draws a custom option as pills and exposes the merchant’s own name for it', async () => {
801
+ const wrapper = await mountReady(mock, {
802
+ storefront: storefrontWith({
803
+ options: [
804
+ option({
805
+ name: 'fabric',
806
+ label: 'Fabric',
807
+ kind: 'custom',
808
+ metadata: 'fabric-chip',
809
+ values: [
810
+ { value: 'merino', label: 'Merino', available: true },
811
+ { value: 'lambswool', label: 'Lambswool', available: true },
812
+ ],
813
+ }),
814
+ ],
815
+ }),
816
+ });
817
+
818
+ const row = wrapper.get('[data-option-kind="custom"]');
819
+ expect(row.attributes('data-option-metadata')).toBe('fabric-chip');
820
+ expect(row.findAll('[data-part="swatch"]')).toHaveLength(0);
821
+ expect(row.findAll('label').map((label) => label.text())).toEqual(['Merino', 'Lambswool']);
822
+ expect(await axe(wrapper.element)).toHaveNoViolations();
823
+ });
824
+
825
+ /**
826
+ * **A Color option whose colours are not set reads its values out loud.** The swatch control
827
+ * hides every value's name in `sr-only` text (`VariantPicker`'s own spec rule — the disc *is*
828
+ * the name), so a picker with nothing to paint would be a row of identical empty circles a
829
+ * sighted shopper cannot choose between. Studio's colour control is clearable and the platform
830
+ * leaves the colour nullable, so this is an ordinary state, not a corrupt one: the option keeps
831
+ * `kind: 'color'` and draws pills with visible labels.
832
+ */
833
+ it('draws a colour option with no colours set as labelled pills, not blank discs', async () => {
834
+ const wrapper = await mountReady(mock, {
835
+ storefront: storefrontWith({
836
+ options: [
837
+ option({
838
+ name: 'colour',
839
+ label: 'Colour',
840
+ kind: 'color',
841
+ values: [
842
+ { value: 'oat', label: 'Oat', available: true },
843
+ { value: 'moss', label: 'Moss', available: true },
844
+ ],
845
+ }),
846
+ ],
847
+ }),
848
+ });
849
+
850
+ const row = wrapper.get('[data-option-kind="color"]');
851
+ expect(row.findAll('[data-part="swatch"]')).toHaveLength(0);
852
+ expect(row.findAll('label').map((label) => label.text())).toEqual(['Oat', 'Moss']);
853
+ expect(await axe(wrapper.element)).toHaveNoViolations();
854
+ });
855
+
856
+ /**
857
+ * One colour is enough, and the value without one keeps its place rather than disappearing — a
858
+ * variant a shopper can buy must stay buyable. Its disc simply carries no background, the way an
859
+ * uncoloured row survives in a filter panel's colour group.
860
+ */
861
+ it('keeps a colourless value inside a swatch group, uncoloured', async () => {
862
+ const wrapper = await mountReady(mock, {
863
+ storefront: storefrontWith({
864
+ options: [
865
+ option({
866
+ name: 'colour',
867
+ label: 'Colour',
868
+ kind: 'color',
869
+ values: [
870
+ { value: 'oat', label: 'Oat', swatch: '#d8cbb0', available: true },
871
+ { value: 'unset', label: 'Unset', available: true },
872
+ ],
873
+ }),
874
+ ],
875
+ }),
876
+ });
877
+
878
+ const swatches = wrapper.get('[data-option-kind="color"]').findAll('[data-part="swatch"]');
879
+ expect(swatches).toHaveLength(2);
880
+ expect(swatches[0]!.attributes('style')).toContain('rgb(216, 203, 176)');
881
+ expect(swatches[1]!.attributes('style')).toBeUndefined();
882
+ expect(await axe(wrapper.element)).toHaveNoViolations();
883
+ });
884
+
885
+ /**
886
+ * Spec Layout, Pickers places the link "at the far end" of *the* legend row, singular. Gating it
887
+ * on the control (`type === 'pills'`) gave every pills option one, so Size plus a `custom`
888
+ * "Fabric" option rendered the link twice. `findAll`, not `get`: `get` returns the first match
889
+ * and cannot see a duplicate, which is why the existing assertion missed this.
890
+ */
891
+ it('shows the size guide link once, even with two pills options', async () => {
892
+ const wrapper = await mountReady(
893
+ { ...mock, sizeGuideHref: '/pages/size-guide' },
894
+ {
895
+ storefront: storefrontWith({
896
+ options: [
897
+ option({
898
+ name: 'size',
899
+ label: 'Size',
900
+ kind: 'none',
901
+ values: [{ value: 'm', label: 'M', available: true }],
902
+ }),
903
+ option({
904
+ name: 'fabric',
905
+ label: 'Fabric',
906
+ kind: 'custom',
907
+ metadata: 'fabric-chip',
908
+ values: [{ value: 'merino', label: 'Merino', available: true }],
909
+ }),
910
+ ],
911
+ }),
912
+ }
913
+ );
914
+
915
+ expect(wrapper.findAll('a[href="/pages/size-guide"]')).toHaveLength(1);
916
+ // And it sits beside the first pills option — the size option on any ordinary product.
917
+ expect(
918
+ wrapper.get('[data-option-kind="none"]').find('a[href="/pages/size-guide"]').exists()
919
+ ).toBe(true);
920
+ });
921
+
922
+ /**
923
+ * Two options can carry the same `name` — the block's own module comment says so, which is why
924
+ * each picker's native radio `name` is suffixed with the block instance id. The link is gated on
925
+ * the option's **position** for exactly that reason; matching on the name would put it back on
926
+ * both rows.
927
+ */
928
+ it('shows the size guide link once even when two options share a name', async () => {
929
+ const values = [{ value: 'm', label: 'M', available: true }];
930
+ const wrapper = await mountReady(
931
+ { ...mock, sizeGuideHref: '/pages/size-guide' },
932
+ {
933
+ storefront: storefrontWith({
934
+ options: [
935
+ option({ name: 'size', label: 'Size', kind: 'none', values }),
936
+ option({ name: 'size', label: 'Inseam', kind: 'none', values }),
937
+ ],
938
+ }),
939
+ }
940
+ );
941
+
942
+ expect(wrapper.findAll('a[href="/pages/size-guide"]')).toHaveLength(1);
943
+ });
944
+
945
+ /** A product whose every option is swatches gets no link at all, as before. */
946
+ it('shows no size guide link when no option is drawn as pills', async () => {
947
+ const wrapper = await mountReady(
948
+ { ...mock, sizeGuideHref: '/pages/size-guide' },
949
+ {
950
+ storefront: storefrontWith({
951
+ options: [
952
+ option({
953
+ name: 'colour',
954
+ label: 'Colour',
955
+ kind: 'color',
956
+ values: [{ value: 'oat', label: 'Oat', swatch: '#d8cbb0', available: true }],
957
+ }),
958
+ ],
959
+ }),
960
+ }
961
+ );
962
+
963
+ expect(wrapper.find('a[href="/pages/size-guide"]').exists()).toBe(false);
964
+ });
965
+ });
966
+
967
+ describe('stock states', () => {
968
+ it('reads in stock for the demo product, axe-clean', async () => {
969
+ const wrapper = await mountReady(mock);
970
+ expect(statusLine(wrapper).text()).toContain('In stock, ready to ship');
971
+ expect(addToCart(wrapper).text()).toContain('Add to cart · $96.00');
972
+ expect(await axe(wrapper.element)).toHaveNoViolations();
973
+ });
974
+
975
+ it('reads low stock only at or below the threshold, never with it off', async () => {
976
+ const low = await mountReady(mock, { storefront: storefrontWith({ inventory: 2 }) });
977
+ expect(statusLine(low).text()).toContain('Low stock: only 2 left in Oat / XS');
978
+ expect(await axe(low.element)).toHaveNoViolations();
979
+
980
+ const above = await mountReady(mock, { storefront: storefrontWith({ inventory: 4 }) });
981
+ expect(above.text()).not.toContain('Low stock');
982
+
983
+ const off = await mountReady(
984
+ { ...mock, lowStockThreshold: 'off' },
985
+ { storefront: storefrontWith({ inventory: 2 }) }
986
+ );
987
+ expect(off.text()).not.toContain('Low stock');
988
+ expect(statusLine(off).text()).toContain('In stock, ready to ship');
989
+ });
990
+
991
+ it('swaps the button for Notify me and hides the stepper when sold out, axe-clean', async () => {
992
+ const wrapper = await mountReady(mock, {
993
+ storefront: storefrontWith({ stock: 'out', inventory: 0 }),
994
+ });
995
+ expect(statusLine(wrapper).text()).toContain('Sold out in Oat / XS');
996
+ expect(addToCart(wrapper).text()).toContain('Notify me');
997
+ expect(wrapper.find('[role="spinbutton"]').exists()).toBe(false);
998
+ expect(await axe(wrapper.element)).toHaveNoViolations();
999
+ });
1000
+
1001
+ it('reads back-order with the ship date for a made-to-order product, axe-clean', async () => {
1002
+ const wrapper = await mountReady(mock, {
1003
+ storefront: storefrontWith({ stock: 'preorder', shipsBy: '14 October' }),
1004
+ });
1005
+ expect(statusLine(wrapper).text()).toContain('Back-order: ships by 14 October');
1006
+ expect(statusLine(wrapper).text()).toContain('we reserve one from the next batch');
1007
+ expect(addToCart(wrapper).text()).toContain('Back-order');
1008
+ expect(await axe(wrapper.element)).toHaveNoViolations();
1009
+ });
1010
+ });
1011
+
1012
+ describe('quantity', () => {
1013
+ it('follows inventory for its maximum and marks the limits aria-disabled', async () => {
1014
+ const wrapper = await mountReady(
1015
+ { ...mock, lowStockThreshold: 'off' },
1016
+ { storefront: storefrontWith({ inventory: 2 }) }
1017
+ );
1018
+ const field = wrapper.get('[role="spinbutton"]');
1019
+ expect(field.attributes('aria-valuemax')).toBe('2');
1020
+ expect(field.attributes('aria-valuenow')).toBe('1');
1021
+
1022
+ const decrease = wrapper.get('[data-part="decrease"]');
1023
+ const increase = wrapper.get('[data-part="increase"]');
1024
+ expect(decrease.attributes('aria-disabled')).toBe('true');
1025
+ expect(increase.attributes('aria-disabled')).toBeUndefined();
1026
+
1027
+ await increase.trigger('click');
1028
+ expect(wrapper.get('[role="spinbutton"]').attributes('aria-valuenow')).toBe('2');
1029
+ expect(wrapper.get('[data-part="increase"]').attributes('aria-disabled')).toBe('true');
1030
+ expect(wrapper.get('[data-part="decrease"]').attributes('aria-disabled')).toBeUndefined();
1031
+ });
1032
+
1033
+ it('is hidden entirely when showQuantity is off', async () => {
1034
+ const wrapper = await mountReady({ ...mock, showQuantity: false });
1035
+ expect(wrapper.find('[role="spinbutton"]').exists()).toBe(false);
1036
+ });
1037
+ });
1038
+
1039
+ it('adds the selected variant and quantity to the cart', async () => {
1040
+ const storefront = storefrontWith();
1041
+ const wrapper = await mountReady(mock, { storefront });
1042
+ await wrapper.get('[data-part="increase"]').trigger('click');
1043
+ await wrapper.get('form').trigger('submit');
1044
+ await flushPromises();
1045
+ expect(storefront.cart.lines.value).toHaveLength(1);
1046
+ expect(storefront.cart.lines.value[0]!.quantity).toBe(2);
1047
+ });
1048
+
1049
+ it('toggles the wishlist button aria-pressed', async () => {
1050
+ const wrapper = await mountReady(mock);
1051
+ const button = wrapper.get('button[aria-pressed]');
1052
+ expect(button.attributes('aria-pressed')).toBe('false');
1053
+ expect(button.attributes('aria-label')).toBe('Save Merino crew sweater to wishlist');
1054
+
1055
+ await button.trigger('click');
1056
+ expect(wrapper.get('button[aria-pressed]').attributes('aria-pressed')).toBe('true');
1057
+ expect(wrapper.get('button[aria-pressed]').attributes('aria-label')).toBe(
1058
+ 'Remove Merino crew sweater from wishlist'
1059
+ );
1060
+ });
1061
+
1062
+ /**
1063
+ * The heart's own feedback. `aria-pressed` flipping is all a mouse user gets from a 20px outline
1064
+ * icon in the corner of the buy box — the same "the button looks like it did nothing" problem the
1065
+ * add-to-cart toast exists for, and the reason the save is confirmed in words.
1066
+ */
1067
+ it('confirms a save with a toast offering the wishlist', async () => {
1068
+ const wrapper = await mountReady(mock);
1069
+ await wrapper.get('button[aria-pressed]').trigger('click');
1070
+
1071
+ expect(toasts()).toEqual([{ title: 'Saved to wishlist', variant: 'success' }]);
1072
+ expect(toastAction()).toEqual({ label: 'View wishlist', href: '/wishlist' });
1073
+ });
1074
+
1075
+ /**
1076
+ * **The toast's offer has to be in the language the shopper is reading.** `@eldrajs/ui`'s `Toast`
1077
+ * renders a `{ label, href }` action as a plain `<a href>` — no router, so `EldraRouterLink` is
1078
+ * not in the path and cannot prefix it. A shopper saving a product on `/is-IS/products/...` who
1079
+ * followed an unprefixed offer would land on the English wishlist, which is also a page whose
1080
+ * saved list is the same `localStorage` — so the mistake looks like nothing but a language
1081
+ * change, and nothing else in this suite sees it. The add-to-cart toast's own fallback
1082
+ * destination (no drawer hosted) is the same decision.
1083
+ */
1084
+ it('offers the wishlist and the cart in the active locale', async () => {
1085
+ const locales = {
1086
+ active: 'is-IS',
1087
+ defaultLocale: 'en-US',
1088
+ supported: ['en-US', 'is-IS'],
1089
+ path: (href: string) => (href.startsWith('/') ? `/is-IS${href}` : href),
1090
+ };
1091
+ const wrapper = await mountReady(mock, { locales });
1092
+ await wrapper.get('button[aria-pressed]').trigger('click');
1093
+
1094
+ // The copy is Icelandic too: `useT()` reads the same active locale, so the label and the
1095
+ // destination of one offer can never disagree about which language the shopper is in.
1096
+ expect(toastAction()).toEqual({ label: isIS.wishlist.view, href: '/is-IS/wishlist' });
1097
+
1098
+ // And the cart offer, on the prerendered state where no drawer is hosted and the toast's
1099
+ // action is a link rather than a button.
1100
+ useToast().clear();
1101
+ const noDrawer = await mountReady(mock, { locales });
1102
+ await addToCart(noDrawer).trigger('click');
1103
+ await flushPromises();
1104
+ expect(toastAction()).toEqual({ label: isIS.cart.viewCart, href: '/is-IS/cart' });
1105
+ });
1106
+
1107
+ /** A removal has nothing to offer: the product just left the list, so there is nothing there to
1108
+ * go and look at, and pressing the heart again is already the undo. */
1109
+ it('says a removal happened, and offers nothing with it', async () => {
1110
+ const wrapper = await mountReady(mock);
1111
+ await wrapper.get('button[aria-pressed]').trigger('click');
1112
+ await wrapper.get('button[aria-pressed]').trigger('click');
1113
+
1114
+ expect(toasts()).toEqual([{ title: 'Removed from wishlist', variant: 'success' }]);
1115
+ expect(toastAction()).toBeUndefined();
1116
+ });
1117
+
1118
+ /** One `id` for both sentences: two toasts that contradict each other must never be on screen
1119
+ * together, and the primitive keeps at most three. */
1120
+ it('replaces its own toast instead of stacking contradicting ones', async () => {
1121
+ const wrapper = await mountReady(mock);
1122
+ await wrapper.get('button[aria-pressed]').trigger('click');
1123
+ await wrapper.get('button[aria-pressed]').trigger('click');
1124
+ await wrapper.get('button[aria-pressed]').trigger('click');
1125
+
1126
+ expect(toasts()).toHaveLength(1);
1127
+ expect(toasts()[0]!.title).toBe('Saved to wishlist');
1128
+ });
1129
+
1130
+ /** The list outlives the page: the store writes through to `localStorage`, so a shopper who
1131
+ * saved a product and navigated away still has it. */
1132
+ it('leaves the saved handle in the browser, not just in the page', async () => {
1133
+ const wrapper = await mountReady(mock);
1134
+ await wrapper.get('button[aria-pressed]').trigger('click');
1135
+
1136
+ expect(JSON.parse(localStorage.getItem('eldra.storefront.wishlist') ?? 'null')).toEqual([
1137
+ 'merino-crew-sweater',
1138
+ ]);
1139
+ });
1140
+
1141
+ it('hides the wishlist button when the field is off', async () => {
1142
+ const wrapper = await mountReady({ ...mock, showWishlist: false });
1143
+ expect(wrapper.find('button[aria-pressed]').exists()).toBe(false);
1144
+ });
1145
+
1146
+ describe('back-in-stock dialog', () => {
1147
+ const soldOut = () => storefrontWith({ stock: 'out', inventory: 0 });
1148
+
1149
+ async function open(wrapper: Wrapper) {
1150
+ const button = addToCart(wrapper);
1151
+ button.element.focus();
1152
+ await wrapper.get('form').trigger('submit');
1153
+ await nextTick();
1154
+ return button;
1155
+ }
1156
+
1157
+ it('opens on Notify me, focuses the email field, and Esc returns focus', async () => {
1158
+ const wrapper = await mountReady(mock, { storefront: soldOut() });
1159
+ const opener = await open(wrapper);
1160
+
1161
+ const dialog = wrapper.get('dialog[aria-labelledby]');
1162
+ expect(dialog.attributes('open')).toBe('');
1163
+ await flushPromises();
1164
+ await nextTick();
1165
+ const email = dialog.get<HTMLInputElement>('input[type="email"]');
1166
+ expect(document.activeElement).toBe(email.element);
1167
+ expect(await axe(wrapper.element)).toHaveNoViolations();
1168
+
1169
+ document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
1170
+ await new Promise((resolve) => setTimeout(resolve));
1171
+ await nextTick();
1172
+ expect(wrapper.get('dialog[aria-labelledby]').attributes('open')).toBeUndefined();
1173
+ expect(document.activeElement).toBe(opener.element);
1174
+ });
1175
+
1176
+ it('refuses a malformed address before anything is sent', async () => {
1177
+ const wrapper = await mountReady(mock, { storefront: soldOut() });
1178
+ await open(wrapper);
1179
+ const dialog = wrapper.get('dialog[aria-labelledby]');
1180
+ await dialog.get('input[type="email"]').setValue('not-an-address');
1181
+ await dialog.get('form').trigger('submit');
1182
+ await flushPromises();
1183
+ expect(dialog.text()).toContain('Enter an email address like name@example.com.');
1184
+ });
1185
+
1186
+ it('confirms a successful sign-up', async () => {
1187
+ const wrapper = await mountReady(mock, { storefront: soldOut() });
1188
+ await open(wrapper);
1189
+ const dialog = wrapper.get('dialog[aria-labelledby]');
1190
+ await dialog.get('input[type="email"]').setValue('maren@example.com');
1191
+ await dialog.get('form').trigger('submit');
1192
+ await flushPromises();
1193
+ expect(dialog.text()).toContain('we will email you as soon as it is back');
1194
+ });
1195
+
1196
+ it('explains a store that does not support back-in-stock emails', async () => {
1197
+ const storefront = soldOut();
1198
+ storefront.catalog.notifyBackInStock = async () => ({
1199
+ ok: false as const,
1200
+ reason: 'unsupported' as const,
1201
+ });
1202
+ const wrapper = await mountReady(mock, { storefront });
1203
+ await open(wrapper);
1204
+ const dialog = wrapper.get('dialog[aria-labelledby]');
1205
+ await dialog.get('input[type="email"]').setValue('maren@example.com');
1206
+ await dialog.get('form').trigger('submit');
1207
+ await flushPromises();
1208
+ expect(dialog.text()).toContain('Back-in-stock emails are not set up for this store yet.');
1209
+ });
1210
+ });
1211
+
1212
+ describe('tabs', () => {
1213
+ it('renders one tab per entry, only the selected one in the tab order', async () => {
1214
+ const wrapper = await mountReady(mock);
1215
+ const tabs = wrapper.findAll('[role="tab"]');
1216
+ expect(tabs.map((tab) => tab.text())).toEqual(['Details', 'Shipping', 'Returns']);
1217
+ expect(tabs.map((tab) => tab.attributes('tabindex'))).toEqual(['0', '-1', '-1']);
1218
+ expect(wrapper.get('[role="tablist"]').attributes('aria-label')).toBe('Product details');
1219
+ expect(wrapper.text()).toContain('extra-fine Merino in a family mill in Biella');
1220
+ });
1221
+
1222
+ it('moves between tabs with arrows (wrapping) and Home/End', async () => {
1223
+ const wrapper = await mountReady(mock);
1224
+ const tabs = () => wrapper.findAll('[role="tab"]');
1225
+ await tabs()[0]!.trigger('keydown', { key: 'ArrowRight' });
1226
+ expect(tabs()[1]!.attributes('aria-selected')).toBe('true');
1227
+ await tabs()[1]!.trigger('keydown', { key: 'ArrowLeft' });
1228
+ expect(tabs()[0]!.attributes('aria-selected')).toBe('true');
1229
+ // Wraps backwards from the first to the last.
1230
+ await tabs()[0]!.trigger('keydown', { key: 'ArrowLeft' });
1231
+ expect(tabs()[2]!.attributes('aria-selected')).toBe('true');
1232
+ await tabs()[2]!.trigger('keydown', { key: 'Home' });
1233
+ expect(tabs()[0]!.attributes('aria-selected')).toBe('true');
1234
+ await tabs()[0]!.trigger('keydown', { key: 'End' });
1235
+ expect(tabs()[2]!.attributes('aria-selected')).toBe('true');
1236
+ });
1237
+
1238
+ it('keeps every panel reachable by keyboard', async () => {
1239
+ const wrapper = await mountReady(mock);
1240
+ const panels = wrapper.findAll('[role="tabpanel"]');
1241
+ expect(panels).toHaveLength(3);
1242
+ // Panels with no focusable content of their own carry `tabindex="0"` so the text is
1243
+ // reachable (`TabPanel`'s own rule); these three are plain prose.
1244
+ for (const panel of panels) expect(panel.attributes('tabindex')).toBe('0');
1245
+ });
1246
+
1247
+ it('puts Add to cart before the tabs in reading order', async () => {
1248
+ const wrapper = await mountReady(mock);
1249
+ const button = addToCart(wrapper).element;
1250
+ const tablist = wrapper.get('[role="tablist"]').element;
1251
+ expect(
1252
+ button.compareDocumentPosition(tablist) & Node.DOCUMENT_POSITION_FOLLOWING
1253
+ ).toBeTruthy();
1254
+ });
1255
+ });
1256
+
1257
+ describe('quick-add bar', () => {
1258
+ it('is absent while the main button is on screen', async () => {
1259
+ const wrapper = await mountReady(mock);
1260
+ expect(wrapper.find('[role="region"]').exists()).toBe(false);
1261
+ expect(wrapper.text()).not.toContain('Quick add');
1262
+ });
1263
+
1264
+ it('appears once the main button scrolls out of view, and never duplicates it otherwise', async () => {
1265
+ const observers: Array<(entries: Array<{ isIntersecting: boolean }>) => void> = [];
1266
+ class StubObserver {
1267
+ constructor(callback: (entries: Array<{ isIntersecting: boolean }>) => void) {
1268
+ observers.push(callback);
1269
+ }
1270
+ observe(): void {}
1271
+ unobserve(): void {}
1272
+ disconnect(): void {}
1273
+ }
1274
+ (globalThis as { IntersectionObserver?: unknown }).IntersectionObserver = StubObserver;
1275
+
1276
+ const wrapper = await mountReady(mock);
1277
+ expect(observers).toHaveLength(1);
1278
+ expect(wrapper.find('[role="region"]').exists()).toBe(false);
1279
+
1280
+ observers[0]!([{ isIntersecting: false }]);
1281
+ await nextTick();
1282
+ const bar = wrapper.get('[role="region"]');
1283
+ expect(bar.attributes('aria-label')).toBe('Quick add');
1284
+ expect(bar.text()).toContain('Merino crew sweater');
1285
+ expect(bar.text()).toContain('Oat / XS · $96.00');
1286
+ // The quick-add button is the one control that exists only below 48rem, where primary
1287
+ // actions are at least 2.75rem tall: it takes the package's `lg` size.
1288
+ expect(bar.get('button[type="button"]').classes()).toContain('control-h-lg');
1289
+ expect(await axe(wrapper.element)).toHaveNoViolations();
1290
+
1291
+ observers[0]!([{ isIntersecting: true }]);
1292
+ await nextTick();
1293
+ expect(wrapper.find('[role="region"]').exists()).toBe(false);
1294
+ });
1295
+
1296
+ it('is never rendered when the field is off', async () => {
1297
+ const observers: Array<(entries: Array<{ isIntersecting: boolean }>) => void> = [];
1298
+ class StubObserver {
1299
+ constructor(callback: (entries: Array<{ isIntersecting: boolean }>) => void) {
1300
+ observers.push(callback);
1301
+ }
1302
+ observe(): void {}
1303
+ unobserve(): void {}
1304
+ disconnect(): void {}
1305
+ }
1306
+ (globalThis as { IntersectionObserver?: unknown }).IntersectionObserver = StubObserver;
1307
+
1308
+ const wrapper = await mountReady({ ...mock, stickyBar: false });
1309
+ expect(observers).toHaveLength(0);
1310
+ expect(wrapper.find('[role="region"]').exists()).toBe(false);
1311
+ });
1312
+ });
1313
+
1314
+ describe('no product bound', () => {
1315
+ it('renders nothing on the live site', async () => {
1316
+ const wrapper = await mountReady(
1317
+ { ...mock, productHandle: '' },
1318
+ { productHandle: null, attach: false }
1319
+ );
1320
+ expect(wrapper.find('section').exists()).toBe(false);
1321
+ expect(wrapper.text()).toBe('');
1322
+ });
1323
+
1324
+ it('shows the "Choose a product" hint in the editor', async () => {
1325
+ const wrapper = await mountReady(
1326
+ { ...mock, productHandle: '' },
1327
+ { productHandle: null, editing: true, attach: false }
1328
+ );
1329
+ expect(wrapper.text()).toContain('Choose a product');
1330
+ expect(wrapper.text()).toContain('On a product template this binds automatically.');
1331
+ expect(await axe(wrapper.element)).toHaveNoViolations();
1332
+ });
1333
+ });
1334
+
1335
+ it('records the product as viewed on mount', async () => {
1336
+ const storefront = storefrontWith();
1337
+ await mountReady(mock, { storefront });
1338
+ expect(storefront.history.recentlyViewed.value[0]).toBe('merino-crew-sweater');
1339
+ });
1340
+
1341
+ it('never renders a countdown, a viewer count or manufactured urgency', async () => {
1342
+ for (const data of [mock, bare]) {
1343
+ const wrapper = await mountReady(data);
1344
+ expect(wrapper.html()).not.toMatch(/\d+ (people|viewing)|only today|hurry/i);
1345
+ }
1346
+ });
1347
+
1348
+ /**
1349
+ * The prerendered page's live refresh (`app/storefront/types.ts`): the HTML shipped with this
1350
+ * product's real price and stock line, and a few hundred milliseconds after mount the storefront
1351
+ * swaps in the backend's current ones. The buy box never redraws for it.
1352
+ */
1353
+ describe('the volatile refresh', () => {
1354
+ /** The demo product, with the result's own flags under the test's control. */
1355
+ function refreshable(patch: Partial<StorefrontProduct> = {}) {
1356
+ const source = storefrontWith(patch);
1357
+ const revalidating = ref<ReadonlySet<VolatileKey>>(new Set());
1358
+ const loading = ref(false);
1359
+ const pending = ref(false);
1360
+ const error = ref<string | null>(null);
1361
+ return {
1362
+ revalidating,
1363
+ loading,
1364
+ pending,
1365
+ error,
1366
+ storefront: {
1367
+ ...source,
1368
+ catalog: {
1369
+ ...source.catalog,
1370
+ product: (handle: Parameters<typeof source.catalog.product>[0]) => {
1371
+ const result = source.catalog.product(handle);
1372
+ return {
1373
+ ...result,
1374
+ pending,
1375
+ loading,
1376
+ error,
1377
+ revalidating,
1378
+ } as unknown as StorefrontResult<StorefrontProduct>;
1379
+ },
1380
+ },
1381
+ } as ReturnType<typeof storefrontWith>,
1382
+ };
1383
+ }
1384
+
1385
+ it('keeps the price and the stock line, marks both busy and draws a spinner beside each', async () => {
1386
+ const { storefront, revalidating } = refreshable();
1387
+ const wrapper = await mountReady(mock, { storefront });
1388
+ expect(wrapper.text()).toContain('$96.00');
1389
+
1390
+ revalidating.value = new Set(['price', 'stock']);
1391
+ await nextTick();
1392
+
1393
+ // The value itself is untouched — this state is a dim and a spinner, never a skeleton.
1394
+ expect(wrapper.text()).toContain('$96.00');
1395
+ expect(wrapper.text()).toContain('In stock, ready to ship');
1396
+ expect(wrapper.find('.eldra-skeleton').exists()).toBe(false);
1397
+
1398
+ const price = wrapper.get('[data-part="root"][aria-busy="true"]');
1399
+ expect(price.find('[data-part="spinner"]').exists()).toBe(true);
1400
+ expect(wrapper.findAll('[data-part="root"][aria-busy="true"]')).toHaveLength(2);
1401
+ // A product page has one price and one stock line, so each announces for itself — unlike a
1402
+ // grid, which announces once for all of its cards (`announce: false` there).
1403
+ expect(wrapper.findAll('[data-part="srStatus"]').length).toBeGreaterThanOrEqual(2);
1404
+ expect(await axe(wrapper.element)).toHaveNoViolations();
1405
+ });
1406
+
1407
+ it('refreshes only the value the storefront named', async () => {
1408
+ const { storefront, revalidating } = refreshable();
1409
+ const wrapper = await mountReady(mock, { storefront });
1410
+
1411
+ revalidating.value = new Set(['price']);
1412
+ await nextTick();
1413
+
1414
+ expect(wrapper.findAll('[data-part="root"][aria-busy="true"]')).toHaveLength(1);
1415
+ expect(wrapper.findAll('[data-part="spinner"]')).toHaveLength(1);
1416
+ });
1417
+
1418
+ it('draws no skeleton and no error over a product the visitor can already see', async () => {
1419
+ const { storefront, pending, loading, error } = refreshable();
1420
+ const wrapper = await mountReady(mock, { storefront });
1421
+
1422
+ // Every flag at once, all of them lying about a page that has its product: none of them may
1423
+ // replace it. `pending` is the skeleton state and nothing else, and a failed read never
1424
+ // regresses a page that already has something to show.
1425
+ pending.value = true;
1426
+ loading.value = true;
1427
+ error.value = 'gateway exploded';
1428
+ await nextTick();
1429
+
1430
+ expect(wrapper.text()).toContain('Merino crew sweater');
1431
+ expect(wrapper.text()).toContain('$96.00');
1432
+ expect(wrapper.text()).not.toContain(enUS.storefront.loading);
1433
+ expect(wrapper.text()).not.toContain(enUS.storefront.error);
1434
+ expect(wrapper.get('[data-part="root"]').attributes('aria-busy')).toBe('true');
1435
+ });
1436
+ });
1437
+
1438
+ /**
1439
+ * A prerendered page outlives the catalogue it was built from: a visitor can follow a bookmark to
1440
+ * a product that has since been deleted. The read answers `null` with no error, which is neither
1441
+ * "still loading" nor "we couldn't ask".
1442
+ */
1443
+ describe('a product that no longer exists', () => {
1444
+ it('says so, rather than rendering nothing at all', async () => {
1445
+ const source = createDemoStorefront();
1446
+ const storefront = {
1447
+ ...source,
1448
+ catalog: {
1449
+ ...source.catalog,
1450
+ product: () =>
1451
+ ({
1452
+ data: ref(null),
1453
+ pending: ref(false),
1454
+ loading: ref(false),
1455
+ error: ref(null),
1456
+ revalidating: ref(new Set()),
1457
+ refresh: async () => {},
1458
+ }) as unknown as StorefrontResult<StorefrontProduct>,
1459
+ },
1460
+ } as ReturnType<typeof storefrontWith>;
1461
+ const wrapper = await mountReady(mock, { storefront });
1462
+
1463
+ expect(wrapper.text()).toContain(enUS.storefront.notFound);
1464
+ expect(wrapper.text()).not.toContain(enUS.storefront.loading);
1465
+ expect(wrapper.text()).not.toContain(enUS.storefront.error);
1466
+ expect(await axe(wrapper.element)).toHaveNoViolations();
1467
+ });
1468
+
1469
+ it('stays on the loading line while the read has not answered', async () => {
1470
+ const source = createDemoStorefront();
1471
+ const storefront = {
1472
+ ...source,
1473
+ catalog: {
1474
+ ...source.catalog,
1475
+ product: () =>
1476
+ ({
1477
+ data: ref(null),
1478
+ pending: ref(true),
1479
+ loading: ref(true),
1480
+ error: ref(null),
1481
+ revalidating: ref(new Set()),
1482
+ refresh: async () => {},
1483
+ }) as unknown as StorefrontResult<StorefrontProduct>,
1484
+ },
1485
+ } as ReturnType<typeof storefrontWith>;
1486
+ const wrapper = await mountReady(mock, { storefront });
1487
+
1488
+ expect(wrapper.text()).toContain(enUS.storefront.loading);
1489
+ expect(wrapper.text()).not.toContain(enUS.storefront.notFound);
1490
+ });
1491
+ });
1492
+ });