@shopware/composables 1.12.0 → 1.13.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.
- package/README.md +50 -10
- package/dist/index.d.mts +47 -16
- package/dist/index.d.ts +47 -16
- package/dist/index.mjs +104 -45
- package/nuxt.config.ts +10 -0
- package/package.json +10 -10
- package/src/cms/useCmsElementConfig.ts +3 -7
- package/src/cms/useCmsElementImage.test.ts +139 -0
- package/src/cms/useCmsElementImage.ts +19 -1
- package/src/types/cmsElementTypes.ts +6 -2
- package/src/useB2bQuoteManagement/useB2bQuoteManagement.test.ts +61 -1
- package/src/useB2bQuoteManagement/useB2bQuoteManagement.ts +121 -14
- package/src/useBreadcrumbs/useBreadcrumbs.ts +1 -1
- package/src/useCart/useCart.test.ts +17 -0
- package/src/useCart/useCart.ts +5 -3
- package/src/useCartItem/useCartItem.test.ts +13 -0
- package/src/useCartItem/useCartItem.ts +14 -7
- package/src/useCategorySearch/useCategorySearch.test.ts +75 -2
- package/src/useCategorySearch/useCategorySearch.ts +30 -16
- package/src/useCountries/useCountries.test.ts +78 -7
- package/src/useCountries/useCountries.ts +9 -5
- package/src/useListing/useListing.ts +3 -1
- package/src/useProductReviews/useProductReviews.test.ts +41 -2
- package/src/useProductReviews/useProductReviews.ts +17 -8
- package/src/useProductSearch/useProductSearch.ts +1 -1
- package/src/useSessionContext/useSessionContext.test.ts +66 -6
- package/src/useSessionContext/useSessionContext.ts +7 -2
- package/src/useUser/useUser.test.ts +20 -0
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { pascalCase } from 'scule';
|
|
2
2
|
import { computed, effectScope, reactive, markRaw, inject, ref, provide, unref, onMounted, watch, resolveComponent } from 'vue';
|
|
3
|
-
import { urlIsAbsolute, relativeUrlSlash, getSrcSetForMedia,
|
|
3
|
+
import { urlIsAbsolute, relativeUrlSlash, getSrcSetForMedia, getTranslatedProperty, getMainImageUrl, getListingFilters, isTechnicalPath, normalizePath, getRouteFromPathInfo, getProductTierPrices, buildUrlPrefix } from '@shopware/helpers';
|
|
4
4
|
import { ApiClientError } from '@shopware/api-client';
|
|
5
5
|
import { createSharedComposable, injectLocal, provideLocal, createInjectionState, syncRefs } from '@vueuse/core';
|
|
6
6
|
import { encodeForQuery } from '@shopware/api-client/helpers';
|
|
@@ -30,9 +30,13 @@ function useCmsElementImage(element) {
|
|
|
30
30
|
}
|
|
31
31
|
return attr;
|
|
32
32
|
});
|
|
33
|
+
const ariaLabel = computed(
|
|
34
|
+
() => element.data?.ariaLabel || getConfigValue("ariaLabel") || ""
|
|
35
|
+
);
|
|
36
|
+
const isDecorative = computed(() => !!getConfigValue("isDecorative"));
|
|
33
37
|
const imageAttrs = computed(() => ({
|
|
34
38
|
src: element.data?.media?.url,
|
|
35
|
-
alt: element.data?.media
|
|
39
|
+
alt: isDecorative.value ? "" : getTranslatedProperty(element.data?.media, "alt"),
|
|
36
40
|
srcset: getSrcSetForMedia(element.data?.media)
|
|
37
41
|
}));
|
|
38
42
|
const displayMode = computed(
|
|
@@ -50,6 +54,8 @@ function useCmsElementImage(element) {
|
|
|
50
54
|
imageAttrs,
|
|
51
55
|
imageContainerAttrs,
|
|
52
56
|
imageLink,
|
|
57
|
+
ariaLabel,
|
|
58
|
+
isDecorative,
|
|
53
59
|
displayMode,
|
|
54
60
|
isVideoElement,
|
|
55
61
|
mimeType
|
|
@@ -357,7 +363,7 @@ function useCartFunction() {
|
|
|
357
363
|
});
|
|
358
364
|
const count = computed(() => {
|
|
359
365
|
return cartItems.value.reduce(
|
|
360
|
-
(accumulator, lineItem) => lineItem.good === true ? lineItem.quantity + accumulator : accumulator,
|
|
366
|
+
(accumulator, lineItem) => lineItem.good === true ? (lineItem.quantity ?? 0) + accumulator : accumulator,
|
|
361
367
|
0
|
|
362
368
|
);
|
|
363
369
|
});
|
|
@@ -378,7 +384,7 @@ function useCartFunction() {
|
|
|
378
384
|
return cartPrice || 0;
|
|
379
385
|
});
|
|
380
386
|
const isVirtualCart = computed(() => {
|
|
381
|
-
return cartItems.value.length > 0 && cartItems.value.filter((element) => element.type !== "promotion").every((item) => item.states
|
|
387
|
+
return cartItems.value.length > 0 && cartItems.value.filter((element) => element.type !== "promotion").every((item) => item.states?.includes("is-download") ?? false);
|
|
382
388
|
});
|
|
383
389
|
const setCartErrors = (cart2) => {
|
|
384
390
|
if (Object.keys(cart2.errors || {}).length) {
|
|
@@ -430,11 +436,12 @@ function useCartItem(cartItem) {
|
|
|
430
436
|
() => cartItem.value?.price?.listPrice?.price && cartItem.value?.price?.unitPrice
|
|
431
437
|
);
|
|
432
438
|
const itemTotalPrice = computed(() => cartItem.value.price?.totalPrice);
|
|
433
|
-
const itemOptions = computed(
|
|
434
|
-
|
|
435
|
-
|
|
439
|
+
const itemOptions = computed(() => {
|
|
440
|
+
const payload = cartItem.value.payload;
|
|
441
|
+
return cartItem.value.type === "product" ? payload?.options ?? [] : [];
|
|
442
|
+
});
|
|
436
443
|
const itemStock = computed(
|
|
437
|
-
() => cartItem.value.deliveryInformation
|
|
444
|
+
() => cartItem.value.deliveryInformation?.stock
|
|
438
445
|
);
|
|
439
446
|
const isDigital = computed(
|
|
440
447
|
() => !!cartItem.value.states?.includes("is-download")
|
|
@@ -527,21 +534,29 @@ function useCategorySearch() {
|
|
|
527
534
|
const { apiClient, cacheableReads } = useShopwareContext();
|
|
528
535
|
async function search(categoryId, options) {
|
|
529
536
|
const associations = options?.withCmsAssociations ? cmsAssociations : {};
|
|
530
|
-
const
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
537
|
+
const criteria = {
|
|
538
|
+
associations,
|
|
539
|
+
...options?.query
|
|
540
|
+
};
|
|
541
|
+
const result = cacheableReads ? await apiClient.invoke("readCategoryGet get /category/{navigationId}", {
|
|
542
|
+
pathParams: {
|
|
543
|
+
navigationId: categoryId
|
|
544
|
+
},
|
|
545
|
+
headers: {
|
|
546
|
+
"sw-include-seo-urls": true
|
|
547
|
+
},
|
|
548
|
+
query: {
|
|
549
|
+
_criteria: encodeForQuery(criteria)
|
|
543
550
|
}
|
|
544
|
-
)
|
|
551
|
+
}) : await apiClient.invoke("readCategory post /category/{navigationId}", {
|
|
552
|
+
pathParams: {
|
|
553
|
+
navigationId: categoryId
|
|
554
|
+
},
|
|
555
|
+
headers: {
|
|
556
|
+
"sw-include-seo-urls": true
|
|
557
|
+
},
|
|
558
|
+
body: criteria
|
|
559
|
+
});
|
|
545
560
|
return result.data;
|
|
546
561
|
}
|
|
547
562
|
async function advancedSearch(options) {
|
|
@@ -702,20 +717,21 @@ function useContext(injectionName, params) {
|
|
|
702
717
|
return _context;
|
|
703
718
|
}
|
|
704
719
|
|
|
705
|
-
function useCountries() {
|
|
720
|
+
function useCountries(criteria) {
|
|
706
721
|
const { apiClient, cacheableReads } = useShopwareContext();
|
|
707
722
|
const _sharedCountries = inject("swCountries", ref());
|
|
708
723
|
provide("swCountries", _sharedCountries);
|
|
724
|
+
const searchCriteria = ref(criteria ?? {});
|
|
709
725
|
async function fetchCountries() {
|
|
710
|
-
const
|
|
726
|
+
const queryCriteria = defu(searchCriteria.value, {
|
|
711
727
|
associations: {
|
|
712
728
|
states: {}
|
|
713
729
|
}
|
|
714
|
-
};
|
|
730
|
+
});
|
|
715
731
|
const result = cacheableReads ? await apiClient.invoke("readCountryGet get /country", {
|
|
716
|
-
query: { _criteria: encodeForQuery(
|
|
732
|
+
query: { _criteria: encodeForQuery(queryCriteria) }
|
|
717
733
|
}) : await apiClient.invoke("readCountry post /country", {
|
|
718
|
-
body:
|
|
734
|
+
body: queryCriteria
|
|
719
735
|
});
|
|
720
736
|
_sharedCountries.value = result.data.elements;
|
|
721
737
|
return result.data;
|
|
@@ -1935,10 +1951,16 @@ function useProductPrice(product) {
|
|
|
1935
1951
|
}
|
|
1936
1952
|
|
|
1937
1953
|
function useProductReviews(product) {
|
|
1938
|
-
const { apiClient } = useShopwareContext();
|
|
1954
|
+
const { apiClient, cacheableReads } = useShopwareContext();
|
|
1939
1955
|
const productReviews = ref([]);
|
|
1940
1956
|
const loadProductReviews = async (parameters = {}) => {
|
|
1941
|
-
const fetchedReviews = await apiClient.invoke(
|
|
1957
|
+
const fetchedReviews = cacheableReads ? await apiClient.invoke(
|
|
1958
|
+
"readProductReviewsGet get /product/{productId}/reviews",
|
|
1959
|
+
{
|
|
1960
|
+
pathParams: { productId: product.value.id },
|
|
1961
|
+
query: { _criteria: encodeForQuery(parameters) }
|
|
1962
|
+
}
|
|
1963
|
+
) : await apiClient.invoke(
|
|
1942
1964
|
"readProductReviews post /product/{productId}/reviews",
|
|
1943
1965
|
{
|
|
1944
1966
|
pathParams: { productId: product.value.id },
|
|
@@ -2092,6 +2114,7 @@ function useSessionContext(newContext) {
|
|
|
2092
2114
|
_sessionContext.value = data;
|
|
2093
2115
|
} catch (e) {
|
|
2094
2116
|
console.error("[UseSessionContext][refreshSessionContext]", e);
|
|
2117
|
+
throw e;
|
|
2095
2118
|
}
|
|
2096
2119
|
};
|
|
2097
2120
|
const selectedShippingMethod = computed(
|
|
@@ -2171,7 +2194,7 @@ function useSessionContext(newContext) {
|
|
|
2171
2194
|
shippingAddressId: address.id
|
|
2172
2195
|
}
|
|
2173
2196
|
});
|
|
2174
|
-
refreshSessionContext();
|
|
2197
|
+
await refreshSessionContext();
|
|
2175
2198
|
};
|
|
2176
2199
|
const activeBillingAddress = computed(
|
|
2177
2200
|
() => sessionContext.value?.customer?.activeBillingAddress || null
|
|
@@ -2187,7 +2210,7 @@ function useSessionContext(newContext) {
|
|
|
2187
2210
|
billingAddressId: address.id
|
|
2188
2211
|
}
|
|
2189
2212
|
});
|
|
2190
|
-
refreshSessionContext();
|
|
2213
|
+
await refreshSessionContext();
|
|
2191
2214
|
};
|
|
2192
2215
|
const setContext = (context) => {
|
|
2193
2216
|
_sessionContext.value = context;
|
|
@@ -2588,31 +2611,64 @@ function useB2bQuoteManagement() {
|
|
|
2588
2611
|
return response.data.elements ?? [];
|
|
2589
2612
|
};
|
|
2590
2613
|
const getQuote = async (quoteId) => {
|
|
2614
|
+
const response = await apiClient.invoke("readQuote post /quote/{id}", {
|
|
2615
|
+
pathParams: {
|
|
2616
|
+
id: quoteId
|
|
2617
|
+
},
|
|
2618
|
+
body: {
|
|
2619
|
+
associations: {
|
|
2620
|
+
lineItems: {},
|
|
2621
|
+
comments: {},
|
|
2622
|
+
stateMachineState: {}
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
});
|
|
2626
|
+
return response.data;
|
|
2627
|
+
};
|
|
2628
|
+
async function createDraftQuoteVersion(quoteId) {
|
|
2591
2629
|
const response = await apiClient.invoke(
|
|
2592
|
-
"
|
|
2630
|
+
"createDraftQuoteVersion post /quote/{id}/draft-version",
|
|
2593
2631
|
{
|
|
2594
2632
|
pathParams: {
|
|
2595
2633
|
id: quoteId
|
|
2596
|
-
},
|
|
2597
|
-
body: {
|
|
2598
|
-
associations: {
|
|
2599
|
-
lineItems: {},
|
|
2600
|
-
comments: {},
|
|
2601
|
-
stateMachineState: {}
|
|
2602
|
-
}
|
|
2603
2634
|
}
|
|
2604
2635
|
}
|
|
2605
2636
|
);
|
|
2606
|
-
|
|
2607
|
-
|
|
2637
|
+
if (!response.data.versionId) {
|
|
2638
|
+
throw new Error(
|
|
2639
|
+
`Could not create a draft version for quote "${quoteId}": the API returned no versionId.`
|
|
2640
|
+
);
|
|
2641
|
+
}
|
|
2642
|
+
return response.data.versionId;
|
|
2643
|
+
}
|
|
2644
|
+
async function deleteDraftQuoteVersion(quoteId, versionId) {
|
|
2645
|
+
await apiClient.invoke(
|
|
2646
|
+
"deleteDraftQuoteVersion delete /quote/{id}/draft-version",
|
|
2647
|
+
{
|
|
2648
|
+
pathParams: {
|
|
2649
|
+
id: quoteId
|
|
2650
|
+
},
|
|
2651
|
+
body: { versionId }
|
|
2652
|
+
}
|
|
2653
|
+
);
|
|
2654
|
+
}
|
|
2608
2655
|
async function declineQuote(quoteId, comment) {
|
|
2609
2656
|
await apiClient.invoke("declineQuote post /quote/{id}/decline", {
|
|
2610
2657
|
pathParams: {
|
|
2611
2658
|
id: quoteId
|
|
2612
2659
|
},
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2660
|
+
// The 6.7.12 schema marks `lineItemId` and `versionId` as required, so a
|
|
2661
|
+
// comment-only body no longer matches the generated type. Sent as-is to
|
|
2662
|
+
// keep the pre-6.7.12 behaviour of this deprecated method unchanged.
|
|
2663
|
+
body: { comment }
|
|
2664
|
+
});
|
|
2665
|
+
}
|
|
2666
|
+
async function declineQuoteWithComment(quoteId, params) {
|
|
2667
|
+
await apiClient.invoke("declineQuote post /quote/{id}/decline", {
|
|
2668
|
+
pathParams: {
|
|
2669
|
+
id: quoteId
|
|
2670
|
+
},
|
|
2671
|
+
body: params
|
|
2616
2672
|
});
|
|
2617
2673
|
}
|
|
2618
2674
|
async function requestChangeQuote(quoteId, comment) {
|
|
@@ -2654,7 +2710,7 @@ function useB2bQuoteManagement() {
|
|
|
2654
2710
|
}
|
|
2655
2711
|
const createOrderFromQuote = async (quoteId, comment) => {
|
|
2656
2712
|
const response = await apiClient.invoke(
|
|
2657
|
-
"createOrderFromQuote post /quote/
|
|
2713
|
+
"createOrderFromQuote post /quote/{id}/order",
|
|
2658
2714
|
{
|
|
2659
2715
|
pathParams: { id: quoteId },
|
|
2660
2716
|
body: { customerComment: comment }
|
|
@@ -2666,6 +2722,9 @@ function useB2bQuoteManagement() {
|
|
|
2666
2722
|
getQuoteList,
|
|
2667
2723
|
getQuote,
|
|
2668
2724
|
declineQuote,
|
|
2725
|
+
declineQuoteWithComment,
|
|
2726
|
+
createDraftQuoteVersion,
|
|
2727
|
+
deleteDraftQuoteVersion,
|
|
2669
2728
|
requestChangeQuote,
|
|
2670
2729
|
changeShippingMethod,
|
|
2671
2730
|
changePaymentMethod,
|
package/nuxt.config.ts
CHANGED
|
@@ -8,6 +8,16 @@ export default defineNuxtConfig({
|
|
|
8
8
|
build: {
|
|
9
9
|
transpile: ["@shopware/composables"],
|
|
10
10
|
},
|
|
11
|
+
vite: {
|
|
12
|
+
build: {
|
|
13
|
+
rolldownOptions: {
|
|
14
|
+
checks: {
|
|
15
|
+
invalidAnnotation: false,
|
|
16
|
+
pluginTimings: false,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
11
21
|
telemetry: {
|
|
12
22
|
enabled: false,
|
|
13
23
|
},
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopware/composables",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "Shopware Frontends composables for Vue",
|
|
5
5
|
"author": "Shopware",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/shopware/frontends.git"
|
|
9
9
|
},
|
|
10
|
-
"homepage": "https://
|
|
10
|
+
"homepage": "https://developer.shopware.com/frontends/packages/composables.html",
|
|
11
11
|
"keywords": [
|
|
12
12
|
"shopware",
|
|
13
13
|
"vue",
|
|
@@ -52,22 +52,22 @@
|
|
|
52
52
|
"app.config.ts"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@vueuse/core": "14.
|
|
55
|
+
"@vueuse/core": "14.4.0",
|
|
56
56
|
"defu": "6.1.7",
|
|
57
57
|
"scule": "1.3.0",
|
|
58
|
-
"@shopware/helpers": "1.
|
|
59
|
-
"@shopware/api-client": "1.
|
|
58
|
+
"@shopware/helpers": "1.8.0",
|
|
59
|
+
"@shopware/api-client": "1.6.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@nuxt/kit": "4.
|
|
62
|
+
"@nuxt/kit": "4.5.2",
|
|
63
63
|
"@typescript/native-preview": "7.0.0-dev.20260205.1",
|
|
64
|
-
"@vitest/coverage-v8": "4.1.
|
|
64
|
+
"@vitest/coverage-v8": "4.1.10",
|
|
65
65
|
"@vue/test-utils": "2.4.11",
|
|
66
|
-
"happy-dom": "20.
|
|
66
|
+
"happy-dom": "20.11.1",
|
|
67
67
|
"typescript": "5.9.3",
|
|
68
68
|
"unbuild": "3.6.1",
|
|
69
|
-
"vitest": "4.1.
|
|
70
|
-
"vue": "3.5.
|
|
69
|
+
"vitest": "4.1.10",
|
|
70
|
+
"vue": "3.5.42",
|
|
71
71
|
"tsconfig": "0.0.0"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
@@ -9,18 +9,14 @@ import type { ElementConfig } from "../types";
|
|
|
9
9
|
*/
|
|
10
10
|
export function useCmsElementConfig<
|
|
11
11
|
T extends Omit<Schemas["CmsSlot"], "config"> & {
|
|
12
|
-
config:
|
|
13
|
-
[key in infer X extends keyof T["config"]]: ElementConfig<unknown>;
|
|
14
|
-
}
|
|
15
|
-
? { [key in X]: ElementConfig<T["config"][key]["value"]> }
|
|
16
|
-
: never;
|
|
12
|
+
config: Record<string, ElementConfig<unknown> | undefined>;
|
|
17
13
|
},
|
|
18
14
|
>(element: T) {
|
|
19
15
|
const getConfigValue = <ELEMENT_CONFIG extends keyof T["config"]>(
|
|
20
16
|
key: ELEMENT_CONFIG,
|
|
21
|
-
):
|
|
17
|
+
): NonNullable<T["config"][ELEMENT_CONFIG]>["value"] => {
|
|
22
18
|
if (!element?.config) {
|
|
23
|
-
return undefined as
|
|
19
|
+
return undefined as NonNullable<T["config"][ELEMENT_CONFIG]>["value"];
|
|
24
20
|
}
|
|
25
21
|
return (
|
|
26
22
|
element.config[key]?.source !== "mapped" && element.config[key]?.value
|
|
@@ -155,6 +155,145 @@ describe("useCmsElementImage", () => {
|
|
|
155
155
|
});
|
|
156
156
|
});
|
|
157
157
|
|
|
158
|
+
it("should prefer the translated media alt over the root alt", () => {
|
|
159
|
+
const { imageAttrs } = useCmsElementImage({
|
|
160
|
+
data: {
|
|
161
|
+
media: {
|
|
162
|
+
url: "https://shopware.com/logo.png",
|
|
163
|
+
alt: "Company logo",
|
|
164
|
+
translated: {
|
|
165
|
+
alt: "Firmenlogo",
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
} as unknown as CmsElementManufacturerLogo);
|
|
170
|
+
|
|
171
|
+
expect(imageAttrs.value.alt).toBe("Firmenlogo");
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("should fall back to the root media alt when translated is missing", () => {
|
|
175
|
+
const { imageAttrs } = useCmsElementImage({
|
|
176
|
+
data: {
|
|
177
|
+
media: {
|
|
178
|
+
url: "https://shopware.com/logo.png",
|
|
179
|
+
alt: "Company logo",
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
} as unknown as CmsElementManufacturerLogo);
|
|
183
|
+
|
|
184
|
+
expect(imageAttrs.value.alt).toBe("Company logo");
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("should fall back to the root media alt when the translated alt is empty", () => {
|
|
188
|
+
const { imageAttrs } = useCmsElementImage({
|
|
189
|
+
data: {
|
|
190
|
+
media: {
|
|
191
|
+
url: "https://shopware.com/logo.png",
|
|
192
|
+
alt: "Company logo",
|
|
193
|
+
translated: {
|
|
194
|
+
alt: "",
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
} as unknown as CmsElementManufacturerLogo);
|
|
199
|
+
|
|
200
|
+
expect(imageAttrs.value.alt).toBe("Company logo");
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("should return an empty alt when the media has no alt at all", () => {
|
|
204
|
+
const { imageAttrs } = useCmsElementImage({
|
|
205
|
+
data: {
|
|
206
|
+
media: {
|
|
207
|
+
url: "https://shopware.com/logo.png",
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
} as unknown as CmsElementManufacturerLogo);
|
|
211
|
+
|
|
212
|
+
expect(imageAttrs.value.alt).toBe("");
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("should keep the alt empty when media has none, the aria label names the link", () => {
|
|
216
|
+
const { imageAttrs, ariaLabel } = useCmsElementImage({
|
|
217
|
+
data: {
|
|
218
|
+
ariaLabel: "Go to the summer collection",
|
|
219
|
+
media: {
|
|
220
|
+
url: "https://shopware.com/banner.png",
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
} as unknown as CmsElementImage);
|
|
224
|
+
|
|
225
|
+
expect(ariaLabel.value).toBe("Go to the summer collection");
|
|
226
|
+
expect(imageAttrs.value.alt).toBe("");
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("should read the aria label from config when data has none", () => {
|
|
230
|
+
const { ariaLabel } = useCmsElementImage({
|
|
231
|
+
config: {
|
|
232
|
+
ariaLabel: {
|
|
233
|
+
value: "Go to the sale",
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
} as unknown as CmsElementImage);
|
|
237
|
+
|
|
238
|
+
expect(ariaLabel.value).toBe("Go to the sale");
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("should return an empty aria label when neither data nor config has one", () => {
|
|
242
|
+
const { ariaLabel } = useCmsElementImage({
|
|
243
|
+
data: {},
|
|
244
|
+
config: {},
|
|
245
|
+
} as unknown as CmsElementImage);
|
|
246
|
+
|
|
247
|
+
expect(ariaLabel.value).toBe("");
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("should drop alternative text when the image is decorative but keep the aria label", () => {
|
|
251
|
+
const { imageAttrs, isDecorative, ariaLabel } = useCmsElementImage({
|
|
252
|
+
data: {
|
|
253
|
+
ariaLabel: "Go to the sale",
|
|
254
|
+
media: {
|
|
255
|
+
url: "https://shopware.com/pattern.png",
|
|
256
|
+
alt: "ignored",
|
|
257
|
+
translated: {
|
|
258
|
+
alt: "ignoriert",
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
config: {
|
|
263
|
+
isDecorative: {
|
|
264
|
+
value: true,
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
} as unknown as CmsElementImage);
|
|
268
|
+
|
|
269
|
+
expect(isDecorative.value).toBe(true);
|
|
270
|
+
expect(imageAttrs.value.alt).toBe("");
|
|
271
|
+
// a decorative image inside a link still needs the link named
|
|
272
|
+
expect(ariaLabel.value).toBe("Go to the sale");
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("should keep the media alt when an aria label is also set", () => {
|
|
276
|
+
const { imageAttrs } = useCmsElementImage({
|
|
277
|
+
data: {
|
|
278
|
+
ariaLabel: "Go to the sale",
|
|
279
|
+
media: {
|
|
280
|
+
url: "https://shopware.com/banner.png",
|
|
281
|
+
alt: "Two mugs on a table",
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
} as unknown as CmsElementImage);
|
|
285
|
+
|
|
286
|
+
expect(imageAttrs.value.alt).toBe("Two mugs on a table");
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("should not be decorative by default", () => {
|
|
290
|
+
const { isDecorative } = useCmsElementImage({
|
|
291
|
+
config: {},
|
|
292
|
+
} as unknown as CmsElementImage);
|
|
293
|
+
|
|
294
|
+
expect(isDecorative.value).toBe(false);
|
|
295
|
+
});
|
|
296
|
+
|
|
158
297
|
it("should return displayMode", () => {
|
|
159
298
|
const { displayMode } = useCmsElementImage({
|
|
160
299
|
config: {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getSrcSetForMedia,
|
|
3
|
+
getTranslatedProperty,
|
|
3
4
|
relativeUrlSlash,
|
|
4
5
|
urlIsAbsolute,
|
|
5
6
|
} from "@shopware/helpers";
|
|
@@ -31,6 +32,8 @@ export type UseCmsElementImage = {
|
|
|
31
32
|
imageAttrs: ComputedRef<ImgHTMLAttributes>;
|
|
32
33
|
imageContainerAttrs: ComputedRef<ImageContainerAttrs>;
|
|
33
34
|
imageLink: ComputedRef<{ newTab: boolean; url: string }>;
|
|
35
|
+
ariaLabel: ComputedRef<string>;
|
|
36
|
+
isDecorative: ComputedRef<boolean>;
|
|
34
37
|
displayMode: ComputedRef<DisplayMode>;
|
|
35
38
|
isVideoElement: ComputedRef<boolean>;
|
|
36
39
|
mimeType: ComputedRef<string | undefined>;
|
|
@@ -74,9 +77,22 @@ export function useCmsElementImage(
|
|
|
74
77
|
return attr;
|
|
75
78
|
});
|
|
76
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Names the link the image sits in, not the image itself. Shopware exposes
|
|
82
|
+
* it on both `data` and `config`.
|
|
83
|
+
*/
|
|
84
|
+
const ariaLabel = computed(
|
|
85
|
+
() => element.data?.ariaLabel || getConfigValue("ariaLabel") || "",
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
// Config only, the element data carries no such field.
|
|
89
|
+
const isDecorative = computed(() => !!getConfigValue("isDecorative"));
|
|
90
|
+
|
|
77
91
|
const imageAttrs: ComputedRef<ImgHTMLAttributes> = computed(() => ({
|
|
78
92
|
src: element.data?.media?.url,
|
|
79
|
-
alt:
|
|
93
|
+
alt: isDecorative.value
|
|
94
|
+
? ""
|
|
95
|
+
: getTranslatedProperty(element.data?.media, "alt"),
|
|
80
96
|
srcset: getSrcSetForMedia(element.data?.media),
|
|
81
97
|
}));
|
|
82
98
|
|
|
@@ -98,6 +114,8 @@ export function useCmsElementImage(
|
|
|
98
114
|
imageAttrs,
|
|
99
115
|
imageContainerAttrs,
|
|
100
116
|
imageLink,
|
|
117
|
+
ariaLabel,
|
|
118
|
+
isDecorative,
|
|
101
119
|
displayMode,
|
|
102
120
|
isVideoElement,
|
|
103
121
|
mimeType,
|
|
@@ -62,9 +62,11 @@ type ImageElementConfig = {
|
|
|
62
62
|
media: ElementConfig<string>;
|
|
63
63
|
newTab: ElementConfig<boolean>;
|
|
64
64
|
product: ElementConfig<string>;
|
|
65
|
+
ariaLabel?: ElementConfig<string | null>;
|
|
65
66
|
boxLayout: ElementConfig<BoxLayout>;
|
|
66
67
|
displayMode: ElementConfig<DisplayMode>;
|
|
67
68
|
minHeight: ElementConfig<string | number>;
|
|
69
|
+
isDecorative?: ElementConfig<boolean>;
|
|
68
70
|
verticalAlign: ElementConfig<VerticalAlign>;
|
|
69
71
|
horizontalAlign: ElementConfig<VerticalAlign>;
|
|
70
72
|
};
|
|
@@ -76,6 +78,7 @@ export type CmsElementImage = Omit<Schemas["CmsSlot"], "config"> & {
|
|
|
76
78
|
mediaId: string;
|
|
77
79
|
url: string;
|
|
78
80
|
newTab: boolean;
|
|
81
|
+
ariaLabel?: string | null;
|
|
79
82
|
apiAlias: "cms_image";
|
|
80
83
|
media: Schemas["Media"];
|
|
81
84
|
};
|
|
@@ -87,8 +90,8 @@ export type SliderElementConfig = {
|
|
|
87
90
|
minHeight: ElementConfig<string | number>;
|
|
88
91
|
verticalAlign?: ElementConfig<VerticalAlign>;
|
|
89
92
|
displayMode?: ElementConfig<"standard" | "cover" | "contain">;
|
|
90
|
-
navigationDots?: ElementConfig<"outside" | "inside" | "">;
|
|
91
|
-
navigationArrows?: ElementConfig<"outside" | "inside" | "">;
|
|
93
|
+
navigationDots?: ElementConfig<"outside" | "inside" | "none" | "">;
|
|
94
|
+
navigationArrows?: ElementConfig<"outside" | "inside" | "none" | "">;
|
|
92
95
|
};
|
|
93
96
|
|
|
94
97
|
type ImageSliderElementConfig = ImageElementConfig &
|
|
@@ -391,6 +394,7 @@ export type CmsElementManufacturerLogo = Omit<Schemas["CmsSlot"], "config"> & {
|
|
|
391
394
|
mediaId: string;
|
|
392
395
|
url: string;
|
|
393
396
|
newTab: boolean;
|
|
397
|
+
ariaLabel?: string | null;
|
|
394
398
|
apiAlias: "cms_manufacturer_logo";
|
|
395
399
|
media: Schemas["Media"];
|
|
396
400
|
};
|
|
@@ -49,7 +49,45 @@ describe("useB2bQuoteManagement", () => {
|
|
|
49
49
|
);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
it("
|
|
52
|
+
it("createDraftQuoteVersion", async () => {
|
|
53
|
+
const { vm, injections } = useSetup(() => useB2bQuoteManagement());
|
|
54
|
+
injections.apiClient.invoke.mockResolvedValue({
|
|
55
|
+
data: { versionId: "test-version-id" },
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(await vm.createDraftQuoteVersion("test-12")).toBe("test-version-id");
|
|
59
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
60
|
+
expect.stringContaining("createDraftQuoteVersion"),
|
|
61
|
+
expect.objectContaining({
|
|
62
|
+
pathParams: { id: "test-12" },
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("createDraftQuoteVersion - no versionId in response", async () => {
|
|
68
|
+
const { vm, injections } = useSetup(() => useB2bQuoteManagement());
|
|
69
|
+
injections.apiClient.invoke.mockResolvedValue({ data: {} });
|
|
70
|
+
|
|
71
|
+
await expect(vm.createDraftQuoteVersion("test-12")).rejects.toThrow(
|
|
72
|
+
/no versionId/,
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("deleteDraftQuoteVersion", async () => {
|
|
77
|
+
const { vm, injections } = useSetup(() => useB2bQuoteManagement());
|
|
78
|
+
injections.apiClient.invoke.mockResolvedValue({ data: null });
|
|
79
|
+
await vm.deleteDraftQuoteVersion("test-12", "test-version-id");
|
|
80
|
+
|
|
81
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
82
|
+
expect.stringContaining("deleteDraftQuoteVersion"),
|
|
83
|
+
expect.objectContaining({
|
|
84
|
+
pathParams: { id: "test-12" },
|
|
85
|
+
body: { versionId: "test-version-id" },
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("declineQuote - deprecated, comment only", async () => {
|
|
53
91
|
const { vm, injections } = useSetup(() => useB2bQuoteManagement());
|
|
54
92
|
injections.apiClient.invoke.mockResolvedValue({ data: null });
|
|
55
93
|
await vm.declineQuote("test-12", "test-comment");
|
|
@@ -63,6 +101,28 @@ describe("useB2bQuoteManagement", () => {
|
|
|
63
101
|
);
|
|
64
102
|
});
|
|
65
103
|
|
|
104
|
+
it("declineQuoteWithComment", async () => {
|
|
105
|
+
const { vm, injections } = useSetup(() => useB2bQuoteManagement());
|
|
106
|
+
injections.apiClient.invoke.mockResolvedValue({ data: null });
|
|
107
|
+
await vm.declineQuoteWithComment("test-12", {
|
|
108
|
+
comment: "test-comment",
|
|
109
|
+
lineItemId: "test-line-item-id",
|
|
110
|
+
versionId: "test-version-id",
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
expect(injections.apiClient.invoke).toHaveBeenCalledWith(
|
|
114
|
+
expect.stringContaining("declineQuote"),
|
|
115
|
+
expect.objectContaining({
|
|
116
|
+
pathParams: { id: "test-12" },
|
|
117
|
+
body: {
|
|
118
|
+
comment: "test-comment",
|
|
119
|
+
lineItemId: "test-line-item-id",
|
|
120
|
+
versionId: "test-version-id",
|
|
121
|
+
},
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
66
126
|
it("requestChangeQuote", async () => {
|
|
67
127
|
const { vm, injections } = useSetup(() => useB2bQuoteManagement());
|
|
68
128
|
injections.apiClient.invoke.mockResolvedValue({ data: null });
|