@eldrajs/theme-cli 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (483) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/LICENSE +21 -0
  3. package/README.md +27 -2
  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-C6jB8_Oc.js +510 -0
  9. package/package.json +56 -3
  10. package/template/.eldra/block-types.d.ts +429 -0
  11. package/template/.eldra/manifest.json +9377 -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 +52 -0
  20. package/template/.storybook/shims-vue.d.ts +10 -0
  21. package/template/.storybook/virtual-eldra.d.ts +27 -0
  22. package/template/README.md +288 -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 +247 -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 +1495 -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 +148 -0
  280. package/template/package.json +55 -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/demo/article-cover.svg +1 -0
  291. package/template/public/demo/article-figure.svg +1 -0
  292. package/template/public/demo/avatar-1.svg +3 -0
  293. package/template/public/demo/avatar-2.svg +3 -0
  294. package/template/public/demo/avatar-3.svg +3 -0
  295. package/template/public/demo/avatar-4.svg +3 -0
  296. package/template/public/demo/avatar-5.svg +3 -0
  297. package/template/public/demo/avatar-6.svg +3 -0
  298. package/template/public/demo/avatar-7.svg +3 -0
  299. package/template/public/demo/avatar-8.svg +3 -0
  300. package/template/public/demo/collection-1.svg +1 -0
  301. package/template/public/demo/collection-2.svg +1 -0
  302. package/template/public/demo/cta-split.svg +1 -0
  303. package/template/public/demo/feature-1.svg +1 -0
  304. package/template/public/demo/feature-2.svg +1 -0
  305. package/template/public/demo/feature-3.svg +1 -0
  306. package/template/public/demo/feature-4.svg +1 -0
  307. package/template/public/demo/gallery-1.svg +1 -0
  308. package/template/public/demo/gallery-2.svg +1 -0
  309. package/template/public/demo/gallery-3.svg +1 -0
  310. package/template/public/demo/gallery-4.svg +1 -0
  311. package/template/public/demo/gallery-5.svg +1 -0
  312. package/template/public/demo/gallery-6.svg +1 -0
  313. package/template/public/demo/gallery-7.svg +1 -0
  314. package/template/public/demo/gallery-8.svg +1 -0
  315. package/template/public/demo/hero-slide-1.svg +1 -0
  316. package/template/public/demo/hero-slide-2.svg +1 -0
  317. package/template/public/demo/hero-slide-3.svg +1 -0
  318. package/template/public/demo/hero-slide-4.svg +1 -0
  319. package/template/public/demo/hero-wide.svg +1 -0
  320. package/template/public/demo/hero.svg +1 -0
  321. package/template/public/demo/logo-1.svg +4 -0
  322. package/template/public/demo/logo-2.svg +4 -0
  323. package/template/public/demo/logo-3.svg +4 -0
  324. package/template/public/demo/logo-4.svg +4 -0
  325. package/template/public/demo/logo-5.svg +4 -0
  326. package/template/public/demo/logo-6.svg +4 -0
  327. package/template/public/demo/logo-7.svg +4 -0
  328. package/template/public/demo/logo-8.svg +4 -0
  329. package/template/public/demo/logo.svg +3 -0
  330. package/template/public/demo/map.svg +1 -0
  331. package/template/public/demo/poster.svg +1 -0
  332. package/template/public/demo/product-1.svg +4 -0
  333. package/template/public/demo/product-10.svg +4 -0
  334. package/template/public/demo/product-11.svg +4 -0
  335. package/template/public/demo/product-12.svg +4 -0
  336. package/template/public/demo/product-2.svg +4 -0
  337. package/template/public/demo/product-3.svg +4 -0
  338. package/template/public/demo/product-4.svg +4 -0
  339. package/template/public/demo/product-5.svg +4 -0
  340. package/template/public/demo/product-6.svg +4 -0
  341. package/template/public/demo/product-7.svg +4 -0
  342. package/template/public/demo/product-8.svg +4 -0
  343. package/template/public/demo/product-9.svg +4 -0
  344. package/template/public/demo/product-square-1.svg +4 -0
  345. package/template/public/demo/product-square-2.svg +4 -0
  346. package/template/public/demo/product-square-3.svg +4 -0
  347. package/template/public/demo/product-square-4.svg +4 -0
  348. package/template/public/demo/product-square-5.svg +4 -0
  349. package/template/public/demo/product-square-6.svg +4 -0
  350. package/template/public/demo/quote-portrait.svg +4 -0
  351. package/template/public/demo/split-1.svg +1 -0
  352. package/template/public/demo/split-2.svg +1 -0
  353. package/template/public/demo/split-3.svg +1 -0
  354. package/template/public/demo/split-4.svg +1 -0
  355. package/template/public/demo/team-1.svg +4 -0
  356. package/template/public/demo/team-2.svg +4 -0
  357. package/template/public/demo/team-3.svg +4 -0
  358. package/template/public/demo/team-4.svg +4 -0
  359. package/template/scripts/demo-images.mjs +393 -0
  360. package/template/scripts/generate-stories.mjs +156 -0
  361. package/template/scripts/previewHash.mjs +125 -0
  362. package/template/scripts/previews.mjs +149 -0
  363. package/template/stories/generated/announcement-bar.stories.ts +44 -0
  364. package/template/stories/generated/article-list.stories.ts +87 -0
  365. package/template/stories/generated/article.stories.ts +27 -0
  366. package/template/stories/generated/breadcrumbs.stories.ts +39 -0
  367. package/template/stories/generated/cart.stories.ts +38 -0
  368. package/template/stories/generated/collection-grid.stories.ts +117 -0
  369. package/template/stories/generated/collection-header.stories.ts +51 -0
  370. package/template/stories/generated/contact.stories.ts +45 -0
  371. package/template/stories/generated/cta.stories.ts +51 -0
  372. package/template/stories/generated/faq.stories.ts +56 -0
  373. package/template/stories/generated/feature-grid.stories.ts +69 -0
  374. package/template/stories/generated/footer.stories.ts +50 -0
  375. package/template/stories/generated/gallery.stories.ts +81 -0
  376. package/template/stories/generated/hero.stories.ts +75 -0
  377. package/template/stories/generated/image.stories.ts +99 -0
  378. package/template/stories/generated/logo-cloud.stories.ts +57 -0
  379. package/template/stories/generated/navigation.stories.ts +62 -0
  380. package/template/stories/generated/newsletter.stories.ts +68 -0
  381. package/template/stories/generated/order-status.stories.ts +32 -0
  382. package/template/stories/generated/pricing-table.stories.ts +44 -0
  383. package/template/stories/generated/product-carousel.stories.ts +75 -0
  384. package/template/stories/generated/product-detail.stories.ts +62 -0
  385. package/template/stories/generated/quote.stories.ts +69 -0
  386. package/template/stories/generated/rich-text.stories.ts +50 -0
  387. package/template/stories/generated/search.stories.ts +56 -0
  388. package/template/stories/generated/split-content.stories.ts +39 -0
  389. package/template/stories/generated/stats.stories.ts +68 -0
  390. package/template/stories/generated/tabs.stories.ts +45 -0
  391. package/template/stories/generated/team.stories.ts +45 -0
  392. package/template/stories/generated/testimonials.stories.ts +69 -0
  393. package/template/stories/generated/timeline.stories.ts +80 -0
  394. package/template/stories/generated/trust-strip.stories.ts +62 -0
  395. package/template/stories/generated/video-embed.stories.ts +63 -0
  396. package/template/stories/generated/wishlist.stories.ts +26 -0
  397. package/template/stories/pages/article.stories.ts +51 -0
  398. package/template/stories/pages/cart.stories.ts +56 -0
  399. package/template/stories/pages/category.stories.ts +56 -0
  400. package/template/stories/pages/collection.stories.ts +51 -0
  401. package/template/stories/pages/home.stories.ts +51 -0
  402. package/template/stories/pages/product.stories.ts +47 -0
  403. package/template/stories/pages/products.stories.ts +58 -0
  404. package/template/stories/pages/search.stories.ts +54 -0
  405. package/template/stories/pages/wishlist.stories.ts +53 -0
  406. package/template/stories/support/pageBlocks.ts +115 -0
  407. package/template/test/blocksEmptyData.spec.ts +52 -0
  408. package/template/test/carouselKeyboard.spec.ts +272 -0
  409. package/template/test/carouselRing.browser.spec.ts +193 -0
  410. package/template/test/carouselSlideWidth.browser.spec.ts +102 -0
  411. package/template/test/cartDrawer.spec.ts +295 -0
  412. package/template/test/cartToast.spec.ts +86 -0
  413. package/template/test/countPill.browser.spec.ts +196 -0
  414. package/template/test/demoImages.spec.ts +140 -0
  415. package/template/test/deps.spec.ts +102 -0
  416. package/template/test/eldraIcon.spec.ts +58 -0
  417. package/template/test/framing.spec.ts +76 -0
  418. package/template/test/i18n.spec.ts +200 -0
  419. package/template/test/iconComponent.spec.ts +91 -0
  420. package/template/test/inlineEditable.spec.ts +334 -0
  421. package/template/test/localePrefix.spec.ts +342 -0
  422. package/template/test/mainCss.spec.ts +107 -0
  423. package/template/test/mockGatewayContract.spec.ts +122 -0
  424. package/template/test/mocks/blocks.ts +20 -0
  425. package/template/test/mocks/breakpoints.ts +7 -0
  426. package/template/test/mocks/manifest.ts +11 -0
  427. package/template/test/moneyFormatting.spec.ts +89 -0
  428. package/template/test/pageTitle.spec.ts +49 -0
  429. package/template/test/pages/article.spec.ts +231 -0
  430. package/template/test/pages/category.spec.ts +185 -0
  431. package/template/test/pages/collection.spec.ts +396 -0
  432. package/template/test/pages/home.spec.ts +295 -0
  433. package/template/test/pages/hydration.spec.ts +557 -0
  434. package/template/test/pages/product.spec.ts +396 -0
  435. package/template/test/pages/seededPages.spec.ts +190 -0
  436. package/template/test/pages/ssr.spec.ts +393 -0
  437. package/template/test/prerenderCommerce.spec.ts +134 -0
  438. package/template/test/prerenderFailure.spec.ts +130 -0
  439. package/template/test/prerenderRefresh.browser.spec.ts +1431 -0
  440. package/template/test/previewsFresh.spec.ts +56 -0
  441. package/template/test/richText.spec.ts +161 -0
  442. package/template/test/richTextTypography.spec.ts +182 -0
  443. package/template/test/setup.ts +21 -0
  444. package/template/test/slugPage.spec.ts +244 -0
  445. package/template/test/slugPageTemplate.spec.ts +194 -0
  446. package/template/test/starter.spec.ts +1416 -0
  447. package/template/test/storefront/cart.spec.ts +404 -0
  448. package/template/test/storefront/categories.spec.ts +235 -0
  449. package/template/test/storefront/collectionSelector.spec.ts +74 -0
  450. package/template/test/storefront/demo.spec.ts +555 -0
  451. package/template/test/storefront/facets.spec.ts +425 -0
  452. package/template/test/storefront/feedback.spec.ts +97 -0
  453. package/template/test/storefront/gateway.spec.ts +2673 -0
  454. package/template/test/storefront/gatewayCart.spec.ts +289 -0
  455. package/template/test/storefront/gatewayPrerender.spec.ts +1037 -0
  456. package/template/test/storefront/history.spec.ts +341 -0
  457. package/template/test/storefront/money.spec.ts +171 -0
  458. package/template/test/storefront/toProductCard.spec.ts +138 -0
  459. package/template/test/storefront/volatile.spec.ts +284 -0
  460. package/template/test/support/axe.ts +14 -0
  461. package/template/test/support/dialog.ts +51 -0
  462. package/template/test/support/hydrate.ts +118 -0
  463. package/template/test/support/i18nText.ts +11 -0
  464. package/template/test/support/mockGateway.ts +1017 -0
  465. package/template/test/support/mountBlock.ts +194 -0
  466. package/template/test/support/mountPage.spec.ts +72 -0
  467. package/template/test/support/mountPage.ts +254 -0
  468. package/template/test/support/mountProbe.client.ts +69 -0
  469. package/template/test/support/renderSsr.ts +97 -0
  470. package/template/test/support/staticServer.ts +96 -0
  471. package/template/test/themeIcons.spec.ts +140 -0
  472. package/template/test/toastAnnouncement.spec.ts +133 -0
  473. package/template/test/tokens.spec.ts +102 -0
  474. package/template/test/uiMessagesPlugin.spec.ts +104 -0
  475. package/template/test/useBlockData.spec.ts +46 -0
  476. package/template/test/useEditing.spec.ts +54 -0
  477. package/template/test/useEldraIcon.spec.ts +126 -0
  478. package/template/test/useUiId.spec.ts +40 -0
  479. package/template/tokens.json +149 -0
  480. package/template/tsconfig.json +3 -0
  481. package/template/tsconfig.storybook.json +17 -0
  482. package/template/vitest-axe.d.ts +13 -0
  483. package/template/vitest.config.ts +44 -0
@@ -0,0 +1,557 @@
1
+ // @vitest-environment jsdom
2
+ //
3
+ // The prerendered page's other half. `test/pages/ssr.spec.ts` proves the server writes real prices
4
+ // and stock lines; this file proves the **browser's first render is that same markup**, which is the
5
+ // half a commerce block can break on its own.
6
+ //
7
+ // It can, because the storefront result is not in the same state on both sides. On a hydrating
8
+ // client `createGatewayResult` (`app/storefront/gateway.ts`) raises `loading` synchronously, fills
9
+ // `data` from the hydration payload in the same turn, and only clears `loading` after
10
+ // `await handle.settled` — so `loading && data !== null` is *true* during the first client render
11
+ // and was false during the render it has to match. A block that draws its refresh treatment
12
+ // straight off that (dimmed values, spinners, `aria-busy`, "Updating…") paints a busy page over a
13
+ // calm one: Vue patches the difference, logs a hydration warning, and the visitor sees the block
14
+ // repaint on arrival. `app/composables/useRevalidating.ts` is the fix — every flag it returns is
15
+ // false until `onMounted`, which never runs on the server and runs after the first client render.
16
+ import { describe, expect, it, afterEach } from 'vitest';
17
+ import { nextTick, onServerPrefetch, ref, type Ref } from 'vue';
18
+ import type { Component } from 'vue';
19
+ import type { EldraClient } from '@eldrajs/sdk';
20
+ import Navigation from '../../blocks/navigation/Block.vue';
21
+ import navigationMock from '../../blocks/navigation/mock.json';
22
+ import ProductDetail from '../../blocks/product-detail/Block.vue';
23
+ import productDetailMock from '../../blocks/product-detail/mock.json';
24
+ import ProductCarousel from '../../blocks/product-carousel/Block.vue';
25
+ import productCarouselMock from '../../blocks/product-carousel/mock.json';
26
+ import CollectionGrid from '../../blocks/collection-grid/Block.vue';
27
+ import collectionGridMock from '../../blocks/collection-grid/mock.json';
28
+ import Search from '../../blocks/search/Block.vue';
29
+ import searchMock from '../../blocks/search/mock.json';
30
+ import Wishlist from '../../blocks/wishlist/Block.vue';
31
+ import wishlistMock from '../../blocks/wishlist/mock.json';
32
+ import { createDemoStorefront } from '../../app/storefront/demo';
33
+ import { createGatewayStorefront, type StorefrontRuntime } from '../../app/storefront/gateway';
34
+ import { STOREFRONT_KEY } from '../../app/storefront/types';
35
+ import type {
36
+ StorefrontResult,
37
+ StorefrontRoute,
38
+ StorefrontSource,
39
+ VolatileKey,
40
+ } from '../../app/storefront/types';
41
+ import enUS from '../../i18n/en-US.json';
42
+ import {
43
+ hydrateBlock,
44
+ hydrationWarnings,
45
+ renderBlockHtml,
46
+ type BlockEntry,
47
+ type HydrationRun,
48
+ } from '../support/hydrate';
49
+
50
+ const runs: HydrationRun[] = [];
51
+ afterEach(() => {
52
+ for (const run of runs.splice(0)) run.unmount();
53
+ // The wishlist cases below put a saved list in `localStorage`, which jsdom keeps for the file.
54
+ localStorage.clear();
55
+ });
56
+
57
+ /** Where the wishlist keeps a shopper's saved handles (`app/storefront/history.ts`). */
58
+ const WISHLIST_KEY = 'eldra.storefront.wishlist';
59
+
60
+ /**
61
+ * A result in the shape `createGatewayResult` hands a block, with the two states that differ
62
+ * between the two renders under the caller's control: `loading` (true while hydrating, until the
63
+ * prerendered read settles) and `revalidating` (raised by the volatile refresh a moment after
64
+ * mount).
65
+ */
66
+ function gatewayShaped<T>(
67
+ value: T,
68
+ options: { loading?: boolean } = {}
69
+ ): {
70
+ result: StorefrontResult<T>;
71
+ loading: Ref<boolean>;
72
+ revalidating: Ref<ReadonlySet<VolatileKey>>;
73
+ } {
74
+ const loading = ref(options.loading ?? false);
75
+ const revalidating = ref<ReadonlySet<VolatileKey>>(new Set());
76
+ const result = {
77
+ data: ref(value),
78
+ pending: ref(false),
79
+ loading,
80
+ error: ref(null),
81
+ revalidating,
82
+ refresh: async () => {},
83
+ } as unknown as StorefrontResult<T>;
84
+ return { result, loading, revalidating };
85
+ }
86
+
87
+ /** The demo catalogue's own answer for one read, settled — the "payload" both renders share. */
88
+ async function demoValue<T>(pick: (source: StorefrontSource) => StorefrontResult<T>): Promise<T> {
89
+ const result = pick(createDemoStorefront());
90
+ await nextTick();
91
+ await nextTick();
92
+ return result.data.value as T;
93
+ }
94
+
95
+ interface Subject {
96
+ name: string;
97
+ component: Component;
98
+ entry: BlockEntry;
99
+ /** The settled value, read once from the demo catalogue. */
100
+ value: () => Promise<unknown>;
101
+ /** A storefront whose one relevant read answers with `result`. */
102
+ storefront: (result: StorefrontResult<never>) => StorefrontSource;
103
+ }
104
+
105
+ const SUBJECTS: Subject[] = [
106
+ {
107
+ name: 'product-detail',
108
+ component: ProductDetail,
109
+ entry: { id: 'h-detail', data: productDetailMock as unknown as Record<string, unknown> },
110
+ value: () => demoValue((source) => source.catalog.product(ref('merino-crew-sweater'))),
111
+ storefront: (result) => {
112
+ const base = createDemoStorefront();
113
+ return { ...base, catalog: { ...base.catalog, product: () => result } };
114
+ },
115
+ },
116
+ {
117
+ name: 'product-carousel',
118
+ component: ProductCarousel,
119
+ entry: { id: 'h-carousel', data: productCarouselMock as unknown as Record<string, unknown> },
120
+ value: () => demoValue((source) => source.catalog.related(ref('merino-crew-sweater'), 8)),
121
+ storefront: (result) => {
122
+ const base = createDemoStorefront();
123
+ return { ...base, catalog: { ...base.catalog, related: () => result } };
124
+ },
125
+ },
126
+ {
127
+ name: 'collection-grid',
128
+ component: CollectionGrid,
129
+ entry: { id: 'h-grid', data: collectionGridMock as unknown as Record<string, unknown> },
130
+ value: () =>
131
+ demoValue((source) =>
132
+ source.catalog.collectionProducts(
133
+ ref({ slug: 'winter-knitwear' }),
134
+ ref({ page: 1, pageSize: 24 })
135
+ )
136
+ ),
137
+ storefront: (result) => {
138
+ const base = createDemoStorefront();
139
+ return { ...base, catalog: { ...base.catalog, collectionProducts: () => result } };
140
+ },
141
+ },
142
+ ];
143
+
144
+ /**
145
+ * `@eldrajs/ui`'s `Carousel` decorates its slides **imperatively after mount** — `useCarousel.ts`
146
+ * `setAttribute`s `data-part="slide"`, `role="group"`, `aria-roledescription="slide"` and an
147
+ * "n of total" label onto whatever children the consumer passed, adds the `eldra-carousel-slide`
148
+ * sizing class, and writes the roving tab stop's `tabindex` (one stop for the whole row, on the
149
+ * active slide; every other slide's controls parked at `-1`) — precisely so a block can hand it
150
+ * plain elements. That is a deliberate progressive enhancement of the package's, not a render the
151
+ * server disagreed with (Vue reports no mismatch for any of it), and `product-detail`'s gallery and
152
+ * `product-carousel`'s row both go through it. The `tabindex` pass is the same kind of thing as the
153
+ * labelling: the server renders the pre-enhancement shape, the first client render matches it
154
+ * exactly, and the model only moves in `onMounted` afterwards — which is why removing it from both
155
+ * sides leaves the comparison below an honest one.
156
+ *
157
+ * **The `tabindex` removal is scoped to the carousel's own track**, through a parse rather than the
158
+ * regex the other four tokens use: `tabindex` is an ordinary attribute a block writes for itself —
159
+ * `collection-grid`, one of the subjects here, renders a `tabindex="-1"` status line and no
160
+ * `Carousel` at all — and a blanket strip would quietly delete that block's own markup from both
161
+ * halves of the comparison, which is exactly the kind of difference this spec exists to catch. Only
162
+ * attributes inside `[data-part="track"]` go, so what is left really is the *block's* own markup.
163
+ * Nothing in `blocks/**` writes any of the other four.
164
+ */
165
+ const CAROUSEL_ENHANCEMENT =
166
+ /\s(?:data-part="slide"|role="group"|aria-roledescription="slide"|aria-label="\d+ of \d+")|\seldra-carousel-slide|eldra-carousel-slide\s/g;
167
+
168
+ function withoutPackageEnhancement(html: string): string {
169
+ // Both halves go through the same parse, so any normalisation the parser does of its own
170
+ // (attribute quoting, void elements) cancels out and a real difference still shows.
171
+ const doc = new DOMParser().parseFromString(`<body>${html}</body>`, 'text/html');
172
+ for (const el of doc.querySelectorAll('[data-part="track"] [tabindex]')) {
173
+ el.removeAttribute('tabindex');
174
+ }
175
+ return doc.body.innerHTML.replace(CAROUSEL_ENHANCEMENT, '');
176
+ }
177
+
178
+ /** A route with a product handle on it, the way the slug page fills one in. */
179
+ function routeFor(handle: string): StorefrontRoute {
180
+ return {
181
+ productHandle: handle,
182
+ collectionHandle: null,
183
+ orderToken: null,
184
+ query: null,
185
+ page: 1,
186
+ sort: null,
187
+ columns: null,
188
+ filters: {},
189
+ setQuery: () => {},
190
+ };
191
+ }
192
+
193
+ /**
194
+ * The **real** gateway storefront on both sides of a prerendered not-found page, with the storefront
195
+ * runtime standing in for the framework's keyed async data at the one boundary that differs between
196
+ * the two renders (`StorefrontPrerenderHandle`):
197
+ *
198
+ * * the server's read ran and answered nothing — no value in hand yet, the render waits for it
199
+ * (`onServerPrefetch`, which is what `useAsyncData` registers);
200
+ * * the browser reads that same answer back out of the page payload, where it is a settled
201
+ * `null` — `{ data: null }`, not "no answer yet".
202
+ *
203
+ * Every state the block then branches on is `createGatewayResult`'s own.
204
+ */
205
+ function gatewayStorefront(handle: string, half: 'server' | 'client'): StorefrontSource {
206
+ const settled = Promise.resolve({ data: null, error: null });
207
+ const runtime: StorefrontRuntime = {
208
+ prerender: () => {
209
+ if (half === 'server') {
210
+ onServerPrefetch(() => settled);
211
+ return { answered: null, settled };
212
+ }
213
+ return { answered: { data: null }, settled };
214
+ },
215
+ };
216
+ // Never called: the read is answered by the runtime on both sides, which is the point.
217
+ const client = { catalog: {}, checkout: { url: async () => '' } } as unknown as EldraClient;
218
+ return createGatewayStorefront(client, { route: routeFor(handle), runtime });
219
+ }
220
+
221
+ describe('hydrating a prerendered commerce block', () => {
222
+ /**
223
+ * The general rule, and the regression guard the review asked for: server render and first client
224
+ * render of the same block over the same prerendered data must be the same markup — with the
225
+ * client's result in the state a hydrating page actually puts it in, `loading` still true.
226
+ *
227
+ * "First client render" is the DOM straight after `app.mount()` on a `createSSRApp` over the
228
+ * server's own HTML: a real hydration, not a re-render. `onMounted` runs inside that mount but the
229
+ * render it schedules is queued, so this is genuinely the paint a visitor sees first.
230
+ *
231
+ * Two assertions, and the first is the load-bearing one: Vue's own hydration warnings. An
232
+ * attribute mismatch is patched in place during hydration, so the two strings would agree
233
+ * *afterwards* — only the warning says it happened. The string equality then catches anything Vue
234
+ * accepts silently.
235
+ */
236
+ it.each(SUBJECTS.map((subject) => [subject.name, subject] as const))(
237
+ '%s renders the same markup on the server and on the browser’s first paint',
238
+ async (_name, subject) => {
239
+ const value = await subject.value();
240
+
241
+ const server = gatewayShaped(value);
242
+ const html = await renderBlockHtml(subject.component, subject.entry, {
243
+ [STOREFRONT_KEY]: subject.storefront(server.result as StorefrontResult<never>),
244
+ });
245
+
246
+ // The hydrating client: same data, `loading` still true — exactly what `gateway.ts` leaves
247
+ // behind between the payload assignment and `await handle.settled`.
248
+ const client = gatewayShaped(value, { loading: true });
249
+ const run = hydrateBlock(subject.component, subject.entry, html, {
250
+ [STOREFRONT_KEY]: subject.storefront(client.result as StorefrontResult<never>),
251
+ });
252
+ runs.push(run);
253
+
254
+ expect(hydrationWarnings(run)).toEqual([]);
255
+ expect(withoutPackageEnhancement(run.firstPaint)).toBe(
256
+ withoutPackageEnhancement(run.expected)
257
+ );
258
+ }
259
+ );
260
+
261
+ /**
262
+ * The same run, read as behaviour rather than as equality: nothing of the refresh treatment is in
263
+ * the first paint, and all of it arrives on the tick after mount while the read is still in
264
+ * flight. Both halves matter — the first is the hydration contract, the second is that gating the
265
+ * flag did not simply turn the treatment off.
266
+ *
267
+ * **What the grid draws for a whole read is its own opacity pulse, not the per-card
268
+ * treatment.** `collection-grid` pulses the card list itself (`animate-eldra-pulse-soft`,
269
+ * 0.7 ↔ 0.9) and keeps the dimmed-value-and-spinner treatment for the volatile price/stock
270
+ * refresh alone — two indicators for one state read as the page stuttering, and the pulse is the
271
+ * one the shopper can actually see from across a 24-card grid. So `eldra-revalidating` and the
272
+ * block's own "Updating prices and stock" region belong to the *other* state here, and the test
273
+ * that proves they still work for it is the volatile one below.
274
+ */
275
+ it('shows no refresh treatment until after mount, then shows it while the read is in flight', async () => {
276
+ const subject = SUBJECTS[2]!; // collection-grid: cards, a busy grid and a count line in one
277
+ const value = await subject.value();
278
+
279
+ const server = gatewayShaped(value);
280
+ const html = await renderBlockHtml(subject.component, subject.entry, {
281
+ [STOREFRONT_KEY]: subject.storefront(server.result as StorefrontResult<never>),
282
+ });
283
+ expect(html).not.toContain('aria-busy');
284
+ expect(html).not.toContain('eldra-revalidating');
285
+ expect(html).not.toContain('animate-eldra-pulse-soft');
286
+ expect(html).not.toContain(enUS.grid.updating);
287
+
288
+ const client = gatewayShaped(value, { loading: true });
289
+ const run = hydrateBlock(subject.component, subject.entry, html, {
290
+ [STOREFRONT_KEY]: subject.storefront(client.result as StorefrontResult<never>),
291
+ });
292
+ runs.push(run);
293
+
294
+ expect(run.firstPaint).not.toContain('aria-busy');
295
+ expect(run.firstPaint).not.toContain('eldra-revalidating');
296
+ expect(run.firstPaint).not.toContain('animate-eldra-pulse-soft');
297
+ expect(run.firstPaint).not.toContain('data-part="spinner"');
298
+ expect(run.firstPaint).not.toContain(enUS.grid.updating);
299
+ expect(run.firstPaint).not.toContain(enUS.storefront.updatingValues);
300
+
301
+ await nextTick();
302
+
303
+ // `loading` has not changed — only `onMounted` has run. The treatment is the block's, not the
304
+ // storefront's.
305
+ expect(client.loading.value).toBe(true);
306
+ expect(run.container.innerHTML).toContain('aria-busy="true"');
307
+ expect(run.container.innerHTML).toContain('animate-eldra-pulse-soft');
308
+ expect(run.container.innerHTML).toContain(enUS.grid.updating);
309
+ // The cards underneath are left alone: one indicator, not two (see the note above).
310
+ expect(run.container.innerHTML).not.toContain('eldra-revalidating');
311
+ expect(run.container.innerHTML).not.toContain(enUS.storefront.updatingValues);
312
+
313
+ // And it clears when the prerendered read finally settles.
314
+ client.loading.value = false;
315
+ await nextTick();
316
+ expect(run.container.innerHTML).not.toContain('aria-busy="true"');
317
+ expect(run.container.innerHTML).not.toContain('animate-eldra-pulse-soft');
318
+ expect(run.container.innerHTML).not.toContain('eldra-revalidating');
319
+ });
320
+
321
+ /**
322
+ * The grid's *other* refresh state, on the same block: the volatile price/stock re-read, which
323
+ * is not a whole read over the list and therefore keeps the per-card treatment and the block's
324
+ * one polite region. This is the half the pulse must not have taken with it.
325
+ */
326
+ it('keeps the grid’s per-card treatment for the volatile refresh', async () => {
327
+ const subject = SUBJECTS[2]!;
328
+ const value = await subject.value();
329
+
330
+ const server = gatewayShaped(value);
331
+ const html = await renderBlockHtml(subject.component, subject.entry, {
332
+ [STOREFRONT_KEY]: subject.storefront(server.result as StorefrontResult<never>),
333
+ });
334
+
335
+ const client = gatewayShaped(value);
336
+ client.revalidating.value = new Set<VolatileKey>(['price', 'stock']);
337
+ const run = hydrateBlock(subject.component, subject.entry, html, {
338
+ [STOREFRONT_KEY]: subject.storefront(client.result as StorefrontResult<never>),
339
+ });
340
+ runs.push(run);
341
+
342
+ expect(run.firstPaint).not.toContain('eldra-revalidating');
343
+
344
+ await nextTick();
345
+
346
+ expect(run.container.innerHTML).toContain('eldra-revalidating');
347
+ expect(run.container.innerHTML).toContain(enUS.storefront.updatingValues);
348
+ // No whole read is in flight, so the list does not pulse and the count still reads a number.
349
+ expect(run.container.innerHTML).not.toContain('animate-eldra-pulse-soft');
350
+ expect(run.container.innerHTML).not.toContain(enUS.grid.updating);
351
+ });
352
+
353
+ /** The volatile refresh itself is gated by the same flag, on the same first paint. */
354
+ it('keeps a revalidating volatile set out of the first paint too', async () => {
355
+ const subject = SUBJECTS[0]!; // product-detail: one price, one stock line
356
+ const value = await subject.value();
357
+
358
+ const server = gatewayShaped(value);
359
+ const html = await renderBlockHtml(subject.component, subject.entry, {
360
+ [STOREFRONT_KEY]: subject.storefront(server.result as StorefrontResult<never>),
361
+ });
362
+
363
+ const client = gatewayShaped(value);
364
+ client.revalidating.value = new Set<VolatileKey>(['price', 'stock']);
365
+ const run = hydrateBlock(subject.component, subject.entry, html, {
366
+ [STOREFRONT_KEY]: subject.storefront(client.result as StorefrontResult<never>),
367
+ });
368
+ runs.push(run);
369
+
370
+ expect(hydrationWarnings(run)).toEqual([]);
371
+ expect(run.firstPaint).not.toContain('eldra-revalidating');
372
+
373
+ await nextTick();
374
+ expect(run.container.innerHTML).toContain('eldra-revalidating');
375
+ });
376
+ /**
377
+ * A prerendered page outlives its catalogue, so a read that answers *nothing* is a real
378
+ * prerendered state: the server writes "this product is no longer available" with nothing
379
+ * pending. The browser has to start from that same answer. It did not — the payload's `null` was
380
+ * indistinguishable from "no answer yet", so the hydrating result stayed `pending` and the first
381
+ * client paint was the loading line over the server's not-found line.
382
+ */
383
+ it('product-detail hydrates a prerendered not-found page as not found, not as loading', async () => {
384
+ const entry: BlockEntry = {
385
+ id: 'h-gone',
386
+ data: { ...(productDetailMock as unknown as Record<string, unknown>), productHandle: '' },
387
+ };
388
+
389
+ const html = await renderBlockHtml(ProductDetail, entry, {
390
+ [STOREFRONT_KEY]: gatewayStorefront('gone-for-good', 'server'),
391
+ });
392
+ expect(html).toContain(enUS.storefront.notFound);
393
+ expect(html).not.toContain(enUS.storefront.loading);
394
+
395
+ const run = hydrateBlock(ProductDetail, entry, html, {
396
+ [STOREFRONT_KEY]: gatewayStorefront('gone-for-good', 'client'),
397
+ });
398
+ runs.push(run);
399
+
400
+ expect(hydrationWarnings(run)).toEqual([]);
401
+ expect(run.firstPaint).toContain(enUS.storefront.notFound);
402
+ expect(run.firstPaint).not.toContain(enUS.storefront.loading);
403
+ expect(withoutPackageEnhancement(run.firstPaint)).toBe(withoutPackageEnhancement(run.expected));
404
+ });
405
+
406
+ /**
407
+ * `/search` is the one route whose prerendered file answers *every* URL: a static host serves the
408
+ * same `search/index.html` for `/search` and for `/search?q=linen`, so the markup it ships knows
409
+ * no query at all (`pages/search.page.json` seeds that page). The browser's first render has to be that same markup
410
+ * even though the address bar — and therefore `useStorefront().route.query` — already carries the
411
+ * query, which is why `blocks/search/Block.vue` adopts it in `onMounted` rather than at setup.
412
+ *
413
+ * Without that gate the first paint is a different `h1` and a `<p role="status">` where the
414
+ * popular-search chips were: Vue patches the difference, warns, and the shopper watches the idle
415
+ * heading flash into the answered one.
416
+ */
417
+ it('search hydrates a prerendered shell as idle, then answers the URL’s query', async () => {
418
+ const entry: BlockEntry = {
419
+ id: 'h-search',
420
+ data: searchMock as unknown as Record<string, unknown>,
421
+ };
422
+
423
+ // The prerender: no query on the route, because the file is built once for every query.
424
+ const html = await renderBlockHtml(Search, entry, {
425
+ [STOREFRONT_KEY]: createDemoStorefront(),
426
+ });
427
+ expect(html).toContain(enUS.search.idleTitle);
428
+ // `not.toContain('No results')` would match the template's own HTML comment, which SSR keeps.
429
+ expect(html).not.toContain('No results for');
430
+
431
+ // The browser: the real URL, `?q=linen`, from the first synchronous read onwards.
432
+ const run = hydrateBlock(Search, entry, html, {
433
+ [STOREFRONT_KEY]: createDemoStorefront({ query: 'linen' }),
434
+ });
435
+ runs.push(run);
436
+
437
+ expect(hydrationWarnings(run)).toEqual([]);
438
+ expect(run.firstPaint).toContain(enUS.search.idleTitle);
439
+ expect(withoutPackageEnhancement(run.firstPaint)).toBe(withoutPackageEnhancement(run.expected));
440
+
441
+ // And the gate did not simply turn the query off: the answer arrives on the ticks after mount.
442
+ await nextTick();
443
+ await nextTick();
444
+ await nextTick();
445
+ expect(run.container.innerHTML).toContain('Results for');
446
+ expect(run.container.innerHTML).not.toContain(enUS.search.idleTitle);
447
+ });
448
+
449
+ /**
450
+ * **The wishlist's half of the same contract, asserted rather than argued.** A shopper's saved
451
+ * list is in their own browser, and one prerendered file is served to all of them — so the markup
452
+ * a build wrote carries no count and no pressed state, and the browser's first render of that file
453
+ * has to be identical to it even though `localStorage` already holds the list.
454
+ *
455
+ * `app/composables/useWishlist.ts` is what makes that true: `WishlistStore.items` stays empty
456
+ * until `hydrate()`, which only `onMounted` calls. The gate is one edit away from being lost — a
457
+ * `hydrate()` moved into `setup`, a `watchEffect`, a `v-if` reading storage for itself — and only
458
+ * a hydration test fails for that reason. `test/pages/ssr.spec.ts` proves the server half; these
459
+ * two prove the client's first paint agrees with it and that the saved state arrives *after*.
460
+ */
461
+ describe('with a wishlist already saved in the browser', () => {
462
+ it('hydrates a header whose heart carries no count, then takes one', async () => {
463
+ localStorage.setItem(WISHLIST_KEY, JSON.stringify(['merino-crew-sweater']));
464
+ const entry: BlockEntry = {
465
+ id: 'h-header',
466
+ data: navigationMock as unknown as Record<string, unknown>,
467
+ };
468
+
469
+ const html = await renderBlockHtml(Navigation, entry);
470
+ // The heart is in the file — it is nobody's state — and its name has no number in it.
471
+ expect(html).toContain('aria-label="Wishlist"');
472
+ expect(html).not.toContain('Wishlist, 1 item');
473
+
474
+ const run = hydrateBlock(Navigation, entry, html);
475
+ runs.push(run);
476
+
477
+ expect(hydrationWarnings(run)).toEqual([]);
478
+ expect(withoutPackageEnhancement(run.firstPaint)).toBe(
479
+ withoutPackageEnhancement(run.expected)
480
+ );
481
+ expect(run.firstPaint).not.toContain('Wishlist, 1 item');
482
+
483
+ // `onMounted` ran inside the mount; the render it queued is the next tick, and the store's
484
+ // read reaches the count through one more.
485
+ await nextTick();
486
+ await nextTick();
487
+ expect(run.container.innerHTML).toContain('Wishlist, 1 item');
488
+ expect(run.container.innerHTML).toContain('href="/wishlist"');
489
+ });
490
+
491
+ it('hydrates a product page with its heart unpressed, then presses it', async () => {
492
+ localStorage.setItem(WISHLIST_KEY, JSON.stringify(['merino-crew-sweater']));
493
+ const subject = SUBJECTS[0]!; // product-detail, over the demo catalogue's own product
494
+ const value = await subject.value();
495
+
496
+ const server = gatewayShaped(value);
497
+ const html = await renderBlockHtml(subject.component, subject.entry, {
498
+ [STOREFRONT_KEY]: subject.storefront(server.result as StorefrontResult<never>),
499
+ });
500
+ expect(html).toContain('aria-pressed="false"');
501
+ expect(html).not.toContain('aria-pressed="true"');
502
+
503
+ const client = gatewayShaped(value, { loading: true });
504
+ const run = hydrateBlock(subject.component, subject.entry, html, {
505
+ [STOREFRONT_KEY]: subject.storefront(client.result as StorefrontResult<never>),
506
+ });
507
+ runs.push(run);
508
+
509
+ expect(hydrationWarnings(run)).toEqual([]);
510
+ expect(run.firstPaint).toContain('aria-pressed="false"');
511
+
512
+ await nextTick();
513
+ await nextTick();
514
+ expect(run.container.innerHTML).toContain('aria-pressed="true"');
515
+ });
516
+
517
+ /**
518
+ * The wishlist **block** — what `/wishlist` is made of now that the page is a document Core
519
+ * seeds rather than a route the theme owns. One `wishlist/index.html` is served to every
520
+ * visitor, so the markup it ships is the empty state, and the browser's first render of that
521
+ * file has to be the empty state too even though the saved list is already in `localStorage`.
522
+ * The cards are the update that follows, never part of the file.
523
+ */
524
+ it('hydrates a prerendered wishlist as empty, then fills it from the browser', async () => {
525
+ localStorage.setItem(WISHLIST_KEY, JSON.stringify(['merino-crew-sweater']));
526
+ const entry: BlockEntry = {
527
+ id: 'h-wishlist',
528
+ data: wishlistMock as unknown as Record<string, unknown>,
529
+ };
530
+
531
+ const html = await renderBlockHtml(Wishlist, entry, {
532
+ [STOREFRONT_KEY]: createDemoStorefront(),
533
+ });
534
+ expect(html).toContain(enUS.wishlist.emptyTitle);
535
+ expect(html).not.toContain('Merino crew sweater');
536
+
537
+ const run = hydrateBlock(Wishlist, entry, html, {
538
+ [STOREFRONT_KEY]: createDemoStorefront(),
539
+ });
540
+ runs.push(run);
541
+
542
+ expect(hydrationWarnings(run)).toEqual([]);
543
+ expect(run.firstPaint).toContain(enUS.wishlist.emptyTitle);
544
+ expect(run.firstPaint).not.toContain('Merino crew sweater');
545
+ expect(withoutPackageEnhancement(run.firstPaint)).toBe(
546
+ withoutPackageEnhancement(run.expected)
547
+ );
548
+
549
+ // Hydration, then the batched read the hydrated list asks for.
550
+ await nextTick();
551
+ await nextTick();
552
+ await nextTick();
553
+ expect(run.container.innerHTML).toContain('Merino crew sweater');
554
+ expect(run.container.innerHTML).not.toContain(enUS.wishlist.emptyTitle);
555
+ });
556
+ });
557
+ });