@eldrajs/theme-cli 0.2.5 → 0.2.7

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 (92) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/package.json +3 -3
  3. package/template/.eldra/block-types.d.ts +1 -1
  4. package/template/.eldra/manifest.json +32 -2
  5. package/template/.eldra/previews.json +35 -35
  6. package/template/app/app.vue +15 -0
  7. package/template/app/composables/useStorefront.ts +7 -2
  8. package/template/app/plugins/eldra-storefront.ts +9 -0
  9. package/template/app/storefront/analytics.ts +15 -7
  10. package/template/app/storefront/cart.ts +228 -51
  11. package/template/app/storefront/commerce.ts +12 -2
  12. package/template/app/storefront/currency.ts +272 -0
  13. package/template/app/storefront/demo.ts +10 -2
  14. package/template/app/storefront/feedback.ts +3 -0
  15. package/template/app/storefront/gateway.ts +153 -35
  16. package/template/app/storefront/money.ts +6 -18
  17. package/template/app/storefront/structuredData.ts +16 -5
  18. package/template/app/storefront/toProductCard.ts +14 -14
  19. package/template/app/storefront/types.ts +13 -0
  20. package/template/app/storefront/volatile.ts +4 -0
  21. package/template/app/utils/seoInput.ts +4 -3
  22. package/template/blocks/announcement-bar/preview.png +0 -0
  23. package/template/blocks/article/preview.png +0 -0
  24. package/template/blocks/article-list/preview.png +0 -0
  25. package/template/blocks/breadcrumbs/preview.png +0 -0
  26. package/template/blocks/cart/Block.vue +41 -22
  27. package/template/blocks/cart/__tests__/Block.spec.ts +2 -3
  28. package/template/blocks/cart/__tests__/loadFailed.spec.ts +135 -0
  29. package/template/blocks/cart/__tests__/notSold.spec.ts +150 -0
  30. package/template/blocks/cart/parts/CartLines.vue +14 -2
  31. package/template/blocks/cart/parts/CheckoutButton.vue +45 -0
  32. package/template/blocks/cart/parts/LoadFailed.vue +37 -0
  33. package/template/blocks/cart/parts/NotSoldNotice.vue +74 -0
  34. package/template/blocks/cart/parts/Summary.vue +9 -21
  35. package/template/blocks/cart/parts/notSold.ts +19 -0
  36. package/template/blocks/cart/preview.png +0 -0
  37. package/template/blocks/collection-grid/Block.vue +15 -2
  38. package/template/blocks/collection-grid/__tests__/Block.spec.ts +14 -0
  39. package/template/blocks/collection-grid/preview.png +0 -0
  40. package/template/blocks/collection-header/preview.png +0 -0
  41. package/template/blocks/contact/preview.png +0 -0
  42. package/template/blocks/cta/preview.png +0 -0
  43. package/template/blocks/faq/preview.png +0 -0
  44. package/template/blocks/feature-grid/preview.png +0 -0
  45. package/template/blocks/footer/Block.vue +20 -45
  46. package/template/blocks/footer/preview.png +0 -0
  47. package/template/blocks/form/preview.png +0 -0
  48. package/template/blocks/gallery/preview.png +0 -0
  49. package/template/blocks/hero/preview.png +0 -0
  50. package/template/blocks/image/preview.png +0 -0
  51. package/template/blocks/logo-cloud/preview.png +0 -0
  52. package/template/blocks/navigation/Block.vue +39 -3
  53. package/template/blocks/navigation/preview.png +0 -0
  54. package/template/blocks/newsletter/preview.png +0 -0
  55. package/template/blocks/order-status/Block.vue +15 -6
  56. package/template/blocks/order-status/preview.png +0 -0
  57. package/template/blocks/pricing-table/preview.png +0 -0
  58. package/template/blocks/product-carousel/Block.vue +5 -2
  59. package/template/blocks/product-carousel/preview.png +0 -0
  60. package/template/blocks/product-detail/Block.vue +68 -10
  61. package/template/blocks/product-detail/__tests__/Block.spec.ts +190 -2
  62. package/template/blocks/product-detail/preview.png +0 -0
  63. package/template/blocks/quote/preview.png +0 -0
  64. package/template/blocks/rich-text/preview.png +0 -0
  65. package/template/blocks/search/Block.vue +8 -2
  66. package/template/blocks/search/TypeSection.vue +8 -2
  67. package/template/blocks/search/preview.png +0 -0
  68. package/template/blocks/search/results.ts +5 -2
  69. package/template/blocks/split-content/preview.png +0 -0
  70. package/template/blocks/stats/preview.png +0 -0
  71. package/template/blocks/tabs/preview.png +0 -0
  72. package/template/blocks/team/preview.png +0 -0
  73. package/template/blocks/testimonials/preview.png +0 -0
  74. package/template/blocks/timeline/preview.png +0 -0
  75. package/template/blocks/trust-strip/preview.png +0 -0
  76. package/template/blocks/video-embed/preview.png +0 -0
  77. package/template/blocks/wishlist/Block.vue +5 -1
  78. package/template/blocks/wishlist/preview.png +0 -0
  79. package/template/i18n/en-US.json +20 -3
  80. package/template/i18n/is-IS.json +20 -3
  81. package/template/test/currencyPicker.spec.ts +66 -0
  82. package/template/test/seoInput.spec.ts +22 -0
  83. package/template/test/storefront/analytics.spec.ts +15 -0
  84. package/template/test/storefront/cart.spec.ts +4 -4
  85. package/template/test/storefront/currency.spec.ts +549 -0
  86. package/template/test/storefront/currencyDefault.spec.ts +475 -0
  87. package/template/test/storefront/currencyStore.spec.ts +845 -0
  88. package/template/test/storefront/gateway.spec.ts +22 -0
  89. package/template/test/storefront/money.spec.ts +2 -8
  90. package/template/test/storefront/structuredData.spec.ts +45 -0
  91. package/template/test/storefront/toProductCard.spec.ts +1 -1
  92. package/template/test/storefront/volatile.spec.ts +11 -0
@@ -0,0 +1,66 @@
1
+ // @vitest-environment jsdom
2
+ import { flushPromises, mount } from '@vue/test-utils';
3
+ import { afterEach, describe, expect, it, vi } from 'vitest';
4
+ import Navigation from '../blocks/navigation/Block.vue';
5
+ import navigationMock from '../blocks/navigation/mock.json';
6
+ import Footer from '../blocks/footer/Block.vue';
7
+ import footerMock from '../blocks/footer/mock.json';
8
+ import { STOREFRONT_KEY, type StorefrontSource } from '../app/storefront/types';
9
+ import { axe } from './support/axe';
10
+ import { mountOptions } from './support/mountBlock';
11
+
12
+ const MULTI = {
13
+ currency: 'ISK',
14
+ taxInclusivePricing: true,
15
+ defaultTaxRate: 0.24,
16
+ currencies: ['ISK', 'EUR', 'USD'],
17
+ };
18
+ const ONE = { currency: 'ISK', taxInclusivePricing: true, defaultTaxRate: 0.24 };
19
+
20
+ afterEach(() => {
21
+ document.body.innerHTML = '';
22
+ localStorage.clear();
23
+ });
24
+
25
+ function mountWith(component: object, commerce: typeof MULTI | typeof ONE, data = {}) {
26
+ const options = mountOptions({ entry: { id: 'c', data } }, { commerce });
27
+ const storefront = options.global.provide[STOREFRONT_KEY] as StorefrontSource;
28
+ storefront.currency.started.value = true;
29
+ const wrapper = mount(component, { ...options, attachTo: document.body });
30
+ return { wrapper, storefront };
31
+ }
32
+
33
+ describe('the currency picker in the starter', () => {
34
+ it('sits in the header of a store that shows more than one currency and moves the visitor', async () => {
35
+ const { wrapper, storefront } = mountWith(Navigation, MULTI, navigationMock);
36
+ const trigger = wrapper.get('[data-eldra-header-actions] button[role="combobox"]');
37
+ expect(trigger.text()).toContain('ISK');
38
+ (trigger.element as HTMLElement).focus();
39
+ await trigger.trigger('keydown', { key: 'ArrowDown' });
40
+ await flushPromises();
41
+ const euro = [...document.querySelectorAll('[role="option"]')].find((node) =>
42
+ node.textContent?.includes('(EUR)')
43
+ ) as HTMLElement;
44
+ euro.click();
45
+ await flushPromises();
46
+ expect(storefront.currency.active.value).toBe('EUR');
47
+ expect(localStorage.getItem('eldra.currency')).toBe('EUR');
48
+ expect(await axe(wrapper.element)).toHaveNoViolations();
49
+ });
50
+
51
+ it('is not in the header of a one-currency store', () => {
52
+ const { wrapper } = mountWith(Navigation, ONE, navigationMock);
53
+ expect(wrapper.find('[data-eldra-header-actions] [role="combobox"]').exists()).toBe(false);
54
+ });
55
+
56
+ it("drives the footer's currency selector too", async () => {
57
+ const { wrapper, storefront } = mountWith(Footer, MULTI, footerMock);
58
+ storefront.currency.choose('USD');
59
+ await vi.waitFor(() => expect(storefront.currency.active.value).toBe('USD'));
60
+ await flushPromises();
61
+ expect(
62
+ wrapper.findAll('button[role="combobox"]').some((node) => node.text().includes('USD'))
63
+ ).toBe(true);
64
+ expect(await axe(wrapper.element)).toHaveNoViolations();
65
+ });
66
+ });
@@ -50,6 +50,28 @@ describe('seoInput', () => {
50
50
  expect(input.options.contentImage).toMatch(/\/lg$/);
51
51
  });
52
52
 
53
+ it("passes a catalog record's own seo value as the entry, beside the template's", () => {
54
+ const own = {
55
+ title: 'The mug',
56
+ canonicalUrl: 'https://shop.example/mugs/the-mug',
57
+ imageUrl: 'https://media.example/share.jpg',
58
+ noindex: true,
59
+ };
60
+ const input = seoInput({
61
+ ...base,
62
+ catalog: { kind: 'product', slug: 'mug' },
63
+ template: { data: { title: 'Product', seo: { description: 'From the template' } } },
64
+ entry: { data: { title: 'Mug', variants: [], seo: own } },
65
+ });
66
+ expect(input.options.entry).toEqual(own);
67
+ expect(input.options.template).toEqual({ description: 'From the template' });
68
+ // A record with none leaves the template's alone.
69
+ expect(
70
+ seoInput({ ...base, catalog: { kind: 'collection', slug: 'mugs' }, entry: { data: {} } })
71
+ .options.entry
72
+ ).toBeNull();
73
+ });
74
+
53
75
  it('sets product.category from the resolved name and no product.brand, even from a record that has one', () => {
54
76
  const input = seoInput({
55
77
  ...base,
@@ -169,6 +169,21 @@ describe('withAnalytics', () => {
169
169
  });
170
170
  });
171
171
 
172
+ it('4662896652: reports a removal in the currency its price was in, though the cart moved meanwhile', async () => {
173
+ const { source, cart } = makeSource();
174
+ const track = vi.fn();
175
+ const wrapped = withAnalytics(source, track);
176
+ await cart.add({ productId: 'p1', variantId: 'v1', quantity: 2 });
177
+ cart.currency.value = 'ISK';
178
+ const removing = wrapped.cart.remove('line-1');
179
+ cart.currency.value = 'EUR';
180
+ await removing;
181
+ expect(track).toHaveBeenLastCalledWith(
182
+ 'remove_from_cart',
183
+ expect.objectContaining({ value: '25', currency: 'ISK' })
184
+ );
185
+ });
186
+
172
187
  it('tracks begin_checkout from the cart state when the shopper follows the link', async () => {
173
188
  const { source, cart } = makeSource();
174
189
  const track = vi.fn();
@@ -172,13 +172,14 @@ describe('createCartStore', () => {
172
172
  },
173
173
  add: async (input) => {
174
174
  addInputs.push(input);
175
- return { lines: [a, c], totals: totalsFor([a, b, c]) };
175
+ return { lines: [a, c, b], totals: totalsFor([a, b, c]) };
176
176
  },
177
177
  })
178
178
  );
179
179
  await settle();
180
180
  await store.remove('b');
181
181
  await store.undoRemove();
182
+ // The server's answer, with the restored line put back where it was.
182
183
  expect(store.lines.value).toEqual([a, b, c]);
183
184
  expect(store.lastRemoved.value).toBeNull();
184
185
  // The re-add is the removed line's own pair — a line id is not something `ops.add` can take.
@@ -374,9 +375,8 @@ describe('createCartStore', () => {
374
375
  await store.undoRemove();
375
376
 
376
377
  expect(store.lastFailure.value?.errorId).toBe('CART_INSUFFICIENT_STOCK');
377
- // The line is still back on screen — the restore is local and deliberate (see `undoRemove`),
378
- // which is exactly why a shopper has to be told the shop could not take it back.
379
- expect(store.lines.value).toEqual([a]);
378
+ // The cart shows what the shop holds: the line it could not take back stays out.
379
+ expect(store.lines.value).toEqual([]);
380
380
  });
381
381
 
382
382
  it('records the failure of an applyDiscount that threw, and still answers an ack', async () => {