@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,1431 @@
1
+ import { chromium, type Browser, type Page } from '@playwright/test';
2
+ import { execa } from 'execa';
3
+ import { cpSync, existsSync, mkdtempSync, readFileSync, rmSync, symlinkSync } from 'node:fs';
4
+ import { tmpdir } from 'node:os';
5
+ import { join, relative, sep } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+ import { afterAll, beforeAll, describe, expect, it } from 'vitest';
8
+ import enUS from '../i18n/en-US.json';
9
+ import isIS from '../i18n/is-IS.json';
10
+ import { formatMoney } from '../app/storefront/money';
11
+ import {
12
+ COLLECTION_HANDLE,
13
+ DEFAULT_LOCALE,
14
+ HOME_PAGE_PATH,
15
+ LINKED_HEADER_LABELS,
16
+ PREFIXED_LOCALE,
17
+ PRODUCT_HANDLE,
18
+ SEEDED_CART_ID,
19
+ SEEDED_CART_QUANTITY,
20
+ SEEDED_PAGE_PATHS,
21
+ startMockGateway,
22
+ type MockGateway,
23
+ } from './support/mockGateway';
24
+ import { startStaticServer, type StaticServer } from './support/staticServer';
25
+
26
+ /**
27
+ * The generate-level proof of the prerender/refresh contract, in a real browser.
28
+ *
29
+ * Every other spec for this feature mounts blocks, or server-renders and hydrates them by hand.
30
+ * Neither can see what this one is about: a `nuxi generate` build, served as static files, driving
31
+ * **Nuxt's own** hydration, payload and lazily-imported block components. Four defects lived
32
+ * happily under the mounted suites and were only visible here:
33
+ *
34
+ * 1. A storefront result whose source is not final at setup time re-keys in the browser and
35
+ * refetches data the page already has — `product-carousel` created a `byHandles` read over
36
+ * `localStorage` history on every product page, prerendered as `[[]]` and re-run as
37
+ * `[["<the product being viewed>"]]` the moment `product-detail` recorded the view.
38
+ * 2. Blocks are lazily imported, so the ones whose chunk lands after the app has mounted created
39
+ * their results after a one-shot volatile refresh had already flushed: the carousel's cards
40
+ * never refreshed and never drew the refresh treatment, and the page's batched read for them
41
+ * never happened.
42
+ * 3. And once every burst refreshed, two bursts asked about the same products twice — the deployed
43
+ * product page issued its detail read and its `id:in` batch twice, 35 ms apart, with identical
44
+ * ids. Which is why every request assertion below is over the **full** log, duplicates
45
+ * included, and why `askedMoreThanOnce` exists.
46
+ * 4. …and the reason there were two bursts at all: the deployed host answers
47
+ * `/products/ash-glaze-mug` with a 308 to the same path plus a trailing slash, while the site
48
+ * is prerendered at the path without one. Nuxt's hydration re-navigates between the two, and
49
+ * because the catch-all route's default key differs between them the page — and every block on
50
+ * it — was destroyed and built again, so every read the page makes was created twice.
51
+ * `startStaticServer` serves the site the same way the host does, and the mount probe below is
52
+ * what makes the second build visible: only one of the two instances ever reaches `mounted`, so
53
+ * a request log or a DOM count sees nothing.
54
+ *
55
+ * The CMS **page** route (`/`) is in here as the control: its prerendered path and its served path
56
+ * are the same string, so it never had the fourth defect, which is exactly how the live
57
+ * discriminator read (home refreshed once, a product page twice).
58
+ *
59
+ * The mock gateway answers the CMS route templates and the catalog for the build, and the catalog
60
+ * again for the browser — with every catalog answer held back (`catalogDelayMs`) while the browser
61
+ * runs, so the refresh is observable while it is in flight rather than over in a millisecond.
62
+ */
63
+
64
+ const templateDir = fileURLToPath(new URL('..', import.meta.url));
65
+ const nuxi = join(templateDir, 'node_modules', '.bin', 'nuxi');
66
+ const ORG_ID = '3fa85f64-5717-4562-b3fc-2c963f66afa6';
67
+ /** Build output and installed dependencies: rebuilt or symlinked in the copy, never copied. */
68
+ const SKIPPED_FROM_COPY = new Set(['node_modules', '.nuxt', '.output', '.git']);
69
+ /** Long enough that a 200 ms sampler cannot step over the whole refresh. */
70
+ const CATALOG_DELAY_MS = 1500;
71
+ /** Long enough that the restored cart's own read is certainly still in flight while the page
72
+ * hydrates — see `MockGateway.cartDelayMs`. */
73
+ const CART_DELAY_MS = 800;
74
+
75
+ let gateway: MockGateway;
76
+ let statics: StaticServer;
77
+ let browser: Browser;
78
+ let root: string;
79
+ let scratch: string;
80
+
81
+ const output = (path: string): string => join(root, '.output', 'public', path);
82
+ const existsInOutput = (path: string): boolean => existsSync(output(path));
83
+ const productPage = `/products/${PRODUCT_HANDLE}`;
84
+ const collectionPage = `/collections/${COLLECTION_HANDLE}`;
85
+
86
+ /** One DOM sample of the refresh treatment the commerce blocks draw. */
87
+ interface Treatment {
88
+ busy: number;
89
+ dimmed: number;
90
+ spinners: number;
91
+ announced: number;
92
+ }
93
+
94
+ interface Visit {
95
+ /** `pathname + search` of every gateway request this page load made, decoded. */
96
+ requests: string[];
97
+ samples: Treatment[];
98
+ /** Console errors and anything Vue said about hydration. */
99
+ warnings: string[];
100
+ /**
101
+ * Every money amount on the page, in order, once everything has settled — read off `<Price>`'s own
102
+ * value part rather than scraped out of the body text, so an authored sentence that mentions an
103
+ * amount ("Free delivery over $80") is not mistaken for a price the storefront formatted.
104
+ */
105
+ prices: string[];
106
+ /**
107
+ * How many component instances each block got, and how many of them mounted, keyed
108
+ * `<component>|<schemaApiId>|<entry id>` — see `test/support/mountProbe.client.ts`. Every value
109
+ * must be 1: a block created a second time runs its `setup` again, and with it every storefront
110
+ * read in it.
111
+ */
112
+ instances: {
113
+ created: Record<string, number>;
114
+ mounted: Record<string, number>;
115
+ };
116
+ /** Where the browser ended up — the host's redirect included, which is the point on a page route. */
117
+ url: string;
118
+ }
119
+
120
+ /** Just the block components' counts, which is what "built once" is about. */
121
+ function blockInstances(visited: Visit): Visit['instances'] {
122
+ const blocksOnly = (counts: Record<string, number>): Record<string, number> =>
123
+ Object.fromEntries(Object.entries(counts).filter(([key]) => key.startsWith('Block|')));
124
+ return {
125
+ created: blocksOnly(visited.instances.created),
126
+ mounted: blocksOnly(visited.instances.mounted),
127
+ };
128
+ }
129
+
130
+ /** The entries whose count is anything but one, as `[key, count]` pairs — `[]` when all is well. */
131
+ function notExactlyOnce(counts: Record<string, number>): Array<[string, number]> {
132
+ return Object.entries(counts).filter(([, count]) => count !== 1);
133
+ }
134
+
135
+ /** Load one generated page in a real browser and watch it refresh. */
136
+ async function visit(path: string): Promise<Visit> {
137
+ gateway.reset();
138
+ const page = await browser.newPage();
139
+ const warnings: string[] = [];
140
+ page.on('console', (message) => {
141
+ const text = message.text();
142
+ if (/hydrat|mismatch/i.test(text) || message.type() === 'error') {
143
+ warnings.push(`${message.type()}: ${text.slice(0, 200)}`);
144
+ }
145
+ });
146
+ page.on('pageerror', (error) => warnings.push(`pageerror: ${error.message.slice(0, 200)}`));
147
+ try {
148
+ await page.goto(`${statics.origin}${path}`, {
149
+ waitUntil: 'domcontentloaded',
150
+ });
151
+ const samples: Treatment[] = [];
152
+ // 4 s covers the whole 1.5 s refresh and the settled state after it.
153
+ for (let elapsed = 0; elapsed < 4000; elapsed += 200) {
154
+ samples.push(
155
+ await page.evaluate(() => ({
156
+ busy: document.querySelectorAll('[aria-busy="true"]').length,
157
+ dimmed: document.querySelectorAll('.eldra-revalidating').length,
158
+ spinners: document.querySelectorAll('[data-part="spinner"]').length,
159
+ announced: [...document.querySelectorAll('[role="status"]')].filter((node) =>
160
+ /Updating/i.test((node as HTMLElement).textContent ?? '')
161
+ ).length,
162
+ }))
163
+ );
164
+ await page.waitForTimeout(200);
165
+ }
166
+ const prices = await page.evaluate(() =>
167
+ [...document.querySelectorAll('[data-part="current"]')]
168
+ .map((node) => (node as HTMLElement).textContent?.trim() ?? '')
169
+ .slice(0, 12)
170
+ );
171
+ const instances = await page.evaluate(() => {
172
+ const probe = window as unknown as {
173
+ __eldraCreated?: Record<string, number>;
174
+ __eldraMounted?: Record<string, number>;
175
+ };
176
+ return {
177
+ created: probe.__eldraCreated ?? {},
178
+ mounted: probe.__eldraMounted ?? {},
179
+ };
180
+ });
181
+ return {
182
+ requests: gateway.requests.map((request) => decodeURIComponent(request)),
183
+ samples,
184
+ warnings,
185
+ prices,
186
+ instances,
187
+ url: page.url(),
188
+ };
189
+ } finally {
190
+ await page.close();
191
+ }
192
+ }
193
+
194
+ /** The `storefront:` async-data keys the prerender wrote into a page's payload. */
195
+ function payloadStorefrontKeys(path: string): string[] {
196
+ const raw = readFileSync(output(join(path, '_payload.json')), 'utf8');
197
+ return [...raw.matchAll(/"(storefront:(?:[^"\\]|\\.)*)"/g)]
198
+ .map((match) => JSON.parse(`"${match[1] ?? ''}"`) as string)
199
+ .sort();
200
+ }
201
+
202
+ /** The page as a visitor with no JavaScript sees it. */
203
+ function staticHtml(path: string): string {
204
+ return readFileSync(output(join(path, 'index.html')), 'utf8');
205
+ }
206
+
207
+ /**
208
+ * What the page asked about more than once across its whole refresh — a product id that appears in
209
+ * two `id:in` batches, or a detail read issued twice. This is the assertion the live request log
210
+ * would have failed: four requests, two of them repeats of the other two.
211
+ */
212
+ function askedMoreThanOnce(requests: readonly string[]): string[] {
213
+ const times = new Map<string, number>();
214
+ const count = (what: string): void => times.set(what, (times.get(what) ?? 0) + 1);
215
+ for (const request of requests) {
216
+ const url = new URL(request, 'http://localhost');
217
+ const filters = url.searchParams.getAll('filter').filter((token) => token.startsWith('id:in:'));
218
+ if (filters.length === 0) {
219
+ count(url.pathname);
220
+ continue;
221
+ }
222
+ for (const token of filters) {
223
+ for (const id of token.slice('id:in:'.length).split(',')) count(id);
224
+ }
225
+ }
226
+ return [...times]
227
+ .filter(([, seen]) => seen > 1)
228
+ .map(([what]) => what)
229
+ .sort();
230
+ }
231
+
232
+ /** One sample of what a visitor can see while the app moves between two routes. */
233
+ interface NavSample {
234
+ /** The whole visible page text — the loading shell's string is in here, or it is not. */
235
+ text: string;
236
+ h1: string;
237
+ }
238
+
239
+ interface Navigation {
240
+ samples: NavSample[];
241
+ /** `pathname + search` of every **gateway** request made from the moment the navigation started. */
242
+ requests: string[];
243
+ url: string;
244
+ warnings: string[];
245
+ }
246
+
247
+ /** The first sample that shows the not-found shell, or -1 — how promptly a 404 was answered. */
248
+ function firstSampleShowing(samples: readonly NavSample[], text: string): number {
249
+ return samples.findIndex((sample) => sample.text.includes(text));
250
+ }
251
+
252
+ /**
253
+ * Load `from`, let its own post-hydration refresh finish, then navigate **inside the app** and
254
+ * watch what the visitor sees and what the gateway is asked, from the click onwards.
255
+ *
256
+ * The wait before `gateway.reset()` is what makes the request log mean anything: the departure
257
+ * page's refresh is held back by `catalogDelayMs`, and a navigation started while it is in flight
258
+ * would put its answers in the log this is about.
259
+ */
260
+ async function navigateFrom(from: string, go: (page: Page) => Promise<void>): Promise<Navigation> {
261
+ const page = await browser.newPage();
262
+ const warnings: string[] = [];
263
+ page.on('console', (message) => {
264
+ const text = message.text();
265
+ if (/hydrat|mismatch/i.test(text) || message.type() === 'error') {
266
+ warnings.push(`${message.type()}: ${text.slice(0, 200)}`);
267
+ }
268
+ });
269
+ page.on('pageerror', (error) => warnings.push(`pageerror: ${error.message.slice(0, 200)}`));
270
+ try {
271
+ await page.goto(`${statics.origin}${from}`, {
272
+ waitUntil: 'domcontentloaded',
273
+ });
274
+ await page.waitForTimeout(CATALOG_DELAY_MS + 1500);
275
+ gateway.reset();
276
+ await go(page);
277
+ const samples: NavSample[] = [];
278
+ // 50 ms, not the 200 ms the hard-load sampler uses: a loading shell that flashes between two
279
+ // prerendered routes is gone in well under a frame budget's worth of coarse sampling.
280
+ for (let elapsed = 0; elapsed < 3000; elapsed += 50) {
281
+ samples.push(
282
+ await page.evaluate(() => ({
283
+ text: document.body.innerText,
284
+ h1: document.querySelector('h1')?.textContent?.trim() ?? '',
285
+ }))
286
+ );
287
+ await page.waitForTimeout(50);
288
+ }
289
+ return {
290
+ samples,
291
+ requests: gateway.requests.map((request) => decodeURIComponent(request)),
292
+ url: page.url(),
293
+ warnings,
294
+ };
295
+ } finally {
296
+ await page.close();
297
+ }
298
+ }
299
+
300
+ /**
301
+ * What the collection grid shows: its card titles, its count line, and where its two price thumbs
302
+ * are.
303
+ *
304
+ * The thumbs rather than the typed fields beside them: a field's resting text is the store's own
305
+ * currency formatting ("4.200 kr."), while `aria-valuenow` is the number the filter is made of —
306
+ * which is what a URL carries and what this spec is about.
307
+ */
308
+ interface GridState {
309
+ titles: string[];
310
+ count: string;
311
+ price: string[];
312
+ }
313
+
314
+ const GRID_SECTION = 'section[aria-label="The winter edit products"]';
315
+
316
+ function readGrid(page: Page): Promise<GridState> {
317
+ return page.evaluate((selector) => {
318
+ const section = document.querySelector(selector);
319
+ // `aria-labelledby`, not any `ul`: that is the grid's own card list. The active-filter chips
320
+ // are a `ul[aria-label]` in the same section, and they only exist once something is filtered.
321
+ const titles = [
322
+ ...(section?.querySelectorAll('ul[aria-labelledby]:not([aria-hidden]) > li') ?? []),
323
+ ].map((card) => (card.querySelector('a')?.textContent ?? '').trim());
324
+ const status = [...(section?.querySelectorAll('p[role="status"]') ?? [])]
325
+ .map((node) => (node as HTMLElement).textContent?.trim() ?? '')
326
+ .filter((text) => text !== '');
327
+ const price = [...(section?.querySelectorAll('aside [role="slider"]') ?? [])].map(
328
+ (thumb) => thumb.getAttribute('aria-valuenow') ?? ''
329
+ );
330
+ return { titles, count: status[0] ?? '', price };
331
+ }, GRID_SECTION);
332
+ }
333
+
334
+ /**
335
+ * A hard load, watched long enough for a filtered read to have gone out and answered — the catalog
336
+ * is held back by `catalogDelayMs`, so this is the settled state, not a race.
337
+ */
338
+ async function visitCollection(path: string): Promise<{
339
+ grid: GridState;
340
+ requests: string[];
341
+ warnings: string[];
342
+ url: string;
343
+ }> {
344
+ gateway.reset();
345
+ const page = await browser.newPage();
346
+ const warnings: string[] = [];
347
+ page.on('console', (message) => {
348
+ const text = message.text();
349
+ if (/hydrat|mismatch/i.test(text) || message.type() === 'error') {
350
+ warnings.push(`${message.type()}: ${text.slice(0, 200)}`);
351
+ }
352
+ });
353
+ page.on('pageerror', (error) => warnings.push(`pageerror: ${error.message.slice(0, 200)}`));
354
+ try {
355
+ await page.goto(`${statics.origin}${path}`, { waitUntil: 'domcontentloaded' });
356
+ await page.waitForTimeout(CATALOG_DELAY_MS + 2500);
357
+ return {
358
+ grid: await readGrid(page),
359
+ requests: gateway.requests.map((request) => decodeURIComponent(request)),
360
+ warnings,
361
+ url: page.url(),
362
+ };
363
+ } finally {
364
+ await page.close();
365
+ }
366
+ }
367
+
368
+ /** The sample with the most of the treatment on screen. */
369
+ function peakOf(samples: readonly Treatment[]): Treatment {
370
+ return samples.reduce((most, sample) => (sample.spinners > most.spinners ? sample : most));
371
+ }
372
+
373
+ const NOTHING: Treatment = { busy: 0, dimmed: 0, spinners: 0, announced: 0 };
374
+
375
+ describe('prerendered commerce data on the generated static site', () => {
376
+ beforeAll(async () => {
377
+ gateway = await startMockGateway();
378
+ scratch = mkdtempSync(join(tmpdir(), 'eldra-prerender-'));
379
+ root = join(scratch, 'site');
380
+ // The starter itself, minus what a build makes: `nuxi generate` writes `.output` into its own
381
+ // working directory, and this suite must not race the one `test/starter.spec.ts` runs.
382
+ cpSync(templateDir, root, {
383
+ recursive: true,
384
+ filter: (source) => {
385
+ const [first] = relative(templateDir, source).split(sep);
386
+ return first === undefined || !SKIPPED_FROM_COPY.has(first);
387
+ },
388
+ });
389
+ symlinkSync(join(templateDir, 'node_modules'), join(root, 'node_modules'), 'dir');
390
+ // The mount counter, installed into the generated copy only. In the starter it sits inert
391
+ // under `test/support/`, where no Nuxt build looks; this is the one place it becomes a plugin.
392
+ cpSync(
393
+ join(templateDir, 'test', 'support', 'mountProbe.client.ts'),
394
+ join(root, 'app', 'plugins', 'zz-mount-probe.client.ts')
395
+ );
396
+ const generated = await execa(nuxi, ['generate'], {
397
+ cwd: root,
398
+ env: { ELDRA_GATEWAY_URL: gateway.url, ELDRA_ORG_ID: ORG_ID },
399
+ reject: false,
400
+ timeout: 600_000,
401
+ });
402
+ expect(generated.exitCode, `${generated.stdout}\n${generated.stderr}`).toBe(0);
403
+ // The build has finished reading the catalog; every answer the browser waits for is held back
404
+ // from here on, so the refresh can be watched rather than inferred.
405
+ gateway.catalogDelayMs = CATALOG_DELAY_MS;
406
+ gateway.cartDelayMs = CART_DELAY_MS;
407
+ statics = await startStaticServer(join(root, '.output', 'public'));
408
+ browser = await chromium.launch();
409
+ }, 900_000);
410
+
411
+ afterAll(async () => {
412
+ await browser?.close();
413
+ await statics?.close();
414
+ await gateway?.close();
415
+ if (scratch !== undefined) rmSync(scratch, { recursive: true, force: true });
416
+ });
417
+
418
+ /**
419
+ * **The seeded pages reach the artifact, and nothing names them by hand.** `/cart`, `/wishlist`
420
+ * and `/search` were code routes listed in `nitro.prerender.routes`; they are CMS pages now, so
421
+ * the only thing that writes `cart/index.html` is `@eldrajs/theme-nuxt`'s `prerender:routes` hook
422
+ * listing every published page's own path. A static host answers 404 for a path it has no file
423
+ * for, however the app would render it — so if this breaks, the header's bag, the drawer's "View
424
+ * cart", the wishlist heart and every search submit all land on a 404 on the deployed site, and
425
+ * no unit test in the suite can see it.
426
+ *
427
+ * Each file also has to carry what the code routes never could: a header, a footer, and the one
428
+ * block the page exists for.
429
+ */
430
+ it('prerenders every seeded page from the gateway\u2019s own page list', () => {
431
+ expect(SEEDED_PAGE_PATHS).toEqual(['/cart', '/wishlist', '/search', '/products']);
432
+ for (const path of SEEDED_PAGE_PATHS) {
433
+ expect(existsInOutput(join(path, 'index.html')), `${path}/index.html`).toBe(true);
434
+ }
435
+
436
+ // `/products` and `/products/<slug>` are different routes and both have to exist: the page is a
437
+ // static CMS page and the product is a route template, and `resolveRoute` matches an exact page
438
+ // before any pattern (`@eldrajs/theme-core`'s `dynamicRoute.ts`). A static host serves them from
439
+ // `products/index.html` and `products/<slug>/index.html`, so nothing shadows anything — and the
440
+ // catalogue page is the one every category crumb links to, so losing it would 404 every crumb.
441
+ const catalogue = staticHtml('/products');
442
+ expect(catalogue).not.toContain('data-eldra-not-found');
443
+ expect(catalogue).not.toContain('data-eldra-invalid-layout');
444
+ expect(catalogue).toContain('All products');
445
+ // **The nested category group, server-rendered from the gateway's own 3.8.0 facets.** The fixture
446
+ // assigns every product to `Cups` under `Tableware` and answers `parentId` + subtree roll-ups
447
+ // (`MockCatalogContract`), so the panel offers the parent row with its child indented inside a
448
+ // group named after it. On the 3.7.0 shape the same page draws neither — that half is pinned in
449
+ // `test/mockGatewayContract.spec.ts` and in the grid's own specs, where it costs no generate.
450
+ expect(catalogue).toContain('aria-label="Under Tableware"');
451
+ expect(catalogue).toContain('Tableware');
452
+ expect(catalogue).toContain('Cups');
453
+ expect(existsInOutput(join('/products', PRODUCT_HANDLE, 'index.html'))).toBe(true);
454
+ expect(staticHtml(`/products/${PRODUCT_HANDLE}`)).not.toContain('data-eldra-not-found');
455
+
456
+ const cart = staticHtml('/cart');
457
+ expect(cart).not.toContain('data-eldra-not-found');
458
+ // The layout rendered at all: a node carrying `locked: true` (Core's own mark on a seed's
459
+ // `required` block) must not fail `@eldrajs/theme-core`'s layout validator.
460
+ expect(cart).not.toContain('data-eldra-invalid-layout');
461
+ expect(cart).toContain(enUS.cart.title);
462
+ expect(cart).toContain('Your cart is empty');
463
+ // The two things the code route had none of, because the runtime resolves them only as part of
464
+ // a page: the banner and the contentinfo.
465
+ expect(cart).toContain('<header');
466
+ expect(cart).toContain('<footer');
467
+ expect(cart).toContain(LINKED_HEADER_LABELS.collection);
468
+
469
+ const wishlist = staticHtml('/wishlist');
470
+ expect(wishlist).not.toContain('data-eldra-not-found');
471
+ expect(wishlist).toContain(enUS.wishlist.emptyTitle);
472
+ expect(wishlist).toContain('<header');
473
+
474
+ // One file answers every `?q=`, so it is the idle state — never "No results for".
475
+ const search = staticHtml('/search');
476
+ expect(search).not.toContain('data-eldra-not-found');
477
+ expect(search).toContain(enUS.search.idleTitle);
478
+ expect(search).not.toContain('No results for');
479
+ expect(search).toContain('<header');
480
+ });
481
+
482
+ /**
483
+ * **A category page is prerendered at its canonical path, and at no other.**
484
+ *
485
+ * The fixture's tree is `Tableware` over `Cups`, so the only two paths the category template
486
+ * answers are `/categories/tableware` and `/categories/tableware/cups` — a leaf on its own is not
487
+ * one of them, and a static host answers a path it has no file for with a 404, which is exactly
488
+ * the canonical-only rule the route is built on. No unit test can see this: the pattern is a
489
+ * catch-all, the path is the storefront's own walk up the tree, and only a real generate writes
490
+ * the files.
491
+ */
492
+ it('prerenders each category at its canonical path and nowhere else', () => {
493
+ expect(existsInOutput(join('/categories/tableware', 'index.html'))).toBe(true);
494
+ expect(existsInOutput(join('/categories/tableware/cups', 'index.html'))).toBe(true);
495
+ // The leaf without its ancestor, which is the mistake a merchant's old link makes.
496
+ expect(existsInOutput(join('/categories/cups', 'index.html'))).toBe(false);
497
+ // And the prefix itself, which is not a category.
498
+ expect(existsInOutput(join('/categories', 'index.html'))).toBe(false);
499
+
500
+ const leaf = staticHtml('/categories/tableware/cups');
501
+ expect(leaf).not.toContain('data-eldra-not-found');
502
+ expect(leaf).not.toContain('data-eldra-invalid-layout');
503
+ // The title is the routed category's, bound on the seed's own layout node.
504
+ expect(leaf).toContain('Cups');
505
+ // The trail's ancestor crumb, linking to that ancestor's own canonical path.
506
+ expect(leaf).toContain('href="/categories/tableware"');
507
+ expect(leaf).toContain('<header');
508
+ expect(leaf).toContain('<footer');
509
+
510
+ // The parent's page is where the strip of children is drawn, each child linking to its own page.
511
+ const root = staticHtml('/categories/tableware');
512
+ expect(root).not.toContain('data-eldra-not-found');
513
+ expect(root).toContain('href="/categories/tableware/cups"');
514
+ });
515
+
516
+ /**
517
+ * **The whole site, once per locale.** The organisation serves `en-US` at `/` and `is-IS` under a
518
+ * prefix (`test/support/mockGateway.ts`), so `@eldrajs/theme-nuxt`'s `prerender:routes` hook has
519
+ * to write a prefixed copy of every content path it discovered — pages, the seeded
520
+ * `cart`/`wishlist`/`search`, the catalog-backed product and collection routes. A static host
521
+ * answers 404 for a path it has no file for, however well the app would have rendered it, so if
522
+ * the fan-out stops happening the entire Icelandic site is a 404 and nothing in the mounted
523
+ * suites can see it.
524
+ */
525
+ it('prerenders every content path under the non-default locale too', () => {
526
+ const prefixed = [
527
+ '',
528
+ ...SEEDED_PAGE_PATHS,
529
+ `/products/${PRODUCT_HANDLE}`,
530
+ `/collections/${COLLECTION_HANDLE}`,
531
+ '/categories/tableware/cups',
532
+ ];
533
+ for (const path of prefixed) {
534
+ const file = join(`/${PREFIXED_LOCALE}${path}`, 'index.html');
535
+ expect(existsInOutput(file), file).toBe(true);
536
+ }
537
+
538
+ // The default locale lives at `/` only: `/en-US/...` is never generated, so a visitor who
539
+ // types it gets the honest 404 a path with no content behind it should give, rather than a
540
+ // second copy of the site competing with the canonical one for every search ranking.
541
+ expect(existsInOutput(join(`/${DEFAULT_LOCALE}`, 'index.html'))).toBe(false);
542
+ });
543
+
544
+ /**
545
+ * `<html lang>` and the `hreflang` set are `@eldrajs/theme-nuxt`'s, not this theme's — nothing in
546
+ * `app/` writes either — and they are the two things a crawler reads to learn that these URLs are
547
+ * one page in two languages rather than duplicates of each other.
548
+ */
549
+ it('declares each page’s language and names its alternates', () => {
550
+ const english = staticHtml(HOME_PAGE_PATH);
551
+ const icelandic = staticHtml(`/${PREFIXED_LOCALE}`);
552
+
553
+ expect(english).toMatch(new RegExp(`<html[^>]*\\slang="${DEFAULT_LOCALE}"`));
554
+ expect(icelandic).toMatch(new RegExp(`<html[^>]*\\slang="${PREFIXED_LOCALE}"`));
555
+
556
+ for (const html of [english, icelandic]) {
557
+ expect(html).toContain(`rel="alternate" hreflang="${DEFAULT_LOCALE}" href="/"`);
558
+ expect(html).toContain(
559
+ `rel="alternate" hreflang="${PREFIXED_LOCALE}" href="/${PREFIXED_LOCALE}"`
560
+ );
561
+ expect(html).toContain('rel="alternate" hreflang="x-default" href="/"');
562
+ }
563
+
564
+ const cart = staticHtml(`/${PREFIXED_LOCALE}/cart`);
565
+ expect(cart).toContain(`rel="alternate" hreflang="${DEFAULT_LOCALE}" href="/cart"`);
566
+ expect(cart).toContain(
567
+ `rel="alternate" hreflang="${PREFIXED_LOCALE}" href="/${PREFIXED_LOCALE}/cart"`
568
+ );
569
+ });
570
+
571
+ /**
572
+ * **A prefixed page is Icelandic all the way down**, in the file a static host serves with no
573
+ * JavaScript at all: the theme's own UI strings, the money formatting, and every link out of it.
574
+ * The three come from three different places — `useT()`, `@eldrajs/ui`'s number locale, and the
575
+ * router-link component — and each of them used to read the default locale on every page.
576
+ */
577
+ it('serves a prefixed page in that language, with every link staying inside it', () => {
578
+ const cart = staticHtml(`/${PREFIXED_LOCALE}/cart`);
579
+ expect(cart).not.toContain('data-eldra-not-found');
580
+ // The theme's own UI strings are Icelandic — the shell's skip link and the header's own
581
+ // vocabulary, which no author can edit. (The block *content* on the page is not: that is the
582
+ // merchant's copy, and this mock serves one locale of it.)
583
+ expect(cart).toContain(isIS.nav.skipToContent);
584
+ expect(cart).not.toContain(enUS.nav.skipToContent);
585
+ expect(cart).toContain(isIS.header.wishlistEmpty);
586
+
587
+ // Every same-site href in the **body** is under the prefix — the header bag and heart, the
588
+ // footer's legal links, the brand wordmark; the skip link's `#main` is not a path. The head is
589
+ // excluded on purpose: its `hreflang` alternates name the *other* locale's spelling of this
590
+ // page, which is the whole job of an alternate.
591
+ const body = cart.slice(cart.indexOf('<body'));
592
+ const hrefs = [...body.matchAll(/href="([^"]*)"/g)].map((match) => match[1] ?? '');
593
+ const internal = hrefs.filter((href) => href.startsWith('/') && !href.startsWith('/_'));
594
+ expect(internal.length).toBeGreaterThan(3);
595
+ for (const href of internal) {
596
+ expect(href, `${href} leaves the ${PREFIXED_LOCALE} site`).toMatch(
597
+ new RegExp(`^/${PREFIXED_LOCALE}(/|$|\\?)`)
598
+ );
599
+ }
600
+
601
+ // The store still sells in ISK; only the formatting follows the page.
602
+ const product = staticHtml(`/${PREFIXED_LOCALE}/products/${PRODUCT_HANDLE}`);
603
+ expect(product).toContain(formatMoney(42, 'ISK', PREFIXED_LOCALE));
604
+ expect(staticHtml(`/products/${PRODUCT_HANDLE}`)).toContain(
605
+ formatMoney(42, 'ISK', DEFAULT_LOCALE)
606
+ );
607
+ expect(formatMoney(42, 'ISK', PREFIXED_LOCALE)).not.toBe(
608
+ formatMoney(42, 'ISK', DEFAULT_LOCALE)
609
+ );
610
+ });
611
+
612
+ /**
613
+ * The footer's language switcher, in the prerendered file: its options are the organisation's own
614
+ * locales, each named in its own language, and choosing one is a navigation to the same page
615
+ * under that locale. The list it used to ship was a `us-en / ca-en / ca-fr` demo set that
616
+ * switched to nothing.
617
+ */
618
+ it('offers the organisation’s own locales in the footer switcher', () => {
619
+ const english = staticHtml(HOME_PAGE_PATH);
620
+ const names = (tag: string): string =>
621
+ new Intl.DisplayNames([tag], { type: 'language' }).of(tag) ?? tag;
622
+
623
+ expect(english).toContain(enUS.footer.localeLabel);
624
+ expect(english).toContain(names(DEFAULT_LOCALE));
625
+ expect(staticHtml(`/${PREFIXED_LOCALE}`)).toContain(isIS.footer.localeLabel);
626
+ // The retired demo list must not be anywhere in the artifact.
627
+ expect(english).not.toContain('Canada · Français');
628
+ });
629
+
630
+ /**
631
+ * The post-hydration refresh is the storefront's, and on a prefixed page it has to re-read the
632
+ * catalog **in that locale** — otherwise the page would be built in Icelandic and corrected into
633
+ * English a second later, in the browser, where no static assertion can see it.
634
+ *
635
+ * **No `warnings` assertion on any prefixed page, and that is a property of the harness, not of
636
+ * the site.** Playwright's bundled Chromium is a reduced-ICU build: `Intl.NumberFormat('is-IS',
637
+ * …)` formats ISK as "kr 42" there where Node writes "42 kr.", and `Intl.DateTimeFormat('is-IS')`
638
+ * answers in English. Every page of this theme carries the footer's currency label, so no
639
+ * prerendered page in a non-English locale can hydrate byte-identically under this browser
640
+ * however correct the site is — a visitor's browser has full ICU and agrees with the renderer.
641
+ * `test/localePrefix.spec.ts` hydrates the prefixed header and footer in jsdom, where both halves
642
+ * share one ICU, which is the comparison that *is* meaningful. The same reason is why
643
+ * `useEldraLocale().name` resolves its labels on the server and carries them in the payload
644
+ * rather than letting each side compute its own: that one is not a harness artifact, because a
645
+ * real browser's ICU need not know every locale's display names either.
646
+ */
647
+ it('refreshes a prefixed page’s catalog reads in that locale', async () => {
648
+ const visited = await visit(`/${PREFIXED_LOCALE}/products/${PRODUCT_HANDLE}`);
649
+ const catalogReads = visited.requests.filter((request) => request.startsWith('/catalog/'));
650
+
651
+ expect(catalogReads.length).toBeGreaterThan(0);
652
+ for (const request of catalogReads) {
653
+ expect(request, request).toContain(`locale=${PREFIXED_LOCALE}`);
654
+ }
655
+ });
656
+
657
+ it('builds every block on a CMS page route exactly once', async () => {
658
+ const visited = await visit(HOME_PAGE_PATH);
659
+ // The control's premise: `/` is served where it was prerendered, nothing to redirect.
660
+ expect(visited.url).toBe(`${statics.origin}${HOME_PAGE_PATH}`);
661
+ const instances = blockInstances(visited);
662
+ // The page's own nine, plus the `cart` block `app/app.vue` hosts as the site's one drawer — it
663
+ // is a block component like any other, so the probe counts it, and it must be built once too.
664
+ expect(Object.keys(instances.created).length).toBe(10);
665
+ expect(notExactlyOnce(instances.created)).toEqual([]);
666
+ expect(notExactlyOnce(instances.mounted)).toEqual([]);
667
+ expect(visited.warnings).toEqual([]);
668
+ });
669
+
670
+ it('builds every block on a route-template page exactly once, served with a trailing slash', async () => {
671
+ const visited = await visit(productPage);
672
+ // The premise first: the host really did redirect, so the browser is hydrating a payload
673
+ // prerendered at a different path from the one it is sitting on. Without this the rest of the
674
+ // case would keep passing while quietly testing nothing.
675
+ expect(visited.url).toBe(`${statics.origin}${productPage}/`);
676
+ const instances = blockInstances(visited);
677
+ // The page's own seven, plus the shell's hosted cart drawer (see the control above).
678
+ expect(Object.keys(instances.created).length).toBe(8);
679
+ // The page is served at `/products/ash-glaze-mug/` and prerendered at
680
+ // `/products/ash-glaze-mug` (`startStaticServer`'s 308 is the deployed host's). Nuxt therefore
681
+ // re-navigates between the two while the page hydrates, and unless the route key and the page
682
+ // composable both read the *canonical* path, that move destroys and rebuilds the page — every
683
+ // block's `setup` runs again, every storefront read in it goes out again, and only one of the
684
+ // two instances ever mounts, so the mount count alone would say nothing is wrong.
685
+ expect(notExactlyOnce(instances.created)).toEqual([]);
686
+ expect(notExactlyOnce(instances.mounted)).toEqual([]);
687
+ expect(visited.warnings).toEqual([]);
688
+ });
689
+
690
+ it('writes real prices and stock into the static HTML, with no skeleton and nothing busy', () => {
691
+ for (const path of [productPage, collectionPage]) {
692
+ const html = staticHtml(path);
693
+ // In the store's own currency, which the build read from the platform
694
+ // (`test/support/mockGateway.ts` publishes ISK — and says why it is not dollars). A page that
695
+ // fell back to `@eldrajs/ui`'s ambient default would read `$42.00` here instead.
696
+ expect(html, path).toContain('commerce:{currency:"ISK"');
697
+ expect(html, path).toContain(formatMoney(42, 'ISK'));
698
+ expect(html, path).not.toContain('$42.00');
699
+ expect(html, path).toContain('Ash glaze mug');
700
+ expect(html, path).not.toContain('eldra-skeleton');
701
+ expect(html, path).not.toContain('eldra-revalidating');
702
+ expect(html, path).not.toContain('aria-busy="true"');
703
+ expect(html, path).not.toContain('Loading…');
704
+ }
705
+ // The carousel's cards are prerendered too, prices and all.
706
+ expect(staticHtml(productPage)).toContain('Cedar serving board');
707
+ });
708
+
709
+ it("bakes every header link's href into the static HTML, and draws no anchor for a target that is gone", () => {
710
+ // The whole point of the `link` field: the header stores what it points at, and the site
711
+ // derives the path from its own route templates at prerender time. A visitor with no
712
+ // JavaScript gets working links; the browser makes no request to resolve one.
713
+ //
714
+ // The links are `mockGateway`'s own fixture, not the theme's seed: the seed ships none, so a
715
+ // header with destinations only ever exists once an author has made some.
716
+ for (const path of [HOME_PAGE_PATH, productPage, collectionPage]) {
717
+ const html = staticHtml(path);
718
+ const anchor = (label: string): RegExpMatchArray | null =>
719
+ html.match(new RegExp(`<a[^>]*href="([^"]*)"[^>]*>(?:(?!</a>).)*${label}`, 's'));
720
+
721
+ expect(anchor(LINKED_HEADER_LABELS.collection)?.[1], path).toBe(
722
+ `/collections/${COLLECTION_HANDLE}`
723
+ );
724
+ expect(anchor(LINKED_HEADER_LABELS.product)?.[1], path).toBe(`/products/${PRODUCT_HANDLE}`);
725
+ expect(anchor(LINKED_HEADER_LABELS.url)?.[1], path).toBe('/journal');
726
+
727
+ // The gateway has never heard of this collection — deleted, archived, or unpublished. The
728
+ // label is still worth showing; an anchor to nowhere is not.
729
+ expect(html, path).toContain(LINKED_HEADER_LABELS.missing);
730
+ expect(anchor(LINKED_HEADER_LABELS.missing), path).toBeNull();
731
+ }
732
+ });
733
+
734
+ it("opens a mega-menu that spans the header's container, whichever item opened it", async () => {
735
+ // Geometry only a real browser can answer. The panel used to be pinned to the item that
736
+ // opened it at a width of its own, so where it started and stopped depended on which word in
737
+ // the bar the visitor happened to hover. It now spans the bar's own container: its left edge
738
+ // on the brand's, its right edge on the actions', and its top on the bar's bottom edge.
739
+ const page = await browser.newPage({ viewport: { width: 1280, height: 900 } });
740
+ try {
741
+ await page.goto(`${statics.origin}${HOME_PAGE_PATH}`, { waitUntil: 'domcontentloaded' });
742
+ const trigger = page
743
+ .locator('header nav')
744
+ .getByRole('button', { name: LINKED_HEADER_LABELS.mega });
745
+ await trigger.click();
746
+ const panelId = await trigger.getAttribute('aria-controls');
747
+ expect(panelId).not.toBeNull();
748
+ // Vitest's `expect` here, not Playwright's — the wait is the locator's own.
749
+ await page.locator(`#${panelId ?? ''}`).waitFor({ state: 'visible' });
750
+ // "Visible" is true from the *first* frame of the panel's entrance, and that entrance carries
751
+ // a 4px rise (`-translate-y-1` over 150ms, `panelTransition` in `blocks/navigation/Block.vue`).
752
+ // Measuring there reads the panel 4px above where it settles — which, plus the bar's own 1px
753
+ // border, is exactly the 5px this geometry case used to fail by whenever the machine got to
754
+ // `evaluate` inside 150ms. So wait for the transition itself to finish, not just for the
755
+ // element to exist.
756
+ await page.waitForFunction(
757
+ (id) =>
758
+ (document.getElementById(id)?.getAnimations() ?? []).every(
759
+ (animation) => animation.playState !== 'running'
760
+ ),
761
+ panelId ?? ''
762
+ );
763
+
764
+ const edges = await page.evaluate((id) => {
765
+ const box = (
766
+ selector: string
767
+ ): { left: number; right: number; bottom: number; top: number } => {
768
+ const element = document.querySelector(selector);
769
+ if (element === null) throw new Error(`no ${selector}`);
770
+ const rect = element.getBoundingClientRect();
771
+ return { left: rect.left, right: rect.right, bottom: rect.bottom, top: rect.top };
772
+ };
773
+ const panel = document.getElementById(id)!;
774
+ const rect = panel.getBoundingClientRect();
775
+ // The first column of the grid, and the "View all" anchor — the two pieces of content
776
+ // that decide whether the panel has an inset at all.
777
+ const firstColumn = panel.firstElementChild!.getBoundingClientRect();
778
+ const viewAll = panel.querySelector('[data-eldra-mega-view-all]')!.getBoundingClientRect();
779
+ return {
780
+ panel: { left: rect.left, right: rect.right, bottom: rect.bottom, top: rect.top },
781
+ firstColumn: { left: firstColumn.left, right: firstColumn.right },
782
+ viewAll: { left: viewAll.left, right: viewAll.right },
783
+ brand: box('header [data-eldra-header-focus]'),
784
+ actions: box('header [data-eldra-header-actions]'),
785
+ bar: box('header'),
786
+ trigger: box(`[aria-controls="${id}"]`),
787
+ };
788
+ }, panelId ?? '');
789
+
790
+ expect(Math.round(edges.panel.left)).toBe(Math.round(edges.brand.left));
791
+ expect(Math.round(edges.panel.right)).toBe(Math.round(edges.actions.right));
792
+ // Directly below the bar — within the bar's own 1px bottom border.
793
+ expect(Math.abs(edges.panel.top - edges.bar.bottom)).toBeLessThanOrEqual(2);
794
+ // And the premise: the trigger is nowhere near either edge, so "spans the container" is a
795
+ // real claim rather than a coincidence of where this item sits.
796
+ expect(edges.trigger.left).toBeGreaterThan(edges.panel.left + 1);
797
+ expect(edges.trigger.right).toBeLessThan(edges.panel.right - 1);
798
+ // And the inset the operator asked for: nothing inside the panel sits flush against its
799
+ // edges. 24px is the narrow-container figure; the wide container's own 32px clears it too,
800
+ // so one bound holds at every width this page is measured at.
801
+ expect(edges.firstColumn.left).toBeGreaterThanOrEqual(edges.panel.left + 24);
802
+ expect(edges.viewAll.right).toBeLessThanOrEqual(edges.panel.right - 24);
803
+ } finally {
804
+ await page.close();
805
+ }
806
+ });
807
+
808
+ it("paints an open mega-menu in the bar's own colour, and eases it in and out", async () => {
809
+ // Two more things only a real browser can answer. First the colour: both the bar and the panel
810
+ // resolve `--eldra-header-surface` through the theme's token variables, which exist only in a
811
+ // real stylesheet — jsdom sees the class names and no colour at all. Second the leave: a panel
812
+ // that merely stops being `display: block` is indistinguishable, in a mounted test, from one
813
+ // that fades out over 120ms, and the fade is the whole point of the change.
814
+ //
815
+ // Both bar states are measured, because they are the two different grounds the bar can be
816
+ // asked about: the home page's header is solid, and the collection template's carries
817
+ // `transparentOverHero`, so at rest it paints nothing at all. An open panel must match the bar
818
+ // in both — which means the bar must have stopped being transparent by the time one is open.
819
+ const page = await browser.newPage({
820
+ viewport: { width: 1280, height: 900 },
821
+ reducedMotion: 'no-preference',
822
+ });
823
+ try {
824
+ for (const [path, transparentAtRest] of [
825
+ [HOME_PAGE_PATH, false],
826
+ [collectionPage, true],
827
+ ] as const) {
828
+ await page.goto(`${statics.origin}${path}`, { waitUntil: 'domcontentloaded' });
829
+ // The header publishes `--eldra-header-height` from its own ResizeObserver, which runs only
830
+ // in the browser: the cheapest proof the bar is hydrated and will answer a click.
831
+ await page.waitForFunction(
832
+ () => document.documentElement.style.getPropertyValue('--eldra-header-height') !== ''
833
+ );
834
+
835
+ const barColour = async (): Promise<string> =>
836
+ page.evaluate(() => getComputedStyle(document.querySelector('header')!).backgroundColor);
837
+ const TRANSPARENT = 'rgba(0, 0, 0, 0)';
838
+ expect((await barColour()) === TRANSPARENT, `${path} at rest`).toBe(transparentAtRest);
839
+
840
+ const trigger = page
841
+ .locator('header nav')
842
+ .getByRole('button', { name: LINKED_HEADER_LABELS.mega });
843
+ await trigger.click();
844
+ const panelId = (await trigger.getAttribute('aria-controls')) ?? '';
845
+ expect(panelId, path).not.toBe('');
846
+ // The enter half: it finishes at full opacity rather than settling somewhere short of it.
847
+ await page.waitForFunction(
848
+ (id) => getComputedStyle(document.getElementById(id)!).opacity === '1',
849
+ panelId
850
+ );
851
+
852
+ const open = await page.evaluate((id) => {
853
+ const bar = document.querySelector('header')!;
854
+ return {
855
+ panel: getComputedStyle(document.getElementById(id)!).backgroundColor,
856
+ bar: getComputedStyle(bar).backgroundColor,
857
+ transparentAttribute: bar.getAttribute('data-eldra-transparent'),
858
+ };
859
+ }, panelId);
860
+ // The whole point of the change: one surface, not two that happen to agree.
861
+ expect(open.panel, path).toBe(open.bar);
862
+ expect(open.panel, path).not.toBe(TRANSPARENT);
863
+ // A panel never floats on a transparent bar, whatever the field says.
864
+ expect(open.transparentAttribute, path).toBeNull();
865
+
866
+ // The leave half, sampled frame by frame from the click that closes it: the panel is still
867
+ // painted, part-way through a fade, for a while after `aria-expanded` has already gone back
868
+ // to false — which is exactly what a `<Transition>` buys over a bare `v-show`.
869
+ const leave = await page.evaluate(
870
+ (id) =>
871
+ new Promise<{ faded: boolean; hiddenAfterMs: number }>((resolve) => {
872
+ const panel = document.getElementById(id)!;
873
+ const start = performance.now();
874
+ let faded = false;
875
+ const tick = (): void => {
876
+ const style = getComputedStyle(panel);
877
+ const elapsed = performance.now() - start;
878
+ if (style.display === 'none' || elapsed > 2000) {
879
+ resolve({ faded, hiddenAfterMs: elapsed });
880
+ return;
881
+ }
882
+ if (Number(style.opacity) < 1) faded = true;
883
+ requestAnimationFrame(tick);
884
+ };
885
+ (document.querySelector(`[aria-controls="${id}"]`) as HTMLElement).click();
886
+ requestAnimationFrame(tick);
887
+ }),
888
+ panelId
889
+ );
890
+ expect(leave.faded, `${path} fades out`).toBe(true);
891
+ // 120ms of leave: comfortably more than the frame a bare `v-show` would have taken, and
892
+ // nowhere near a panel that never leaves at all.
893
+ expect(leave.hiddenAfterMs, path).toBeGreaterThanOrEqual(60);
894
+ expect(leave.hiddenAfterMs, path).toBeLessThan(1000);
895
+ expect(await trigger.getAttribute('aria-expanded'), path).toBe('false');
896
+ }
897
+ } finally {
898
+ await page.close();
899
+ }
900
+ });
901
+
902
+ it('hides the sticky bar on the way down, brings it back on the way up, and pins it while in use', async () => {
903
+ // Where the bar actually is, which only a real browser can answer. The reveal is a class on the
904
+ // bar, and a mounted test can read that class off a bar that is nowhere near the screen: on a
905
+ // generated page the bar sits inside the single-block wrapper the block zone renders around it,
906
+ // a box exactly the bar's own height, and a bar clamped to that box never travels at all — it
907
+ // stays at the top of the *page*, scrolls out of view with it, and "revealed" means a class
908
+ // change on something 900px above the viewport. So every assertion here is a rectangle.
909
+ const page = await browser.newPage({ viewport: { width: 1280, height: 900 } });
910
+ try {
911
+ await page.goto(`${statics.origin}${HOME_PAGE_PATH}`, { waitUntil: 'domcontentloaded' });
912
+ // The bar publishes its height from its own ResizeObserver, which runs only once hydrated.
913
+ await page.waitForFunction(
914
+ () => document.documentElement.style.getPropertyValue('--eldra-header-height') !== ''
915
+ );
916
+
917
+ const bar = async (): Promise<{
918
+ top: number;
919
+ bottom: number;
920
+ height: number;
921
+ position: string;
922
+ scrollY: number;
923
+ maxScroll: number;
924
+ }> =>
925
+ page.evaluate(() => {
926
+ const element = document.querySelector('header');
927
+ if (element === null) throw new Error('no header');
928
+ const rect = element.getBoundingClientRect();
929
+ return {
930
+ top: rect.top,
931
+ bottom: rect.bottom,
932
+ height: rect.height,
933
+ position: getComputedStyle(element).position,
934
+ scrollY: window.scrollY,
935
+ maxScroll: document.documentElement.scrollHeight - window.innerHeight,
936
+ };
937
+ });
938
+ /** The hide and the reveal are a transform transition; give it room to land. */
939
+ const settle = async (): Promise<void> => {
940
+ await page.waitForTimeout(600);
941
+ };
942
+
943
+ const atTop = await bar();
944
+ expect(atTop.position).toBe('fixed');
945
+ expect(Math.round(atTop.top)).toBe(0);
946
+ // The premise of everything below: this page is tall enough to scroll 1200px.
947
+ expect(atTop.maxScroll).toBeGreaterThan(1200);
948
+ // And the bar reserves in the flow exactly the height it no longer occupies there, so the
949
+ // page below it starts where it always did: the block still takes up the bar's own height.
950
+ const flow = await page.evaluate(() => {
951
+ const element = document.querySelector('header');
952
+ if (element === null) throw new Error('no header');
953
+ const spacer = document.querySelector('[data-eldra-header-spacer]');
954
+ const wrapper = element.closest('[data-eldra-block]');
955
+ return {
956
+ spacer: spacer === null ? null : spacer.getBoundingClientRect().height,
957
+ // The height the spacer's *classes* alone reserve — all the first paint of a prerendered
958
+ // page has, before the bar has been measured at all — against the bar's own box for those
959
+ // same classes. A difference here is a page that jumps on hydration.
960
+ reserved:
961
+ spacer === null ? null : spacer.firstElementChild!.getBoundingClientRect().height,
962
+ nav: element.querySelector('nav')!.getBoundingClientRect().height,
963
+ wrapper: wrapper === null ? null : wrapper.getBoundingClientRect().height,
964
+ };
965
+ });
966
+ expect(flow.spacer).toBe(atTop.height);
967
+ expect(flow.reserved).toBe(flow.nav);
968
+ expect(flow.wrapper).toBe(atTop.height);
969
+
970
+ await page.evaluate(() => window.scrollTo(0, 1200));
971
+ await settle();
972
+ const down = await bar();
973
+ expect(down.scrollY).toBe(1200);
974
+ // Off the screen entirely — translated out, not merely left behind.
975
+ expect(down.bottom).toBeLessThanOrEqual(0);
976
+
977
+ await page.evaluate(() => window.scrollBy(0, -300));
978
+ await settle();
979
+ const up = await bar();
980
+ expect(up.scrollY).toBe(900);
981
+ expect(Math.round(up.top)).toBe(0);
982
+ expect(up.bottom).toBeGreaterThan(0);
983
+ // Vitest's `expect` here, not Playwright's: the visibility is read, not awaited.
984
+ expect(await page.locator('header').isVisible()).toBe(true);
985
+
986
+ // In use: an open mega-menu pins the bar through a scroll-down that would otherwise hide it.
987
+ const trigger = page
988
+ .locator('header nav')
989
+ .getByRole('button', { name: LINKED_HEADER_LABELS.mega });
990
+ await trigger.click();
991
+ const panelId = await trigger.getAttribute('aria-controls');
992
+ await page.locator(`#${panelId ?? ''}`).waitFor({ state: 'visible' });
993
+ await page.evaluate(() => window.scrollBy(0, 400));
994
+ await settle();
995
+ const pinned = await bar();
996
+ expect(pinned.scrollY).toBe(1300);
997
+ expect(Math.round(pinned.top)).toBe(0);
998
+ expect(await trigger.getAttribute('aria-expanded')).toBe('true');
999
+ expect(await page.locator(`#${panelId ?? ''}`).isVisible()).toBe(true);
1000
+ } finally {
1001
+ await page.close();
1002
+ }
1003
+ });
1004
+
1005
+ it('prerenders every storefront read the product page makes, under the key the browser computes', () => {
1006
+ // The whole set, not a sample: a key the browser computes differently is a key missing from
1007
+ // this list, and `byHandles` is the one that used to be — `[[]]` here, `[["ash-glaze-mug"]]`
1008
+ // in the browser. The request assertions below are the other half of the proof: a key the
1009
+ // browser does not find in the payload fetches, and nothing here fetches.
1010
+ expect(payloadStorefrontKeys(productPage)).toEqual([
1011
+ 'storefront:catalog.byHandles:[[]]',
1012
+ // `breadcrumbs`' own category read, keyed `null` on a product page — the route resolved a
1013
+ // product, so there is no category to place. Like the `collectionProducts:[null,…]` beside
1014
+ // it, a null-sourced result makes no request and carries no data; it is in the payload
1015
+ // because it exists, and the browser computes the same key for it.
1016
+ 'storefront:catalog.category:[null]',
1017
+ 'storefront:catalog.collectionProducts:[null,{"page":1,"pageSize":8}]',
1018
+ 'storefront:catalog.product:["ash-glaze-mug"]',
1019
+ 'storefront:catalog.related:["ash-glaze-mug",8]',
1020
+ 'storefront:search.run:[""]',
1021
+ ]);
1022
+ });
1023
+
1024
+ it('refreshes the product page with the detail read and one batched read, and nothing else', async () => {
1025
+ const visited = await visit(productPage);
1026
+ // The **full** log, duplicates included, not a set of unique URLs. `product-detail` re-reads
1027
+ // its own product (only that read knows the variant-level inventory the products list cannot
1028
+ // answer about), and every card on the page — the carousel's six — is one batched `id:in` read.
1029
+ // Nothing else: no re-run of a prerendered non-volatile read, and nothing twice.
1030
+ expect(visited.requests).toEqual([
1031
+ `/catalog/v1/products/${PRODUCT_HANDLE}`,
1032
+ '/catalog/v1/products/list?pageSize=6&filter=id:in:prod-cedar-serving-board,' +
1033
+ 'prod-flax-tea-towel,prod-stoneware-bowl,prod-brass-candle-holder,prod-linen-napkin-set,' +
1034
+ 'prod-walnut-spoon',
1035
+ // The detail read's second half: the product's own inventory, which the list read has none of.
1036
+ '/inventory/v1/stock/availability',
1037
+ ]);
1038
+ expect(askedMoreThanOnce(visited.requests)).toEqual([]);
1039
+ expect(visited.warnings).toEqual([]);
1040
+ });
1041
+
1042
+ it('draws the refresh treatment on every value it is re-reading, then clears it', async () => {
1043
+ const visited = await visit(productPage);
1044
+ const peak = peakOf(visited.samples);
1045
+ // Two values on the product itself (price, stock line) and two on each of the six cards.
1046
+ expect(peak.spinners).toBe(14);
1047
+ expect(peak.dimmed).toBeGreaterThanOrEqual(14);
1048
+ expect(peak.busy).toBeGreaterThan(0);
1049
+ // Something says so out loud — the carousel's one row-level region, plus the product's own
1050
+ // price and stock line, which announce for themselves. How many regions each block owns is
1051
+ // that block's spec; what matters here is that the announcement reaches a real page at all.
1052
+ expect(peak.announced).toBeGreaterThanOrEqual(1);
1053
+ // …and it is gone once the refresh has answered, with the prerendered values still on screen.
1054
+ expect(visited.samples[visited.samples.length - 1]).toEqual(NOTHING);
1055
+ expect(visited.prices).toContain(formatMoney(42, 'ISK'));
1056
+ expect(visited.prices).toContain(formatMoney(68, 'ISK'));
1057
+ });
1058
+
1059
+ /**
1060
+ * Two blocks over the same collection — the grid and a carousel below it — which is the shape the
1061
+ * deployed pages showed the duplicate in: different blocks are different lazily imported chunks,
1062
+ * so they register in different bursts, and until this round each burst asked the gateway about
1063
+ * the same seven products all over again.
1064
+ */
1065
+ it('asks about the collection page’s products once, however many blocks show them', async () => {
1066
+ const visited = await visit(collectionPage);
1067
+ // One request for the whole page, not one per burst — and asserted as the full log.
1068
+ expect(visited.requests).toEqual([
1069
+ '/catalog/v1/products/list?pageSize=7&filter=id:in:prod-ash-glaze-mug,' +
1070
+ 'prod-cedar-serving-board,prod-flax-tea-towel,prod-stoneware-bowl,prod-brass-candle-holder,' +
1071
+ 'prod-linen-napkin-set,prod-walnut-spoon',
1072
+ ]);
1073
+ expect(askedMoreThanOnce(visited.requests)).toEqual([]);
1074
+ expect(visited.warnings).toEqual([]);
1075
+ // Both blocks still draw the treatment and both end up showing the refreshed values: the block
1076
+ // that arrived second folds in the answer the first one's read had already brought back.
1077
+ const peak = peakOf(visited.samples);
1078
+ expect(peak.spinners).toBe(28); // seven cards in the grid, seven in the carousel, two each
1079
+ expect(peak.busy).toBeGreaterThan(0);
1080
+ expect(peak.announced).toBe(2); // one row-level region per block
1081
+ expect(visited.samples[visited.samples.length - 1]).toEqual(NOTHING);
1082
+ });
1083
+
1084
+ /**
1085
+ * Client-side navigation between two **prerendered** routes. Everything the destination needs is
1086
+ * in the build: Nuxt's own payload plugin loads `/products/<handle>/_payload.json` in
1087
+ * `router.beforeResolve` and writes it into `nuxtApp.static.data` before the page component
1088
+ * exists. A route resolution that reaches the gateway anyway is a resolution the build already
1089
+ * did — and it is visible, because the page renders its loading shell while it waits.
1090
+ *
1091
+ * The request log is asserted whole: the only reads a static navigation may make are the
1092
+ * destination page's own volatile refresh (the product's detail read, and one batched `id:in`
1093
+ * for the carousel's cards). A CMS read, or a read belonging to the collection page being left,
1094
+ * is a defect — the first says the route was resolved again, the second says a departing block
1095
+ * re-ran on the route change before it unmounted.
1096
+ */
1097
+ it('shows no loading state and asks nothing about the route when a card is clicked', async () => {
1098
+ const visited = await navigateFrom(collectionPage, async (page) => {
1099
+ await page.locator('#main a[href^="/products/"]').first().click();
1100
+ });
1101
+ // The premise: a real client-side navigation happened, to the product this spec is about.
1102
+ expect(visited.url).toBe(`${statics.origin}${productPage}`);
1103
+ expect(
1104
+ visited.samples.map((sample) => sample.text).filter((text) => text.includes(enUS.loading))
1105
+ ).toEqual([]);
1106
+ expect(visited.samples[visited.samples.length - 1]?.h1).toBe('Ash glaze mug');
1107
+ // The **whole** log. One read, and it is the product page's own volatile refresh: the detail
1108
+ // read `product-detail` makes for itself, because the id it shows is a *variant's* and the
1109
+ // batched `id:in` read cannot answer about it (`app/storefront/refresh.ts`). There is no
1110
+ // batched read beside it — the six cards on this page are products the collection page already
1111
+ // re-read a moment ago, and the refresher answers for a product once per page load, client
1112
+ // navigations included. The product page itself is not one of those answers: a result that
1113
+ // reads for itself is never satisfied by a batch (`app/storefront/refresh.ts`), because the
1114
+ // batch cannot answer the variant-level inventory this page's stock line is about.
1115
+ // Everything else the page shows came out of the payload Nuxt loaded for the route: no `/cms/`
1116
+ // read to resolve it, and nothing belonging to the collection page being left.
1117
+ expect(visited.requests).toEqual([
1118
+ `/catalog/v1/products/${PRODUCT_HANDLE}`,
1119
+ '/inventory/v1/stock/availability',
1120
+ ]);
1121
+ expect(askedMoreThanOnce(visited.requests)).toEqual([]);
1122
+ expect(visited.warnings).toEqual([]);
1123
+ });
1124
+
1125
+ /**
1126
+ * A route the build does not know. The prerendered route list is shipped with the site (Nuxt's
1127
+ * app manifest), so "no such route" is an answer the browser already holds: the not-found shell
1128
+ * must appear at once, and the gateway must not be asked a single question to reach it.
1129
+ */
1130
+ it('answers an unknown route as not found at once, with no gateway call at all', async () => {
1131
+ const visited = await navigateFrom(collectionPage, async (page) => {
1132
+ await page.evaluate(() =>
1133
+ (
1134
+ window as unknown as {
1135
+ __eldraPush: (path: string) => Promise<unknown>;
1136
+ }
1137
+ ).__eldraPush('/products/does-not-exist')
1138
+ );
1139
+ });
1140
+ expect(visited.requests).toEqual([]);
1141
+ expect(
1142
+ visited.samples.map((sample) => sample.text).filter((text) => text.includes(enUS.loading))
1143
+ ).toEqual([]);
1144
+ // Within four samples — 200 ms — rather than after a round of gateway reads.
1145
+ const shown = firstSampleShowing(visited.samples, enUS.notFound.title);
1146
+ expect(shown).toBeGreaterThanOrEqual(0);
1147
+ expect(shown).toBeLessThan(4);
1148
+ expect(visited.warnings).toEqual([]);
1149
+ });
1150
+
1151
+ /**
1152
+ * The header's bag, on a generated site, in a real browser. Two reported defects meet here: "the
1153
+ * cart does not seem to work, it just redirects to /cart" (the bag named a path nothing in the
1154
+ * theme answered, so the catch-all asked the gateway for a CMS page called "cart", found none, and
1155
+ * the shopper got the not-found shell), and then that it redirected at all — a cart belongs in a
1156
+ * drawer over the page the shopper is reading.
1157
+ *
1158
+ * So this is the whole progression a generated page goes through, which only this spec can see:
1159
+ * the prerendered HTML carries the bag as a real `<a href="/cart">` and the theme's drawer closed
1160
+ * (a visitor with no JavaScript, and a reader who arrives before hydration, still have somewhere to
1161
+ * go); once hydrated the drawer is mounted and the bag is a `<button>` that opens it with no
1162
+ * navigation at all; and `/cart` is still a prerendered file that renders the cart page when the
1163
+ * router is sent there.
1164
+ *
1165
+ * The generated site's cart is empty — a prerender has no shopper's session — so the drawer shows
1166
+ * its empty state, and its filled footer (subtotal, Check out, View cart) is the block spec's
1167
+ * ground rather than this one's.
1168
+ */
1169
+ it('opens the hosted cart drawer from the header bag, with /cart still there behind it', async () => {
1170
+ // The file first: `/cart` is prerendered by name (`nuxt.config.ts`), so a static host has
1171
+ // something to serve for it. Without this the navigation below would still "work" in the
1172
+ // router while the deployed site answered 404.
1173
+ const prerendered = staticHtml('/cart');
1174
+ expect(prerendered).toContain(enUS.cart.emptyFallbackTitle);
1175
+ expect(prerendered).not.toContain('data-eldra-not-found');
1176
+
1177
+ // The home page as a static host serves it: one closed drawer (the `open` attribute, never the
1178
+ // `open:flex` utility in its class list), and the bag still a link.
1179
+ const home = staticHtml(HOME_PAGE_PATH);
1180
+ // Exactly one cart drawer in the markup — its close button names it, where "Your cart" alone
1181
+ // would also match the empty state inside it.
1182
+ expect(home.match(/aria-label="Close Your cart"/g) ?? []).toHaveLength(1);
1183
+ expect(home).not.toMatch(/<dialog[^>]*\sopen[=\s>]/);
1184
+ expect(home).toContain('href="/cart"');
1185
+
1186
+ const page = await browser.newPage();
1187
+ const warnings: string[] = [];
1188
+ page.on('console', (message) => {
1189
+ const text = message.text();
1190
+ if (/hydrat|mismatch/i.test(text) || message.type() === 'error') {
1191
+ warnings.push(`${message.type()}: ${text.slice(0, 200)}`);
1192
+ }
1193
+ });
1194
+ page.on('pageerror', (error) => warnings.push(`pageerror: ${error.message.slice(0, 200)}`));
1195
+ try {
1196
+ await page.goto(`${statics.origin}${HOME_PAGE_PATH}`, { waitUntil: 'domcontentloaded' });
1197
+ await page.waitForTimeout(CATALOG_DELAY_MS + 1500);
1198
+ gateway.reset();
1199
+
1200
+ // Hydrated: the drawer is mounted, so the bag swapped from a link to a button (`drawerAvailable`
1201
+ // in `app/storefront/cart.ts`). The swap happens *after* hydration, which is why `warnings`
1202
+ // below must still be empty — a mismatch would mean the server and the first client render
1203
+ // disagreed.
1204
+ const bag = page.locator('header button[aria-label^="Cart"]');
1205
+ await bag.waitFor({ state: 'visible', timeout: 5000 });
1206
+ expect(await page.locator('header a[href="/cart"]').count()).toBe(0);
1207
+
1208
+ await bag.click();
1209
+ const opened = await page.evaluate(() => {
1210
+ const open = [...document.querySelectorAll('dialog[open]')];
1211
+ return {
1212
+ count: open.length,
1213
+ title: open[0]?.querySelector('[data-part="title"]')?.textContent ?? '',
1214
+ text: (open[0] as HTMLElement | undefined)?.innerText ?? '',
1215
+ path: location.pathname,
1216
+ };
1217
+ });
1218
+ // One drawer, it is the cart, and the shopper is still on the page they were reading.
1219
+ expect(opened.count).toBe(1);
1220
+ expect(opened.title).toContain(enUS.cart.title);
1221
+ expect(opened.text).toContain(enUS.cart.emptyFallbackTitle);
1222
+ expect(opened.path).toBe(HOME_PAGE_PATH);
1223
+ // Opening the cart asks the gateway nothing: the cart is the shopper's own session state.
1224
+ expect(gateway.requests.filter((request) => request.startsWith('/cms/'))).toEqual([]);
1225
+
1226
+ // Esc closes the top dialog and hands focus back to the bag that opened it.
1227
+ await page.keyboard.press('Escape');
1228
+ await page.waitForTimeout(100);
1229
+ expect(await page.locator('dialog[open]').count()).toBe(0);
1230
+ expect(
1231
+ await page.evaluate(() => document.activeElement?.getAttribute('aria-label') ?? '')
1232
+ ).toMatch(/^Cart/);
1233
+
1234
+ // And the deep link is still a real route: a client-side navigation to it renders the
1235
+ // prerendered cart page, not the not-found shell.
1236
+ await page.evaluate(() =>
1237
+ (window as unknown as { __eldraPush: (path: string) => Promise<unknown> }).__eldraPush(
1238
+ '/cart'
1239
+ )
1240
+ );
1241
+ await page.waitForURL(`${statics.origin}/cart`);
1242
+ await page.waitForTimeout(500);
1243
+ const settled = await page.evaluate(() => ({
1244
+ h1: document.querySelector('main#main h1')?.textContent?.trim() ?? '',
1245
+ text: document.body.innerText,
1246
+ }));
1247
+ expect(settled.h1).toContain(enUS.cart.title);
1248
+ expect(settled.text).toContain(enUS.cart.emptyFallbackTitle);
1249
+ expect(settled.text).not.toContain(enUS.notFound.title);
1250
+ // A code route: the gateway is never asked to resolve it.
1251
+ expect(gateway.requests.filter((request) => request.startsWith('/cms/'))).toEqual([]);
1252
+ expect(warnings).toEqual([]);
1253
+ } finally {
1254
+ await page.close();
1255
+ }
1256
+ });
1257
+
1258
+ /**
1259
+ * **A reload with a cart already in the browser.**
1260
+ *
1261
+ * Shopper state never reaches a prerendered file: the build has no browser, so every generated
1262
+ * page says "Cart, empty" and nothing on it is waiting for a cart. A returning shopper's browser
1263
+ * does have one — `@eldrajs/sdk`'s `createCartSession` keeps the cart id in `localStorage` — and
1264
+ * the cart store reads it, and asks for the cart, during the storefront plugin's `setup`, which
1265
+ * runs *before* the app hydrates. So for the whole width of that request the cart is `pending`,
1266
+ * and anything that renders `cart.pending` without a mount gate renders the first client frame
1267
+ * differently from the file Nuxt is hydrating: one `Hydration completed but contains mismatches`,
1268
+ * and Vue re-renders that subtree from scratch.
1269
+ *
1270
+ * That is what this measures, and it is why the product page is the one it measures it on: the
1271
+ * home page carries the header, whose count is gated on mount already, and nothing else that
1272
+ * reads the cart — so it was silent while the product page (whose Add to cart button and sticky
1273
+ * bar both took their busy state straight from `cart.pending`) warned on every reload. Both are
1274
+ * asserted, the home page as the control that says the harness would have noticed either way.
1275
+ *
1276
+ * Only a real generate, served the way the host serves it and hydrated by Nuxt itself, can see
1277
+ * this: a mounted spec never hydrates against a server-rendered string, and a `renderSsr` spec
1278
+ * has no `localStorage` and no plugin running before the first client render.
1279
+ */
1280
+ describe('a reload with a cart already in the browser', () => {
1281
+ /** The settled header bag, plus everything `visit` already collects. */
1282
+ async function visitWithCart(path: string): Promise<{ warnings: string[]; cartLabel: string }> {
1283
+ gateway.reset();
1284
+ const page = await browser.newPage();
1285
+ const warnings: string[] = [];
1286
+ page.on('console', (message) => {
1287
+ const text = message.text();
1288
+ if (/hydrat|mismatch/i.test(text) || message.type() === 'error') {
1289
+ warnings.push(`${message.type()}: ${text.slice(0, 200)}`);
1290
+ }
1291
+ });
1292
+ page.on('pageerror', (error) => warnings.push(`pageerror: ${error.message.slice(0, 200)}`));
1293
+ try {
1294
+ // Before any script of the page runs, which is what makes this a *reload* with a cart
1295
+ // rather than a cart added on this visit.
1296
+ await page.addInitScript(
1297
+ ([key, id]) => window.localStorage.setItem(key as string, id as string),
1298
+ ['eldra.cartId', SEEDED_CART_ID]
1299
+ );
1300
+ await page.goto(`${statics.origin}${path}`, { waitUntil: 'domcontentloaded' });
1301
+ await page.waitForTimeout(CATALOG_DELAY_MS + CART_DELAY_MS + 1500);
1302
+ return {
1303
+ warnings,
1304
+ cartLabel: await page.evaluate(
1305
+ () =>
1306
+ document.querySelector('header [aria-label^="Cart"]')?.getAttribute('aria-label') ??
1307
+ ''
1308
+ ),
1309
+ };
1310
+ } finally {
1311
+ await page.close();
1312
+ }
1313
+ }
1314
+
1315
+ it('says nothing about hydration on a product page, and restores the count after', async () => {
1316
+ // The file itself: no cart of anyone's in it.
1317
+ expect(staticHtml(productPage)).toContain(enUS.header.cartEmpty);
1318
+
1319
+ const visited = await visitWithCart(productPage);
1320
+
1321
+ expect(visited.warnings).toEqual([]);
1322
+ // ...and the restored cart arrives as an ordinary update once the read lands.
1323
+ expect(visited.cartLabel).toBe(
1324
+ enUS.header.cartMany.replace('{count}', String(SEEDED_CART_QUANTITY))
1325
+ );
1326
+ });
1327
+
1328
+ it('says nothing on the home page either, the control', async () => {
1329
+ const visited = await visitWithCart(HOME_PAGE_PATH);
1330
+
1331
+ expect(visited.warnings).toEqual([]);
1332
+ expect(visited.cartLabel).toBe(
1333
+ enUS.header.cartMany.replace('{count}', String(SEEDED_CART_QUANTITY))
1334
+ );
1335
+ });
1336
+ });
1337
+
1338
+ /**
1339
+ * The facets a visitor arrives with, on a generated page.
1340
+ *
1341
+ * `app/storefront/facets.ts` filters the gateway's results, and the block reads `price` off the
1342
+ * storefront route — and none of that reached a deployed site, because on a
1343
+ * prerendered page the URL's query is not in the route the block is built under. Nuxt hydrates a
1344
+ * prerendered route under the **payload's** path (`hasDeferredRoute` in its own router plugin:
1345
+ * the query arrives only after `app:suspense:resolve`), so the block seeded its filter state from
1346
+ * an empty query, kept it forever, and the page stayed exactly as the build wrote it: all seven
1347
+ * products, "7 products", both price inputs blank, and not one catalog request but the volatile
1348
+ * batch.
1349
+ *
1350
+ * Both halves are asserted here rather than in a mounted spec, because a mounted spec hands the
1351
+ * block a route object with the filters already on it — which is precisely the thing that does
1352
+ * not happen on a generated page.
1353
+ */
1354
+ describe('collection facets from the URL', () => {
1355
+ /** 42, 52 and 44 of the seven — the prices `test/support/mockGateway.ts` seeds. The range is
1356
+ * in major units, so it reads the same whatever the store's currency is. */
1357
+ const IN_RANGE = ['Ash glaze mug', 'Brass candle holder', 'Linen napkin set'];
1358
+ /** The seven products' own span (18–68), which is what the unfiltered thumbs sit at. */
1359
+ const SPAN = ['18', '68'];
1360
+
1361
+ it('renders the filtered set on a hard load, with the range in the inputs', async () => {
1362
+ const visited = await visitCollection(`${collectionPage}/?price=40-60`);
1363
+
1364
+ expect(visited.grid.titles).toEqual(IN_RANGE);
1365
+ expect(visited.grid.count).toBe(enUS.grid.nProducts.replace('{count}', '3'));
1366
+ expect(visited.grid.price).toEqual(['40', '60']);
1367
+ // The build's payload holds the *unfiltered* result, so a filtered view has to read live —
1368
+ // under a key of its own (the filters are part of it), which is what makes it miss the
1369
+ // payload rather than silently reuse it. The range goes out as the endpoint's own
1370
+ // `minPrice`/`maxPrice` (minor units, and this store sells in krónur, which have none), and
1371
+ // `facets=true` is what fills the panel's groups.
1372
+ const read = visited.requests.find((request) =>
1373
+ request.startsWith(`/catalog/v1/collections/${COLLECTION_HANDLE}/products`)
1374
+ );
1375
+ expect(read).toBeDefined();
1376
+ const sent = new URL(read!, statics.origin).searchParams;
1377
+ expect(sent.get('minPrice')).toBe('40');
1378
+ expect(sent.get('maxPrice')).toBe('60');
1379
+ expect(sent.get('facets')).toBe('true');
1380
+ // The server rendered the unfiltered page; the client applies the query after mounting, so
1381
+ // the first paint is still the server's and Vue has nothing to complain about.
1382
+ expect(visited.warnings).toEqual([]);
1383
+ expect(visited.url).toBe(`${statics.origin}${collectionPage}/?price=40-60`);
1384
+ });
1385
+
1386
+ it('re-reads and re-renders when the query changes under the block', async () => {
1387
+ gateway.reset();
1388
+ const page = await browser.newPage();
1389
+ const warnings: string[] = [];
1390
+ page.on('console', (message) => {
1391
+ const text = message.text();
1392
+ if (/hydrat|mismatch/i.test(text) || message.type() === 'error') {
1393
+ warnings.push(`${message.type()}: ${text.slice(0, 200)}`);
1394
+ }
1395
+ });
1396
+ page.on('pageerror', (error) => warnings.push(`pageerror: ${error.message.slice(0, 200)}`));
1397
+ try {
1398
+ await page.goto(`${statics.origin}${collectionPage}`, { waitUntil: 'domcontentloaded' });
1399
+ await page.waitForTimeout(CATALOG_DELAY_MS + 1500);
1400
+ const before = await readGrid(page);
1401
+ expect(before.titles).toHaveLength(7);
1402
+ expect(before.price).toEqual(SPAN);
1403
+
1404
+ gateway.reset();
1405
+ await page.evaluate(
1406
+ (to) =>
1407
+ (window as unknown as { __eldraPush: (path: string) => Promise<unknown> }).__eldraPush(
1408
+ to
1409
+ ),
1410
+ `${collectionPage}?price=40-60`
1411
+ );
1412
+ await page.waitForTimeout(CATALOG_DELAY_MS + 2500);
1413
+
1414
+ const after = await readGrid(page);
1415
+ expect(after.titles).toEqual(IN_RANGE);
1416
+ expect(after.count).toBe(enUS.grid.nProducts.replace('{count}', '3'));
1417
+ expect(after.price).toEqual(['40', '60']);
1418
+ const requests = gateway.requests.map((request) => decodeURIComponent(request));
1419
+ expect(
1420
+ requests.some((request) =>
1421
+ request.startsWith(`/catalog/v1/collections/${COLLECTION_HANDLE}/products`)
1422
+ )
1423
+ ).toBe(true);
1424
+ expect(page.url()).toBe(`${statics.origin}${collectionPage}?price=40-60`);
1425
+ expect(warnings).toEqual([]);
1426
+ } finally {
1427
+ await page.close();
1428
+ }
1429
+ });
1430
+ });
1431
+ });