@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,2030 @@
1
+ // @vitest-environment jsdom
2
+ import { mount, type DOMWrapper } from '@vue/test-utils';
3
+ import { afterEach, describe, expect, it, vi } from 'vitest';
4
+ import { ELDRA_KEY, createEldraPreviewState } from '@eldrajs/theme-vue';
5
+ import { Badge } from '@eldrajs/ui';
6
+ import { enUS as uiEnUS } from '@eldrajs/ui';
7
+ import { axe } from '../../../test/support/axe';
8
+ import Block from '../Block.vue';
9
+ import mock from '../mock.json';
10
+ import { mountOptions } from '../../../test/support/mountBlock';
11
+ import { computed, nextTick, ref, type Ref } from 'vue';
12
+ import { STOREFRONT_KEY } from '../../../app/storefront/types';
13
+ import type { StorefrontResult, StorefrontSearchResponse } from '../../../app/storefront/types';
14
+ import { createDemoStorefront } from '../../../app/storefront/demo';
15
+
16
+ // `mock.json` is the seed Studio writes when an author inserts the block — media fields
17
+ // (`brandLogo`) are absent, and a collection destination is named by handle, because a theme
18
+ // cannot know an organisation's catalog ids.
19
+ //
20
+ // Core rewrites those handles to ids when it seeds the entry, and the site resolves each id to a
21
+ // slug and a title before rendering. `resolveTargets` does both here, so a spec can assert the
22
+ // hrefs a real page produces; `mock` itself stays the unresolved seed, which is what a header
23
+ // looks like the moment it is inserted and nothing has resolved yet.
24
+ const COLLECTION_TEMPLATE = {
25
+ id: 'rt-collection',
26
+ data: {
27
+ schemaApiId: 'catalog:collection',
28
+ routePattern: '/collections/:slug',
29
+ slugField: 'slug',
30
+ },
31
+ };
32
+
33
+ interface SeedTarget {
34
+ _type: string;
35
+ slug?: string;
36
+ id?: string;
37
+ }
38
+ interface SeedLink {
39
+ kind: string;
40
+ target?: SeedTarget;
41
+ url?: string;
42
+ label?: string;
43
+ group?: string;
44
+ children?: SeedLink[];
45
+ }
46
+
47
+ function resolveTargets<T extends Record<string, unknown>>(
48
+ data: T
49
+ ): {
50
+ data: T;
51
+ links: { templates: (typeof COLLECTION_TEMPLATE)[]; targets: Map<string, unknown> };
52
+ } {
53
+ const targets = new Map<string, unknown>();
54
+ const rewrite = (link: SeedLink): SeedLink => {
55
+ const slug = link.target?.slug;
56
+ if (link.target === undefined || slug === undefined) {
57
+ return { ...link, ...(link.children ? { children: link.children.map(rewrite) } : {}) };
58
+ }
59
+ const id = `id-${slug}`;
60
+ targets.set(`${link.target._type}:${id}`, { slug, title: link.label });
61
+ return {
62
+ ...link,
63
+ target: { _type: link.target._type, id },
64
+ ...(link.children ? { children: link.children.map(rewrite) } : {}),
65
+ };
66
+ };
67
+ const next = { ...data } as Record<string, unknown>;
68
+ if (Array.isArray(next.links)) next.links = (next.links as SeedLink[]).map(rewrite);
69
+ if (next.cta !== undefined) next.cta = rewrite(next.cta as SeedLink);
70
+ return { data: next as T, links: { templates: [COLLECTION_TEMPLATE], targets } };
71
+ }
72
+
73
+ const resolved = resolveTargets(mock);
74
+
75
+ /** The injected fetcher still resolves through a promise; flush one microtask/macrotask turn
76
+ * before asserting on icon markup — the same wait `trust-strip`'s/`team`'s own specs use. */
77
+ async function flushIcons(): Promise<void> {
78
+ await new Promise((resolve) => setTimeout(resolve));
79
+ }
80
+
81
+ /**
82
+ * jsdom implements the `:focus-visible` syntax but never matches it — not even for a real
83
+ * `.focus()` call — so it cannot tell a keyboard focus from a pointer one on its own. The sticky
84
+ * bar's focus specs need that distinction, so they patch `Element.prototype.matches` to answer
85
+ * deterministically for just that selector and restore the original afterwards.
86
+ */
87
+ function stubFocusVisible(matches: boolean): () => void {
88
+ const original = Element.prototype.matches;
89
+ Element.prototype.matches = function (this: Element, selector: string): boolean {
90
+ return selector === ':focus-visible' ? matches : original.call(this, selector);
91
+ };
92
+ return () => {
93
+ Element.prototype.matches = original;
94
+ };
95
+ }
96
+
97
+ function mountBlock(data: Record<string, unknown>, opts?: { attachTo?: Element }) {
98
+ const base = mountOptions({ entry: { id: 'e1', data } }, { links: resolved.links });
99
+ return mount(Block, {
100
+ ...base,
101
+ ...opts,
102
+ });
103
+ }
104
+
105
+ /** Overrides the Eldra preview context's `active`/`mode` — the same shape `useEditing.spec.ts`
106
+ * builds directly, since `mountOptions()` always provides a read-only, inactive preview. */
107
+ function mountWithEditing(data: Record<string, unknown>, editing: boolean) {
108
+ const base = mountOptions({ entry: { id: 'e1', data } });
109
+ return mount(Block, {
110
+ ...base,
111
+ global: {
112
+ ...base.global,
113
+ provide: {
114
+ ...base.global.provide,
115
+ [ELDRA_KEY]: {
116
+ client: {},
117
+ designTokens: { colors: {} },
118
+ links: resolved.links,
119
+ preview: Object.assign(createEldraPreviewState(), {
120
+ active: editing,
121
+ mode: editing ? 'edit' : 'preview',
122
+ }),
123
+ },
124
+ },
125
+ },
126
+ });
127
+ }
128
+
129
+ /** A demo storefront whose cart reports a fixed `count`, so the three "Cart, …" phrasings and the
130
+ * 99+ ceiling can each be exercised without driving the real cart store through `add()`. */
131
+ function mountWithCartCount(data: Record<string, unknown>, count: number) {
132
+ const base = mountOptions({ entry: { id: 'e1', data } });
133
+ const storefront = createDemoStorefront();
134
+ const cart = { ...storefront.cart, count: computed(() => count) };
135
+ return mount(Block, {
136
+ ...base,
137
+ global: {
138
+ ...base.global,
139
+ provide: {
140
+ ...base.global.provide,
141
+ [STOREFRONT_KEY]: { ...storefront, cart },
142
+ },
143
+ },
144
+ });
145
+ }
146
+
147
+ /** The header as it renders on a live page: a storefront whose drawer is mounted and live, which is
148
+ * exactly what `blocks/cart/Block.vue` reports from `onMounted` once `app/app.vue` has hosted one. */
149
+ function mountWithDrawer(data: Record<string, unknown>, opts: { editing?: boolean } = {}) {
150
+ const base = mountOptions({ entry: { id: 'e1', data } });
151
+ const storefront = createDemoStorefront();
152
+ storefront.cart.drawerAvailable.value = true;
153
+ const provide: Record<symbol, unknown> = {
154
+ ...base.global.provide,
155
+ [STOREFRONT_KEY]: storefront,
156
+ };
157
+ if (opts.editing === true) {
158
+ provide[ELDRA_KEY] = {
159
+ client: {},
160
+ designTokens: { colors: {} },
161
+ links: resolved.links,
162
+ preview: Object.assign(createEldraPreviewState(), { active: true, mode: 'edit' }),
163
+ };
164
+ }
165
+ const wrapper = mount(Block, { ...base, global: { ...base.global, provide } });
166
+ return { wrapper, storefront };
167
+ }
168
+
169
+ /**
170
+ * The count pill drawn over one control's own corner — the `<Badge>` that is its sibling inside the
171
+ * `relative inline-flex` span the actions row wraps each of them in. `null` when that control has
172
+ * no pill.
173
+ *
174
+ * Scoped to the control rather than found with `wrapper.findComponent(Badge)`, which answers the
175
+ * *first* badge in the tree: there are two pills in the actions row now (the wishlist heart's comes
176
+ * before the bag's), so a global lookup silently asserts the wrong element the moment a spec has
177
+ * something saved as well as something in the cart.
178
+ */
179
+ /** The bag, in whichever form it rendered: an `<a href="/cart">` while no drawer is mounted, a
180
+ * `<button>` once one is. Module level because both the cart and the wishlist specs need it. */
181
+ function findCartButtonIn(wrapper: ReturnType<typeof mountBlock>): DOMWrapper<Element> | undefined {
182
+ return wrapper
183
+ .findAll('a, button')
184
+ .find((control) => control.attributes('aria-label')?.startsWith('Cart'));
185
+ }
186
+
187
+ function countPill(control: DOMWrapper<Element>): Element | null {
188
+ const siblings = Array.from(control.element.parentElement?.children ?? []);
189
+ return siblings.find((element) => element !== control.element) ?? null;
190
+ }
191
+
192
+ describe('header block (navigation apiId)', () => {
193
+ afterEach(() => {
194
+ window.history.pushState({}, '', '/');
195
+ // The wishlist heart reads `localStorage`, which jsdom keeps for the whole file. Hygiene only:
196
+ // every pill assertion is scoped to its own control (`countPill`), so a list left behind can no
197
+ // longer be mistaken for the bag's count.
198
+ localStorage.clear();
199
+ });
200
+
201
+ it('renders the bare mock.json content — the freshly-inserted state, no images, axe-clean', async () => {
202
+ // Nothing is resolved yet: every label shows, and every catalog destination is still a handle
203
+ // the site has not turned into a path, so the rows are plain text and the call to action —
204
+ // which is a button or nothing, never a button to nowhere — is not drawn at all.
205
+ const wrapper = mountBlock(mock);
206
+ expect(wrapper.find('img').exists()).toBe(false);
207
+ expect(wrapper.text()).toContain(mock.brandText);
208
+ for (const link of mock.links) expect(wrapper.text()).toContain(link.label);
209
+ expect(wrapper.text()).not.toContain(mock.ctaLabel);
210
+ expect(await axe(wrapper.element)).toHaveNoViolations();
211
+ });
212
+
213
+ it('draws the call to action once its destination resolves', async () => {
214
+ const wrapper = mountBlock(resolved.data);
215
+ const cta = wrapper.findAll('a').find((a) => a.text() === mock.ctaLabel)!;
216
+ expect(cta.attributes('href')).toBe('/collections/gifts');
217
+ expect(await axe(wrapper.element)).toHaveNoViolations();
218
+ });
219
+
220
+ it('renders a resolved collection row as /collections/<slug>, axe-clean', async () => {
221
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
222
+ expect(await axe(wrapper.element)).toHaveNoViolations();
223
+ const kitchen = wrapper.findAll('a').find((a) => a.text() === 'Kitchen')!;
224
+ expect(kitchen.attributes('href')).toBe('/collections/kitchen');
225
+ // A row with no catalog target at all still renders its own URL.
226
+ const journal = wrapper.findAll('a').find((a) => a.text() === 'Journal')!;
227
+ expect(journal.attributes('href')).toBe('/journal');
228
+ wrapper.unmount();
229
+ });
230
+
231
+ it('renders a row whose target no longer exists as plain text, never a dead anchor', async () => {
232
+ // The site resolved nothing for this target — deleted, unpublished, or a kind the theme has no
233
+ // route for. The label is still worth showing; an anchor to nowhere is not.
234
+ const wrapper = mountBlock({
235
+ ...resolved.data,
236
+ links: [
237
+ { kind: 'collection', target: { _type: 'collection', id: 'id-gone' }, label: 'Gone' },
238
+ ],
239
+ });
240
+ expect(wrapper.text()).toContain('Gone');
241
+ expect(wrapper.findAll('a').some((a) => a.text() === 'Gone')).toBe(false);
242
+ expect(await axe(wrapper.element)).toHaveNoViolations();
243
+ });
244
+
245
+ it('renders nothing at all for a row with no label', async () => {
246
+ const wrapper = mountBlock({
247
+ ...resolved.data,
248
+ links: [
249
+ { kind: 'url', url: '/journal' },
250
+ { kind: 'url', url: '/pages/visit', label: 'Visit' },
251
+ ],
252
+ });
253
+ const rows = wrapper.findAll('nav ul li');
254
+ expect(rows).toHaveLength(1);
255
+ expect(rows[0]!.text()).toBe('Visit');
256
+ });
257
+
258
+ it('renders a row with children as a mega-menu disclosure', async () => {
259
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
260
+ const knitwear = wrapper.findAll('button').find((b) => b.text().includes('Knitwear'))!;
261
+ expect(knitwear.attributes('aria-expanded')).toBe('false');
262
+ await knitwear.trigger('click');
263
+ const panel = wrapper.get(`#${knitwear.attributes('aria-controls')}`);
264
+ expect(panel.text()).toContain('Women');
265
+ const sweaters = panel.findAll('a').find((a) => a.text() === 'Sweaters')!;
266
+ expect(sweaters.attributes('href')).toBe('/collections/womens-sweaters');
267
+ wrapper.unmount();
268
+ });
269
+
270
+ it('renders a heading-only mega-menu parent as a disclosure with no destination', async () => {
271
+ // `kind: "none"`: the trigger has a label and children and goes nowhere,
272
+ // which is what a mega-menu parent without its own page is.
273
+ const wrapper = mountBlock(
274
+ {
275
+ ...resolved.data,
276
+ links: [
277
+ {
278
+ kind: 'none',
279
+ label: 'Workshop',
280
+ children: [{ kind: 'url', url: '/journal', label: 'Journal' }],
281
+ },
282
+ ],
283
+ },
284
+ { attachTo: document.body }
285
+ );
286
+ const trigger = wrapper.findAll('button').find((b) => b.text().includes('Workshop'))!;
287
+ expect(trigger.attributes('aria-expanded')).toBe('false');
288
+ expect(wrapper.findAll('a').some((a) => a.text() === 'Workshop')).toBe(false);
289
+ await trigger.trigger('click');
290
+ const panel = wrapper.get(`#${trigger.attributes('aria-controls')}`);
291
+ expect(
292
+ panel
293
+ .findAll('a')
294
+ .find((a) => a.text() === 'Journal')!
295
+ .attributes('href')
296
+ ).toBe('/journal');
297
+ expect(await axe(wrapper.element)).toHaveNoViolations();
298
+ wrapper.unmount();
299
+ });
300
+
301
+ it('renders each declared variant with the resolved content, axe-clean', async () => {
302
+ for (const variant of ['default', 'centered', 'minimal']) {
303
+ const wrapper = mountBlock({ ...resolved.data, variant });
304
+ expect(await axe(wrapper.element)).toHaveNoViolations();
305
+ }
306
+ });
307
+
308
+ it('has no h1 anywhere in the header (block headings are never h1)', () => {
309
+ const wrapper = mountBlock(resolved.data);
310
+ expect(wrapper.find('h1').exists()).toBe(false);
311
+ });
312
+
313
+ it('labels the primary navigation landmark', () => {
314
+ // Exactly one `<nav>` — the bar's own row. The drawer's copy of the link list is a plain
315
+ // `<div>`/`<ul>` with no `nav` landmark of its own: with no real stylesheet loaded, jsdom/axe
316
+ // cannot tell "hidden below 64rem" from "visible", so a second identically-labelled `nav`
317
+ // would trip axe's `landmark-unique` rule the moment both exist in the same render.
318
+ const wrapper = mountBlock(resolved.data);
319
+ const navs = wrapper.findAll('nav[aria-label="Primary navigation"]');
320
+ expect(navs).toHaveLength(1);
321
+ });
322
+
323
+ it('establishes its own @container context on the root, so @tablet:/@content: classes measure the block’s own width', () => {
324
+ // The block root — a plain `<header>`, not `@eldrajs/ui`'s `Section` (see `barRootClasses`'s
325
+ // own comment: the header must never emit `data-section-bg` and take part in the
326
+ // adjacent-background padding-collapse rule) — carries `@container` itself. `Container` does
327
+ // not establish one of its own. Losing this silently strands every `@tablet:`/`@content:` class
328
+ // at its mobile value regardless of the block's real width (the footer review's own
329
+ // regression: it shipped its mobile layout at 1280px).
330
+ const wrapper = mountBlock(resolved.data);
331
+ expect(wrapper.get('header').classes()).toContain('@container');
332
+ });
333
+
334
+ it('never emits data-section/data-section-bg (it is not a Section, so a following Hero keeps its own top padding)', () => {
335
+ const wrapper = mountBlock(resolved.data);
336
+ const header = wrapper.get('header').element;
337
+ expect(header.hasAttribute('data-section')).toBe(false);
338
+ expect(header.hasAttribute('data-section-bg')).toBe(false);
339
+ });
340
+
341
+ it('marks the brand link as the header’s announced focus target for announcement-bar dismissal', () => {
342
+ // Cross-block contract (the announcement-bar block): after dismissing itself, it moves focus to
343
+ // `[data-eldra-header-focus]` in the header, falling back to `#main`. The brand link is the
344
+ // first focusable element in DOM order ahead of the primary links list.
345
+ const wrapper = mountBlock(resolved.data);
346
+ const marked = wrapper.get('[data-eldra-header-focus]');
347
+ expect(marked.element.tagName).toBe('A');
348
+ expect(marked.attributes('href')).toBe('/');
349
+ // It's the brand — ahead of every nav link in DOM order.
350
+ const allFocusTargets = wrapper.findAll('a, button');
351
+ expect(allFocusTargets.findIndex((el) => el.element === marked.element)).toBeLessThan(
352
+ allFocusTargets.findIndex((el) => el.text() === mock.links[0]!.label)
353
+ );
354
+ });
355
+
356
+ describe('mega-menu keyboard', () => {
357
+ it('Enter/Space toggles the trigger; hover alone never opens it; opening one closes the other', async () => {
358
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
359
+ // Locate the two mega-menu triggers by their accessible label text.
360
+ const knitwear = wrapper.findAll('button').find((b) => b.text().includes('Knitwear'))!;
361
+ const ceramics = wrapper.findAll('button').find((b) => b.text().includes('Ceramics'))!;
362
+
363
+ expect(knitwear.attributes('aria-expanded')).toBe('false');
364
+ await knitwear.trigger('mouseenter');
365
+ expect(knitwear.attributes('aria-expanded')).toBe('false'); // nothing opens on hover alone (no wait)
366
+ await knitwear.trigger('mouseleave');
367
+
368
+ await knitwear.trigger('keydown', { key: 'Enter' });
369
+ expect(knitwear.attributes('aria-expanded')).toBe('true');
370
+
371
+ // Opening the other one closes the first.
372
+ await ceramics.trigger('keydown', { key: ' ' });
373
+ expect(ceramics.attributes('aria-expanded')).toBe('true');
374
+ expect(knitwear.attributes('aria-expanded')).toBe('false');
375
+
376
+ // Toggling the same trigger again closes it.
377
+ await ceramics.trigger('keydown', { key: 'Enter' });
378
+ expect(ceramics.attributes('aria-expanded')).toBe('false');
379
+
380
+ wrapper.unmount();
381
+ });
382
+
383
+ it('hover opens a panel after 150ms, leaving it closes it after 150ms, and a click-opened panel stays', async () => {
384
+ vi.useFakeTimers();
385
+ try {
386
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
387
+ const knitwear = wrapper.findAll('button').find((b) => b.text().includes('Knitwear'))!;
388
+ const panel = () => wrapper.find(`#${knitwear.attributes('aria-controls')}`);
389
+
390
+ await knitwear.trigger('mouseenter');
391
+ vi.advanceTimersByTime(160);
392
+ await nextTick();
393
+ expect(knitwear.attributes('aria-expanded')).toBe('true');
394
+
395
+ // Crossing from the trigger into the panel keeps it open.
396
+ await knitwear.trigger('mouseleave');
397
+ await panel().trigger('mouseenter');
398
+ vi.advanceTimersByTime(300);
399
+ await nextTick();
400
+ expect(knitwear.attributes('aria-expanded')).toBe('true');
401
+
402
+ // Leaving the panel closes what hover opened.
403
+ await panel().trigger('mouseleave');
404
+ vi.advanceTimersByTime(160);
405
+ await nextTick();
406
+ expect(knitwear.attributes('aria-expanded')).toBe('false');
407
+
408
+ // A panel opened by Enter is not hover-owned: the pointer leaving does not close it.
409
+ await knitwear.trigger('keydown', { key: 'Enter' });
410
+ expect(knitwear.attributes('aria-expanded')).toBe('true');
411
+ await knitwear.trigger('mouseenter');
412
+ await knitwear.trigger('mouseleave');
413
+ vi.advanceTimersByTime(300);
414
+ await nextTick();
415
+ expect(knitwear.attributes('aria-expanded')).toBe('true');
416
+
417
+ wrapper.unmount();
418
+ } finally {
419
+ vi.useRealTimers();
420
+ }
421
+ });
422
+
423
+ /**
424
+ * The bar travels against the viewport, not against the box it is rendered in. A `sticky` bar
425
+ * is clamped to its containing block, and a block's containing block is the single-block
426
+ * wrapper the block zone (or a layout node) renders around it — a box exactly the bar's own
427
+ * height, which leaves a sticky bar nowhere to go: it sits at the top of the page, scrolls out
428
+ * of view with it and never comes back, however this state machine sets its classes. So the bar
429
+ * is `fixed`, and the spacer below it holds the flow the bar left.
430
+ */
431
+ it('positions the sticky bar against the viewport and reserves its height in the flow', async () => {
432
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
433
+ const header = wrapper.get('header');
434
+ expect(header.classes()).toContain('fixed');
435
+ expect(header.classes()).toContain('inset-x-0');
436
+ expect(header.classes()).toContain('top-0');
437
+ expect(header.classes()).not.toContain('sticky');
438
+
439
+ const spacer = wrapper.get('[data-eldra-header-spacer]');
440
+ expect(spacer.attributes('aria-hidden')).toBe('true');
441
+ expect(spacer.text()).toBe('');
442
+ // The bar's own height, and the 1px its bottom hairline adds, reserved to the pixel: the
443
+ // spacer mirrors the bar's own two boxes, the hairline and the `@container` on the outer one
444
+ // (as on the `<header>`) and the height on the inner (as on the `<nav>`).
445
+ expect(spacer.classes()).toContain('@container');
446
+ expect(spacer.classes()).toContain('border-b');
447
+ expect(spacer.classes()).toContain('border-transparent');
448
+ const reserved = spacer.get('div');
449
+ const bar = wrapper.get('header nav');
450
+ for (const height of ['h-16', '@content:h-[4.5rem]']) {
451
+ expect(bar.classes()).toContain(height);
452
+ expect(reserved.classes()).toContain(height);
453
+ }
454
+
455
+ wrapper.unmount();
456
+ });
457
+
458
+ it('reserves nothing for a non-sticky bar: it occupies its own space in the flow', () => {
459
+ const wrapper = mountBlock({ ...resolved.data, sticky: false }, { attachTo: document.body });
460
+ expect(wrapper.find('[data-eldra-header-spacer]').exists()).toBe(false);
461
+ expect(wrapper.get('header').classes()).not.toContain('fixed');
462
+ wrapper.unmount();
463
+ });
464
+
465
+ it('a sticky bar hides on scroll-down, returns on scroll-up or at the top, and never hides while in use', async () => {
466
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
467
+ const header = wrapper.get('header');
468
+ Object.defineProperty(header.element, 'offsetHeight', { value: 72, configurable: true });
469
+ const scrollTo = async (y: number) => {
470
+ Object.defineProperty(window, 'scrollY', { value: y, configurable: true });
471
+ window.dispatchEvent(new Event('scroll'));
472
+ await nextTick();
473
+ };
474
+
475
+ expect(header.classes()).not.toContain('-translate-y-full');
476
+ await scrollTo(40); // still within the bar's own height: never hides
477
+ expect(header.classes()).not.toContain('-translate-y-full');
478
+ await scrollTo(300); // down past the bar: hides
479
+ expect(header.classes()).toContain('-translate-y-full');
480
+ expect(header.classes()).toContain('shadow-float');
481
+ await scrollTo(302); // a 2px jitter changes nothing
482
+ expect(header.classes()).toContain('-translate-y-full');
483
+ await scrollTo(250); // up: returns
484
+ expect(header.classes()).not.toContain('-translate-y-full');
485
+ await scrollTo(600);
486
+ expect(header.classes()).toContain('-translate-y-full');
487
+ await scrollTo(0); // at the top: shown, no shadow
488
+ expect(header.classes()).not.toContain('-translate-y-full');
489
+ expect(header.classes()).not.toContain('shadow-float');
490
+
491
+ // In use: an open mega-menu keeps the bar on screen through a scroll-down …
492
+ const knitwear = wrapper.findAll('button').find((b) => b.text().includes('Knitwear'))!;
493
+ await knitwear.trigger('keydown', { key: 'Enter' });
494
+ await scrollTo(900);
495
+ expect(header.classes()).not.toContain('-translate-y-full');
496
+ await knitwear.trigger('keydown', { key: 'Escape' });
497
+ await nextTick();
498
+ // Keyboard focus inside the bar keeps it shown too — the dedicated `:focus-visible` specs
499
+ // below cover that (and the mouse-click case that must *not* pin it open).
500
+
501
+ await scrollTo(0);
502
+ wrapper.unmount();
503
+ });
504
+
505
+ it('a mouse click that focuses the bag does not pin a scrolled-away bar open', async () => {
506
+ // A plain click focuses the clicked control, but never matches `:focus-visible` — the
507
+ // distinction `focusWithinBar` now keys off so the header can hide again after the cart
508
+ // drawer (or search dialog) returns focus to the button that opened it. jsdom's own
509
+ // `:focus-visible` already evaluates to `false` here even for a real `.focus()` call, so
510
+ // this stub only makes that assumption explicit rather than relying on an engine quirk.
511
+ const restore = stubFocusVisible(false);
512
+ try {
513
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
514
+ const header = wrapper.get('header');
515
+ Object.defineProperty(header.element, 'offsetHeight', { value: 72, configurable: true });
516
+ const scrollTo = async (y: number) => {
517
+ Object.defineProperty(window, 'scrollY', { value: y, configurable: true });
518
+ window.dispatchEvent(new Event('scroll'));
519
+ await nextTick();
520
+ };
521
+ const bag = wrapper
522
+ .findAll('a, button')
523
+ .find((el) => el.attributes('aria-label')?.startsWith('Cart'))!;
524
+
525
+ await bag.trigger('focusin');
526
+ await scrollTo(300);
527
+ expect(header.classes()).toContain('-translate-y-full');
528
+
529
+ await scrollTo(0);
530
+ wrapper.unmount();
531
+ } finally {
532
+ restore();
533
+ }
534
+ });
535
+
536
+ it('keyboard focus-visible on a bar control keeps a scrolled-away bar on screen', async () => {
537
+ // jsdom never matches `:focus-visible`, even right after a real `.focus()` call, so it
538
+ // cannot tell this case apart from the click above on its own; stub it to prove the keyboard
539
+ // side of the same rule.
540
+ const restore = stubFocusVisible(true);
541
+ try {
542
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
543
+ const header = wrapper.get('header');
544
+ Object.defineProperty(header.element, 'offsetHeight', { value: 72, configurable: true });
545
+ const scrollTo = async (y: number) => {
546
+ Object.defineProperty(window, 'scrollY', { value: y, configurable: true });
547
+ window.dispatchEvent(new Event('scroll'));
548
+ await nextTick();
549
+ };
550
+ const searchButton = wrapper.get('button[aria-label="Search"]');
551
+
552
+ await searchButton.trigger('focusin');
553
+ await scrollTo(300);
554
+ expect(header.classes()).not.toContain('-translate-y-full');
555
+
556
+ await searchButton.trigger('focusout', { relatedTarget: document.body });
557
+ await scrollTo(600);
558
+ expect(header.classes()).toContain('-translate-y-full');
559
+
560
+ await scrollTo(0);
561
+ wrapper.unmount();
562
+ } finally {
563
+ restore();
564
+ }
565
+ });
566
+
567
+ it('a non-sticky bar scrolls away with the page and never hides itself', async () => {
568
+ const wrapper = mountBlock({ ...resolved.data, sticky: false }, { attachTo: document.body });
569
+ const header = wrapper.get('header');
570
+ Object.defineProperty(window, 'scrollY', { value: 800, configurable: true });
571
+ window.dispatchEvent(new Event('scroll'));
572
+ await nextTick();
573
+ expect(header.classes()).not.toContain('sticky');
574
+ expect(header.classes()).not.toContain('fixed');
575
+ expect(header.classes()).not.toContain('-translate-y-full');
576
+ Object.defineProperty(window, 'scrollY', { value: 0, configurable: true });
577
+ wrapper.unmount();
578
+ });
579
+
580
+ it('Esc on the trigger closes the panel and returns focus to the trigger', async () => {
581
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
582
+ const knitwear = wrapper.findAll('button').find((b) => b.text().includes('Knitwear'))!;
583
+ await knitwear.trigger('click');
584
+ expect(knitwear.attributes('aria-expanded')).toBe('true');
585
+
586
+ knitwear.element.focus();
587
+ await knitwear.trigger('keydown', { key: 'Escape' });
588
+ await wrapper.vm.$nextTick();
589
+
590
+ expect(knitwear.attributes('aria-expanded')).toBe('false');
591
+ expect(document.activeElement).toBe(knitwear.element);
592
+ wrapper.unmount();
593
+ });
594
+
595
+ it('Esc from inside the panel closes it and returns focus to the trigger', async () => {
596
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
597
+ const knitwear = wrapper.findAll('button').find((b) => b.text().includes('Knitwear'))!;
598
+ await knitwear.trigger('click');
599
+ const panelId = knitwear.attributes('aria-controls')!;
600
+ const panel = wrapper.get(`#${panelId}`);
601
+ const firstLinkInPanel = panel.findAll('a')[0]!;
602
+
603
+ firstLinkInPanel.element.focus();
604
+ await firstLinkInPanel.trigger('keydown', { key: 'Escape' });
605
+ await wrapper.vm.$nextTick();
606
+
607
+ expect(knitwear.attributes('aria-expanded')).toBe('false');
608
+ expect(document.activeElement).toBe(knitwear.element);
609
+ wrapper.unmount();
610
+ });
611
+
612
+ /**
613
+ * The WAI-ARIA APG "Disclosure Navigation Menu" pattern with its arrow-key extension. There is
614
+ * no `role="menu"` and no `aria-activedescendant`: focus is real focus on the real links, so
615
+ * every assertion here reads `document.activeElement` — which is only meaningful with the
616
+ * wrapper attached to the document, as every spec in this describe does.
617
+ *
618
+ * The mock's bar is Knitwear (mega-menu), Ceramics (mega-menu), Kitchen, Journal and Visit the
619
+ * studio (plain links), which is exactly the mix the keys have to cope with.
620
+ */
621
+ describe('arrow keys', () => {
622
+ type Wrapper = ReturnType<typeof mountBlock>;
623
+ const triggerFor = (wrapper: Wrapper, label: string): DOMWrapper<HTMLElement> =>
624
+ wrapper
625
+ .findAll('button')
626
+ .find((button) => button.text().includes(label))! as DOMWrapper<HTMLElement>;
627
+ const panelFor = (wrapper: Wrapper, trigger: DOMWrapper<HTMLElement>): DOMWrapper<Element> =>
628
+ wrapper.get(`#${trigger.attributes('aria-controls')}`);
629
+ const panelLinks = (wrapper: Wrapper, trigger: DOMWrapper<HTMLElement>) =>
630
+ panelFor(wrapper, trigger).findAll('a');
631
+ /** The bar's own top-level items, in bar order: the first element of each `<li>`. */
632
+ const topLevel = (trigger: DOMWrapper<HTMLElement>): Element[] =>
633
+ Array.from(trigger.element.closest('ul')!.children).map((li) => li.firstElementChild!);
634
+
635
+ it('ArrowDown on a trigger opens its panel and moves focus to the first link', async () => {
636
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
637
+ const knitwear = triggerFor(wrapper, 'Knitwear');
638
+ knitwear.element.focus();
639
+
640
+ await knitwear.trigger('keydown', { key: 'ArrowDown' });
641
+ await nextTick();
642
+
643
+ expect(knitwear.attributes('aria-expanded')).toBe('true');
644
+ const links = panelLinks(wrapper, knitwear);
645
+ expect(document.activeElement).toBe(links[0]!.element);
646
+ // A panel a visitor has arrowed into is still a clean one.
647
+ expect(await axe(wrapper.element)).toHaveNoViolations();
648
+ wrapper.unmount();
649
+ });
650
+
651
+ it('ArrowUp on a trigger opens its panel and moves focus to the last link', async () => {
652
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
653
+ const knitwear = triggerFor(wrapper, 'Knitwear');
654
+ knitwear.element.focus();
655
+
656
+ await knitwear.trigger('keydown', { key: 'ArrowUp' });
657
+ await nextTick();
658
+
659
+ expect(knitwear.attributes('aria-expanded')).toBe('true');
660
+ const links = panelLinks(wrapper, knitwear);
661
+ // The panel's own reading order ends on the "View all" row.
662
+ expect(links[links.length - 1]!.attributes('data-eldra-mega-view-all')).toBe('');
663
+ expect(document.activeElement).toBe(links[links.length - 1]!.element);
664
+ wrapper.unmount();
665
+ });
666
+
667
+ it('ArrowDown and ArrowUp walk the panel in reading order and clamp at both ends', async () => {
668
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
669
+ const knitwear = triggerFor(wrapper, 'Knitwear');
670
+ await knitwear.trigger('click');
671
+ const links = panelLinks(wrapper, knitwear);
672
+ expect(links.length).toBeGreaterThan(2);
673
+
674
+ links[0]!.element.focus();
675
+ await links[0]!.trigger('keydown', { key: 'ArrowDown' });
676
+ expect(document.activeElement).toBe(links[1]!.element);
677
+
678
+ await links[1]!.trigger('keydown', { key: 'ArrowUp' });
679
+ expect(document.activeElement).toBe(links[0]!.element);
680
+
681
+ // Clamped, never wrapped: the first link keeps focus instead of jumping to the last.
682
+ await links[0]!.trigger('keydown', { key: 'ArrowUp' });
683
+ expect(document.activeElement).toBe(links[0]!.element);
684
+
685
+ const last = links[links.length - 1]!;
686
+ last.element.focus();
687
+ await last.trigger('keydown', { key: 'ArrowDown' });
688
+ expect(document.activeElement).toBe(last.element);
689
+ expect(knitwear.attributes('aria-expanded')).toBe('true');
690
+ wrapper.unmount();
691
+ });
692
+
693
+ it('ArrowUp with focus not on a panel link enters at the last link, mirroring ArrowDown', async () => {
694
+ // Nothing in a panel but its links is focusable today, so this is the deliberate shape of an
695
+ // edge rather than a path a visitor can walk: Down enters at the first row, so Up enters at
696
+ // the last instead of clamping to the first.
697
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
698
+ const knitwear = triggerFor(wrapper, 'Knitwear');
699
+ await knitwear.trigger('click');
700
+ const links = panelLinks(wrapper, knitwear);
701
+ wrapper.get('a[data-eldra-header-focus]').element.focus();
702
+
703
+ await panelFor(wrapper, knitwear).trigger('keydown', { key: 'ArrowUp' });
704
+ await nextTick();
705
+ expect(document.activeElement).toBe(links[links.length - 1]!.element);
706
+ wrapper.unmount();
707
+ });
708
+
709
+ it('Home and End inside a panel jump to its first and last link', async () => {
710
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
711
+ const knitwear = triggerFor(wrapper, 'Knitwear');
712
+ await knitwear.trigger('click');
713
+ const links = panelLinks(wrapper, knitwear);
714
+
715
+ links[2]!.element.focus();
716
+ await links[2]!.trigger('keydown', { key: 'End' });
717
+ await nextTick();
718
+ expect(document.activeElement).toBe(links[links.length - 1]!.element);
719
+
720
+ await links[links.length - 1]!.trigger('keydown', { key: 'Home' });
721
+ await nextTick();
722
+ expect(document.activeElement).toBe(links[0]!.element);
723
+ wrapper.unmount();
724
+ });
725
+
726
+ it('Home and End on a trigger move to the first and last top-level item', async () => {
727
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
728
+ const ceramics = triggerFor(wrapper, 'Ceramics');
729
+ const items = topLevel(ceramics);
730
+ expect(items).toHaveLength(5);
731
+ expect(items[items.length - 1]!.textContent).toContain('Visit the studio');
732
+
733
+ ceramics.element.focus();
734
+ await ceramics.trigger('keydown', { key: 'End' });
735
+ await nextTick();
736
+ expect(document.activeElement).toBe(items[items.length - 1]);
737
+
738
+ await wrapper
739
+ .findAll('a')
740
+ .find((link) => link.element === items[items.length - 1])!
741
+ .trigger('keydown', { key: 'Home' });
742
+ await nextTick();
743
+ expect(document.activeElement).toBe(items[0]);
744
+ wrapper.unmount();
745
+ });
746
+
747
+ it('ArrowRight along the bar carries an open panel onto the next trigger', async () => {
748
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
749
+ const knitwear = triggerFor(wrapper, 'Knitwear');
750
+ const ceramics = triggerFor(wrapper, 'Ceramics');
751
+ await knitwear.trigger('click');
752
+ knitwear.element.focus();
753
+
754
+ await knitwear.trigger('keydown', { key: 'ArrowRight' });
755
+ await nextTick();
756
+ expect(document.activeElement).toBe(ceramics.element);
757
+ expect(ceramics.attributes('aria-expanded')).toBe('true');
758
+ expect(knitwear.attributes('aria-expanded')).toBe('false');
759
+
760
+ // With nothing open, the same key is a plain focus move: no panel opens behind it.
761
+ await ceramics.trigger('keydown', { key: 'Escape' });
762
+ await nextTick();
763
+ await ceramics.trigger('keydown', { key: 'ArrowLeft' });
764
+ await nextTick();
765
+ expect(document.activeElement).toBe(knitwear.element);
766
+ expect(knitwear.attributes('aria-expanded')).toBe('false');
767
+ wrapper.unmount();
768
+ });
769
+
770
+ it('ArrowRight from inside a panel lands on the next item itself, panel open', async () => {
771
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
772
+ const knitwear = triggerFor(wrapper, 'Knitwear');
773
+ const ceramics = triggerFor(wrapper, 'Ceramics');
774
+ const items = topLevel(knitwear);
775
+ await knitwear.trigger('click');
776
+ const first = panelLinks(wrapper, knitwear)[0]!;
777
+ first.element.focus();
778
+
779
+ // "Moves focus to the next button and expands its dropdown": the trigger itself takes
780
+ // focus, not a row inside the panel that just opened — ArrowDown is what enters that.
781
+ await first.trigger('keydown', { key: 'ArrowRight' });
782
+ await nextTick();
783
+ expect(knitwear.attributes('aria-expanded')).toBe('false');
784
+ expect(ceramics.attributes('aria-expanded')).toBe('true');
785
+ expect(document.activeElement).toBe(ceramics.element);
786
+
787
+ await ceramics.trigger('keydown', { key: 'ArrowDown' });
788
+ await nextTick();
789
+ expect(document.activeElement).toBe(panelLinks(wrapper, ceramics)[0]!.element);
790
+
791
+ // Kitchen has no groups, so it is an ordinary link: it takes focus and the panel closes
792
+ // behind it rather than one opening that does not exist.
793
+ await panelLinks(wrapper, ceramics)[0]!.trigger('keydown', { key: 'ArrowRight' });
794
+ await nextTick();
795
+ expect(ceramics.attributes('aria-expanded')).toBe('false');
796
+ expect(document.activeElement).toBe(items[2]);
797
+
798
+ // And the travel keys work on from a plain link, so the row is never a one-way street.
799
+ await wrapper
800
+ .findAll('a')
801
+ .find((link) => link.element === items[2])!
802
+ .trigger('keydown', { key: 'ArrowRight' });
803
+ await nextTick();
804
+ expect(document.activeElement).toBe(items[3]);
805
+ wrapper.unmount();
806
+ });
807
+
808
+ it('lands on the trigger of a panel with no focusable row rather than losing focus', async () => {
809
+ // Every child of this heading points at something the site cannot resolve, so its panel
810
+ // renders plain text and no "View all" (the parent is a `kind: "none"` heading): zero
811
+ // focusable rows. Crossing onto it must still leave focus somewhere operable.
812
+ const wrapper = mountBlock(
813
+ {
814
+ ...resolved.data,
815
+ links: [
816
+ resolved.data.links[0],
817
+ {
818
+ kind: 'none',
819
+ label: 'Workshop',
820
+ children: [
821
+ {
822
+ kind: 'collection',
823
+ target: { _type: 'collection', id: 'id-gone' },
824
+ label: 'Gone',
825
+ },
826
+ ],
827
+ },
828
+ ],
829
+ },
830
+ { attachTo: document.body }
831
+ );
832
+ const knitwear = triggerFor(wrapper, 'Knitwear');
833
+ const workshop = triggerFor(wrapper, 'Workshop');
834
+ await knitwear.trigger('click');
835
+ const first = panelLinks(wrapper, knitwear)[0]!;
836
+ first.element.focus();
837
+
838
+ await first.trigger('keydown', { key: 'ArrowRight' });
839
+ await nextTick();
840
+ expect(panelLinks(wrapper, workshop)).toHaveLength(0);
841
+ expect(workshop.attributes('aria-expanded')).toBe('true');
842
+ expect(document.activeElement).toBe(workshop.element);
843
+
844
+ // ArrowDown finds nothing to enter, and leaves focus on the trigger rather than nowhere.
845
+ await workshop.trigger('keydown', { key: 'ArrowDown' });
846
+ await nextTick();
847
+ expect(document.activeElement).toBe(workshop.element);
848
+ wrapper.unmount();
849
+ });
850
+
851
+ it('clamps at the end of the bar instead of wrapping', async () => {
852
+ // A bar whose last item *is* a mega-menu trigger, so both the trigger and the panel sit at
853
+ // the end: the mock's own last item is a plain link.
854
+ const wrapper = mountBlock(
855
+ { ...resolved.data, links: resolved.data.links.slice(0, 2) },
856
+ { attachTo: document.body }
857
+ );
858
+ const ceramics = triggerFor(wrapper, 'Ceramics');
859
+ ceramics.element.focus();
860
+ await ceramics.trigger('keydown', { key: 'ArrowDown' });
861
+ await nextTick();
862
+ const links = panelLinks(wrapper, ceramics);
863
+ expect(document.activeElement).toBe(links[0]!.element);
864
+
865
+ await links[0]!.trigger('keydown', { key: 'ArrowRight' });
866
+ await nextTick();
867
+ expect(ceramics.attributes('aria-expanded')).toBe('true');
868
+ expect(document.activeElement).toBe(links[0]!.element);
869
+
870
+ ceramics.element.focus();
871
+ await ceramics.trigger('keydown', { key: 'ArrowRight' });
872
+ await nextTick();
873
+ expect(document.activeElement).toBe(ceramics.element);
874
+ expect(ceramics.attributes('aria-expanded')).toBe('true');
875
+ wrapper.unmount();
876
+ });
877
+
878
+ it('closes the panel once focus leaves the item, and keeps it while focus moves inside', async () => {
879
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
880
+ const knitwear = triggerFor(wrapper, 'Knitwear');
881
+ await knitwear.trigger('click');
882
+ const links = panelLinks(wrapper, knitwear);
883
+
884
+ links[0]!.element.focus();
885
+ links[1]!.element.focus();
886
+ await nextTick();
887
+ expect(knitwear.attributes('aria-expanded')).toBe('true');
888
+
889
+ // Leaving the trigger-and-panel pair — what Tab past the last link, Shift+Tab before the
890
+ // trigger and a click elsewhere all amount to. The panel closes; focus is left alone.
891
+ const brand = wrapper.get('a[data-eldra-header-focus]');
892
+ brand.element.focus();
893
+ await nextTick();
894
+ expect(knitwear.attributes('aria-expanded')).toBe('false');
895
+ expect(document.activeElement).toBe(brand.element);
896
+ wrapper.unmount();
897
+ });
898
+
899
+ /**
900
+ * Dispatched by hand rather than through `trigger()`, which does not hand back the event, and
901
+ * `defaultPrevented` is the whole assertion here.
902
+ */
903
+ const press = (el: Element, key: string): boolean => {
904
+ const event = new KeyboardEvent('keydown', { key, bubbles: true, cancelable: true });
905
+ el.dispatchEvent(event);
906
+ return event.defaultPrevented;
907
+ };
908
+
909
+ /**
910
+ * The panel is `v-show`n: it is in the DOM with `display: none` until the open state flushes,
911
+ * and a browser will not focus a hidden element. jsdom focuses one happily, so the outcome
912
+ * cannot be asserted — the ordering can: focus must not be attempted while the panel is still
913
+ * hidden, only on the tick after Vue has shown it.
914
+ */
915
+ it('focuses into the panel only after it has been shown, never in the same tick', async () => {
916
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
917
+ const knitwear = triggerFor(wrapper, 'Knitwear');
918
+ const first = panelLinks(wrapper, knitwear)[0]!.element;
919
+ const focusSpy = vi.spyOn(first, 'focus');
920
+
921
+ knitwear.element.focus();
922
+ expect(press(knitwear.element, 'ArrowDown')).toBe(true);
923
+ // Nothing has flushed yet: the panel is still hidden, so nothing may have been focused.
924
+ expect(knitwear.attributes('aria-expanded')).toBe('false');
925
+ expect(focusSpy).not.toHaveBeenCalled();
926
+
927
+ await nextTick();
928
+ expect(knitwear.attributes('aria-expanded')).toBe('true');
929
+ expect(focusSpy).toHaveBeenCalled();
930
+ expect(document.activeElement).toBe(first);
931
+ focusSpy.mockRestore();
932
+ wrapper.unmount();
933
+ });
934
+
935
+ it('takes only the keys it handles, and leaves every other one to the page', async () => {
936
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
937
+ const knitwear = triggerFor(wrapper, 'Knitwear');
938
+ const kitchen = topLevel(knitwear)[2]!;
939
+
940
+ // A trigger and a plain bar link both pass unhandled keys straight through, so the header's
941
+ // own `/` and `⌘K` shortcuts and the page's scrolling are untouched.
942
+ for (const key of ['PageDown', 'a', 'Tab']) {
943
+ expect(press(knitwear.element, key)).toBe(false);
944
+ expect(press(kitchen, key)).toBe(false);
945
+ }
946
+ expect(press(knitwear.element, 'ArrowDown')).toBe(true);
947
+ await nextTick();
948
+
949
+ const first = panelLinks(wrapper, knitwear)[0]!.element;
950
+ for (const key of ['PageDown', 'a', 'Tab']) expect(press(first, key)).toBe(false);
951
+ expect(press(first, 'ArrowDown')).toBe(true);
952
+ wrapper.unmount();
953
+ });
954
+
955
+ it('leaves Down and Up alone on a plain bar link, which has no panel to open', async () => {
956
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
957
+ const kitchen = topLevel(triggerFor(wrapper, 'Knitwear'))[2]!;
958
+ kitchen.focus();
959
+
960
+ expect(press(kitchen, 'ArrowDown')).toBe(false);
961
+ expect(press(kitchen, 'ArrowUp')).toBe(false);
962
+ expect(document.activeElement).toBe(kitchen);
963
+ // The travel keys it does take still work.
964
+ expect(press(kitchen, 'ArrowRight')).toBe(true);
965
+ wrapper.unmount();
966
+ });
967
+
968
+ it('drops a pending hover-open when focus leaves the menus', async () => {
969
+ vi.useFakeTimers();
970
+ try {
971
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
972
+ const knitwear = triggerFor(wrapper, 'Knitwear');
973
+ const ceramics = triggerFor(wrapper, 'Ceramics');
974
+ await knitwear.trigger('click');
975
+ panelLinks(wrapper, knitwear)[0]!.element.focus();
976
+
977
+ // The pointer has come to rest on the next trigger: its 150ms open is armed, not fired.
978
+ await ceramics.trigger('mouseenter');
979
+ // Focus leaves the header's menus, which closes the open panel…
980
+ wrapper.get('a[data-eldra-header-focus]').element.focus();
981
+ await nextTick();
982
+ expect(knitwear.attributes('aria-expanded')).toBe('false');
983
+
984
+ // …and takes the pending hover-open with it, so nothing springs open behind the keyboard.
985
+ vi.advanceTimersByTime(300);
986
+ await nextTick();
987
+ expect(ceramics.attributes('aria-expanded')).toBe('false');
988
+ wrapper.unmount();
989
+ } finally {
990
+ vi.useRealTimers();
991
+ }
992
+ });
993
+
994
+ it('hands a hover-opened panel over to the keyboard once focus is inside it', async () => {
995
+ vi.useFakeTimers();
996
+ try {
997
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
998
+ const knitwear = triggerFor(wrapper, 'Knitwear');
999
+
1000
+ await knitwear.trigger('mouseenter');
1001
+ vi.advanceTimersByTime(160);
1002
+ await nextTick();
1003
+ expect(knitwear.attributes('aria-expanded')).toBe('true');
1004
+
1005
+ // Focus has arrived inside what hover opened, so the pointer no longer owns it: closing
1006
+ // on the way out would strand that focus on a link the panel has just hidden.
1007
+ panelLinks(wrapper, knitwear)[0]!.element.focus();
1008
+ await knitwear.trigger('mouseleave');
1009
+ vi.advanceTimersByTime(300);
1010
+ await nextTick();
1011
+ expect(knitwear.attributes('aria-expanded')).toBe('true');
1012
+
1013
+ // Focus leaving is what closes it now.
1014
+ wrapper.get('a[data-eldra-header-focus]').element.focus();
1015
+ await nextTick();
1016
+ expect(knitwear.attributes('aria-expanded')).toBe('false');
1017
+ wrapper.unmount();
1018
+ } finally {
1019
+ vi.useRealTimers();
1020
+ }
1021
+ });
1022
+
1023
+ it("keeps the panel's links in the tab sequence, in DOM order right after the trigger", async () => {
1024
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
1025
+ const knitwear = triggerFor(wrapper, 'Knitwear');
1026
+ await knitwear.trigger('click');
1027
+ const links = panelLinks(wrapper, knitwear);
1028
+
1029
+ // No roving tabindex: this is a disclosure, not a menu.
1030
+ for (const link of links) expect(link.attributes('tabindex')).toBeUndefined();
1031
+ const order = wrapper.findAll('a, button').map((el) => el.element);
1032
+ const at = order.indexOf(knitwear.element);
1033
+ expect(at).toBeGreaterThanOrEqual(0);
1034
+ expect(order.slice(at + 1, at + 1 + links.length)).toEqual(links.map((l) => l.element));
1035
+ wrapper.unmount();
1036
+ });
1037
+ });
1038
+ });
1039
+
1040
+ describe('drawer keyboard', () => {
1041
+ it('opens as a dialog with the first focusable row focused', async () => {
1042
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
1043
+ const menuButton = wrapper.get('button[aria-haspopup="dialog"][aria-controls]');
1044
+ await menuButton.trigger('click');
1045
+
1046
+ const dialog = wrapper.get('dialog');
1047
+ expect(dialog.attributes('open')).toBe('');
1048
+ // The first row of the drawer's own list — a disclosure button (Knitwear has a mega-menu).
1049
+ const firstRow = wrapper.get('dialog ul li:first-child button, dialog ul li:first-child a');
1050
+ expect(document.activeElement).toBe(firstRow.element);
1051
+ wrapper.unmount();
1052
+ });
1053
+
1054
+ it('Esc closes the drawer and returns focus to the menu button', async () => {
1055
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
1056
+ const menuButton = wrapper.get('button[aria-haspopup="dialog"][aria-controls]');
1057
+ // A real click focuses the button before it fires; `trigger('click')` only dispatches the
1058
+ // event, so the opener has to be focused explicitly for `useDialog`'s "return focus to
1059
+ // whatever had it before the dialog opened" to have anything correct to return it to.
1060
+ menuButton.element.focus();
1061
+ await menuButton.trigger('click');
1062
+ expect(wrapper.get('dialog').attributes('open')).toBe('');
1063
+
1064
+ document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
1065
+ await new Promise((resolve) => setTimeout(resolve));
1066
+ await wrapper.vm.$nextTick();
1067
+
1068
+ expect(wrapper.get('dialog').attributes('open')).toBeUndefined();
1069
+ expect(document.activeElement).toBe(menuButton.element);
1070
+ wrapper.unmount();
1071
+ });
1072
+ });
1073
+
1074
+ describe('cart button', () => {
1075
+ // The demo storefront's `drawerAvailable` is off, so the cart control renders as an `<a
1076
+ // href="/cart">` (Button's own link form), not a `<button>` — `findCartButtonIn` searches both
1077
+ // tags. Every assertion here is about a header that has a bag, so the non-null is the point.
1078
+ function findCartButton(wrapper: ReturnType<typeof mountBlock>): DOMWrapper<Element> {
1079
+ return findCartButtonIn(wrapper)!;
1080
+ }
1081
+
1082
+ it('reads "Cart, empty" with nothing in the cart, and shows no badge', () => {
1083
+ const wrapper = mountBlock(resolved.data); // demo storefront's cart starts empty
1084
+ expect(findCartButton(wrapper).attributes('aria-label')).toBe('Cart, empty');
1085
+ expect(countPill(findCartButton(wrapper))).toBeNull();
1086
+ });
1087
+
1088
+ // The count is read only once the block has mounted (the server never knows it), so each of
1089
+ // these waits one tick for that update before looking at the bag.
1090
+ it('reads "Cart, 1 item" for a single item', async () => {
1091
+ const wrapper = mountWithCartCount(mock, 1);
1092
+ await nextTick();
1093
+ expect(findCartButton(wrapper).attributes('aria-label')).toBe('Cart, 1 item');
1094
+ });
1095
+
1096
+ it('reads "Cart, {n} items" for more than one, with an aria-hidden badge carrying the count', async () => {
1097
+ const wrapper = mountWithCartCount(mock, 2);
1098
+ await nextTick();
1099
+ const bag = findCartButton(wrapper);
1100
+ expect(bag.attributes('aria-label')).toBe('Cart, 2 items');
1101
+ const badge = countPill(bag)!;
1102
+ expect(badge.getAttribute('aria-hidden')).toBe('true');
1103
+ expect(badge.textContent?.trim()).toBe('2');
1104
+ // The pill is a sibling drawn over the bag's corner, and with the count it grows across the
1105
+ // middle of the button; a pointer on it must still reach the bag underneath.
1106
+ expect(badge.classList.contains('pointer-events-none')).toBe(true);
1107
+ });
1108
+
1109
+ it('reads "99+" above 99', async () => {
1110
+ const wrapper = mountWithCartCount(mock, 120);
1111
+ await nextTick();
1112
+ const bag = findCartButton(wrapper);
1113
+ expect(bag.attributes('aria-label')).toBe('Cart, 120 items');
1114
+ expect(countPill(bag)?.textContent?.trim()).toBe('99+');
1115
+ });
1116
+
1117
+ /**
1118
+ * A corner badge, not the spec's own "1.25rem, flush right,
1119
+ * ring" pill — that reading put the pill beside the bag's icon rather than on it. 0.875rem
1120
+ * (`-3.5`) square, nudged just outside the button's own top-right corner (`-top-0.5
1121
+ * -right-0.5`: `top-0.5 right-0.5` was tried first and, measured in a real browser, still
1122
+ * buried roughly a third of the icon under it), no ring (a ring separates a pill from what
1123
+ * sits *beside* it; this one sits deliberately *on* the icon's corner). `Badge`'s own
1124
+ * `min-h-6`/`text-badge` must not survive the merge — that overshoot (1.5rem tall, the wrong
1125
+ * type scale) was the original defect.
1126
+ */
1127
+ it('sizes and positions the pill as a corner badge, with none of Badge’s own oversized defaults left behind', async () => {
1128
+ const wrapper = mountWithCartCount(mock, 2);
1129
+ await nextTick();
1130
+ const badge = countPill(findCartButton(wrapper))!;
1131
+ for (const token of [
1132
+ 'min-h-3.5',
1133
+ 'min-w-3.5',
1134
+ 'h-3.5',
1135
+ 'px-1',
1136
+ 'text-[0.625rem]',
1137
+ 'font-bold',
1138
+ 'tabular-nums',
1139
+ 'leading-none',
1140
+ '-top-0.5',
1141
+ '-right-0.5',
1142
+ ]) {
1143
+ expect([...badge.classList]).toContain(token);
1144
+ }
1145
+ for (const stale of [
1146
+ 'min-h-6',
1147
+ 'text-badge',
1148
+ 'top-0.5',
1149
+ 'right-0.5',
1150
+ 'ring-2',
1151
+ 'ring-background',
1152
+ 'min-h-5',
1153
+ 'min-w-5',
1154
+ 'h-5',
1155
+ 'right-0',
1156
+ ]) {
1157
+ expect([...badge.classList]).not.toContain(stale);
1158
+ }
1159
+ });
1160
+
1161
+ // The bag's two forms, and the destination of the link form. With no drawer mounted the bag is
1162
+ // an anchor to `/cart`, which is the site's own cart page: the theme seeds it
1163
+ // (`pages/cart.page.json`), the catch-all serves it, and `@eldrajs/theme-nuxt`'s
1164
+ // `prerender:routes` hook writes its file from the page document — nothing names the path in
1165
+ // `nuxt.config.ts`. It used to be an anchor to a path nothing in the theme answered at all, so
1166
+ // the catch-all asked the gateway for a page called "cart", found none, and every shopper who
1167
+ // clicked the bag landed on the not-found shell.
1168
+ it('links to the cart page when no drawer is mounted, and claims no popup', () => {
1169
+ const wrapper = mountBlock(resolved.data); // the demo storefront claims no drawer
1170
+ const bag = findCartButton(wrapper);
1171
+ expect(bag.element.tagName).toBe('A');
1172
+ expect(bag.attributes('href')).toBe('/cart');
1173
+ // A link to a page pops nothing up; only the button form is a dialog trigger.
1174
+ expect(bag.attributes('aria-haspopup')).toBeUndefined();
1175
+ });
1176
+
1177
+ it('is a button that opens the drawer when one is mounted, and navigates nowhere', async () => {
1178
+ const { wrapper, storefront } = mountWithDrawer(resolved.data);
1179
+
1180
+ const bag = findCartButton(wrapper);
1181
+ expect(bag.element.tagName).toBe('BUTTON');
1182
+ expect(bag.attributes('href')).toBeUndefined();
1183
+ // Spec "Cart": "It opens from the header bag button (`aria-haspopup=\"dialog\"`)" — the same
1184
+ // annotation the Menu and search triggers carry.
1185
+ expect(bag.attributes('aria-haspopup')).toBe('dialog');
1186
+
1187
+ expect(storefront.cart.drawerOpen.value).toBe(false);
1188
+ await bag.trigger('click');
1189
+ expect(storefront.cart.drawerOpen.value).toBe(true);
1190
+ });
1191
+
1192
+ /**
1193
+ * In Studio's editor the bag does nothing. The preview overlay cancels a click that carries an
1194
+ * `href` (that is how it keeps an author from navigating away while editing), but a button's click
1195
+ * is not an `href` click and reaches this handler — and a modal `<dialog>` over the canvas makes
1196
+ * the rest of the page inert and unscrollable until the author finds Escape. An author inspecting
1197
+ * the header is not shopping.
1198
+ */
1199
+ it('does nothing when the bag is clicked in the editor', async () => {
1200
+ const { wrapper, storefront } = mountWithDrawer(resolved.data, { editing: true });
1201
+
1202
+ const bag = findCartButton(wrapper);
1203
+ expect(bag.element.tagName).toBe('BUTTON');
1204
+ await bag.trigger('click');
1205
+ expect(storefront.cart.drawerOpen.value).toBe(false);
1206
+ });
1207
+ });
1208
+
1209
+ /**
1210
+ * The entry point to `/wishlist`. One rule decides whether it is in the DOM at all — the
1211
+ * variant — because a way into the list belongs in the bar whether or not this visitor has used
1212
+ * it. What a prerendered file must not carry is the *count*, and that is the badge's rule, not
1213
+ * the heart's: `test/pages/ssr.spec.ts` and `test/pages/hydration.spec.ts` hold the halves of it
1214
+ * that only a server render and a real hydration can see.
1215
+ */
1216
+ describe('wishlist heart', () => {
1217
+ /** The demo storefront claims no cart drawer, so every action here is `Button`'s link form. */
1218
+ function findHeart(wrapper: ReturnType<typeof mountBlock>) {
1219
+ return wrapper
1220
+ .findAll('a, button')
1221
+ .find((control) => control.attributes('aria-label')?.startsWith('Wishlist'));
1222
+ }
1223
+
1224
+ function saveInBrowser(...handles: string[]): void {
1225
+ localStorage.setItem('eldra.storefront.wishlist', JSON.stringify(handles));
1226
+ }
1227
+
1228
+ it('is there with nothing saved, named without a count and carrying no pill', () => {
1229
+ const wrapper = mountBlock(resolved.data);
1230
+ const heart = findHeart(wrapper)!;
1231
+ // No number in the name, so the prerendered header reads the same for every visitor — and
1232
+ // the destination is there from the first paint, not grown later.
1233
+ expect(heart.attributes('aria-label')).toBe('Wishlist');
1234
+ expect(heart.attributes('href')).toBe('/wishlist');
1235
+ expect(countPill(heart)).toBeNull();
1236
+ // The bag's own pill is absent too (an empty cart), so this is the whole actions row: two
1237
+ // icons, no badges.
1238
+ expect(wrapper.findAllComponents(Badge)).toHaveLength(0);
1239
+ });
1240
+
1241
+ /**
1242
+ * Spec "Header" -> Variants, `minimal`: "Brand left; search, cart and a 'Menu' button on the
1243
+ * right at every width. Links … and call to action live only in the drawer." A third icon there
1244
+ * would be the theme deciding that variant means something else — and the drawer has no
1245
+ * wishlist row either, so it would be inconsistent in both directions. The call to action
1246
+ * carries the same guard.
1247
+ */
1248
+ it('is absent in the minimal variant, saved list or not', async () => {
1249
+ saveInBrowser('merino-crew-sweater');
1250
+ const wrapper = mountBlock({ ...resolved.data, variant: 'minimal' });
1251
+ await nextTick();
1252
+
1253
+ expect(findHeart(wrapper)).toBeUndefined();
1254
+ // The bag is still there, which is what makes this about the heart and not about the row.
1255
+ expect(findCartButtonIn(wrapper)).toBeDefined();
1256
+ });
1257
+
1258
+ it('takes its count after mount once something is saved, linking to the wishlist route', async () => {
1259
+ saveInBrowser('merino-crew-sweater');
1260
+ const wrapper = mountBlock(resolved.data);
1261
+ await nextTick();
1262
+
1263
+ const heart = findHeart(wrapper)!;
1264
+ expect(heart.attributes('aria-label')).toBe('Wishlist, 1 item');
1265
+ expect(heart.element.tagName).toBe('A');
1266
+ expect(heart.attributes('href')).toBe('/wishlist');
1267
+ // It is a link to a page, so it claims no popup — the same rule the bag's link form follows.
1268
+ expect(heart.attributes('aria-haspopup')).toBeUndefined();
1269
+ });
1270
+
1271
+ it('carries an aria-hidden count pill that cannot swallow the click', async () => {
1272
+ saveInBrowser('merino-crew-sweater', 'speckled-latte-mug');
1273
+ const wrapper = mountBlock(resolved.data);
1274
+ await nextTick();
1275
+
1276
+ const heart = findHeart(wrapper)!;
1277
+ expect(heart.attributes('aria-label')).toBe('Wishlist, 2 items');
1278
+ const badge = countPill(heart)!;
1279
+ expect(badge.getAttribute('aria-hidden')).toBe('true');
1280
+ expect(badge.textContent?.trim()).toBe('2');
1281
+ expect(badge.classList.contains('pointer-events-none')).toBe(true);
1282
+ });
1283
+
1284
+ it('reads "99+" above 99, like the bag', async () => {
1285
+ saveInBrowser(...Array.from({ length: 120 }, (_, index) => `product-${index}`));
1286
+ const wrapper = mountBlock(resolved.data);
1287
+ await nextTick();
1288
+
1289
+ const heart = findHeart(wrapper)!;
1290
+ expect(heart.attributes('aria-label')).toBe('Wishlist, 120 items');
1291
+ expect(countPill(heart)?.textContent?.trim()).toBe('99+');
1292
+ });
1293
+
1294
+ /** Two pills in one row, each carrying its own control's count — the asymmetry a global badge
1295
+ * lookup used to hide. */
1296
+ it('keeps its own count apart from the bag’s', async () => {
1297
+ saveInBrowser('merino-crew-sweater', 'speckled-latte-mug');
1298
+ const wrapper = mountWithCartCount(mock, 5);
1299
+ await nextTick();
1300
+
1301
+ expect(countPill(findHeart(wrapper)!)?.textContent?.trim()).toBe('2');
1302
+ expect(countPill(findCartButtonIn(wrapper)!)?.textContent?.trim()).toBe('5');
1303
+ });
1304
+
1305
+ /** Same override, not two copies that could drift apart (`COUNT_PILL_CLASSES` in the block). */
1306
+ it('shares its pill’s classes with the bag’s, byte for byte', async () => {
1307
+ saveInBrowser('merino-crew-sweater');
1308
+ const wrapper = mountWithCartCount(mock, 3);
1309
+ await nextTick();
1310
+
1311
+ const heartPill = countPill(findHeart(wrapper)!)!;
1312
+ const cartPill = countPill(findCartButtonIn(wrapper)!)!;
1313
+ expect(heartPill.className).toBe(cartPill.className);
1314
+ // And the corner-badge classes are actually on it, not just shared with an equally-wrong
1315
+ // sibling.
1316
+ for (const token of ['min-h-3.5', 'min-w-3.5', 'h-3.5', '-top-0.5', '-right-0.5']) {
1317
+ expect([...heartPill.classList]).toContain(token);
1318
+ }
1319
+ });
1320
+
1321
+ it('is axe-clean with the heart and its pill in the actions row', async () => {
1322
+ saveInBrowser('merino-crew-sweater', 'speckled-latte-mug');
1323
+ const wrapper = mountBlock(resolved.data);
1324
+ await nextTick();
1325
+
1326
+ expect(findHeart(wrapper)).toBeDefined();
1327
+ expect(await axe(wrapper.element)).toHaveNoViolations();
1328
+ });
1329
+
1330
+ /** And with no count on it either — an icon-only link whose whole accessible name is the
1331
+ * control's own, which is the state every prerendered page is served in. */
1332
+ it('is axe-clean with nothing saved, where the heart carries no pill', async () => {
1333
+ const wrapper = mountBlock(resolved.data);
1334
+ expect(findHeart(wrapper)!.attributes('aria-label')).toBe('Wishlist');
1335
+ expect(await axe(wrapper.element)).toHaveNoViolations();
1336
+ });
1337
+ });
1338
+
1339
+ it('marks the current link with aria-current="page"', async () => {
1340
+ window.history.pushState({}, '', '/collections/kitchen');
1341
+ const wrapper = mountBlock(resolved.data);
1342
+ const current = wrapper
1343
+ .findAll('a')
1344
+ .find((a) => a.attributes('href') === '/collections/kitchen')!;
1345
+ expect(current.attributes('aria-current')).toBe('page');
1346
+ const other = wrapper.findAll('a').find((a) => a.attributes('href') === '/journal')!;
1347
+ expect(other.attributes('aria-current')).toBeUndefined();
1348
+ });
1349
+
1350
+ it('renders 8 links with no overflow markup errors', async () => {
1351
+ const eightLinks = [
1352
+ ...resolved.data.links,
1353
+ { kind: 'url', url: '/collections/sale', label: 'Sale' },
1354
+ { kind: 'url', url: '/collections/gifts', label: 'Gifts' },
1355
+ { kind: 'url', url: '/pages/about', label: 'About' },
1356
+ ];
1357
+ const wrapper = mountBlock({ ...resolved.data, links: eightLinks });
1358
+ expect(wrapper.findAll('nav ul li, ul.list-none > li').length).toBeGreaterThan(0);
1359
+ for (const link of eightLinks) expect(wrapper.text()).toContain(link.label);
1360
+ expect(await axe(wrapper.element)).toHaveNoViolations();
1361
+ });
1362
+
1363
+ it('spreads mega-menu groups across the full width', async () => {
1364
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
1365
+ const knitwear = wrapper.findAll('button').find((b) => b.text().includes('Knitwear'))!;
1366
+ await knitwear.trigger('click');
1367
+ const panelId = knitwear.attributes('aria-controls')!;
1368
+ const panel = wrapper.get(`#${panelId}`);
1369
+ expect(panel.find('img').exists()).toBe(false);
1370
+ expect(panel.text()).toContain('Women');
1371
+ expect(panel.text()).toContain('Merino essentials');
1372
+ wrapper.unmount();
1373
+ });
1374
+
1375
+ describe('mega-menu panel geometry', () => {
1376
+ // jsdom computes no layout, so the proof that the panel really lands on the brand's left edge
1377
+ // and the actions' right edge is the browser case in `test/prerenderRefresh.browser.spec.ts`.
1378
+ // What is checkable here is the arrangement that produces it: the panel is pinned to the
1379
+ // header's own content box — the `<nav>` — rather than to the item that opened it, and its
1380
+ // columns are the container's 12-column grid.
1381
+ it('pins the panel to the header container, not to the trigger that opened it', async () => {
1382
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
1383
+ const nav = wrapper.get('nav');
1384
+ // The positioning context: the panel's `left-0 right-0` only means "the header container"
1385
+ // because this is the nearest positioned ancestor.
1386
+ expect(nav.classes()).toContain('relative');
1387
+ // …and no row of the bar may reclaim it, or the panel would hang under its own item again.
1388
+ for (const row of wrapper.findAll('nav > ul > li')) {
1389
+ expect(row.classes()).not.toContain('relative');
1390
+ }
1391
+
1392
+ const knitwear = wrapper.findAll('button').find((b) => b.text().includes('Knitwear'))!;
1393
+ await knitwear.trigger('click');
1394
+ const panel = wrapper.get(`#${knitwear.attributes('aria-controls')}`);
1395
+ expect(panel.attributes('data-eldra-mega-panel')).toBe('');
1396
+ for (const token of ['absolute', 'top-full', 'left-0', 'right-0']) {
1397
+ expect(panel.classes()).toContain(token);
1398
+ }
1399
+ // A width of its own is exactly what the old panel had, and what made it feel arbitrary.
1400
+ expect(panel.classes()).not.toContain('w-screen');
1401
+ expect(panel.classes().some((token) => token.startsWith('max-w-'))).toBe(false);
1402
+ // The hairline above the panel is the bar's own full-bleed bottom border, so the panel takes
1403
+ // no top border of its own; the other three sides are the border token, the bottom corners
1404
+ // are rounded, and the shadow falls below.
1405
+ for (const token of [
1406
+ 'border',
1407
+ 'border-t-0',
1408
+ 'border-border',
1409
+ 'rounded-b-lg',
1410
+ 'shadow-float',
1411
+ ]) {
1412
+ expect(panel.classes()).toContain(token);
1413
+ }
1414
+
1415
+ // The container's grid: 12 columns, 24px gutters, and an inset that keeps every column off
1416
+ // the panel's own edges — 24px, 32px once the container passes `wide`. The browser case
1417
+ // measures what this produces; here it is only the arrangement.
1418
+ for (const token of ['grid', 'grid-cols-12', 'gap-6', 'p-6', '@wide:p-8']) {
1419
+ expect(panel.classes()).toContain(token);
1420
+ }
1421
+ expect(panel.classes()).not.toContain('py-8');
1422
+ wrapper.unmount();
1423
+ });
1424
+
1425
+ it('lays three-column groups out left-aligned instead of stretching them to fill', async () => {
1426
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
1427
+ const ceramics = wrapper.findAll('button').find((b) => b.text().includes('Ceramics'))!;
1428
+ await ceramics.trigger('click');
1429
+ const panel = wrapper.get(`#${ceramics.attributes('aria-controls')}`);
1430
+ // Ceramics has a single group; Knitwear has three. Both get the same column width — a lone
1431
+ // group sits at a quarter of the container rather than stretching across all twelve.
1432
+ const columns = panel
1433
+ .findAll('ul[aria-labelledby]')
1434
+ .map((list) => list.element.parentElement!);
1435
+ expect(columns).toHaveLength(1);
1436
+ for (const column of columns) expect([...column.classList]).toContain('col-span-3');
1437
+ wrapper.unmount();
1438
+ });
1439
+
1440
+ it("offers the parent's own destination as a View all row, and a heading none", async () => {
1441
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
1442
+ const knitwear = wrapper.findAll('button').find((b) => b.text().includes('Knitwear'))!;
1443
+ await knitwear.trigger('click');
1444
+ const panel = wrapper.get(`#${knitwear.attributes('aria-controls')}`);
1445
+ const viewAll = panel.get('[data-eldra-mega-view-all]');
1446
+ // The trigger gave the destination up when it became a disclosure; the panel offers it.
1447
+ expect(viewAll.attributes('href')).toBe('/collections/knitwear');
1448
+ expect(viewAll.text()).toBe('View all');
1449
+ // Self-descriptive out of context (2.4.4), opening with the visible text (2.5.3).
1450
+ expect(viewAll.attributes('aria-label')).toBe('View all Knitwear');
1451
+ // Right-aligned under a rule that spans the panel's content width, 16px above it.
1452
+ for (const token of ['justify-end', 'border-t', 'border-border', 'pt-4', 'col-span-12']) {
1453
+ expect([...viewAll.element.parentElement!.classList]).toContain(token);
1454
+ }
1455
+ // The trailing arrow the theme's other "view all" links carry, drawn outside the label so
1456
+ // the underline runs under the words only.
1457
+ expect(viewAll.find('[data-part="arrow"]').exists()).toBe(true);
1458
+ expect(await axe(wrapper.element)).toHaveNoViolations();
1459
+ wrapper.unmount();
1460
+ });
1461
+
1462
+ it('takes its ground from the bar instead of naming one, and the bar publishes it', async () => {
1463
+ // Two `bg-background` utilities read the same today and drift the moment either side's ground
1464
+ // changes. The bar publishes the colour it paints and the panel reads it, so there is one
1465
+ // surface rather than two that happen to agree. The colours themselves are a browser matter
1466
+ // (a token variable resolves to nothing in jsdom) — `test/prerenderRefresh.browser.spec.ts`
1467
+ // compares the two computed grounds, with the bar solid and with `transparentOverHero` on.
1468
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
1469
+ expect(wrapper.get('header').attributes('style')).toContain(
1470
+ '--eldra-header-surface: var(--color-background)'
1471
+ );
1472
+
1473
+ const knitwear = wrapper.findAll('button').find((b) => b.text().includes('Knitwear'))!;
1474
+ await knitwear.trigger('click');
1475
+ const panel = wrapper.get(`#${knitwear.attributes('aria-controls')}`);
1476
+ expect(panel.attributes('style')).toContain('background: var(--eldra-header-surface)');
1477
+ // And no ground token of its own left behind to drift away from the bar's.
1478
+ expect(panel.classes()).not.toContain('bg-background');
1479
+ wrapper.unmount();
1480
+ });
1481
+
1482
+ it('eases the panel in and out, with the rise dropped under reduced motion', async () => {
1483
+ // A `<Transition>` applies its from/active classes in the same patch that opens or closes the
1484
+ // panel, one frame before the to-classes land, so this is the frame they can be read in.
1485
+ // jsdom computes no transition at all, which is also why the leave's own duration is proven in
1486
+ // the browser spec instead; what is checkable here is the wiring and the numbers on it.
1487
+ //
1488
+ // `stubs: { transition: false }` is the one thing this test needs that no other does:
1489
+ // `@vue/test-utils` stubs `<Transition>` by default, and a stub applies no classes at all.
1490
+ const base = mountOptions(
1491
+ { entry: { id: 'e1', data: resolved.data } },
1492
+ {
1493
+ links: resolved.links,
1494
+ }
1495
+ );
1496
+ const wrapper = mount(Block, {
1497
+ ...base,
1498
+ attachTo: document.body,
1499
+ global: { ...base.global, stubs: { ...base.global.stubs, transition: false } },
1500
+ });
1501
+ const knitwear = wrapper.findAll('button').find((b) => b.text().includes('Knitwear'))!;
1502
+ const panel = (): DOMWrapper<Element> =>
1503
+ wrapper.get(`#${knitwear.attributes('aria-controls')}`);
1504
+
1505
+ await knitwear.trigger('click');
1506
+ expect(knitwear.attributes('aria-expanded')).toBe('true');
1507
+ for (const token of [
1508
+ 'opacity-0',
1509
+ 'motion-safe:-translate-y-1',
1510
+ 'transition-[opacity,transform]',
1511
+ 'duration-[150ms]',
1512
+ 'ease-out',
1513
+ ]) {
1514
+ expect(panel().classes(), 'enter').toContain(token);
1515
+ }
1516
+
1517
+ await knitwear.trigger('click');
1518
+ // The panel is still there, and still addressable, while it leaves — that is the whole point
1519
+ // of a `<Transition>` over a bare `v-show` — but it can no longer be pointed at, so a pointer
1520
+ // crossing it on its way out never clears the close timer and pulls it back open.
1521
+ expect(knitwear.attributes('aria-expanded')).toBe('false');
1522
+ for (const token of [
1523
+ 'pointer-events-none',
1524
+ 'transition-[opacity,transform]',
1525
+ 'duration-[120ms]',
1526
+ 'ease-in',
1527
+ ]) {
1528
+ expect(panel().classes(), 'leave').toContain(token);
1529
+ }
1530
+ wrapper.unmount();
1531
+ });
1532
+
1533
+ it('renders no View all row for a kind: "none" heading', async () => {
1534
+ const wrapper = mountBlock(
1535
+ {
1536
+ ...resolved.data,
1537
+ links: [
1538
+ {
1539
+ kind: 'none',
1540
+ label: 'Workshop',
1541
+ children: [{ kind: 'url', url: '/journal', label: 'Journal' }],
1542
+ },
1543
+ ],
1544
+ },
1545
+ { attachTo: document.body }
1546
+ );
1547
+ const trigger = wrapper.findAll('button').find((b) => b.text().includes('Workshop'))!;
1548
+ await trigger.trigger('click');
1549
+ const panel = wrapper.get(`#${trigger.attributes('aria-controls')}`);
1550
+ expect(panel.find('[data-eldra-mega-view-all]').exists()).toBe(false);
1551
+ wrapper.unmount();
1552
+ });
1553
+ });
1554
+
1555
+ it('the search control has aria-haspopup="dialog" and opens SearchModal', async () => {
1556
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
1557
+ const searchButton = wrapper.get('button[aria-label="Search"]');
1558
+ expect(searchButton.attributes('aria-haspopup')).toBe('dialog');
1559
+ await searchButton.trigger('click');
1560
+ const dialogs = wrapper.findAll('dialog');
1561
+ expect(dialogs.some((d) => d.attributes('open') === '')).toBe(true);
1562
+ wrapper.unmount();
1563
+ });
1564
+
1565
+ /**
1566
+ * The header's search overlay. Two defects lived here, both in what the block hands `SearchModal`
1567
+ * rather than in the modal itself:
1568
+ *
1569
+ * - **`pending` is not "a read is in flight."** It is the skeleton flag — "a read in flight with
1570
+ * *nothing to show*" (`app/storefront/types.ts`) — so it is false for every search after the
1571
+ * first, and the modal never reached its loading view.
1572
+ * - **`data` holds the *previous* answer while the next read runs.** The very first thing
1573
+ * `search.run()` answers is the empty query's own `{ total: 0 }`, and a `results` object with a
1574
+ * zero total is the modal's *"nothing found"* view. So the whole time the request for "bowl" was
1575
+ * in flight, the overlay read "No results for “bowl”" — then popped the results in.
1576
+ */
1577
+ describe('the search overlay', () => {
1578
+ const ANSWER: StorefrontSearchResponse = {
1579
+ query: 'bowl',
1580
+ total: 1,
1581
+ products: [
1582
+ {
1583
+ handle: 'speckled-latte-mug',
1584
+ title: 'Speckled latte mug',
1585
+ url: '/products/speckled-latte-mug',
1586
+ featuredImage: null,
1587
+ price: { amount: 28, compareAt: null },
1588
+ stock: 'in',
1589
+ available: true,
1590
+ productId: 'speckled-latte-mug',
1591
+ },
1592
+ ],
1593
+ articles: [],
1594
+ pages: [],
1595
+ suggestion: null,
1596
+ };
1597
+ /** The empty query's own answer — what `search.run()` has in `data` before any real search, and
1598
+ * the value that was being presented as the answer to the query in flight. */
1599
+ const EMPTY: StorefrontSearchResponse = {
1600
+ query: '',
1601
+ total: 0,
1602
+ products: [],
1603
+ articles: [],
1604
+ pages: [],
1605
+ suggestion: null,
1606
+ };
1607
+
1608
+ /** A storefront whose search answers `answer` with `loading` as given, however the field is
1609
+ * retyped — the gateway's own mid-read shape, held still so it can be asserted. */
1610
+ function mountWithSearch(answer: StorefrontSearchResponse, loading: boolean) {
1611
+ const base = mountOptions(
1612
+ { entry: { id: 'e1', data: resolved.data } },
1613
+ {
1614
+ links: resolved.links,
1615
+ }
1616
+ );
1617
+ const storefront = createDemoStorefront();
1618
+ const result: StorefrontResult<StorefrontSearchResponse> = {
1619
+ data: ref(answer) as Ref<StorefrontSearchResponse | null>,
1620
+ // False on purpose: there is an answer on screen, which is exactly when `pending` is false
1621
+ // and the overlay used to show no loading state at all.
1622
+ pending: ref(false),
1623
+ loading: ref(loading),
1624
+ revalidating: ref(new Set()),
1625
+ error: ref(null),
1626
+ refresh: async () => {},
1627
+ };
1628
+ return mount(Block, {
1629
+ attachTo: document.body,
1630
+ ...base,
1631
+ global: {
1632
+ ...base.global,
1633
+ provide: {
1634
+ ...base.global.provide,
1635
+ [STOREFRONT_KEY]: { ...storefront, search: { run: () => result } },
1636
+ },
1637
+ },
1638
+ });
1639
+ }
1640
+
1641
+ async function openOverlay(wrapper: ReturnType<typeof mountWithSearch>) {
1642
+ await wrapper.get('button[aria-label="Search"]').trigger('click');
1643
+ return wrapper.get('dialog[open] input[type="search"]');
1644
+ }
1645
+
1646
+ it('shows the loading view while the read for the typed query is in flight', async () => {
1647
+ vi.useFakeTimers();
1648
+ const wrapper = mountWithSearch(EMPTY, true);
1649
+ try {
1650
+ const input = await openOverlay(wrapper);
1651
+ await input.setValue('bowl');
1652
+ await nextTick();
1653
+
1654
+ // Before the loading view's own 300ms, and the heart of the defect: the block hands the
1655
+ // modal no `results` at all for a query it has no answer for, so the panel stays empty
1656
+ // instead of answering with the previous read's zero total.
1657
+ expect(document.body.textContent).not.toContain('No results');
1658
+
1659
+ vi.advanceTimersByTime(300);
1660
+ await nextTick();
1661
+
1662
+ expect(document.querySelector('[data-part="loading"]')).not.toBeNull();
1663
+ expect(document.body.textContent).not.toContain('No results');
1664
+
1665
+ // The announcement is the half a screen-reader user gets, and it is debounced 400ms — past
1666
+ // the loading view's own 300ms. It has to agree with the panel: "Searching…", never
1667
+ // "No results for “bowl”" for a read that has not come back.
1668
+ vi.advanceTimersByTime(100);
1669
+ await nextTick();
1670
+ const live = document.querySelector('[data-part="liveRegion"]');
1671
+ expect(live?.textContent).toBe(uiEnUS.searchLoading);
1672
+ } finally {
1673
+ vi.useRealTimers();
1674
+ wrapper.unmount();
1675
+ }
1676
+ });
1677
+
1678
+ it('shows the results once the read for that query has answered', async () => {
1679
+ vi.useFakeTimers();
1680
+ const wrapper = mountWithSearch(ANSWER, false);
1681
+ try {
1682
+ const input = await openOverlay(wrapper);
1683
+ await input.setValue('bowl');
1684
+ await nextTick();
1685
+
1686
+ expect(document.querySelector('[data-part="loading"]')).toBeNull();
1687
+ expect(document.body.textContent).not.toContain('No results');
1688
+ const rows = [...document.querySelectorAll('[role="option"]')];
1689
+ expect(rows.some((row) => row.textContent?.includes('Speckled latte mug'))).toBe(true);
1690
+ // The product's real price, from the catalogue read behind `search.run()`.
1691
+ expect(rows.some((row) => row.textContent?.includes('$28.00'))).toBe(true);
1692
+
1693
+ vi.advanceTimersByTime(400);
1694
+ await nextTick();
1695
+ expect(document.querySelector('[data-part="liveRegion"]')?.textContent).toBe(
1696
+ uiEnUS.resultsCount(1, 'bowl')
1697
+ );
1698
+ } finally {
1699
+ vi.useRealTimers();
1700
+ wrapper.unmount();
1701
+ }
1702
+ });
1703
+
1704
+ /**
1705
+ * A product the storefront could not price (`StorefrontSearchProduct.price === null`: the
1706
+ * pricing read failed, or the catalogue did not answer about this id). `SearchResultItem.price`
1707
+ * is optional, so the row keeps the product and drops the price — never the store's own
1708
+ * "$0.00", which is a real price and the wrong one.
1709
+ */
1710
+ it('renders a row with no price at all for a product it could not price', async () => {
1711
+ const unpriced: StorefrontSearchResponse = {
1712
+ ...ANSWER,
1713
+ products: [{ ...ANSWER.products[0]!, price: null }],
1714
+ };
1715
+ const wrapper = mountWithSearch(unpriced, false);
1716
+ try {
1717
+ const input = await openOverlay(wrapper);
1718
+ await input.setValue('bowl');
1719
+ await nextTick();
1720
+
1721
+ const row = [...document.querySelectorAll('[role="option"]')].find((node) =>
1722
+ node.textContent?.includes('Speckled latte mug')
1723
+ );
1724
+ expect(row).toBeDefined();
1725
+ expect(row?.textContent).not.toContain('0.00');
1726
+ expect(row?.textContent).not.toContain('$');
1727
+ } finally {
1728
+ wrapper.unmount();
1729
+ }
1730
+ });
1731
+
1732
+ /**
1733
+ * Enter with no active option submits the modal's own `method="get"` form, and "See all N
1734
+ * results" is the same destination as a row. Both are `${action}?q=…`, and `action` defaults to
1735
+ * `/search` — the page the theme seeds (`pages/search.page.json`). Until it existed, every one of these
1736
+ * landed the shopper on the not-found shell.
1737
+ */
1738
+ it('submits to /search?q=… — the route the theme serves', async () => {
1739
+ const wrapper = mountWithSearch(ANSWER, false);
1740
+ try {
1741
+ const input = await openOverlay(wrapper);
1742
+ const form = document.querySelector('dialog[open] form[role="search"]')!;
1743
+ expect(form.getAttribute('method')).toBe('get');
1744
+ expect(form.getAttribute('action')).toBe('/search');
1745
+ expect(input.attributes('name')).toBe('q');
1746
+
1747
+ await input.setValue('bowl');
1748
+ await nextTick();
1749
+ // The last row of the panel: the modal's own "See … results" row, whose destination is the
1750
+ // same `${action}?q=…` the form submits to.
1751
+ const rows = [...document.querySelectorAll<HTMLElement>('[role="option"]')];
1752
+ const viewAll = rows[rows.length - 1];
1753
+ expect(viewAll?.textContent).toContain('result');
1754
+ expect(viewAll?.getAttribute('href')).toBe('/search?q=bowl');
1755
+ } finally {
1756
+ wrapper.unmount();
1757
+ }
1758
+ });
1759
+ });
1760
+
1761
+ it('minimal variant keeps the links and the call to action only in the drawer', () => {
1762
+ const wrapper = mountBlock({ ...resolved.data, variant: 'minimal' });
1763
+ expect(wrapper.find('ul.list-none.items-center').exists()).toBe(false);
1764
+ expect(wrapper.findAll('button').some((b) => b.text() === 'Menu')).toBe(true);
1765
+ // The bar itself shows no call to action in `minimal` — only the drawer's own copy of it,
1766
+ // inside the (closed, but always-rendered) dialog.
1767
+ expect(wrapper.findAll('a, button').filter((el) => el.text() === mock.ctaLabel)).toHaveLength(
1768
+ 1
1769
+ );
1770
+ // The drawer's own list still carries every link (rendered regardless of `open`).
1771
+ for (const link of mock.links) expect(wrapper.text()).toContain(link.label);
1772
+ });
1773
+
1774
+ describe('actions row spacing', () => {
1775
+ // Regression for an uneven header: a `@tablet:gap-4` on the bar's own grid put 1rem between
1776
+ // the search column and this row, against the 0.25rem `gap-1` puts between its own buttons —
1777
+ // so search read as detached from the wishlist/cart cluster, which themselves looked glued
1778
+ // together.
1779
+ it('puts one 0.25rem gap everywhere in the bar’s grid — never a larger one between columns', () => {
1780
+ const wrapper = mountBlock(resolved.data);
1781
+ const nav = wrapper.get('nav[aria-label="Primary navigation"]');
1782
+ expect(nav.classes()).toContain('gap-1');
1783
+ expect(nav.classes().some((cls) => cls.includes('gap-4'))).toBe(false);
1784
+
1785
+ const actions = wrapper.get('[data-eldra-header-actions]');
1786
+ expect(actions.classes()).toContain('gap-1');
1787
+ });
1788
+
1789
+ it('gives the call to action its own 0.75rem from the cart, not only the row’s 0.25rem gap', () => {
1790
+ const wrapper = mountBlock(resolved.data);
1791
+ const actions = wrapper.get('[data-eldra-header-actions]');
1792
+ const cta = wrapper.findAll('a, button').find((el) => el.text() === mock.ctaLabel)!;
1793
+ // 0.5rem of margin on top of the row's own 0.25rem `gap-1` — spec "Header" -> Layout, "From
1794
+ // 64rem": the call to action "sits 0.75rem after the cart".
1795
+ expect(cta.classes()).toContain('@content:ml-2');
1796
+ // And the row's only hidden/visible pair lands on the button's own root — the flex item the
1797
+ // row's `gap-1` actually counts — not on a wrapper around it. A wrapper carrying `hidden`
1798
+ // while the button inside it carries the visible class would still occupy a gap slot: the
1799
+ // parent check is what rules that out, not just the classes existing somewhere in the tree.
1800
+ expect(cta.classes()).toEqual(expect.arrayContaining(['hidden', '@content:inline-flex']));
1801
+ expect(cta.element.parentElement).toBe(actions.element);
1802
+ });
1803
+ });
1804
+
1805
+ describe('empty / editor state', () => {
1806
+ /**
1807
+ * The header a fresh store actually starts with, copied from the shape every
1808
+ * `pages/*.page.json` seeds: brand, search, cart — no links and no call to action.
1809
+ * `mock.json` keeps its demo links because it is the state an author sees the moment they
1810
+ * *insert* the block, not the state a deploy seeds.
1811
+ */
1812
+ const SEEDED = {
1813
+ variant: 'default',
1814
+ brandText: 'Northwind Goods',
1815
+ links: [],
1816
+ showSearch: true,
1817
+ searchStyle: 'icon',
1818
+ sticky: true,
1819
+ transparentOverHero: false,
1820
+ };
1821
+
1822
+ it('renders the seeded header as brand and actions only — no links, no CTA, axe-clean', async () => {
1823
+ const wrapper = mountBlock(SEEDED);
1824
+ expect(wrapper.text()).toContain('Northwind Goods');
1825
+ // The bar's link list is not drawn at all with nothing in it, so no empty `<ul>` is left
1826
+ // sitting in the grid.
1827
+ expect(wrapper.find('ul.list-none.items-center').exists()).toBe(false);
1828
+ expect(wrapper.find('button[aria-label="Search"]').exists()).toBe(true);
1829
+ expect(wrapper.find('[aria-label="Cart, empty"]').exists()).toBe(true);
1830
+ expect(await axe(wrapper.element)).toHaveNoViolations();
1831
+ });
1832
+
1833
+ it('draws no Menu button and no drawer when the drawer would be empty', () => {
1834
+ // The drawer holds the links and the call to action. With neither there is nothing to open,
1835
+ // and a Menu button that opens an empty sheet is a control that does nothing.
1836
+ const wrapper = mountBlock(SEEDED);
1837
+ expect(wrapper.find('button[aria-label="Open menu"]').exists()).toBe(false);
1838
+ // `dialog[aria-label="Menu"]` is the drawer itself; the search overlay's own `<dialog>`
1839
+ // renders either way, so the drawer has to be named rather than counted.
1840
+ expect(wrapper.find('dialog[aria-label="Menu"]').exists()).toBe(false);
1841
+ expect(mountBlock(resolved.data).find('dialog[aria-label="Menu"]').exists()).toBe(true);
1842
+ });
1843
+
1844
+ it('keeps the Menu button as soon as the drawer has something to show', () => {
1845
+ for (const data of [
1846
+ { ...SEEDED, links: [{ kind: 'url', url: '/journal', label: 'Journal' }] },
1847
+ { ...SEEDED, ctaLabel: 'Shop', cta: { kind: 'url', url: '/collections/all' } },
1848
+ ]) {
1849
+ const wrapper = mountBlock(data);
1850
+ expect(wrapper.find('button[aria-label="Open menu"]').exists()).toBe(true);
1851
+ }
1852
+ });
1853
+
1854
+ /**
1855
+ * `showAccount` is retired as of `block.json` version 4 — the platform has no customer login,
1856
+ * so an account icon in the bar leads nowhere — and Core keeps whatever an entry held as
1857
+ * `showAccount__v3`. Nothing in the block reads either id, which is the point: a header
1858
+ * configured while the field existed renders exactly the header a fresh one does, and the
1859
+ * stashed value cannot bring a Menu button back for a drawer row that no longer exists.
1860
+ */
1861
+ it('ignores a retired showAccount an entry still carries, under either id', () => {
1862
+ for (const stored of [{ showAccount: true }, { showAccount__v3: true }]) {
1863
+ const wrapper = mountBlock({ ...SEEDED, ...stored });
1864
+ expect(
1865
+ wrapper.findAll('a, button').some((control) => control.attributes('href') === '/account')
1866
+ ).toBe(false);
1867
+ expect(wrapper.text()).not.toContain('Account');
1868
+ expect(wrapper.find('button[aria-label="Open menu"]').exists()).toBe(false);
1869
+ expect(wrapper.find('dialog[aria-label="Menu"]').exists()).toBe(false);
1870
+ }
1871
+ });
1872
+
1873
+ it('shows the "Add a link" editor hint only while editing, with no links', () => {
1874
+ const empty = { ...resolved.data, links: [] };
1875
+ const editing = mountWithEditing(empty, true);
1876
+ expect(editing.text()).toContain('Add a link');
1877
+
1878
+ const live = mountWithEditing(empty, false);
1879
+ expect(live.text()).not.toContain('Add a link');
1880
+ });
1881
+ });
1882
+
1883
+ describe('transparentOverHero', () => {
1884
+ it('field off renders solid, with no data-eldra-transparent attribute', () => {
1885
+ const wrapper = mountBlock({ ...resolved.data, transparentOverHero: false });
1886
+ expect(wrapper.find('header').attributes('data-eldra-transparent')).toBeUndefined();
1887
+ });
1888
+
1889
+ it('field on sets the transparent attribute (the block only reads its own field)', () => {
1890
+ const wrapper = mountBlock({ ...resolved.data, transparentOverHero: true });
1891
+ expect(wrapper.find('header').attributes('data-eldra-transparent')).toBe('true');
1892
+ });
1893
+ });
1894
+
1895
+ describe('icons', () => {
1896
+ /** `EldraIcon` strips the fetched SVG's own outer `<svg>` tag (see that component's own doc
1897
+ * comment) and keeps only its inner markup, so a resolved icon is identified by a path `d`
1898
+ * unique to it, not by a wrapper class name. Each string below is copied from the real Tabler
1899
+ * outline SVG (`node_modules/@tabler/icons/icons/outline/<name>.svg`). */
1900
+ const PATHS = {
1901
+ 'menu-2': 'M4 6l16 0',
1902
+ 'chevron-down': 'M6 9l6 6l6 -6',
1903
+ search: 'M21 21l-6 -6',
1904
+ heart: 'M19.5 12.572l-7.5 7.428l-7.5 -7.428',
1905
+ 'shopping-bag': 'M9 11v-5a3 3 0 0 1 6 0v5',
1906
+ };
1907
+
1908
+ it('replaces every hand-rolled <svg> with EldraIcon, resolving each Tabler icon by name', async () => {
1909
+ const wrapper = mountBlock(resolved.data, { attachTo: document.body });
1910
+ await flushIcons();
1911
+ await nextTick();
1912
+ const html = wrapper.html();
1913
+ for (const [name, path] of Object.entries(PATHS)) {
1914
+ expect(
1915
+ html,
1916
+ `expected the resolved "${name}" icon's own path in the rendered markup`
1917
+ ).toContain(path);
1918
+ }
1919
+ expect(await axe(wrapper.element)).toHaveNoViolations();
1920
+ wrapper.unmount();
1921
+ });
1922
+ });
1923
+
1924
+ describe('--eldra-header-height', () => {
1925
+ /** Mirrors `trust-strip`'s own `ResizeObserver` stub: jsdom has none at all, so this replaces
1926
+ * `globalThis.ResizeObserver` with a fake that only captures the callback the block passes,
1927
+ * letting a test call `trigger()` after changing the header's measured height. */
1928
+ function stubResizeObserver(): { trigger: () => void; restore: () => void } {
1929
+ let captured: ResizeObserverCallback | null = null;
1930
+ class FakeResizeObserver {
1931
+ constructor(callback: ResizeObserverCallback) {
1932
+ captured = callback;
1933
+ }
1934
+ observe(): void {}
1935
+ unobserve(): void {}
1936
+ disconnect(): void {}
1937
+ }
1938
+ const original = (globalThis as { ResizeObserver?: typeof ResizeObserver }).ResizeObserver;
1939
+ (globalThis as { ResizeObserver?: unknown }).ResizeObserver = FakeResizeObserver;
1940
+ return {
1941
+ trigger: () => captured?.([] as unknown as ResizeObserverEntry[], {} as ResizeObserver),
1942
+ restore: () => {
1943
+ (globalThis as { ResizeObserver?: typeof ResizeObserver }).ResizeObserver = original;
1944
+ },
1945
+ };
1946
+ }
1947
+
1948
+ function stubHeaderHeight(el: HTMLElement, height: number): void {
1949
+ Object.defineProperty(el, 'getBoundingClientRect', {
1950
+ value: () => ({
1951
+ height,
1952
+ width: 0,
1953
+ top: 0,
1954
+ left: 0,
1955
+ right: 0,
1956
+ bottom: 0,
1957
+ x: 0,
1958
+ y: 0,
1959
+ toJSON() {},
1960
+ }),
1961
+ configurable: true,
1962
+ });
1963
+ }
1964
+
1965
+ afterEach(() => {
1966
+ document.documentElement.style.removeProperty('--eldra-header-height');
1967
+ });
1968
+
1969
+ it('publishes the sticky header’s rendered height on document.documentElement, tracks a resize, and clears it on unmount', async () => {
1970
+ const stub = stubResizeObserver();
1971
+ try {
1972
+ const wrapper = mountBlock({ ...resolved.data, sticky: true }, { attachTo: document.body });
1973
+ const header = wrapper.get('header').element as HTMLElement;
1974
+ stubHeaderHeight(header, 64);
1975
+ await nextTick();
1976
+ expect(document.documentElement.style.getPropertyValue('--eldra-header-height')).toBe(
1977
+ '64px'
1978
+ );
1979
+
1980
+ // A real resize (breakpoint change, search style switching in) — the observer's own
1981
+ // callback re-reads the header's height and republishes it.
1982
+ stubHeaderHeight(header, 96);
1983
+ stub.trigger();
1984
+ expect(document.documentElement.style.getPropertyValue('--eldra-header-height')).toBe(
1985
+ '96px'
1986
+ );
1987
+
1988
+ wrapper.unmount();
1989
+ expect(document.documentElement.style.getPropertyValue('--eldra-header-height')).toBe('');
1990
+ } finally {
1991
+ stub.restore();
1992
+ }
1993
+ });
1994
+
1995
+ it('hands the same measurement to the spacer, so the flow it reserves is the bar’s own height', async () => {
1996
+ const stub = stubResizeObserver();
1997
+ try {
1998
+ const wrapper = mountBlock({ ...resolved.data, sticky: true }, { attachTo: document.body });
1999
+ const header = wrapper.get('header').element as HTMLElement;
2000
+ stubHeaderHeight(header, 64);
2001
+ await nextTick();
2002
+ expect(wrapper.get('[data-eldra-header-spacer]').attributes('style')).toBe('height: 64px;');
2003
+
2004
+ stubHeaderHeight(header, 96);
2005
+ stub.trigger();
2006
+ await nextTick();
2007
+ expect(wrapper.get('[data-eldra-header-spacer]').attributes('style')).toBe('height: 96px;');
2008
+
2009
+ wrapper.unmount();
2010
+ } finally {
2011
+ stub.restore();
2012
+ }
2013
+ });
2014
+
2015
+ it('never publishes the variable for a non-sticky header', async () => {
2016
+ const stub = stubResizeObserver();
2017
+ try {
2018
+ const wrapper = mountBlock(
2019
+ { ...resolved.data, sticky: false },
2020
+ { attachTo: document.body }
2021
+ );
2022
+ await nextTick();
2023
+ expect(document.documentElement.style.getPropertyValue('--eldra-header-height')).toBe('');
2024
+ wrapper.unmount();
2025
+ } finally {
2026
+ stub.restore();
2027
+ }
2028
+ });
2029
+ });
2030
+ });