@eldrajs/theme-cli 0.2.9 → 0.2.11
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.
- package/CHANGELOG.md +12 -1
- package/package.json +3 -3
- package/template/.eldra/block-types.d.ts +4 -6
- package/template/.eldra/manifest.json +228 -246
- package/template/.eldra/previews.json +35 -35
- package/template/.storybook/eldra.ts +7 -2
- package/template/app/assets/main.css +5 -0
- package/template/app/composables/useBlockData.ts +9 -2
- package/template/app/composables/usePriceTokens.ts +150 -0
- package/template/app/composables/useQuickAdd.ts +95 -0
- package/template/app/composables/useRegionalFormat.ts +94 -0
- package/template/app/icons.ts +4 -0
- package/template/app/plugins/eldra-storefront.ts +2 -0
- package/template/app/plugins/eldra-ui-messages.ts +22 -8
- package/template/app/storefront/demo.ts +188 -16
- package/template/app/storefront/gateway.ts +19 -0
- package/template/app/storefront/productCardLook.ts +76 -0
- package/template/app/storefront/productReference.ts +17 -0
- package/template/app/storefront/toProductCard.ts +12 -8
- package/template/app/storefront/types.ts +17 -0
- package/template/blocks/announcement-bar/__tests__/Block.spec.ts +19 -7
- package/template/blocks/announcement-bar/block.json +2 -1
- package/template/blocks/announcement-bar/mock.json +1 -1
- package/template/blocks/announcement-bar/preview.png +0 -0
- package/template/blocks/article/Block.vue +8 -18
- package/template/blocks/article/block.json +3 -1
- package/template/blocks/article/preview.png +0 -0
- package/template/blocks/article-list/block.json +10 -1
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/Block.vue +15 -3
- package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +13 -0
- package/template/blocks/breadcrumbs/block.json +1 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/Block.vue +15 -5
- package/template/blocks/cart/__tests__/Block.spec.ts +53 -10
- package/template/blocks/cart/__tests__/ShippingBar.spec.ts +10 -8
- package/template/blocks/cart/block.json +8 -5
- package/template/blocks/cart/mock.json +2 -2
- package/template/blocks/cart/parts/ShippingBar.vue +24 -30
- package/template/blocks/cart/parts/notSold.ts +4 -3
- package/template/blocks/collection-grid/Block.vue +168 -85
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +101 -23
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/Block.vue +51 -17
- package/template/blocks/collection-header/__tests__/Block.spec.ts +80 -4
- package/template/blocks/collection-header/block.json +2 -0
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/contact/block.json +4 -0
- package/template/blocks/contact/preview.png +0 -0
- package/template/blocks/cta/block.json +2 -0
- package/template/blocks/faq/Block.vue +5 -10
- package/template/blocks/faq/block.json +2 -1
- package/template/blocks/faq/mock.json +12 -1
- package/template/blocks/faq/preview.png +0 -0
- package/template/blocks/feature-grid/__tests__/Block.spec.ts +30 -7
- package/template/blocks/feature-grid/block.json +3 -2
- package/template/blocks/feature-grid/mock.json +1 -1
- package/template/blocks/feature-grid/preview.png +0 -0
- package/template/blocks/footer/Block.vue +64 -21
- package/template/blocks/footer/__tests__/Block.spec.ts +97 -1
- package/template/blocks/footer/block.json +5 -2
- package/template/blocks/footer/mock.json +1 -1
- package/template/blocks/footer/preview.png +0 -0
- package/template/blocks/form/block.json +1 -0
- package/template/blocks/gallery/preview.png +0 -0
- package/template/blocks/hero/Block.vue +38 -9
- package/template/blocks/hero/__tests__/Block.spec.ts +71 -19
- package/template/blocks/hero/block.json +16 -22
- package/template/blocks/hero/preview.json +1 -3
- package/template/blocks/hero/preview.png +0 -0
- package/template/blocks/image/block.json +2 -1
- package/template/blocks/image/preview.png +0 -0
- package/template/blocks/logo-cloud/block.json +1 -0
- package/template/blocks/logo-cloud/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +405 -159
- package/template/blocks/navigation/__tests__/Block.spec.ts +816 -172
- package/template/blocks/navigation/__tests__/currentItem.spec.ts +90 -0
- package/template/blocks/navigation/block.json +2 -11
- package/template/blocks/navigation/mock.json +3 -3
- package/template/blocks/navigation/parts/LocalePicker.vue +103 -0
- package/template/blocks/navigation/parts/currentItem.ts +82 -0
- package/template/blocks/navigation/preview.json +7 -1
- package/template/blocks/navigation/preview.png +0 -0
- package/template/blocks/newsletter/Block.vue +6 -2
- package/template/blocks/newsletter/block.json +2 -0
- package/template/blocks/newsletter/preview.png +0 -0
- package/template/blocks/order-status/Block.vue +8 -17
- package/template/blocks/order-status/block.json +3 -0
- package/template/blocks/order-status/preview.png +0 -0
- package/template/blocks/pricing-table/__tests__/Block.spec.ts +12 -4
- package/template/blocks/pricing-table/block.json +2 -0
- package/template/blocks/pricing-table/mock.json +6 -6
- package/template/blocks/pricing-table/preview.png +0 -0
- package/template/blocks/product-carousel/Block.vue +36 -126
- package/template/blocks/product-carousel/__tests__/Block.spec.ts +88 -0
- package/template/blocks/product-carousel/block.json +1 -0
- package/template/blocks/product-carousel/preview.png +0 -0
- package/template/blocks/product-detail/Block.vue +84 -31
- package/template/blocks/product-detail/__tests__/Block.spec.ts +86 -0
- package/template/blocks/product-detail/__tests__/specs.spec.ts +79 -0
- package/template/blocks/product-detail/block.json +3 -1
- package/template/blocks/product-detail/mock.json +54 -4
- package/template/blocks/product-detail/parts/Gallery.vue +8 -2
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/product-detail/specs.ts +75 -0
- package/template/blocks/quote/block.json +1 -0
- package/template/blocks/rich-text/preview.png +0 -0
- package/template/blocks/search/Block.vue +6 -1
- package/template/blocks/search/TypeSection.vue +8 -1
- package/template/blocks/search/__tests__/Block.spec.ts +24 -1
- package/template/blocks/search/block.json +1 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/split-content/Block.vue +12 -5
- package/template/blocks/split-content/__tests__/Block.spec.ts +13 -0
- package/template/blocks/split-content/block.json +4 -2
- package/template/blocks/split-content/preview.png +0 -0
- package/template/blocks/stats/preview.png +0 -0
- package/template/blocks/tabs/Block.vue +3 -4
- package/template/blocks/tabs/block.json +1 -1
- package/template/blocks/tabs/preview.png +0 -0
- package/template/blocks/team/block.json +3 -1
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/testimonials/block.json +2 -0
- package/template/blocks/testimonials/preview.png +0 -0
- package/template/blocks/timeline/block.json +2 -1
- package/template/blocks/timeline/preview.png +0 -0
- package/template/blocks/trust-strip/Block.vue +2 -2
- package/template/blocks/trust-strip/__tests__/Block.spec.ts +38 -9
- package/template/blocks/trust-strip/block.json +1 -1
- package/template/blocks/trust-strip/mock.json +1 -1
- package/template/blocks/trust-strip/preview.json +1 -1
- package/template/blocks/trust-strip/preview.png +0 -0
- package/template/blocks/video-embed/block.json +2 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/blocks/wishlist/Block.vue +2 -2
- package/template/blocks/wishlist/preview.png +0 -0
- package/template/i18n/en-US.json +13 -5
- package/template/i18n/is-IS.json +12 -4
- package/template/pages/article.page.json +1 -3
- package/template/pages/cart.page.json +1 -3
- package/template/pages/category.page.json +2 -4
- package/template/pages/collection.page.json +1 -3
- package/template/pages/home.page.json +7 -18
- package/template/pages/product.page.json +62 -131
- package/template/pages/products.page.json +1 -3
- package/template/pages/search.page.json +1 -3
- package/template/pages/wishlist.page.json +1 -3
- package/template/stories/generated/footer.stories.ts +6 -0
- package/template/stories/generated/navigation.stories.ts +0 -18
- package/template/test/inlineEditable.spec.ts +10 -2
- package/template/test/localePrefix.spec.ts +2 -19
- package/template/test/pages/article.spec.ts +0 -2
- package/template/test/pages/category.spec.ts +35 -13
- package/template/test/pages/home.spec.ts +33 -17
- package/template/test/pages/product.spec.ts +64 -44
- package/template/test/pages/ssr.spec.ts +3 -1
- package/template/test/prerenderRefresh.browser.spec.ts +30 -25
- package/template/test/previewParity.browser.spec.ts +36 -2
- package/template/test/priceTokens.spec.ts +309 -0
- package/template/test/regionalFormat.spec.ts +80 -0
- package/template/test/starter.spec.ts +23 -7
- package/template/test/storefront/demo.spec.ts +19 -18
- package/template/test/storefront/toProductCard.spec.ts +17 -2
- package/template/test/structuredData.generate.spec.ts +4 -2
- package/template/test/support/mockGateway.ts +21 -1
- package/template/test/support/mountBlock.ts +25 -4
- package/template/test/support/priceTokens.ts +20 -0
- package/template/test/uiMessagesPlugin.spec.ts +34 -1
- package/template/tokens.json +8 -8
|
@@ -4,6 +4,7 @@ import { beforeEach, describe, expect, it } from 'vitest';
|
|
|
4
4
|
import { ELDRA_KEY, type EldraContext } from '@eldrajs/theme-vue';
|
|
5
5
|
import { axe } from '../../../test/support/axe';
|
|
6
6
|
import { mountOptions } from '../../../test/support/mountBlock';
|
|
7
|
+
import { shown } from '../../../test/support/priceTokens';
|
|
7
8
|
import Block from '../Block.vue';
|
|
8
9
|
import mock from '../mock.json';
|
|
9
10
|
|
|
@@ -32,7 +33,7 @@ describe('announcement-bar block', () => {
|
|
|
32
33
|
it('renders the mock content (merged data — this block has no preview.json)', async () => {
|
|
33
34
|
const wrapper = mountAnnouncement({ ...mock });
|
|
34
35
|
await flushPromises();
|
|
35
|
-
expect(wrapper.text()).toContain(mock.message);
|
|
36
|
+
expect(wrapper.text()).toContain(shown(mock.message));
|
|
36
37
|
// `linkHref` ships empty in the seed (no dead demo link) — `linkLabel` only renders inside
|
|
37
38
|
// the link itself (see the "shows only the message with no link" test below), so it is not
|
|
38
39
|
// expected in the bare-mock text either.
|
|
@@ -60,7 +61,7 @@ describe('announcement-bar block', () => {
|
|
|
60
61
|
it('renders the bare mock.json content and passes axe', async () => {
|
|
61
62
|
const wrapper = mountAnnouncement(mock);
|
|
62
63
|
await flushPromises();
|
|
63
|
-
expect(wrapper.text()).toContain(mock.message);
|
|
64
|
+
expect(wrapper.text()).toContain(shown(mock.message));
|
|
64
65
|
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
65
66
|
});
|
|
66
67
|
|
|
@@ -69,7 +70,7 @@ describe('announcement-bar block', () => {
|
|
|
69
70
|
async (variant) => {
|
|
70
71
|
const wrapper = mountAnnouncement({ ...mock, variant });
|
|
71
72
|
await flushPromises();
|
|
72
|
-
expect(wrapper.text()).toContain(mock.message);
|
|
73
|
+
expect(wrapper.text()).toContain(shown(mock.message));
|
|
73
74
|
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
74
75
|
}
|
|
75
76
|
);
|
|
@@ -104,7 +105,11 @@ describe('announcement-bar block', () => {
|
|
|
104
105
|
// behaviour (Enter/Space -> click) still runs — the same contract check
|
|
105
106
|
// `packages/ui/src/components/button/__tests__/button.spec.ts` uses for every button.
|
|
106
107
|
for (const key of ['Enter', ' ']) {
|
|
107
|
-
const event = new KeyboardEvent('keydown', {
|
|
108
|
+
const event = new KeyboardEvent('keydown', {
|
|
109
|
+
key,
|
|
110
|
+
bubbles: true,
|
|
111
|
+
cancelable: true,
|
|
112
|
+
});
|
|
108
113
|
button.dispatchEvent(event);
|
|
109
114
|
expect(event.defaultPrevented).toBe(false);
|
|
110
115
|
}
|
|
@@ -155,7 +160,10 @@ describe('announcement-bar block', () => {
|
|
|
155
160
|
expect(second.find('section').exists()).toBe(false);
|
|
156
161
|
second.unmount();
|
|
157
162
|
|
|
158
|
-
const changed = mountAnnouncement({
|
|
163
|
+
const changed = mountAnnouncement({
|
|
164
|
+
...mock,
|
|
165
|
+
message: 'A brand new announcement',
|
|
166
|
+
});
|
|
159
167
|
await flushPromises();
|
|
160
168
|
expect(changed.find('section').exists()).toBe(true);
|
|
161
169
|
expect(changed.text()).toContain('A brand new announcement');
|
|
@@ -176,7 +184,11 @@ describe('announcement-bar block', () => {
|
|
|
176
184
|
});
|
|
177
185
|
|
|
178
186
|
it('shows only the link with no dismiss button when not dismissable', async () => {
|
|
179
|
-
const wrapper = mountAnnouncement({
|
|
187
|
+
const wrapper = mountAnnouncement({
|
|
188
|
+
...mock,
|
|
189
|
+
dismissable: false,
|
|
190
|
+
linkHref: '/pages/shipping',
|
|
191
|
+
});
|
|
180
192
|
await flushPromises();
|
|
181
193
|
expect(wrapper.find('button').exists()).toBe(false);
|
|
182
194
|
const focusable = wrapper.element.querySelectorAll('a[href], button');
|
|
@@ -222,6 +234,6 @@ describe('announcement-bar block', () => {
|
|
|
222
234
|
const editingWrapper = mountAnnouncement(mock, { editing: true });
|
|
223
235
|
await flushPromises();
|
|
224
236
|
expect(editingWrapper.find('section').exists()).toBe(true);
|
|
225
|
-
expect(editingWrapper.text()).toContain(mock.message);
|
|
237
|
+
expect(editingWrapper.text()).toContain(shown(mock.message));
|
|
226
238
|
});
|
|
227
239
|
});
|
|
Binary file
|
|
@@ -33,9 +33,10 @@
|
|
|
33
33
|
* `mock.json`'s body doc; this block does not compensate for either.
|
|
34
34
|
*/
|
|
35
35
|
import { computed, ref } from 'vue';
|
|
36
|
-
import { Avatar, Container, EditorPlaceholder, Link, Section
|
|
37
|
-
import { DEFAULT_IMAGE_FRAMING, EldraRichText
|
|
36
|
+
import { Avatar, Container, EditorPlaceholder, Link, Section } from '@eldrajs/ui';
|
|
37
|
+
import { DEFAULT_IMAGE_FRAMING, EldraRichText } from '@eldrajs/theme-vue';
|
|
38
38
|
import { useBlockData } from '../../app/composables/useBlockData';
|
|
39
|
+
import { useFormatDate } from '../../app/composables/useRegionalFormat';
|
|
39
40
|
import { useEditing } from '../../app/composables/useEditing';
|
|
40
41
|
import { useRichTextScrollRegions } from '../../app/composables/useRichTextScrollRegions';
|
|
41
42
|
import { useI18n } from 'vue-i18n';
|
|
@@ -50,18 +51,9 @@ const editing = useEditing();
|
|
|
50
51
|
const { t } = useI18n();
|
|
51
52
|
const titleId = `article-title-${useUiId()}`;
|
|
52
53
|
|
|
53
|
-
/**
|
|
54
|
-
*
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
return useEldra();
|
|
58
|
-
} catch {
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
/** The content locale `formatDate` renders the date in — the same source `useT()` reads for its
|
|
63
|
-
* own locale lookup, exposed here because `formatDate` needs the raw string, not a translation. */
|
|
64
|
-
const locale = computed(() => tryUseEldra()?.preview.locale ?? 'en-US');
|
|
54
|
+
/** `@eldrajs/ui`'s `formatDate` in the organisation's regional format and time zone — not the
|
|
55
|
+
* content locale: an Icelandic store's English page still prints an Icelandic date. */
|
|
56
|
+
const formatRegionalDate = useFormatDate();
|
|
65
57
|
|
|
66
58
|
const title = computed(() => (data.value.title ?? '').trim());
|
|
67
59
|
const hasTitle = computed(() => title.value !== '');
|
|
@@ -81,12 +73,10 @@ const categoryLinkAs = computed(() =>
|
|
|
81
73
|
* style; the long form asks for `month: 'long'` — see the module doc comment for how the two
|
|
82
74
|
* are toggled. */
|
|
83
75
|
const formattedDateShort = computed(() =>
|
|
84
|
-
data.value.publishedAt ?
|
|
76
|
+
data.value.publishedAt ? formatRegionalDate(data.value.publishedAt) : null
|
|
85
77
|
);
|
|
86
78
|
const formattedDateLong = computed(() =>
|
|
87
|
-
data.value.publishedAt
|
|
88
|
-
? formatDate(data.value.publishedAt, locale.value, { month: 'long' })
|
|
89
|
-
: null
|
|
79
|
+
data.value.publishedAt ? formatRegionalDate(data.value.publishedAt, { month: 'long' }) : null
|
|
90
80
|
);
|
|
91
81
|
const hasDate = computed(() => formattedDateShort.value !== null);
|
|
92
82
|
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"fieldId": "categoryHref",
|
|
34
34
|
"name": "Category link",
|
|
35
35
|
"type": "string",
|
|
36
|
+
"allowPrices": false,
|
|
36
37
|
"helpText": "URL of the filtered Article list."
|
|
37
38
|
},
|
|
38
39
|
{
|
|
@@ -126,7 +127,8 @@
|
|
|
126
127
|
{
|
|
127
128
|
"fieldId": "authorLinkHref",
|
|
128
129
|
"name": "Author link",
|
|
129
|
-
"type": "string"
|
|
130
|
+
"type": "string",
|
|
131
|
+
"allowPrices": false
|
|
130
132
|
},
|
|
131
133
|
{
|
|
132
134
|
"fieldId": "showByline",
|
|
Binary file
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"fieldId": "viewAllHref",
|
|
34
34
|
"name": "View all URL",
|
|
35
35
|
"type": "string",
|
|
36
|
+
"allowPrices": false,
|
|
36
37
|
"helpText": "The journal index."
|
|
37
38
|
},
|
|
38
39
|
{
|
|
@@ -47,6 +48,7 @@
|
|
|
47
48
|
"fieldId": "categoryHref",
|
|
48
49
|
"name": "Category URL",
|
|
49
50
|
"type": "string",
|
|
51
|
+
"allowPrices": false,
|
|
50
52
|
"helpText": "Used when source is category. Also matched against each chip to mark the active one."
|
|
51
53
|
},
|
|
52
54
|
{
|
|
@@ -73,6 +75,7 @@
|
|
|
73
75
|
"fieldId": "href",
|
|
74
76
|
"name": "Link URL",
|
|
75
77
|
"type": "string",
|
|
78
|
+
"allowPrices": false,
|
|
76
79
|
"validators": { "required": true }
|
|
77
80
|
},
|
|
78
81
|
{
|
|
@@ -81,7 +84,12 @@
|
|
|
81
84
|
"type": "string",
|
|
82
85
|
"localized": true
|
|
83
86
|
},
|
|
84
|
-
{
|
|
87
|
+
{
|
|
88
|
+
"fieldId": "categoryHref",
|
|
89
|
+
"name": "Category URL",
|
|
90
|
+
"type": "string",
|
|
91
|
+
"allowPrices": false
|
|
92
|
+
},
|
|
85
93
|
{
|
|
86
94
|
"fieldId": "publishedAt",
|
|
87
95
|
"name": "Published at",
|
|
@@ -143,6 +151,7 @@
|
|
|
143
151
|
"fieldId": "href",
|
|
144
152
|
"name": "Link URL",
|
|
145
153
|
"type": "string",
|
|
154
|
+
"allowPrices": false,
|
|
146
155
|
"validators": { "required": true }
|
|
147
156
|
}
|
|
148
157
|
]
|
|
Binary file
|
|
@@ -223,8 +223,20 @@ const linkAs = computed(() =>
|
|
|
223
223
|
* width, matching the spec's "the breadcrumb responds to its own width" rule). Below that width
|
|
224
224
|
* the trail keeps the primitive's own default wrapping behaviour, per the spec's "may wrap to a
|
|
225
225
|
* second line" note for narrow widths.
|
|
226
|
+
*
|
|
227
|
+
* The rest is the Northwind trail (design `.nw-crumbs`): a "/" between crumbs in the
|
|
228
|
+
* `border-strong` tone, 0.5rem either side of it, underlined muted links, and the current title in
|
|
229
|
+
* the same muted, regular weight as the links rather than the primitive's emphasised one. All through `classes`, the
|
|
230
|
+
* primitive's own extension point: the separator span keeps its 1.5rem frame and `aria-hidden`, its
|
|
231
|
+
* chevron is hidden and a `::before` "/" drawn in its place (CSS-generated, so never read out —
|
|
232
|
+
* the same silence the hidden chevron had). The margins add up to the design's gaps: the list's own
|
|
233
|
+
* 0.25rem column gap plus `ms-1` before the slash, the item's 0.5rem gap after it.
|
|
226
234
|
*/
|
|
227
|
-
const
|
|
235
|
+
const trailClasses = {
|
|
236
|
+
separator: "ms-1 me-0 text-border-strong [&>svg]:hidden before:content-['/']",
|
|
237
|
+
link: 'decoration-current',
|
|
238
|
+
current: 'text-muted font-normal @content:truncate @content:max-w-[40ch]',
|
|
239
|
+
};
|
|
228
240
|
|
|
229
241
|
/**
|
|
230
242
|
* 40ch CSS truncation only ever *visually* clips text — the full string stays in the DOM and in
|
|
@@ -258,14 +270,14 @@ watchEffect(() => {
|
|
|
258
270
|
|
|
259
271
|
<template>
|
|
260
272
|
<div v-if="hasTrail" class="bg-background text-text @container">
|
|
261
|
-
<Container :width="containerWidth" class="
|
|
273
|
+
<Container :width="containerWidth" class="pt-5">
|
|
262
274
|
<div ref="breadcrumbRoot" class="contents">
|
|
263
275
|
<Breadcrumb
|
|
264
276
|
:items="items"
|
|
265
277
|
:collapse-after="1"
|
|
266
278
|
:keep-last="2"
|
|
267
279
|
:link-as="linkAs"
|
|
268
|
-
:classes="
|
|
280
|
+
:classes="trailClasses"
|
|
269
281
|
:structured-data="false"
|
|
270
282
|
/>
|
|
271
283
|
</div>
|
|
@@ -131,6 +131,19 @@ describe('breadcrumbs block', () => {
|
|
|
131
131
|
expect(nav.get('ol').exists()).toBe(true);
|
|
132
132
|
});
|
|
133
133
|
|
|
134
|
+
/** The Northwind trail (design `.nw-crumbs`): a "/" drawn by CSS between crumbs, in place of the
|
|
135
|
+
* primitive's chevron, still inside the `aria-hidden` separator so it is never read out. */
|
|
136
|
+
it('separates the crumbs with a CSS "/" in place of the chevron, hidden from assistive tech', () => {
|
|
137
|
+
const wrapper = mountBlock(mock);
|
|
138
|
+
const separators = wrapper.findAll('[data-part="separator"]');
|
|
139
|
+
expect(separators.length).toBeGreaterThan(0);
|
|
140
|
+
for (const separator of separators) {
|
|
141
|
+
expect(separator.attributes('aria-hidden')).toBe('true');
|
|
142
|
+
expect(separator.classes()).toContain("before:content-['/']");
|
|
143
|
+
expect(separator.classes()).toContain('[&>svg]:hidden');
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
134
147
|
it('marks the current page as a span[aria-current=page], never a link', () => {
|
|
135
148
|
const wrapper = mountBlock(mock);
|
|
136
149
|
const current = wrapper.get('[data-part="current"]');
|
|
Binary file
|
|
@@ -66,6 +66,7 @@ import {
|
|
|
66
66
|
Section,
|
|
67
67
|
} from '@eldrajs/ui';
|
|
68
68
|
import { useBlockData } from '../../app/composables/useBlockData';
|
|
69
|
+
import { storeAmountIn, useStoreAmounts } from '../../app/composables/usePriceTokens';
|
|
69
70
|
import { useEditing } from '../../app/composables/useEditing';
|
|
70
71
|
import { iconComponent } from '../../app/composables/iconComponent';
|
|
71
72
|
import { useStorefront } from '../../app/composables/useStorefront';
|
|
@@ -100,9 +101,6 @@ const storefront = useStorefront();
|
|
|
100
101
|
const cart = storefront.cart;
|
|
101
102
|
// Every price under the cart is in the cart's own currency, which can differ from the store's.
|
|
102
103
|
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
104
|
const hasNotSold = computed(() => cart.notSold.value.length > 0);
|
|
107
105
|
|
|
108
106
|
const uid = useUiId();
|
|
@@ -172,9 +170,21 @@ const hasContinueLink = computed(() => emptyLinkHref.value !== null);
|
|
|
172
170
|
|
|
173
171
|
const showDiscountField = computed(() => data.value.showDiscountField ?? true);
|
|
174
172
|
const showPaymentIcons = computed(() => data.value.showPaymentIcons ?? true);
|
|
175
|
-
|
|
173
|
+
const storeAmounts = useStoreAmounts();
|
|
174
|
+
/**
|
|
175
|
+
* The store's own free-shipping threshold in the cart's currency — the lowest among its delivery
|
|
176
|
+
* methods there, the same amount a `⟦store freeShippingThreshold⟧` sentence writes — so the bar and
|
|
177
|
+
* the copy can never disagree, and a cart in another currency gets that currency's threshold, never
|
|
178
|
+
* a converted one. None in that currency, or the bar switched off: no bar.
|
|
179
|
+
*/
|
|
176
180
|
const threshold = computed(() =>
|
|
177
|
-
|
|
181
|
+
(data.value.showShippingBar ?? true)
|
|
182
|
+
? storeAmountIn(
|
|
183
|
+
storeAmounts,
|
|
184
|
+
'freeShippingThreshold',
|
|
185
|
+
cart.currency.value ?? money.currency.value
|
|
186
|
+
)
|
|
187
|
+
: null
|
|
178
188
|
);
|
|
179
189
|
|
|
180
190
|
/** The theme's own cart page path — the same one `blocks/navigation/Block.vue` sends the bag to
|
|
@@ -7,15 +7,17 @@ import { axe } from '../../../test/support/axe';
|
|
|
7
7
|
import Block from '../Block.vue';
|
|
8
8
|
import mock from '../mock.json';
|
|
9
9
|
import { mountOptions } from '../../../test/support/mountBlock';
|
|
10
|
+
import { shown } from '../../../test/support/priceTokens';
|
|
10
11
|
import { EldraHttpError } from '@eldrajs/sdk';
|
|
12
|
+
import type { StoreAmounts } from '@eldrajs/sdk/tokens';
|
|
11
13
|
import { createDemoStorefront, DEMO_CART_LINES } from '../../../app/storefront/demo';
|
|
12
14
|
import { createCartStore, type CartSnapshot } from '../../../app/storefront/cart';
|
|
13
15
|
import { STOREFRONT_KEY, type StorefrontSource } from '../../../app/storefront/types';
|
|
14
16
|
import type { StorefrontCartLine } from '../../../app/storefront/types';
|
|
15
17
|
|
|
16
18
|
/** Only `variant` is required at the schema level — the "genuinely minimal" fixture every rebuilt
|
|
17
|
-
* block spec covers alongside the full `mock.json`.
|
|
18
|
-
*
|
|
19
|
+
* block spec covers alongside the full `mock.json`. The shipping bar follows the store's own
|
|
20
|
+
* threshold (on by default), and with no empty copy the empty state falls back to its own heading. */
|
|
19
21
|
const bare = { variant: 'drawer' as const };
|
|
20
22
|
|
|
21
23
|
/**
|
|
@@ -71,6 +73,8 @@ async function mountCart(
|
|
|
71
73
|
refuseMutations?: unknown;
|
|
72
74
|
/** Refuse only the re-add behind Undo, so the removal itself still succeeds. */
|
|
73
75
|
refuseOnly?: 'add';
|
|
76
|
+
/** The store's own amounts (free-shipping threshold per currency); the demo store's by default. */
|
|
77
|
+
storeAmounts?: StoreAmounts | null;
|
|
74
78
|
} = {}
|
|
75
79
|
): Promise<{ wrapper: VueWrapper; storefront: StorefrontSource }> {
|
|
76
80
|
const lines = options.cartLines ?? DEMO_CART_LINES;
|
|
@@ -78,7 +82,10 @@ async function mountCart(
|
|
|
78
82
|
options.refuseMutations === undefined
|
|
79
83
|
? createDemoStorefront({ cartLines: lines })
|
|
80
84
|
: refusingStorefront(lines, options.refuseMutations, options.refuseOnly);
|
|
81
|
-
const base = mountOptions(
|
|
85
|
+
const base = mountOptions(
|
|
86
|
+
{ entry: { id: 'cart', data } },
|
|
87
|
+
options.storeAmounts === undefined ? {} : { storeAmounts: options.storeAmounts }
|
|
88
|
+
);
|
|
82
89
|
const wrapper = mount(Harness, {
|
|
83
90
|
props: { entry: { id: 'cart', data }, storefront },
|
|
84
91
|
attachTo: document.body,
|
|
@@ -88,7 +95,11 @@ async function mountCart(
|
|
|
88
95
|
// `transition-group-stub` element between the `<ul>` and its `<li>`s and break the list
|
|
89
96
|
// semantics axe checks — in a browser it renders a fragment and there is no wrapper at all.
|
|
90
97
|
// Rendering the real thing is both what the page does and what the axe gate has to see.
|
|
91
|
-
stubs: {
|
|
98
|
+
stubs: {
|
|
99
|
+
...base.global.stubs,
|
|
100
|
+
transition: false,
|
|
101
|
+
'transition-group': false,
|
|
102
|
+
},
|
|
92
103
|
provide: {
|
|
93
104
|
...base.global.provide,
|
|
94
105
|
[STOREFRONT_KEY]: storefront,
|
|
@@ -132,7 +143,13 @@ function refusingStorefront(
|
|
|
132
143
|
let held = lines.map((line) => ({ ...line }));
|
|
133
144
|
const snapshot = (): CartSnapshot => ({
|
|
134
145
|
lines: held.map((line) => ({ ...line })),
|
|
135
|
-
totals: {
|
|
146
|
+
totals: {
|
|
147
|
+
subtotal: 0,
|
|
148
|
+
discount: null,
|
|
149
|
+
shipping: null,
|
|
150
|
+
tax: null,
|
|
151
|
+
total: 0,
|
|
152
|
+
},
|
|
136
153
|
});
|
|
137
154
|
const refuse = async (): Promise<never> => {
|
|
138
155
|
throw thrown;
|
|
@@ -459,7 +476,9 @@ describe('cart block', () => {
|
|
|
459
476
|
});
|
|
460
477
|
|
|
461
478
|
it('moves focus to the empty-state heading when the last line goes', async () => {
|
|
462
|
-
const { wrapper } = await mountCart(mock, {
|
|
479
|
+
const { wrapper } = await mountCart(mock, {
|
|
480
|
+
cartLines: [DEMO_CART_LINES[0]!],
|
|
481
|
+
});
|
|
463
482
|
await openDrawer(wrapper);
|
|
464
483
|
|
|
465
484
|
await wrapper
|
|
@@ -482,15 +501,39 @@ describe('cart block', () => {
|
|
|
482
501
|
const status = wrapper
|
|
483
502
|
.findAll('[role="status"]')
|
|
484
503
|
.find((element) => element.text().includes('Free shipping'))!;
|
|
485
|
-
// $210.00 against the
|
|
504
|
+
// $210.00 against the demo store's own $80.00 threshold (`DEMO_STORE_AMOUNTS`).
|
|
486
505
|
expect(status.text()).toBe('Free shipping unlocked');
|
|
487
506
|
expect(status.attributes('aria-live')).toBeUndefined(); // role="status" is already polite
|
|
488
507
|
expect(wrapper.find('[aria-hidden="true"] > div').exists()).toBe(true);
|
|
489
508
|
expect(wrapper.find('[role="progressbar"]').exists()).toBe(false);
|
|
490
509
|
});
|
|
491
510
|
|
|
492
|
-
it(
|
|
493
|
-
|
|
511
|
+
it("measures against the store's own threshold in the cart's currency", async () => {
|
|
512
|
+
// The store's delivery methods say $250 in USD: $210.00 is $40.00 short.
|
|
513
|
+
const { wrapper } = await mountCart(
|
|
514
|
+
{ ...bare, variant: 'page' },
|
|
515
|
+
{ storeAmounts: { freeShippingThreshold: { USD: 25000, ISK: 15000 } } }
|
|
516
|
+
);
|
|
517
|
+
const status = wrapper
|
|
518
|
+
.findAll('[role="status"]')
|
|
519
|
+
.find((element) => element.text().includes('free shipping'))!;
|
|
520
|
+
expect(status.text()).toContain('$40.00');
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
it.each([
|
|
524
|
+
[
|
|
525
|
+
'the store has no threshold in the cart’s currency (never converted)',
|
|
526
|
+
{ freeShippingThreshold: { ISK: 15000 } },
|
|
527
|
+
],
|
|
528
|
+
['the store’s thresholds could not be read', null],
|
|
529
|
+
])('renders no bar at all when %s', async (_, storeAmounts) => {
|
|
530
|
+
const { wrapper } = await mountCart({ ...bare, variant: 'page' }, { storeAmounts });
|
|
531
|
+
expect(wrapper.text()).not.toContain('free shipping');
|
|
532
|
+
expect(wrapper.text()).not.toContain('Free shipping');
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
it('renders no bar when the merchant switches it off', async () => {
|
|
536
|
+
const { wrapper } = await mountCart({ ...bare, variant: 'page', showShippingBar: false });
|
|
494
537
|
expect(wrapper.text()).not.toContain('free shipping');
|
|
495
538
|
expect(wrapper.text()).not.toContain('Free shipping');
|
|
496
539
|
});
|
|
@@ -532,7 +575,7 @@ describe('cart block', () => {
|
|
|
532
575
|
expect(wrapper.get(`a[href="${mock.emptyLinkHref}"]`).text()).toContain('Continue shopping');
|
|
533
576
|
|
|
534
577
|
const empty = await mountCart({ ...mock, variant: 'page' }, { cartLines: [] });
|
|
535
|
-
expect(empty.wrapper.text()).toContain(mock.emptyText);
|
|
578
|
+
expect(empty.wrapper.text()).toContain(shown(mock.emptyText));
|
|
536
579
|
expect(empty.wrapper.findAll(`a[href="${mock.emptyLinkHref}"]`).length).toBe(2);
|
|
537
580
|
expect(empty.wrapper.find('aside').exists()).toBe(false);
|
|
538
581
|
});
|
|
@@ -12,7 +12,7 @@ afterEach(() => {
|
|
|
12
12
|
|
|
13
13
|
/** `mountOptions` supplies the same currency/locale/messages provides a real page does, which is
|
|
14
14
|
* what the `<Price>` inside the sentence reads. */
|
|
15
|
-
function mountBar(props: { threshold?:
|
|
15
|
+
function mountBar(props: { threshold?: number | null; subtotal: number; panel?: 'edge' | 'card' }) {
|
|
16
16
|
const base = mountOptions({ entry: { id: 'cart', data: {} } });
|
|
17
17
|
const wrapper = mount(ShippingBar, {
|
|
18
18
|
props,
|
|
@@ -29,16 +29,18 @@ function barWidth(wrapper: ReturnType<typeof mountBar>): string | undefined {
|
|
|
29
29
|
describe('cart shipping bar', () => {
|
|
30
30
|
it('says how much is left in words, with the amount as a formatted price', async () => {
|
|
31
31
|
// $80.00 threshold, $68.00 subtotal — the spec's own drawer example.
|
|
32
|
-
const wrapper = mountBar({ threshold:
|
|
32
|
+
const wrapper = mountBar({ threshold: 80, subtotal: 68 });
|
|
33
33
|
const status = wrapper.get('[role="status"]');
|
|
34
34
|
expect(status.text()).toContain("You're");
|
|
35
35
|
expect(status.text()).toContain('$12.00');
|
|
36
36
|
expect(status.text()).toContain('away from free shipping');
|
|
37
|
+
// The amount sits where the sentence puts it, not after it.
|
|
38
|
+
expect(status.text().replace(/\s+/g, ' ').trim()).toBe("You're $12.00 away from free shipping");
|
|
37
39
|
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
38
40
|
});
|
|
39
41
|
|
|
40
42
|
it('fills the bar to the share of the threshold already reached, and hides it from assistive tech', () => {
|
|
41
|
-
const wrapper = mountBar({ threshold:
|
|
43
|
+
const wrapper = mountBar({ threshold: 80, subtotal: 68 });
|
|
42
44
|
const track = wrapper.get('[aria-hidden="true"]');
|
|
43
45
|
expect(track.exists()).toBe(true);
|
|
44
46
|
expect(barWidth(wrapper)).toContain('width: 85%');
|
|
@@ -47,7 +49,7 @@ describe('cart shipping bar', () => {
|
|
|
47
49
|
});
|
|
48
50
|
|
|
49
51
|
it('switches to the unlocked message once the subtotal reaches the threshold', () => {
|
|
50
|
-
const wrapper = mountBar({ threshold:
|
|
52
|
+
const wrapper = mountBar({ threshold: 80, subtotal: 210 });
|
|
51
53
|
const status = wrapper.get('[role="status"]');
|
|
52
54
|
expect(status.text()).toBe('Free shipping unlocked');
|
|
53
55
|
expect(status.classes()).toContain('text-success');
|
|
@@ -55,12 +57,12 @@ describe('cart shipping bar', () => {
|
|
|
55
57
|
});
|
|
56
58
|
|
|
57
59
|
it('treats the threshold as reached exactly at the threshold', () => {
|
|
58
|
-
const wrapper = mountBar({ threshold:
|
|
60
|
+
const wrapper = mountBar({ threshold: 80, subtotal: 80 });
|
|
59
61
|
expect(wrapper.get('[role="status"]').text()).toBe('Free shipping unlocked');
|
|
60
62
|
});
|
|
61
63
|
|
|
62
64
|
it('renders nothing at all without a usable threshold', () => {
|
|
63
|
-
for (const threshold of [undefined,
|
|
65
|
+
for (const threshold of [undefined, null, 0, -10, Number.NaN]) {
|
|
64
66
|
const wrapper = mountBar({ threshold, subtotal: 68 });
|
|
65
67
|
expect(wrapper.find('[role="status"]').exists(), `threshold: ${String(threshold)}`).toBe(
|
|
66
68
|
false
|
|
@@ -70,9 +72,9 @@ describe('cart shipping bar', () => {
|
|
|
70
72
|
});
|
|
71
73
|
|
|
72
74
|
it('reads the threshold in the same major units the cart’s own amounts use', () => {
|
|
73
|
-
//
|
|
75
|
+
// 80 and a $68.00 subtotal are both major units, so the shopper is $12.00 short — the
|
|
74
76
|
// amount itself is a `<Price>`, which takes minor units, so it is converted on the way in.
|
|
75
|
-
const wrapper = mountBar({ threshold:
|
|
77
|
+
const wrapper = mountBar({ threshold: 80, subtotal: 68 });
|
|
76
78
|
expect(wrapper.get('[role="status"]').text()).toContain('$12.00');
|
|
77
79
|
});
|
|
78
80
|
});
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
"description": "The shopper's cart as a slide-in drawer or a full page: editable line items, a free-shipping progress note, discount codes, totals and checkout.",
|
|
5
5
|
"icon": "shopping-bag",
|
|
6
6
|
"category": "commerce",
|
|
7
|
-
"version":
|
|
7
|
+
"version": 2,
|
|
8
|
+
"migrations": [{ "version": 2, "renames": [] }],
|
|
8
9
|
"fields": [
|
|
9
10
|
{
|
|
10
11
|
"fieldId": "variant",
|
|
@@ -17,10 +18,11 @@
|
|
|
17
18
|
"validators": { "required": true }
|
|
18
19
|
},
|
|
19
20
|
{
|
|
20
|
-
"fieldId": "
|
|
21
|
-
"name": "
|
|
22
|
-
"type": "
|
|
23
|
-
"
|
|
21
|
+
"fieldId": "showShippingBar",
|
|
22
|
+
"name": "Show free-shipping progress",
|
|
23
|
+
"type": "bool",
|
|
24
|
+
"default": true,
|
|
25
|
+
"helpText": "How far the cart is from free shipping. The threshold is your delivery settings' own, in the shopper's currency; a currency with none shows no bar."
|
|
24
26
|
},
|
|
25
27
|
{
|
|
26
28
|
"fieldId": "showDiscountField",
|
|
@@ -68,6 +70,7 @@
|
|
|
68
70
|
"fieldId": "emptyLinkHref",
|
|
69
71
|
"name": "Empty link",
|
|
70
72
|
"type": "string",
|
|
73
|
+
"allowPrices": false,
|
|
71
74
|
"helpText": "Where the empty state's button goes, e.g. /collections/all."
|
|
72
75
|
}
|
|
73
76
|
]
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"variant": "drawer",
|
|
3
|
-
"
|
|
3
|
+
"showShippingBar": true,
|
|
4
4
|
"showDiscountField": true,
|
|
5
5
|
"showPaymentIcons": true,
|
|
6
6
|
"note": "Taxes and shipping calculated at checkout.",
|
|
7
7
|
"emptyTitle": "Your cart is empty",
|
|
8
|
-
"emptyText": "Winter knitwear is back in stock
|
|
8
|
+
"emptyText": "Winter knitwear is back in stock. Orders over ⟦store freeShippingThreshold⟧ ship free.",
|
|
9
9
|
"emptyLinkLabel": "Continue shopping",
|
|
10
10
|
"emptyLinkHref": "/collections/all"
|
|
11
11
|
}
|