@eldrajs/theme-cli 0.2.4 → 0.2.6

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 (167) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +6 -0
  3. package/dist/cli.js +8 -2
  4. package/dist/index.d.ts +6 -0
  5. package/dist/index.js +1 -1
  6. package/dist/{validate-FjQ-5_ne.js → validate-CC6Mp5i_.js} +2 -1
  7. package/package.json +3 -3
  8. package/template/.eldra/block-types.d.ts +1 -1
  9. package/template/.eldra/manifest.json +30 -2
  10. package/template/.eldra/previews.json +35 -35
  11. package/template/README.md +3 -1
  12. package/template/app/app.vue +16 -3
  13. package/template/app/assets/main.css +13 -15
  14. package/template/app/components/ui/UiImage.vue +29 -17
  15. package/template/app/components/ui/__tests__/UiImage.spec.ts +24 -15
  16. package/template/app/composables/useStorefront.ts +7 -2
  17. package/template/app/pages/[...slug].vue +1 -1
  18. package/template/app/plugins/eldra-storefront.ts +9 -0
  19. package/template/app/storefront/analytics.ts +15 -7
  20. package/template/app/storefront/cart.ts +228 -51
  21. package/template/app/storefront/commerce.ts +8 -2
  22. package/template/app/storefront/currency.ts +205 -0
  23. package/template/app/storefront/demo.ts +10 -2
  24. package/template/app/storefront/feedback.ts +2 -0
  25. package/template/app/storefront/gateway.ts +153 -35
  26. package/template/app/storefront/money.ts +6 -18
  27. package/template/app/storefront/structuredData.ts +16 -5
  28. package/template/app/storefront/toProductCard.ts +14 -14
  29. package/template/app/storefront/types.ts +13 -0
  30. package/template/app/storefront/volatile.ts +4 -0
  31. package/template/app/utils/seoInput.ts +4 -3
  32. package/template/blocks/announcement-bar/Block.vue +3 -2
  33. package/template/blocks/announcement-bar/__tests__/Block.spec.ts +1 -1
  34. package/template/blocks/announcement-bar/preview.png +0 -0
  35. package/template/blocks/article/Block.vue +3 -4
  36. package/template/blocks/article/preview.png +0 -0
  37. package/template/blocks/article-list/Block.vue +18 -9
  38. package/template/blocks/article-list/preview.png +0 -0
  39. package/template/blocks/breadcrumbs/Block.vue +1 -1
  40. package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +9 -9
  41. package/template/blocks/breadcrumbs/preview.png +0 -0
  42. package/template/blocks/cart/Block.vue +42 -23
  43. package/template/blocks/cart/__tests__/Block.spec.ts +2 -3
  44. package/template/blocks/cart/__tests__/loadFailed.spec.ts +135 -0
  45. package/template/blocks/cart/__tests__/notSold.spec.ts +109 -0
  46. package/template/blocks/cart/parts/CartLines.vue +16 -3
  47. package/template/blocks/cart/parts/CheckoutButton.vue +45 -0
  48. package/template/blocks/cart/parts/LoadFailed.vue +37 -0
  49. package/template/blocks/cart/parts/NotSoldNotice.vue +69 -0
  50. package/template/blocks/cart/parts/ShippingBar.vue +1 -1
  51. package/template/blocks/cart/parts/Summary.vue +14 -30
  52. package/template/blocks/cart/parts/notSold.ts +19 -0
  53. package/template/blocks/cart/preview.png +0 -0
  54. package/template/blocks/collection-grid/Block.vue +26 -16
  55. package/template/blocks/collection-grid/__tests__/Block.spec.ts +26 -14
  56. package/template/blocks/collection-grid/preview.png +0 -0
  57. package/template/blocks/collection-header/Block.vue +5 -5
  58. package/template/blocks/collection-header/preview.png +0 -0
  59. package/template/blocks/contact/Block.vue +1 -1
  60. package/template/blocks/contact/__tests__/Block.spec.ts +2 -2
  61. package/template/blocks/contact/preview.png +0 -0
  62. package/template/blocks/cta/Block.vue +16 -18
  63. package/template/blocks/cta/__tests__/Block.spec.ts +8 -12
  64. package/template/blocks/cta/preview.png +0 -0
  65. package/template/blocks/faq/Block.vue +3 -13
  66. package/template/blocks/faq/__tests__/Block.spec.ts +2 -2
  67. package/template/blocks/faq/preview.png +0 -0
  68. package/template/blocks/feature-grid/Block.vue +1 -1
  69. package/template/blocks/feature-grid/__tests__/Block.spec.ts +1 -1
  70. package/template/blocks/feature-grid/preview.png +0 -0
  71. package/template/blocks/footer/Block.vue +33 -55
  72. package/template/blocks/footer/__tests__/Block.spec.ts +5 -5
  73. package/template/blocks/footer/preview.png +0 -0
  74. package/template/blocks/form/Block.vue +1 -1
  75. package/template/blocks/form/preview.png +0 -0
  76. package/template/blocks/gallery/__tests__/Block.spec.ts +1 -1
  77. package/template/blocks/gallery/preview.png +0 -0
  78. package/template/blocks/hero/Block.vue +8 -11
  79. package/template/blocks/hero/__tests__/Block.spec.ts +9 -7
  80. package/template/blocks/hero/preview.png +0 -0
  81. package/template/blocks/image/Block.vue +4 -4
  82. package/template/blocks/image/__tests__/Block.spec.ts +5 -6
  83. package/template/blocks/image/preview.png +0 -0
  84. package/template/blocks/logo-cloud/__tests__/Block.spec.ts +1 -1
  85. package/template/blocks/logo-cloud/preview.png +0 -0
  86. package/template/blocks/navigation/Block.vue +55 -29
  87. package/template/blocks/navigation/__tests__/Block.spec.ts +22 -20
  88. package/template/blocks/navigation/preview.png +0 -0
  89. package/template/blocks/newsletter/__tests__/Block.spec.ts +1 -1
  90. package/template/blocks/newsletter/preview.png +0 -0
  91. package/template/blocks/order-status/Block.vue +23 -15
  92. package/template/blocks/order-status/__tests__/Block.spec.ts +1 -2
  93. package/template/blocks/order-status/preview.png +0 -0
  94. package/template/blocks/pricing-table/__tests__/Block.spec.ts +1 -1
  95. package/template/blocks/pricing-table/preview.png +0 -0
  96. package/template/blocks/product-carousel/Block.vue +11 -8
  97. package/template/blocks/product-carousel/__tests__/Block.spec.ts +26 -8
  98. package/template/blocks/product-carousel/preview.png +0 -0
  99. package/template/blocks/product-detail/Block.vue +54 -18
  100. package/template/blocks/product-detail/__tests__/Block.spec.ts +79 -2
  101. package/template/blocks/product-detail/parts/Gallery.vue +1 -1
  102. package/template/blocks/product-detail/preview.png +0 -0
  103. package/template/blocks/quote/Block.vue +1 -1
  104. package/template/blocks/quote/__tests__/Block.spec.ts +7 -4
  105. package/template/blocks/quote/preview.png +0 -0
  106. package/template/blocks/rich-text/preview.png +0 -0
  107. package/template/blocks/search/Block.vue +10 -4
  108. package/template/blocks/search/PopularChips.vue +1 -1
  109. package/template/blocks/search/TypeSection.vue +8 -2
  110. package/template/blocks/search/preview.png +0 -0
  111. package/template/blocks/search/results.ts +5 -2
  112. package/template/blocks/split-content/Block.vue +2 -3
  113. package/template/blocks/split-content/__tests__/Block.spec.ts +2 -2
  114. package/template/blocks/split-content/preview.png +0 -0
  115. package/template/blocks/stats/__tests__/Block.spec.ts +1 -1
  116. package/template/blocks/stats/preview.png +0 -0
  117. package/template/blocks/tabs/Block.vue +4 -5
  118. package/template/blocks/tabs/__tests__/Block.spec.ts +2 -2
  119. package/template/blocks/tabs/preview.png +0 -0
  120. package/template/blocks/team/preview.png +0 -0
  121. package/template/blocks/testimonials/Block.vue +10 -9
  122. package/template/blocks/testimonials/__tests__/Block.spec.ts +1 -1
  123. package/template/blocks/testimonials/preview.png +0 -0
  124. package/template/blocks/timeline/__tests__/Block.spec.ts +2 -2
  125. package/template/blocks/timeline/preview.png +0 -0
  126. package/template/blocks/trust-strip/Block.vue +1 -1
  127. package/template/blocks/trust-strip/__tests__/Block.spec.ts +1 -1
  128. package/template/blocks/trust-strip/preview.png +0 -0
  129. package/template/blocks/video-embed/Block.vue +3 -3
  130. package/template/blocks/video-embed/__tests__/Block.spec.ts +1 -1
  131. package/template/blocks/video-embed/preview.png +0 -0
  132. package/template/blocks/wishlist/Block.vue +6 -2
  133. package/template/blocks/wishlist/preview.png +0 -0
  134. package/template/i18n/en-US.json +19 -3
  135. package/template/i18n/is-IS.json +19 -3
  136. package/template/nuxt.config.ts +5 -4
  137. package/template/package.json +1 -0
  138. package/template/stories/pages/article.stories.ts +2 -3
  139. package/template/stories/pages/cart.stories.ts +2 -3
  140. package/template/stories/pages/category.stories.ts +2 -3
  141. package/template/stories/pages/collection.stories.ts +2 -3
  142. package/template/stories/pages/home.stories.ts +2 -3
  143. package/template/stories/pages/product.stories.ts +3 -4
  144. package/template/stories/pages/products.stories.ts +2 -3
  145. package/template/stories/pages/search.stories.ts +2 -3
  146. package/template/stories/pages/wishlist.stories.ts +2 -3
  147. package/template/test/carouselKeyboard.spec.ts +2 -2
  148. package/template/test/carouselRing.browser.spec.ts +2 -2
  149. package/template/test/carouselSlideWidth.browser.spec.ts +9 -9
  150. package/template/test/currencyPicker.spec.ts +66 -0
  151. package/template/test/eldraIcon.spec.ts +1 -1
  152. package/template/test/mainCss.spec.ts +7 -0
  153. package/template/test/pages/article.spec.ts +5 -5
  154. package/template/test/pages/collection.spec.ts +5 -5
  155. package/template/test/pages/hydration.spec.ts +10 -10
  156. package/template/test/prerenderRefresh.browser.spec.ts +1 -1
  157. package/template/test/seoInput.spec.ts +22 -0
  158. package/template/test/storefront/analytics.spec.ts +15 -0
  159. package/template/test/storefront/cart.spec.ts +4 -4
  160. package/template/test/storefront/currency.spec.ts +549 -0
  161. package/template/test/storefront/currencyStore.spec.ts +845 -0
  162. package/template/test/storefront/gateway.spec.ts +22 -0
  163. package/template/test/storefront/money.spec.ts +2 -8
  164. package/template/test/storefront/structuredData.spec.ts +45 -0
  165. package/template/test/storefront/toProductCard.spec.ts +1 -1
  166. package/template/test/storefront/volatile.spec.ts +11 -0
  167. package/template/test/support/mountPage.ts +2 -3
@@ -205,6 +205,10 @@ function applyPrice(current: StorefrontPrice | null, next: StorefrontPrice): Sto
205
205
  // catalogue the page has never had, not a value being refreshed over one it is already showing, so
206
206
  // the rule above does not apply to it.
207
207
  if (current === null) return next;
208
+ // A price in another currency is a different price, `from` and all.
209
+ if (current.currency !== next.currency || current.soldInCurrency !== next.soldInCurrency) {
210
+ return next;
211
+ }
208
212
  const compareAt = next.compareAt ?? null;
209
213
  if (current.amount === next.amount && (current.compareAt ?? null) === compareAt) return current;
210
214
  return { ...current, amount: next.amount, compareAt };
@@ -82,9 +82,10 @@ export function seoInput(parts: SeoInputParts): SeoInput {
82
82
  if (catalogKind === 'collection') contentImage = shareImage(entryData.image);
83
83
  }
84
84
 
85
- // A catalog object is not an authored document: its own fields are not an `seo` value, only the
86
- // shared route template's are.
87
- const entry = catalogKind === null ? seoValue(parts.page?.data?.seo) : null;
85
+ // A catalog object carries the merchant's own `seo` value in the same shape a CMS entry does
86
+ // (contract 6.6.0: title, description, canonicalUrl, ogTitle, ogDescription, imageUrl, noindex),
87
+ // so it is the route's entry value and wins over the shared route template's, field by field.
88
+ const entry = seoValue(catalogKind === null ? parts.page?.data?.seo : entryData.seo);
88
89
  const template = seoValue(parts.template?.data?.seo);
89
90
 
90
91
  if (parts.isNotFound) {
@@ -127,7 +127,7 @@ function moveFocusAfterDismiss(): void {
127
127
  * `Section` marks every ground, `none` included, with `data-section-bg`, which is what its own
128
128
  * adjacent-same-background CSS rule keys off to drop the *next* sibling's top padding — the reason
129
129
  * `breadcrumbs` deliberately avoids it (see that block's own comment). This bar needs `Section`
130
- * anyway: `background` is `primary` or `accent`, and `Section` is what marks `group/section` +
130
+ * anyway: `background` is `primary` or `accent`, and `Section` is what marks
131
131
  * `data-section` so the `Link` inside the bar inverts itself against an inverted ground.
132
132
  * Hand-rolling that marker would be re-implementing `Section`, which the starter's rules forbid
133
133
  * outright.
@@ -165,7 +165,8 @@ function moveFocusAfterDismiss(): void {
165
165
  :as="linkAs"
166
166
  variant="standalone"
167
167
  arrow
168
- :classes="{ root: 'ml-2', label: 'whitespace-nowrap' }"
168
+ class="ml-2"
169
+ :classes="{ label: 'whitespace-nowrap' }"
169
170
  >
170
171
  {{ data.linkLabel }}
171
172
  </Link>
@@ -188,7 +188,7 @@ describe('announcement-bar block', () => {
188
188
  it('the link is identifiable by its underline, not colour alone', () => {
189
189
  const wrapper = mountAnnouncement({ ...mock, linkHref: '/pages/shipping' });
190
190
  const link = wrapper.get('a');
191
- expect(link.classes()).toContain('underline');
191
+ expect(link.classes()).toContain('eldra:underline');
192
192
  });
193
193
 
194
194
  it('renders no editor placeholder (or anything else) for an empty message outside the editor', () => {
@@ -166,7 +166,7 @@ useRichTextScrollRegions(richTextRoot, (caption) => caption ?? t('article.richTe
166
166
  v-if="hasCategory"
167
167
  :href="categoryHref!"
168
168
  :as="categoryLinkAs"
169
- :classes="{ root: 'target-min text-accent inline-flex items-center font-semibold' }"
169
+ class="target-min text-accent inline-flex items-center font-semibold"
170
170
  >
171
171
  {{ categoryLabel }}
172
172
  </Link>
@@ -205,7 +205,7 @@ useRichTextScrollRegions(richTextRoot, (caption) => caption ?? t('article.richTe
205
205
  v-if="hasAuthorLink"
206
206
  :href="authorLinkHref!"
207
207
  :as="authorLinkAs"
208
- :classes="{ root: 'font-semibold' }"
208
+ class="font-semibold"
209
209
  >{{ authorName }}</Link
210
210
  ><template v-else>{{ authorName }}</template
211
211
  >{{ bylineRoleSuffix }}{{ bylineParts.after }}
@@ -233,10 +233,9 @@ useRichTextScrollRegions(richTextRoot, (caption) => caption ?? t('article.richTe
233
233
  <EditorPlaceholder
234
234
  v-else-if="showCoverHint"
235
235
  inline
236
- class="@tablet:mt-12 mt-8"
236
+ class="@tablet:mt-12 @tablet:aspect-[16/9] mt-8 aspect-[4/3] w-full"
237
237
  :label="t('article.coverHintLabel')"
238
238
  :help="t('article.coverHintHelp')"
239
- :classes="{ root: 'aspect-[4/3] w-full @tablet:aspect-[16/9]' }"
240
239
  />
241
240
  </Container>
242
241
 
Binary file
@@ -212,16 +212,24 @@ const GRID_ROOT_CLASS =
212
212
  const LIST_ROOT_CLASS = 'flex flex-col border-t border-border';
213
213
  const listContainerClass = computed(() => (isList.value ? LIST_ROOT_CLASS : GRID_ROOT_CLASS));
214
214
 
215
+ const FEATURED_CARD_CLASS =
216
+ 'grid gap-6 @tablet:grid-cols-[7fr_5fr] @tablet:items-center @tablet:gap-8 @content:gap-12';
215
217
  const FEATURED_CARD_CLASSES: Partial<Record<ContentCardPart, string>> = {
216
- root: 'grid gap-6 @tablet:grid-cols-[7fr_5fr] @tablet:items-center @tablet:gap-8 @content:gap-12',
217
218
  title: '@content:text-[2rem] @content:leading-[1.15]',
218
219
  body: '@content:gap-4',
219
220
  };
221
+ const LIST_CARD_CLASS =
222
+ 'grid grid-cols-[6.5rem_1fr] items-start gap-4 @tablet:grid-cols-[15rem_1fr] @tablet:items-center @tablet:gap-8';
220
223
  const LIST_CARD_CLASSES: Partial<Record<ContentCardPart, string>> = {
221
- root: 'grid grid-cols-[6.5rem_1fr] items-start gap-4 @tablet:grid-cols-[15rem_1fr] @tablet:items-center @tablet:gap-8',
222
224
  excerpt: '@max-tablet:hidden',
223
225
  };
224
226
 
227
+ function cardClass(card: CardView): string | undefined {
228
+ if (card.featured) return FEATURED_CARD_CLASS;
229
+ if (isList.value) return LIST_CARD_CLASS;
230
+ return undefined;
231
+ }
232
+
225
233
  function cardClasses(card: CardView): Partial<Record<ContentCardPart, string>> | undefined {
226
234
  if (card.featured) return FEATURED_CARD_CLASSES;
227
235
  if (isList.value) return LIST_CARD_CLASSES;
@@ -261,7 +269,7 @@ function itemWrapperClass(card: CardView): string {
261
269
  :as="viewAllLinkAs"
262
270
  variant="standalone"
263
271
  arrow
264
- :classes="{ root: 'text-control' }"
272
+ class="text-control"
265
273
  >
266
274
  {{ viewAllLabel }}
267
275
  </Link>
@@ -275,12 +283,12 @@ function itemWrapperClass(card: CardView): string {
275
283
  :as="filter.linkAs"
276
284
  :underline="false"
277
285
  :aria-current="filter.active ? 'true' : undefined"
278
- :classes="{
279
- root: filter.active
280
- ? 'inline-flex min-h-10 items-center rounded-full border border-primary bg-primary px-4 text-control font-semibold text-primary-contrast'
281
- : 'inline-flex min-h-10 items-center rounded-full border border-border-strong px-4 text-control font-medium text-text hover:border-text',
282
- label: 'inline-flex items-center gap-1',
283
- }"
286
+ :class="
287
+ filter.active
288
+ ? 'border-primary bg-primary text-control text-primary-contrast inline-flex min-h-10 items-center rounded-full border px-4 font-semibold'
289
+ : 'border-border-strong text-control text-text hover:border-text inline-flex min-h-10 items-center rounded-full border px-4 font-medium'
290
+ "
291
+ :classes="{ label: 'inline-flex items-center gap-1' }"
284
292
  >
285
293
  <EldraIcon v-if="filter.active" name="check" size="sm" />
286
294
  {{ filter.label }}
@@ -303,6 +311,7 @@ function itemWrapperClass(card: CardView): string {
303
311
  :meta="card.readingTime"
304
312
  :excerpt="card.dek"
305
313
  :heading-level="3"
314
+ :class="cardClass(card)"
306
315
  :classes="cardClasses(card)"
307
316
  />
308
317
  </li>
@@ -258,7 +258,7 @@ watchEffect(() => {
258
258
 
259
259
  <template>
260
260
  <div v-if="hasTrail" class="bg-background text-text @container">
261
- <Container :width="containerWidth" :classes="{ root: 'py-3' }">
261
+ <Container :width="containerWidth" class="py-3">
262
262
  <div ref="breadcrumbRoot" class="contents">
263
263
  <Breadcrumb
264
264
  :items="items"
@@ -118,7 +118,7 @@ describe('breadcrumbs block', () => {
118
118
  async (container) => {
119
119
  const wrapper = mountBlock({ ...mock, container });
120
120
  const wideOrContent =
121
- container === 'wide' ? 'eldra-container-wide' : 'eldra-container-content';
121
+ container === 'wide' ? 'eldra:eldra-container-wide' : 'eldra:eldra-container-content';
122
122
  expect(wrapper.getComponent(Container).classes()).toContain(wideOrContent);
123
123
  expect(await axe(wrapper.element)).toHaveNoViolations();
124
124
  }
@@ -189,20 +189,20 @@ describe('breadcrumbs block', () => {
189
189
 
190
190
  const hiddenLevels = wrapper
191
191
  .findAll('[data-part="item"]')
192
- .filter((item) => item.classes().includes('@max-tablet:hidden'));
192
+ .filter((item) => item.classes().includes('eldra:@max-tablet:hidden'));
193
193
  expect(hiddenLevels.map((item) => item.text())).toEqual(['Kitchen', 'Table & serving']);
194
194
  });
195
195
 
196
196
  it('reaches Home, then the "…" button, then the parent, in that order', () => {
197
- // The collapsed middle levels carry `@max-tablet:hidden` (a container-query class jsdom does
198
- // not evaluate — there is no real layout — so "reaches" is asserted the same way the
199
- // package's own Breadcrumb.spec.ts does: by document order over the levels that are *not*
200
- // collapse-hidden, which below the 48rem collapse threshold is exactly the operable Tab path
201
- // a real browser gives (a `display:none` element is never a Tab stop).
197
+ // The collapsed middle levels carry `eldra:@max-tablet:hidden` (a container-query class
198
+ // jsdom does not evaluate — there is no real layout — so "reaches" is asserted the same way
199
+ // the package's own Breadcrumb.spec.ts does: by document order over the levels that are
200
+ // *not* collapse-hidden, which below the 48rem collapse threshold is exactly the operable Tab
201
+ // path a real browser gives (a `display:none` element is never a Tab stop).
202
202
  const wrapper = mountBlock(deepTrailData);
203
203
  const visibleFocusable = wrapper
204
204
  .findAll('[data-part="item"]')
205
- .filter((item) => !item.classes().includes('@max-tablet:hidden'))
205
+ .filter((item) => !item.classes().includes('eldra:@max-tablet:hidden'))
206
206
  .map((item) => {
207
207
  const link = item.find('[data-part="link"]');
208
208
  if (link.exists()) return link.text();
@@ -239,7 +239,7 @@ describe('breadcrumbs block', () => {
239
239
 
240
240
  expect(wrapper.find('[data-part="ellipsis"]').exists()).toBe(false);
241
241
  for (const item of wrapper.findAll('[data-part="item"]')) {
242
- expect(item.classes()).not.toContain('@max-tablet:hidden');
242
+ expect(item.classes()).not.toContain('eldra:@max-tablet:hidden');
243
243
  }
244
244
 
245
245
  const links = wrapper.findAll('[data-part="link"]');
@@ -49,6 +49,7 @@ import {
49
49
  nextTick,
50
50
  onBeforeUnmount,
51
51
  onMounted,
52
+ provide,
52
53
  ref,
53
54
  watch,
54
55
  type Component,
@@ -58,6 +59,7 @@ import {
58
59
  Container,
59
60
  Drawer,
60
61
  EditorPlaceholder,
62
+ CURRENCY_KEY,
61
63
  EmptyState,
62
64
  Link,
63
65
  Price,
@@ -76,6 +78,9 @@ import { useMoney } from '../../app/storefront/money';
76
78
  import CartLines from './parts/CartLines.vue';
77
79
  import ShippingBar from './parts/ShippingBar.vue';
78
80
  import Summary from './parts/Summary.vue';
81
+ import NotSoldNotice from './parts/NotSoldNotice.vue';
82
+ import CheckoutButton from './parts/CheckoutButton.vue';
83
+ import LoadFailed from './parts/LoadFailed.vue';
79
84
 
80
85
  const props = defineProps<{
81
86
  entry: EldraBlockEntry<'cart'>;
@@ -91,7 +96,14 @@ const editing = useEditing();
91
96
  const { t } = useI18n();
92
97
  /** The cart subtotal is major units (`app/storefront/types.ts`); `<Price>` reads minor. */
93
98
  const money = useMoney();
94
- const cart = useStorefront().cart;
99
+ const storefront = useStorefront();
100
+ const cart = storefront.cart;
101
+ // Every price under the cart is in the cart's own currency, which can differ from the store's.
102
+ provide(CURRENCY_KEY, () => cart.currency.value ?? money.currency.value);
103
+ const cartInStoreCurrency = computed(
104
+ () => cart.currency.value === undefined || cart.currency.value === storefront.currency.base
105
+ );
106
+ const hasNotSold = computed(() => cart.notSold.value.length > 0);
95
107
 
96
108
  const uid = useUiId();
97
109
  const headingId = `cart-title-${uid}`;
@@ -160,11 +172,9 @@ const hasContinueLink = computed(() => emptyLinkHref.value !== null);
160
172
 
161
173
  const showDiscountField = computed(() => data.value.showDiscountField ?? true);
162
174
  const showPaymentIcons = computed(() => data.value.showPaymentIcons ?? true);
163
- const threshold = computed(() => (data.value.freeShippingThreshold ?? '').trim());
164
-
165
- const checkoutHref = computed(() => safeHref(cart.checkoutUrl.value));
166
- const checkoutAs = computed(() =>
167
- checkoutHref.value !== null && isInternalHref(checkoutHref.value) ? EldraRouterLink : undefined
175
+ /** Typed in the store's own currency, so it says nothing about a cart in another. */
176
+ const threshold = computed(() =>
177
+ cartInStoreCurrency.value ? (data.value.freeShippingThreshold ?? '').trim() : ''
168
178
  );
169
179
 
170
180
  /** The theme's own cart page path — the same one `blocks/navigation/Block.vue` sends the bag to
@@ -241,7 +251,9 @@ const DRAWER_CLASSES = {
241
251
  >
242
252
  <template v-if="isEmpty">
243
253
  <div ref="emptyRoot" class="my-6 px-4">
254
+ <LoadFailed />
244
255
  <EmptyState
256
+ v-if="!cart.loadFailed.value"
245
257
  plain
246
258
  :icon="ShoppingBagIcon"
247
259
  :title="emptyTitle || t('cart.emptyFallbackTitle')"
@@ -262,6 +274,8 @@ const DRAWER_CLASSES = {
262
274
  <template v-else>
263
275
  <ShippingBar panel="edge" :threshold="threshold" :subtotal="subtotal" />
264
276
  <div class="px-4">
277
+ <LoadFailed class="mt-4" />
278
+ <NotSoldNotice v-if="hasNotSold" class="mt-4" />
265
279
  <CartLines :lines="lines" @removing="onRemoving" />
266
280
  </div>
267
281
  </template>
@@ -270,25 +284,23 @@ const DRAWER_CLASSES = {
270
284
  <div class="flex items-baseline justify-between gap-4">
271
285
  <span class="text-text text-base font-semibold">{{ t('cart.subtotal') }}</span>
272
286
  <Price
273
- :amount="money.minor(subtotal)"
274
- :classes="{ root: 'text-text text-base font-semibold tabular-nums' }"
287
+ :amount="money.minor(subtotal, cart.currency.value)"
288
+ class="text-text text-base font-semibold tabular-nums"
275
289
  />
276
290
  </div>
277
- <p v-if="note" class="text-muted text-body-sm text-center">{{ note }}</p>
278
- <Button
279
- v-if="checkoutHref"
280
- variant="primary"
281
- size="lg"
282
- block
283
- :href="checkoutHref"
284
- :as="checkoutAs"
285
- @click="cart.beginCheckout()"
291
+ <p
292
+ v-if="cart.notSold.value.length > 0"
293
+ class="text-muted text-body-sm"
294
+ data-eldra-not-included
286
295
  >
287
- <template #leadingIcon>
288
- <EldraIcon name="lock" size="sm" />
289
- </template>
290
- {{ t('cart.checkout') }}
291
- </Button>
296
+ {{
297
+ cart.notSold.value.length === 1
298
+ ? t('currency.notIncludedOne')
299
+ : t('currency.notIncludedMany', { count: cart.notSold.value.length })
300
+ }}
301
+ </p>
302
+ <p v-if="note" class="text-muted text-body-sm text-center">{{ note }}</p>
303
+ <CheckoutButton />
292
304
  <!-- No `@click` close: this is a router link like the line titles beside it, and the app
293
305
  shell closes the drawer on the route change (`app/storefront/cart.ts`, `drawerOpen`). -->
294
306
  <Button
@@ -310,7 +322,10 @@ const DRAWER_CLASSES = {
310
322
  class="font-heading text-text @tablet:text-h2 flex flex-wrap items-baseline gap-3 text-[1.625rem] leading-[1.15] font-bold tracking-[-0.015em]"
311
323
  >
312
324
  {{ t('cart.title') }}
313
- <span class="font-body text-muted text-base font-normal tracking-normal">
325
+ <span
326
+ v-if="!cart.loadFailed.value"
327
+ class="font-body text-muted text-base font-normal tracking-normal"
328
+ >
314
329
  {{ countLabel }}
315
330
  </span>
316
331
  </h1>
@@ -327,7 +342,9 @@ const DRAWER_CLASSES = {
327
342
  </div>
328
343
 
329
344
  <div v-if="isEmpty" ref="emptyRoot">
345
+ <LoadFailed />
330
346
  <EmptyState
347
+ v-if="!cart.loadFailed.value"
331
348
  :icon="ShoppingBagIcon"
332
349
  :heading-level="2"
333
350
  :title="emptyTitle || t('cart.emptyFallbackTitle')"
@@ -350,6 +367,8 @@ const DRAWER_CLASSES = {
350
367
  >
351
368
  <div class="grid min-w-0 gap-2">
352
369
  <ShippingBar panel="card" :threshold="threshold" :subtotal="subtotal" />
370
+ <LoadFailed />
371
+ <NotSoldNotice v-if="hasNotSold" />
353
372
  <div
354
373
  aria-hidden="true"
355
374
  class="border-border text-body-sm text-muted @tablet:grid hidden grid-cols-[6rem_1fr_11rem_6rem] gap-x-4 border-b pt-4 pb-3"
@@ -451,9 +451,8 @@ describe('cart block', () => {
451
451
 
452
452
  expect(alertToast()?.textContent).toContain('This item is out of stock.');
453
453
  expect(toastRoot()?.textContent ?? '').not.toContain('removed');
454
- // The line is back on screen — the restore is local and deliberate — which is exactly why the
455
- // shopper has to be told the shop could not take it back.
456
- expect(storefront.cart.lines.value.map((line) => line.title)).toContain(
454
+ // The cart shows what the shop holds: the line it could not take back stays out.
455
+ expect(storefront.cart.lines.value.map((line) => line.title)).not.toContain(
457
456
  'Merino crew sweater'
458
457
  );
459
458
  expect(await axe(wrapper.element)).toHaveNoViolations();
@@ -0,0 +1,135 @@
1
+ // @vitest-environment jsdom
2
+ import { flushPromises, mount } from '@vue/test-utils';
3
+ import { defineComponent, h, ref } from 'vue';
4
+ import { Toaster, useToast } from '@eldrajs/ui';
5
+ import { afterEach, describe, expect, it } from 'vitest';
6
+ import { axe } from '../../../test/support/axe';
7
+ import { mountOptions } from '../../../test/support/mountBlock';
8
+ import { createCartStore, type CartSnapshot } from '../../../app/storefront/cart';
9
+ import { createDemoStorefront, DEMO_CART_LINES } from '../../../app/storefront/demo';
10
+ import { STOREFRONT_KEY, type StorefrontSource } from '../../../app/storefront/types';
11
+ import Navigation from '../../navigation/Block.vue';
12
+ import navigationMock from '../../navigation/mock.json';
13
+ import Block from '../Block.vue';
14
+ import mock from '../mock.json';
15
+
16
+ afterEach(() => {
17
+ useToast().clear?.();
18
+ document.body.innerHTML = '';
19
+ });
20
+
21
+ const fails = async (): Promise<CartSnapshot> => {
22
+ throw new Error('timeout');
23
+ };
24
+ const answersLines = async (): Promise<CartSnapshot> => ({
25
+ lines: DEMO_CART_LINES,
26
+ totals: { subtotal: 0, discount: null, shipping: null, tax: null, total: 0 },
27
+ });
28
+
29
+ /** A storefront whose cart reads answer in turn: by default the first fails and the next answers. */
30
+ function unreadCartStorefront(
31
+ answers: Array<() => Promise<CartSnapshot>> = [fails, answersLines]
32
+ ): StorefrontSource {
33
+ const unused = async (): Promise<never> => {
34
+ throw new Error('unused');
35
+ };
36
+ const cart = createCartStore({
37
+ init: () => answers.shift()!(),
38
+ add: unused,
39
+ setQuantity: unused,
40
+ remove: unused,
41
+ applyDiscount: async () => ({ ack: { ok: false, reason: 'failed' } }),
42
+ removeDiscount: unused,
43
+ checkoutUrl: ref(null),
44
+ });
45
+ return { ...createDemoStorefront(), cart };
46
+ }
47
+
48
+ async function mountWith(
49
+ component: object,
50
+ data: Record<string, unknown>,
51
+ storefront: StorefrontSource
52
+ ) {
53
+ const options = mountOptions({ entry: { id: 'cart', data } });
54
+ const wrapper = mount(component, {
55
+ ...options,
56
+ props: { entry: { id: 'cart', data } },
57
+ attachTo: document.body,
58
+ global: {
59
+ ...options.global,
60
+ provide: { ...options.global.provide, [STOREFRONT_KEY]: storefront },
61
+ stubs: { ...options.global.stubs, transition: false, 'transition-group': false },
62
+ },
63
+ });
64
+ await flushPromises();
65
+ return wrapper;
66
+ }
67
+
68
+ describe('a cart whose read failed', () => {
69
+ it('shows only the error and Try again on the cart page, no count and no empty state', async () => {
70
+ const storefront = unreadCartStorefront();
71
+ const wrapper = await mountWith(Block, { ...mock, variant: 'page' }, storefront);
72
+
73
+ const notice = wrapper.get('[data-eldra-cart-load-failed]');
74
+ expect(notice.text()).toContain("We couldn't load your cart.");
75
+ expect(wrapper.text()).not.toContain('Your cart is empty');
76
+ expect(wrapper.text()).not.toContain('0 items');
77
+ expect(await axe(wrapper.element)).toHaveNoViolations();
78
+
79
+ await notice.get('button').trigger('click');
80
+ await flushPromises();
81
+ expect(wrapper.find('[data-eldra-cart-load-failed]').exists()).toBe(false);
82
+ expect(storefront.cart.lines.value).toHaveLength(DEMO_CART_LINES.length);
83
+ });
84
+
85
+ it('shows only the error in the drawer, accessibly', async () => {
86
+ const storefront = unreadCartStorefront();
87
+ storefront.cart.drawerOpen.value = true;
88
+ const wrapper = await mountWith(Block, { ...mock, variant: 'drawer' }, storefront);
89
+ const dialog = document.body.querySelector<HTMLElement>('dialog')!;
90
+ expect(dialog.querySelector('[data-eldra-cart-load-failed]')).not.toBeNull();
91
+ expect(dialog.textContent).not.toContain('Your cart is empty');
92
+ expect(await axe(dialog)).toHaveNoViolations();
93
+ wrapper.unmount();
94
+ });
95
+
96
+ it('4662896752: says so again when Try again fails too', async () => {
97
+ const storefront = unreadCartStorefront([fails, fails]);
98
+ const Harness = defineComponent({
99
+ setup: () => () =>
100
+ h('div', [
101
+ h(Block as never, { entry: { id: 'cart', data: { ...mock, variant: 'page' } } }),
102
+ h(Toaster),
103
+ ]),
104
+ });
105
+ const wrapper = await mountWith(Harness, {}, storefront);
106
+ await wrapper.get('[data-eldra-cart-load-failed] button').trigger('click');
107
+ await flushPromises();
108
+ // The notice itself is an alert too; the new signal is a toast outside it.
109
+ const toasts = [...document.body.querySelectorAll('[role="alert"]')].filter(
110
+ (node) => node.closest('[data-eldra-cart-load-failed]') === null
111
+ );
112
+ expect(toasts.map((node) => node.textContent).join(' ')).toContain(
113
+ 'Something went wrong. Please try again.'
114
+ );
115
+ });
116
+
117
+ it('Block.vue:252: shows the error over the lines a cart kept when a later read fails', async () => {
118
+ const storefront = unreadCartStorefront([answersLines, fails]);
119
+ const wrapper = await mountWith(Block, { ...mock, variant: 'page' }, storefront);
120
+ expect(wrapper.find('[data-eldra-cart-load-failed]').exists()).toBe(false);
121
+ await storefront.cart.reload();
122
+ await flushPromises();
123
+ expect(wrapper.find('[data-eldra-cart-load-failed]').exists()).toBe(true);
124
+ expect(storefront.cart.lines.value).toHaveLength(DEMO_CART_LINES.length);
125
+ });
126
+
127
+ it('gives the header bag no count', async () => {
128
+ const storefront = unreadCartStorefront();
129
+ const wrapper = await mountWith(Navigation, navigationMock, storefront);
130
+ const bag = wrapper
131
+ .findAll('[data-eldra-header-actions] a, [data-eldra-header-actions] button')
132
+ .find((node) => (node.attributes('aria-label') ?? '').startsWith('Cart'));
133
+ expect(bag?.attributes('aria-label')).toBe('Cart');
134
+ });
135
+ });
@@ -0,0 +1,109 @@
1
+ // @vitest-environment jsdom
2
+ import { flushPromises, mount } from '@vue/test-utils';
3
+ import { computed } from 'vue';
4
+ import { afterEach, describe, expect, it, vi } from 'vitest';
5
+ import { axe } from '../../../test/support/axe';
6
+ import { mountOptions } from '../../../test/support/mountBlock';
7
+ import { createDemoStorefront, DEMO_CART_LINES } from '../../../app/storefront/demo';
8
+ import { STOREFRONT_KEY } from '../../../app/storefront/types';
9
+ import Block from '../Block.vue';
10
+ import mock from '../mock.json';
11
+
12
+ const NOT_SOLD = { ...DEMO_CART_LINES[0]!, soldInCurrency: false };
13
+ const SOLD = DEMO_CART_LINES[1]!;
14
+
15
+ afterEach(() => {
16
+ document.body.innerHTML = '';
17
+ vi.restoreAllMocks();
18
+ });
19
+
20
+ async function mountCart(lines = [NOT_SOLD, SOLD], checkoutStaysOpen = false) {
21
+ const demo = createDemoStorefront({ cartLines: lines });
22
+ const storefront = checkoutStaysOpen
23
+ ? { ...demo, cart: { ...demo.cart, checkoutUrl: computed(() => '/checkout/demo-cart') } }
24
+ : demo;
25
+ const options = mountOptions({ entry: { id: 'cart', data: { ...mock, variant: 'page' } } });
26
+ const wrapper = mount(Block, {
27
+ ...options,
28
+ attachTo: document.body,
29
+ global: {
30
+ ...options.global,
31
+ provide: { ...options.global.provide, [STOREFRONT_KEY]: storefront },
32
+ stubs: { ...options.global.stubs, transition: false, 'transition-group': false },
33
+ },
34
+ });
35
+ await flushPromises();
36
+ return { wrapper, storefront };
37
+ }
38
+
39
+ describe('a cart with a line not sold in its currency', () => {
40
+ it('holds Check out with the reason under it, rather than hiding it', async () => {
41
+ const { wrapper } = await mountCart();
42
+ const checkout = wrapper.findAll('button, a').find((node) => node.text().includes('Check out'));
43
+ expect(checkout).toBeDefined();
44
+ expect(checkout!.attributes('disabled')).toBeDefined();
45
+ const reasonId = checkout!.attributes('aria-describedby')!;
46
+ expect(wrapper.get(`[id="${reasonId}"]`).text()).toContain(NOT_SOLD.title);
47
+ expect(await axe(wrapper.element)).toHaveNoViolations();
48
+ });
49
+
50
+ it('says the total leaves the line out and turns its stepper off', async () => {
51
+ const { wrapper } = await mountCart();
52
+ expect(wrapper.get('[data-eldra-not-included]').text()).toBe('1 item not included');
53
+ const row = wrapper.get('[data-eldra-line-not-sold]').element.closest('li')!;
54
+ const steppers = [...row.querySelectorAll('[role="group"] button')] as HTMLButtonElement[];
55
+ expect(steppers.length).toBeGreaterThan(0);
56
+ expect(steppers.every((button) => button.disabled)).toBe(true);
57
+ });
58
+
59
+ it('checks out once the lines are removed', async () => {
60
+ const { wrapper, storefront } = await mountCart();
61
+ const assign = vi.fn();
62
+ vi.spyOn(window, 'location', 'get').mockReturnValue({ ...window.location, assign } as Location);
63
+ const remove = wrapper
64
+ .get('[data-eldra-not-sold-notice]')
65
+ .findAll('button')
66
+ .find((node) => node.text() === 'Remove and check out')!;
67
+ await remove.trigger('click');
68
+ await flushPromises();
69
+ expect(storefront.cart.notSold.value).toEqual([]);
70
+ expect(assign).toHaveBeenCalledWith('/checkout/demo-cart');
71
+ });
72
+
73
+ it('4662896758: a second press while the first is working checks out once', async () => {
74
+ const { wrapper, storefront } = await mountCart();
75
+ const assign = vi.fn();
76
+ vi.spyOn(window, 'location', 'get').mockReturnValue({ ...window.location, assign } as Location);
77
+ const removeNotSold = vi.spyOn(storefront.cart, 'removeNotSold');
78
+ const remove = wrapper
79
+ .get('[data-eldra-not-sold-notice]')
80
+ .findAll('button')
81
+ .find((node) => node.text() === 'Remove and check out')!;
82
+ await remove.trigger('click');
83
+ await remove.trigger('click');
84
+ await flushPromises();
85
+ expect(removeNotSold).toHaveBeenCalledTimes(1);
86
+ expect(assign).toHaveBeenCalledTimes(1);
87
+ });
88
+
89
+ it('stays on the cart when removing the lines leaves it empty', async () => {
90
+ const { wrapper, storefront } = await mountCart([NOT_SOLD], true);
91
+ const assign = vi.fn();
92
+ vi.spyOn(window, 'location', 'get').mockReturnValue({ ...window.location, assign } as Location);
93
+ const remove = wrapper
94
+ .get('[data-eldra-not-sold-notice]')
95
+ .findAll('button')
96
+ .find((node) => node.text() === 'Remove and check out')!;
97
+ await remove.trigger('click');
98
+ await flushPromises();
99
+ expect(storefront.cart.lines.value).toEqual([]);
100
+ expect(assign).not.toHaveBeenCalled();
101
+ });
102
+
103
+ it('shows no note and a working Check out when every line is sold', async () => {
104
+ const { wrapper } = await mountCart([SOLD]);
105
+ expect(wrapper.find('[data-eldra-not-included]').exists()).toBe(false);
106
+ const checkout = wrapper.findAll('a').find((node) => node.text().includes('Check out'));
107
+ expect(checkout?.attributes('href')).toBe('/checkout/demo-cart');
108
+ });
109
+ });